Mandatory technical reference for AI agents. Focus on commands and imperative rules. For engineering principles and architecture, see CONTRIBUTING.md.
- Type: Backend API (FastAPI v0.127)
- Stack: Python 3.10, PostgreSQL, SQLAlchemy (Sync), uv
- Testing: pytest (Isolate via
make test-unit) - Quality: pre-commit, Ruff (via
make cs)
- Testing: NEVER run
pytestdirectly. ALWAYS usemake test-unit. - Production: Assume any DB access is production. No destructive operations without explicit approval.
- Dependencies: Use
uv add <package>. No global installs.
- Sessions: Always use
SessionLocal()in a context manager. - Cleanup: Ensure sessions are closed (handled by context manager).
- Queries: Prefer
select()over deprecated ORM patterns.
from app.orm.database import SessionLocal
from sqlalchemy import select
from app.orm.models import Task
def get_tasks():
with SessionLocal() as session:
query = select(Task).where(Task.status == "pending")
return session.execute(query).scalars().all()Reference: app/services/tasks/initializer.py:_check_cleanup_tasks
- Exceptions: Use
ApiException(or its subclasses) fromapp.api.errors. - Validation: Rely on Pydantic models for request/response.
- Logic: Keep business logic in services, not routers.
from app.api.errors import ApiException
from fastapi import status
def validate_data(data: dict):
if "important_key" not in data:
raise ApiException(
status_code=status.HTTP_400_BAD_REQUEST,
error_code="MISSING_DATA",
message="Required key is missing"
)Reference: app/api/errors.py
Imperative Rules:
- Test Database Availability: Tests MAY fail if the test database does not exist. This can happen if the database container was fully removed. IF tests fail due to missing test database, the agent MUST recreate it by running:
make test-setup. After that, the agent MUST rerun:make test-unit - Implement: Focused, minimal changes.
- Test:
make test-unit(Mandatory). - Lint:
make csANDpre-commit run --all-files(Mandatory). - Docs: Update docstrings if logic changes.