Start the FastAPI runtime with owned database resources #6

Open
opened 2026-11-01 20:11:27 +00:00 by viacheslavshuka · 0 comments

Quorum needs an executable API before product workflows can connect their adapters. Establish startup, configuration, and resource ownership without inventing business capabilities.

Scope

Create the Python application package and FastAPI composition entrypoint. Run production HTTP serving through Granian with --loop uvloop. Use a pooled asyncpg connection lifecycle and standard UUID objects from uuid_utils.compat.

Keep framework and database imports outside the application core. Define concrete ports with their first required interaction. Do not add an empty repository hierarchy or generic service layers.

Acceptance criteria

  • The configured entrypoint starts on Python 3.14 with uv-managed dependencies and validated environment configuration.
  • Startup acquires the asyncpg pool within the application lifespan. Shutdown closes the pool and other owned resources, including after partial startup failure.
  • A readiness operation reports a usable application and database connection. A database outage cannot produce a healthy readiness result.
  • Readiness and release-identity responses expose only the information needed by deployment verification. They do not expose connection strings or credentials.
  • Importing application modules does not open connections or contact external services. Test composition can replace required external interactions without changing the core.
  • FastAPI request and response models describe actual JSON values. The initial operations have stable unique operation IDs, summaries, descriptions, tags, and documented errors.
  • Application errors use fastapi-error-map when mapped errors exist. Framework validation and authentication errors receive separate contract declarations where applicable.
  • Project-owned runtime code and scripts satisfy the existing strict typing rules without using Any to bypass them.

Validation

Exercise startup, readiness, database failure, partial-startup cleanup, and shutdown against disposable PostgreSQL. Check actual response bodies and resource cleanup. Confirm isolated application construction does not perform network work during import.

Quorum needs an executable API before product workflows can connect their adapters. Establish startup, configuration, and resource ownership without inventing business capabilities. ## Scope Create the Python application package and FastAPI composition entrypoint. Run production HTTP serving through Granian with `--loop uvloop`. Use a pooled asyncpg connection lifecycle and standard UUID objects from `uuid_utils.compat`. Keep framework and database imports outside the application core. Define concrete ports with their first required interaction. Do not add an empty repository hierarchy or generic service layers. ## Acceptance criteria - The configured entrypoint starts on Python 3.14 with uv-managed dependencies and validated environment configuration. - Startup acquires the asyncpg pool within the application lifespan. Shutdown closes the pool and other owned resources, including after partial startup failure. - A readiness operation reports a usable application and database connection. A database outage cannot produce a healthy readiness result. - Readiness and release-identity responses expose only the information needed by deployment verification. They do not expose connection strings or credentials. - Importing application modules does not open connections or contact external services. Test composition can replace required external interactions without changing the core. - FastAPI request and response models describe actual JSON values. The initial operations have stable unique operation IDs, summaries, descriptions, tags, and documented errors. - Application errors use fastapi-error-map when mapped errors exist. Framework validation and authentication errors receive separate contract declarations where applicable. - Project-owned runtime code and scripts satisfy the existing strict typing rules without using `Any` to bypass them. ## Validation Exercise startup, readiness, database failure, partial-startup cleanup, and shutdown against disposable PostgreSQL. Check actual response bodies and resource cleanup. Confirm isolated application construction does not perform network work during import. ## Related work - [#8: Apply PostgreSQL migrations with release compatibility checks](https://code.viacheslavshuka.com/viacheslavshuka/quorum/issues/8) - [#10: Generate and verify OpenAPI and the TypeScript client](https://code.viacheslavshuka.com/viacheslavshuka/quorum/issues/10)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
viacheslavshuka/quorum#6
No description provided.