What is the baseline for the hAPI codebase? Decide Python version and tooling (package manager, linting, typing), ORM and migrations, module layout for the modular monolith, API versioning and error conventions, configuration loading, testing approach, and container build.
Part of #44
## Question
What is the baseline for the hAPI codebase? Decide Python version and tooling (package manager, linting, typing), ORM and migrations, module layout for the modular monolith, API versioning and error conventions, configuration loading, testing approach, and container build.
Baseline for the hAPI codebase (decided in a grilling session, 2026-11-23):
Language & tooling
Python 3.14, single pinned minor (.python-version + base image).
uv for deps/lockfile (uv.lock) and Python install; one pyproject.toml at the root. Hatch was considered (PEP 751 lockfiles since v1.17), but its env-matrix strength doesn't apply to a single-version app.
Ruff (lint + format, broad rule set incl. DTZ) + pyright strict, enforced in CI.
just for task recipes (just dev/test/lint/migrate); pre-commit runs Ruff + pyright; CI calls the same just recipes.
Renovate for Python deps, base-image digest, and uv version (patch updates grouped weekly). Where it runs → How do code changes reach the cluster?
App architecture
Async end to end (handlers, DB driver, outbound HTTP).
SQLAlchemy 2.x async (typed Mapped[]) + separate Pydantic v2 API schemas. A shared mixin gives every domain model its owner + Recorded by columns (ADR-0001).
Layout: src/hapi/platform/ (config, db, auth, errors, logging, pagination) + one package per domain (finance, fitness, home_maintenance, smart_home), each with models / schemas / service / router. Domains may import platform and only other domains' public service API; enforced by import-linter in CI.
Config: pydantic-settings, HAPI_-prefixed env vars, .env only in local dev, fail fast at startup. Secret delivery → How are secrets stored and delivered?
Logging: structlog, JSON to stdout in prod / console in dev, request_id + principal_id bound per request, redaction processor so Personal data is never logged. Collection → How are health, logs, and metrics exposed and collected?
Errors: RFC 9457 Problem Details (application/problem+json) with code + request_id extensions; validation errors reshaped to match; typed domain exceptions → one handler.
IDs: UUIDv7 primary keys generated in the app, exposed as-is.
Time:timestamptz in UTC, aware datetimes only, RFC 3339 with offset; calendar concepts as date + the Household's configured timezone.
Pagination: cursor-based, {items, next_cursor}, limit default-capped at 100, one shared helper.
OpenAPI/docs, /redoc, /openapi.json disabled in prod; schema exported as a CI artifact.
Data & tests
Alembic, one env, single linear history across all domain schemas, strict constraint naming convention, autogenerate + mandatory review. Runs as an explicit hapi migrate step, never on app startup (how it's triggered → delivery ticket).
pytest + pytest-asyncio against real Postgres (prod major version) via testcontainers; per-test transaction rollback; API tests via httpx.AsyncClient + ASGITransport. Mostly service tests; API tests cover authZ and Personal/Household visibility, and every endpoint gets a wrong-Principal-can't-see-it test. No DB mocking; only external systems (HA, ntfy) are mocked.
One uvicorn process per pod, no gunicorn; scale via replicas; graceful-shutdown timeout aligned with terminationGracePeriodSeconds.
Local dev: app on host (uv run fastapi dev) + Postgres in Docker Compose (prod major version); opt-in full Compose profile runs the real image; CI smoke-tests the built image.
No ADR: conventional and cheap to reverse; the modular-monolith shape is already a standing map decision. No new glossary terms.
## Resolution
**Baseline for the hAPI codebase** (decided in a grilling session, 2026-11-23):
**Language & tooling**
- **Python 3.14**, single pinned minor (`.python-version` + base image).
- **uv** for deps/lockfile (`uv.lock`) and Python install; one `pyproject.toml` at the root. Hatch was considered (PEP 751 lockfiles since v1.17), but its env-matrix strength doesn't apply to a single-version app.
- **Ruff** (lint + format, broad rule set incl. `DTZ`) + **pyright strict**, enforced in CI.
- **just** for task recipes (`just dev/test/lint/migrate`); **pre-commit** runs Ruff + pyright; CI calls the same `just` recipes.
- **Renovate** for Python deps, base-image digest, and uv version (patch updates grouped weekly). Where it runs → *How do code changes reach the cluster?*
**App architecture**
- **Async end to end** (handlers, DB driver, outbound HTTP).
- **SQLAlchemy 2.x async** (typed `Mapped[]`) + separate **Pydantic v2** API schemas. A shared mixin gives every domain model its owner + Recorded by columns (ADR-0001).
- Layout: `src/hapi/platform/` (config, db, auth, errors, logging, pagination) + one package per domain (`finance`, `fitness`, `home_maintenance`, `smart_home`), each with `models` / `schemas` / `service` / `router`. Domains may import `platform` and only other domains' public `service` API; enforced by **import-linter** in CI.
- **Config:** pydantic-settings, `HAPI_`-prefixed env vars, `.env` only in local dev, fail fast at startup. Secret delivery → *How are secrets stored and delivered?*
- **Logging:** structlog, JSON to stdout in prod / console in dev, `request_id` + `principal_id` bound per request, redaction processor so Personal data is never logged. Collection → *How are health, logs, and metrics exposed and collected?*
**API conventions**
- **`/v1` path prefix**, domains beneath (`/v1/finance/...`); `/healthz`, `/readyz` unversioned.
- **Errors:** RFC 9457 Problem Details (`application/problem+json`) with `code` + `request_id` extensions; validation errors reshaped to match; typed domain exceptions → one handler.
- **IDs:** UUIDv7 primary keys generated in the app, exposed as-is.
- **Time:** `timestamptz` in UTC, aware datetimes only, RFC 3339 with offset; calendar concepts as `date` + the Household's configured timezone.
- **Pagination:** cursor-based, `{items, next_cursor}`, `limit` default-capped at 100, one shared helper.
- **OpenAPI** `/docs`, `/redoc`, `/openapi.json` disabled in prod; schema exported as a CI artifact.
**Data & tests**
- **Alembic**, one env, single linear history across all domain schemas, strict constraint naming convention, autogenerate + mandatory review. Runs as an explicit `hapi migrate` step, never on app startup (how it's triggered → delivery ticket).
- **pytest + pytest-asyncio** against **real Postgres** (prod major version) via testcontainers; per-test transaction rollback; API tests via `httpx.AsyncClient` + `ASGITransport`. Mostly service tests; API tests cover authZ and Personal/Household visibility, and **every endpoint gets a wrong-Principal-can't-see-it test**. No DB mocking; only external systems (HA, ntfy) are mocked.
**Runtime & dev**
- **Multi-stage Dockerfile:** uv builder → `python:3.14-slim` pinned by digest, venv + app only, non-root, read-only rootfs.
- **One uvicorn process per pod**, no gunicorn; scale via replicas; graceful-shutdown timeout aligned with `terminationGracePeriodSeconds`.
- **Local dev:** app on host (`uv run fastapi dev`) + Postgres in Docker Compose (prod major version); opt-in `full` Compose profile runs the real image; CI smoke-tests the built image.
No ADR: conventional and cheap to reverse; the modular-monolith shape is already a standing map decision. No new glossary terms.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Part of #44
Question
What is the baseline for the hAPI codebase? Decide Python version and tooling (package manager, linting, typing), ORM and migrations, module layout for the modular monolith, API versioning and error conventions, configuration loading, testing approach, and container build.
Resolution
Baseline for the hAPI codebase (decided in a grilling session, 2026-11-23):
Language & tooling
.python-version+ base image).uv.lock) and Python install; onepyproject.tomlat the root. Hatch was considered (PEP 751 lockfiles since v1.17), but its env-matrix strength doesn't apply to a single-version app.DTZ) + pyright strict, enforced in CI.just dev/test/lint/migrate); pre-commit runs Ruff + pyright; CI calls the samejustrecipes.App architecture
Mapped[]) + separate Pydantic v2 API schemas. A shared mixin gives every domain model its owner + Recorded by columns (ADR-0001).src/hapi/platform/(config, db, auth, errors, logging, pagination) + one package per domain (finance,fitness,home_maintenance,smart_home), each withmodels/schemas/service/router. Domains may importplatformand only other domains' publicserviceAPI; enforced by import-linter in CI.HAPI_-prefixed env vars,.envonly in local dev, fail fast at startup. Secret delivery → How are secrets stored and delivered?request_id+principal_idbound per request, redaction processor so Personal data is never logged. Collection → How are health, logs, and metrics exposed and collected?API conventions
/v1path prefix, domains beneath (/v1/finance/...);/healthz,/readyzunversioned.application/problem+json) withcode+request_idextensions; validation errors reshaped to match; typed domain exceptions → one handler.timestamptzin UTC, aware datetimes only, RFC 3339 with offset; calendar concepts asdate+ the Household's configured timezone.{items, next_cursor},limitdefault-capped at 100, one shared helper./docs,/redoc,/openapi.jsondisabled in prod; schema exported as a CI artifact.Data & tests
hapi migratestep, never on app startup (how it's triggered → delivery ticket).httpx.AsyncClient+ASGITransport. Mostly service tests; API tests cover authZ and Personal/Household visibility, and every endpoint gets a wrong-Principal-can't-see-it test. No DB mocking; only external systems (HA, ntfy) are mocked.Runtime & dev
python:3.14-slimpinned by digest, venv + app only, non-root, read-only rootfs.terminationGracePeriodSeconds.uv run fastapi dev) + Postgres in Docker Compose (prod major version); opt-infullCompose profile runs the real image; CI smoke-tests the built image.No ADR: conventional and cheap to reverse; the modular-monolith shape is already a standing map decision. No new glossary terms.