6.4 KiB
6.4 KiB
Web Directory Refactoring - Current Status
✅ Completed Steps
1. Directory Structure Created
src/web/
├── api/
│ ├── v1/
│ │ ├── admin/ (documents.py, annotations.py, training.py)
│ │ ├── async_api/ (routes.py)
│ │ ├── batch/ (routes.py)
│ │ └── routes.py (public inference API)
├── schemas/
│ ├── admin.py (admin schemas)
│ ├── inference.py (inference + async schemas)
│ └── common.py (ErrorResponse)
├── services/
│ ├── autolabel.py
│ ├── async_processing.py
│ ├── batch_upload.py
│ └── inference.py
├── core/
│ ├── auth.py
│ ├── rate_limiter.py
│ └── scheduler.py
└── workers/
├── async_queue.py
└── batch_queue.py
2. Files Copied and Imports Updated
Admin API (✅ Complete)
admin_routes.py→api/v1/admin/documents.py(imports updated)admin_annotation_routes.py→api/v1/admin/annotations.py(imports updated)admin_training_routes.py→api/v1/admin/training.py(imports updated)api/v1/admin/__init__.pycreated with exports
Public & Async API (✅ Complete)
routes.py→api/v1/routes.py(imports updated)async_routes.py→api/v1/async_api/routes.py(imports updated)batch_upload_routes.py→api/v1/batch/routes.py(copied, imports pending)
Schemas (✅ Complete)
admin_schemas.py→schemas/admin.pyschemas.py→schemas/inference.pyschemas/common.pycreatedschemas/__init__.pycreated with exports
Services (✅ Complete)
admin_autolabel.py→services/autolabel.pyasync_service.py→services/async_processing.pybatch_upload_service.py→services/batch_upload.pyservices.py→services/inference.pyservices/__init__.pycreated
Core Components (✅ Complete)
admin_auth.py→core/auth.pyrate_limiter.py→core/rate_limiter.pyadmin_scheduler.py→core/scheduler.pycore/__init__.pycreated
Workers (✅ Complete)
async_queue.py→workers/async_queue.pybatch_queue.py→workers/batch_queue.pyworkers/__init__.pycreated
Main App (✅ Complete)
app.pyimports updated to use new structure
⏳ Remaining Work
1. Update Remaining File Imports (HIGH PRIORITY)
Files that need import updates:
api/v1/batch/routes.py- update to use new schema/service importsservices/autolabel.py- may need import updates if it references old pathsservices/async_processing.py- check for old import referencesservices/batch_upload.py- check for old import referencesservices/inference.py- check for old import references
2. Update ALL Test Files (CRITICAL)
Test files need to import from new locations. Pattern:
Old:
from src.web.admin_routes import create_admin_router
from src.web.admin_schemas import DocumentItem
from src.web.admin_auth import validate_admin_token
New:
from src.web.api.v1.admin import create_admin_router
from src.web.schemas.admin import DocumentItem
from src.web.core.auth import validate_admin_token
Test files to update:
tests/web/test_admin_annotations.pytests/web/test_admin_auth.pytests/web/test_admin_routes.pytests/web/test_admin_routes_enhanced.pytests/web/test_admin_training.pytests/web/test_annotation_locks.pytests/web/test_annotation_phase5.pytests/web/test_async_queue.pytests/web/test_async_routes.pytests/web/test_async_service.pytests/web/test_autolabel_with_locks.pytests/web/test_batch_queue.pytests/web/test_batch_upload_routes.pytests/web/test_batch_upload_service.pytests/web/test_rate_limiter.pytests/web/test_training_phase4.py
3. Create Backward Compatibility Layer (OPTIONAL)
Keep old imports working temporarily:
# src/web/admin_routes.py (temporary compatibility shim)
\"\"\"
DEPRECATED: Use src.web.api.v1.admin.documents instead.
This file will be removed in next version.
\"\"\"
import warnings
from src.web.api.v1.admin.documents import *
warnings.warn(
"Importing from src.web.admin_routes is deprecated. "
"Use src.web.api.v1.admin.documents instead.",
DeprecationWarning,
stacklevel=2
)
4. Verify and Test
- Run tests:
pytest tests/web/ -v
- Check for any import errors:
python -c "from src.web.app import create_app; create_app()"
- Start server and test endpoints:
python run_server.py
5. Clean Up Old Files (ONLY AFTER TESTS PASS)
Old files to remove:
src/web/admin_*.py(7 files)src/web/async_*.py(3 files)src/web/batch_*.py(3 files)src/web/routes.pysrc/web/services.pysrc/web/schemas.pysrc/web/rate_limiter.py
Keep these files (don't remove):
src/web/__init__.pysrc/web/app.pysrc/web/config.pysrc/web/dependencies.py
🎯 Next Immediate Steps
- Update batch/routes.py imports - Quick fix for remaining API route
- Update test file imports - Critical for verification
- Run test suite - Verify nothing broke
- Fix any import errors - Address failures
- Remove old files - Clean up after tests pass
📊 Migration Impact Summary
| Category | Files Moved | Imports Updated | Status |
|---|---|---|---|
| API Routes | 7 | 5/7 | 🟡 In Progress |
| Schemas | 3 | 3/3 | ✅ Complete |
| Services | 4 | 0/4 | ⚠️ Pending |
| Core | 3 | 3/3 | ✅ Complete |
| Workers | 2 | 2/2 | ✅ Complete |
| Tests | 0 | 0/16 | ❌ Not Started |
Overall Progress: 65%
🚀 Benefits After Migration
- Better Organization: Clear separation by function
- Easier Navigation: Find files by purpose, not prefix
- Scalability: Easy to add new API versions
- Standard Structure: Follows FastAPI best practices
- Maintainability: Each module has single responsibility
📝 Notes
- All original files are still in place (no data loss risk)
- New structure is operational but needs import updates
- Backward compatibility can be added if needed
- Tests will validate the migration success