App factory pequena, blueprints por domínio, configuração explícita, health checks.
Constitution — Flask microservice
Version 1.0.0 · Ratified 2026-11-10
These principles hold for every spec, plan and task of the project. A spec may add rules; it never weakens these.
-
Small app factory. The app is built by
create_app(config), which registers extensions, blueprints and error handlers and nothing else. No module creates a globalFlaskapp at import time, so tests build a fresh app per test. -
Blueprints per domain. Each business area is one blueprint with its routes, schemas and services. Blueprints do not import each other’s routes; shared logic lives in plain service modules.
-
Explicit config. Config is a class per environment filled from environment variables and validated in
create_app. Code readscurrent_app.config, neveros.environ, and a missing secret stops the app at startup. -
Health checks.
/healthzanswers without touching dependencies and/readyzchecks the database and the services the app needs, with a timeout of at most 2 seconds. Both are excluded from authentication and from request logs. -
Validated input, typed output. Request bodies are parsed with marshmallow or Pydantic schemas before the view logic runs; invalid input returns a 400 with the failing fields. Errors are returned by registered error handlers in one JSON shape.
-
Production server and tests. The service runs under gunicorn, never the development server. Every route has a test using
app.test_client()for success and for invalid input.