← Todas las plantillas

App factory pequeña, blueprints por dominio, configuración 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.

  1. 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 global Flask app at import time, so tests build a fresh app per test.

  2. 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.

  3. Explicit config. Config is a class per environment filled from environment variables and validated in create_app. Code reads current_app.config, never os.environ, and a missing secret stops the app at startup.

  4. Health checks. /healthz answers without touching dependencies and /readyz checks 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.

  5. 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.

  6. 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.