3.1 KiB
3.1 KiB
Project Guide
Project
- Python clean architecture template
- FastAPI is the current HTTP adapter
- The web layer must stay replaceable
- Repository and usecase instances are created once at startup
- Config comes from YAML plus env into one dataclass tree
- Logs metrics and traces stay behind interfaces and use OTel adapters
- Request logging middleware is used
- Metrics middleware is used
- Custom trace middleware is not used
- API versioning lives under
/api/v1
Structure
domain/core model and domain errorsdomain/error.pydomain errorsdomain/user.pyexample domain modelusecase/interfaces and usecasesusecase/interface.pyrepository and observability interfacesusecase/user.pyexample user usecaserepository/repository implementationsrepository/user.pyexample in-memory repositoryadapter/config/config models and loaderadapter/otel/logger metrics tracer and OTel setupadapter/di/container and startup wiringadapter/http/fastapi/app dependencies lifespan middleware routersconfig/app YAML and OTel collector configdocs/ADR filestasks.mdtask listmain.pylocal entrypoint
Boundaries
- Keep dependency direction inward
domainimports nothing internalusecasemay importdomainrepositorymay importusecaseanddomainadaptermay importusecaseanddomain- Do not import FastAPI into
domainorusecase - Do not import OpenTelemetry into
domainorusecase - Keep HTTP models and middleware inside
adapter/http/fastapi/
Workflow
- Use
tasks.mdfor planning - Do not use Beads
- Do not use
bd - Use
uvfor Python commands and dependency management - Do not create commits on your own
- Work on one task at a time
- Prefer delegation for implementation
- Delegate only one task at a time
- After one task return to the user with result verification and next options
- Wait for the user before the next task commit or fix
Makefile
make installinstall deps withuvmake runstart the app locallymake run-otelstart the app with OTel envmake lintrunruffmake typecheckrunmypymake testrunpytestmake pre-commitrun lint typecheck testmake compose-buildbuild the containersmake compose-upstart app and collectormake compose-downstop the stackmake compose-logsshow app and collector logsmake compose-psshow compose status
Runtime
- Local run needs
APP_API_TOKENandAPP_SIGNING_KEY - Base config lives in
config/app.yaml - Env overrides come from shell vars or
.env - OTel collector config lives in
config/otel-collector.yaml
Style
- Comments are short and have no trailing period
- Error messages are short and have no trailing period
- Use single-word comments when possible
- Use single-word error messages when possible
- Keep names simple
- Keep adapters thin
- Keep
__init__.pyempty - Prefer explicit wiring over magic
- Do not expand scope without user approval
- Do not
from __future__ import annotations - Do not
from importlib import import_module - Do not
importlib - Do not
cast