Step-by-step guide for migrating a flat
src/project to the two-layer architecture
Quick Reference: Two-Layer Architecture | Decision Tree
If you have an old project with a flat src/ directory, migrating to the two-layer structure provides:
- Clear separation between infrastructure and project code
- Better code reuse across projects
- Independent test coverage requirements per layer
- Multi-project support
# Create the infrastructure directory (if it doesn't exist)
mkdir -p infrastructure
# Create the project source directory
mkdir -p projects/{name}/src
# Create supporting directories
mkdir -p projects/{name}/tests
mkdir -p projects/{name}/scripts
mkdir -p projects/{name}/manuscript- Infrastructure modules →
infrastructure/ - Project modules →
projects/{name}/src/
Use the Decision Tree to determine which layer each module belongs in:
| Question | If Yes → | If No → |
|---|---|---|
| Is this reusable across projects? | infrastructure/ |
projects/{name}/src/ |
| Is this generic build/validation/tooling? | infrastructure/ |
projects/{name}/src/ |
| Is this domain-specific science/analysis? | projects/{name}/src/ |
infrastructure/ |
| Is this custom visualization for your data? | projects/{name}/src/ |
infrastructure/ |
| Module Type | Destination |
|---|---|
| PDF generation, validation, figure management | infrastructure/ |
| Simulation algorithms, statistical analysis | projects/{name}/src/ |
| Custom visualization for your data | projects/{name}/src/ |
| Build artifact verification, generic utilities | infrastructure/ |
- from example import calculate_average
+ from projects.{name}.src.example import calculate_average
# Build verification is handled by the validation module- Infrastructure tests →
tests/infra_tests/ - Project tests →
projects/{name}/tests/ - Update
conftest.pyif needed
pytest tests/ projects/{name}/tests/ --cov=infrastructure --cov=projects/{name}/src
uv run python scripts/execute_pipeline.py --project {name} --core-only- All imports updated to new paths
- Infrastructure tests pass independently
- Project tests pass independently
- No infrastructure → project imports exist
- Coverage requirements met (60% infra, 90% project)
- Pipeline executes successfully
- Documentation updated (
AGENTS.md,README.mdin each directory)
Related Documentation:
- Two-Layer Architecture — Architecture overview
- Decision Tree — Code placement decisions
- New Project Setup — Setting up a new project