Skip to content

Harden template with app factory, typed boundaries and stricter gates - #206

Merged
Subhransu-De merged 5 commits into
mainfrom
production-ready-foundation
Oct 2, 2026
Merged

Subhransu-De merged 5 commits into
mainfrom
production-ready-foundation

Conversation

@Subhransu-De

Copy link
Copy Markdown
Owner

What changes

Turns the template into a base that is safe to build on: the type system describes every boundary, the app is built from explicit settings instead of import-time singletons, and the gates fail on the mistakes they previously let through.

Architecture

  • create_app(settings) and a lifespan that owns the engine, session factory and token validator. Importing app.main has no side effects. Uvicorn runs the factory.
  • One frozen Settings root; module-level settings instances, global, and the session-maker proxy are removed.
  • Typed AuthClaims returned by authentication, require_role("entities:write") on write routes, the role added to both Keycloak realm exports.
  • ProblemDetails model for every error, declared per route in OpenAPI as application/problem+json. OperationalError maps to 503.
  • One generic Repository, predicate-based find_by, typed Ordering. Service depends on an EntityStore protocol.
  • Readiness probe at /health/ready running SELECT 1; container health checks in the Dockerfile and Compose.
  • Timezone-aware timestamps with a migration; request schemas reject unknown fields.

Telemetry

  • FastAPI 0.142.2. Logfire keeps ownership of instrumentation; native telemetry is configured with auto_configure off and health probes excluded, so it stays dormant and cannot add a second exporter.
  • SQLAlchemy spans restored: the instrumentor had been refusing SQLAlchemy 2.1 silently.
  • JWKS refresh cooldown is configurable via OIDC_JWKS_REFRESH_COOLDOWN_SECONDS; the cache TTL must be positive.

Gates

  • ruff format --check, ty --error-on-warning, ANN for tests, typos, and an AST test forbidding getattr/setattr/hasattr/cast/Any in app/.
  • Committed OpenAPI snapshot, alembic check plus downgrade round trip, coverage floor of 90% in pyproject.toml.
  • pytest-randomly, pytest-timeout, warnings as errors, Hypothesis on parsing boundaries, weekly mutation testing.
  • CI runs 3.13 and 3.14, with 3.15 as a non-blocking experimental leg. Runtime images use 3.14.
  • make check, pre-commit hooks, AGENTS.md, CONTRIBUTING.md, LICENSE, CODEOWNERS, PR template.

Behaviour changes for API clients

  • Validation errors return 422 instead of 400.
  • PUT /entities/{id} replaces the whole resource; omitting description clears it.
  • Create, update and delete require the entities:write realm role; reads need only a valid token.
  • Unknown request fields return 422.

Gates

  • make check is green
  • make test-integration is green
  • tests/contract/openapi.json is updated and the diff is intended
  • New Keycloak roles are added to both realm exports in .docker/

Full suite: 212 passed, coverage 96.3%.

Notes for the reviewer

The Lambda Web Adapter readiness path still points at /health; moving it to /health/ready would make cold starts fail while the database is unreachable, so it is left as a separate decision.

Note

From claude-opus-5-5

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T10:58:46.142561Z 3886cc1 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1d3bbad182

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/routes/__init__.py
Comment thread app/telemetry.py Outdated
Comment thread tests/conftest.py Outdated
@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Critical risk] Adds role-based access control and alters database schema.

The PR appears safe to merge based on the changes reviewed.

Summary

The PR builds the application from explicit settings and lifespan-managed resources, adds typed authentication and repository boundaries, readiness checks, Problem Details responses, and stricter quality gates. Since the previous review, it also maps SQLAlchemy pool timeouts to 503 responses. All three previous Greptile threads are resolved, and no new actionable issue was identified.

Reviews (4) · Last reviewed commit: "Map connection pool timeouts to 503"

Comment thread app/routes/health.py
Comment thread app/routes/__init__.py
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41dd8887d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/unit/io/test_entity.py Outdated
Comment thread tests/unit/property/test_parsing_boundaries.py Outdated
Comment thread tests/support.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5061ef498c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/exceptions/handlers.py Outdated
@Subhransu-De

Copy link
Copy Markdown
Owner Author

@codex review

Note

From claude-opus-5-5

@sonarqubecloud

sonarqubecloud Bot commented Oct 2, 2026

Copy link
Copy Markdown

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 3886cc1058

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Subhransu-De
Subhransu-De merged commit 300efb1 into main Oct 2, 2026
39 of 41 checks passed
@Subhransu-De
Subhransu-De deleted the production-ready-foundation branch October 2, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant