| # 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 | |
| ``` | |