Skip to content

Latest commit

 

History

History
91 lines (68 loc) · 3.31 KB

development.md

File metadata and controls

91 lines (68 loc) · 3.31 KB

Development Guide

Recommended workflow

  1. Create a focused branch for the change.
  2. Update or add an Alembic migration when the database schema changes.
  3. Keep HTTP concerns in routers and business rules in services.
  4. Reuse repositories for database access instead of adding queries to route handlers.
  5. Update the API or frontend documentation when behavior changes.
  6. Run the validation commands below before opening a pull request.

Backend commands

# Install dependencies
poetry install

# Start the API with reload
poetry run uvicorn app.core.main:app --reload --host 0.0.0.0 --port 8888

# Apply migrations
poetry run alembic upgrade head

# Inspect migration state
poetry run alembic current
poetry run alembic history

# Check Python syntax
python -m compileall app

Frontend commands

cd frontend
yarn install
yarn dev
yarn lint
yarn build

Adding a backend feature

For a new resource or use case, use this sequence:

  1. Add or update SQLAlchemy models under app/db/models/.
  2. Generate and review an Alembic revision.
  3. Add Pydantic schemas under app/schemas/.
  4. Implement persistence methods in a repository.
  5. Implement business logic in a service.
  6. Expose the feature through a router and register it in app/core/main.py.
  7. Add the corresponding frontend service, types, page, or admin component.
  8. Document the endpoints in docs/api.md.

Migrations

poetry run alembic revision --autogenerate -m "describe the schema change"
poetry run alembic upgrade head

Autogenerated migrations must be reviewed manually, especially enum changes, nullable constraints, foreign keys, indexes, and data migrations. Do not edit an already-applied migration; create a new revision instead.

Validation checklist

  • The API starts successfully with the documented environment variables.
  • GET /health/ready answers 200 with the database reachable.
  • poetry run alembic upgrade head succeeds on a clean database.
  • Protected routes reject unauthenticated requests.
  • Admin routes reject regular users.
  • python -m compileall app completes without errors.
  • yarn lint completes without errors.
  • yarn build completes without errors.
  • Documentation contains no local secrets or machine-specific URLs.

Quality gates

poetry run ruff check . && poetry run ruff format --check .
poetry run pytest --cov            # needs Docker (testcontainers) or TEST_DATABASE_URL
poetry run pytest -n auto --cov    # in parallel (pytest-xdist): one database per worker
poetry run pip-audit
cd frontend && yarn eslint . --max-warnings 0 && yarn tsc -b && yarn test:cov && yarn build

Tests use a throw-away PostgreSQL started by testcontainers; set TEST_DATABASE_URL=postgresql+asyncpg://user:pass@host:port/db to use an existing one. The schema is built once per run with alembic upgrade head; data is truncated after every test. CI (.github/workflows/ci.yml) runs the same checks plus content, Docker image and secret scans. After changing an endpoint run poetry run python scripts/gen_api_docs.py and yarn gen:api (in frontend/) — CI fails if the docs or generated types are stale.

Current project limitations

  • A license file has not yet been added.
  • Production database access is intentionally not part of this repository's tooling; see docs/audit/ for the owner-side checklists.