3d_model / docs /FILE_ORGANIZATION.md
Azan
Clean deployment build (Squashed)
7a87926
# File Organization
## Directory Structure
The YLFF package follows a clear organizational structure:
```
ylff/
β”œβ”€β”€ __init__.py # Package initialization with backward compatibility
β”œβ”€β”€ __main__.py # Entry point for `python -m ylff`
β”œβ”€β”€ app.py # Unified CLI/API entry point
β”œβ”€β”€ cli.py # CLI command definitions (Typer)
β”œβ”€β”€ api.py # Backward compatibility wrapper
β”œβ”€β”€ config.py # Configuration management (Pydantic Settings)
β”‚
β”œβ”€β”€ models/ # Pydantic API models
β”‚ β”œβ”€β”€ __init__.py
β”‚ └── api_models.py
β”‚
β”œβ”€β”€ routers/ # FastAPI route handlers
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ health.py
β”‚ β”œβ”€β”€ jobs.py
β”‚ β”œβ”€β”€ models.py
β”‚ β”œβ”€β”€ profiling.py
β”‚ β”œβ”€β”€ training.py
β”‚ β”œβ”€β”€ validation.py
β”‚ └── visualization.py
β”‚
β”œβ”€β”€ services/ # Business logic
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ arkit_processor.py
β”‚ β”œβ”€β”€ ba_validator.py
β”‚ β”œβ”€β”€ data_pipeline.py
β”‚ β”œβ”€β”€ evaluate.py
β”‚ β”œβ”€β”€ fine_tune.py
β”‚ └── pretrain.py
β”‚
└── utils/ # Utilities and helpers
β”œβ”€β”€ __init__.py
β”œβ”€β”€ api_middleware.py
β”œβ”€β”€ coordinate_utils.py
β”œβ”€β”€ exceptions.py # Custom exception classes
β”œβ”€β”€ job_manager.py
β”œβ”€β”€ losses.py # Loss functions for training
β”œβ”€β”€ model_loader.py # ML model loading utilities
β”œβ”€β”€ profiler.py
β”œβ”€β”€ visualization_gui.py
└── wandb_utils.py
```
## Organization Principles
### Root Level (`ylff/`)
Only core application files:
- **`app.py`**: Unified entry point (CLI/API)
- **`cli.py`**: CLI command definitions
- **`config.py`**: Configuration management
- **`api.py`**: Backward compatibility wrapper
- **`__init__.py`**: Package initialization
### `models/` - Pydantic API Models
- Request/response models for the API
- Data validation and serialization
- Example: `JobResponse`, `ValidateSequenceRequest`
### `routers/` - API Route Handlers
- FastAPI route definitions
- One router per domain (health, jobs, validation, etc.)
- Thin layer that delegates to services
### `services/` - Business Logic
- Core application logic
- Domain-specific functionality
- Examples: `BAValidator`, `ARKitProcessor`, `fine_tune_da3`
### `utils/` - Utilities and Helpers
- Reusable utilities across the codebase
- **`exceptions.py`**: Custom exception classes
- **`losses.py`**: Loss functions for training
- **`model_loader.py`**: ML model loading utilities
- **`profiler.py`**: Performance profiling
- **`coordinate_utils.py`**: Coordinate system conversions
- **`job_manager.py`**: Background job management
- **`visualization_gui.py`**: GUI utilities
- **`wandb_utils.py`**: Weights & Biases integration
## Import Patterns
### From Utils
```python
# Exceptions
from ylff.utils.exceptions import DataError, ModelLoadError
# Loss functions
from ylff.utils.losses import pose_loss, geodesic_rotation_loss
# Model loading
from ylff.utils.model_loader import load_da3_model, get_recommended_model
# Other utilities
from ylff.utils.profiler import Profiler
from ylff.utils.coordinate_utils import convert_arkit_to_opencv
```
### From Services
```python
from ylff.services.ba_validator import BAValidator
from ylff.services.arkit_processor import ARKitProcessor
from ylff.services.fine_tune import fine_tune_da3
```
### From Models
```python
from ylff.models import JobResponse, ValidateSequenceRequest
```
### From Routers
```python
from ylff.routers import health_router, validation_router
```
## Migration History
### Moved to `utils/`
- **`exceptions.py`** β†’ `utils/exceptions.py` (was at root)
- **`losses.py`** β†’ `utils/losses.py` (was at root)
- **`model_loader.py`** β†’ `utils/model_loader.py` (was at root, renamed from `models.py`)
### Rationale
- All three files are utilities used across multiple modules
- Keeps the root `ylff/` directory clean and focused
- Makes it clear these are reusable utilities, not core application logic
- Follows the principle: "If it's used by multiple services, it's a utility"
## Backward Compatibility
The `ylff/__init__.py` provides backward compatibility imports:
```python
# Still works (via __getattr__)
from ylff import BAValidator, Profiler, load_da3_model
```
But preferred imports are:
```python
from ylff.utils.model_loader import load_da3_model
from ylff.utils.losses import pose_loss
from ylff.utils.exceptions import DataError
```