flask-architect
Architect-level Flask guidance — app factory and blueprint boundaries, WSGI and sync concurrency model, extension configuration, request/application context discipline, error handlers, and when Flask is the right choice over FastAPI or Django. Use when designing or reviewing a Flask service.
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- flask-architect
- license
- MIT
- metadata
- { "crusor-path": "website-architect/backend-development-architect/python-architect/flask-architect", "crusor-domain": "website-architect", "crusor-origin": "original", "crusor-sources": "flask.palletsprojects.com; wsgi.readthedocs.io", "crusor-triggers": "flask, wsgi, blueprints, app factory, jinja, gunicorn", "crusor-verified-on": "2026-10-30" }
- description
- Architect-level Flask guidance — app factory and blueprint boundaries, WSGI and sync concurrency model, extension configuration, request/application context discipline, error handlers, and when Flask is the right choice over FastAPI or Django. Use when designing or reviewing a Flask service.
- compatibility
- Flask 3.x, WSGI (gunicorn/uWSGI)
03 SKILL.md 正文
Flask Architect
Flask is a library, not a platform: it gives you routing and a request cycle, and you decide everything else. Architecture here is mostly about what you refuse to put in the app.
When to use
- Small/medium service or internal API with explicit control over the stack.
- Server-rendered pages with Jinja and light interactivity.
- A WSGI deployment that must stay simple (no async requirement).
- Prototypes that will grow — provided the factory/blueprint discipline below is in place from day one.
When NOT to use
- Many concurrent I/O waits (see
fastapi-architect; Flask's sync model bounds you to worker processes). - A product with admin, auth, and a large ORM surface (see
django-architect). - OpenAPI-first contract delivery — FastAPI makes that native.
Decision 1 — App factory + blueprints
def create_app(config: Config) -> Flask:
app = Flask(__name__)
app.config.from_object(config)
app.register_blueprint(api_v1, url_prefix="/v1")
return app
- No module-level
app. The factory is what makes tests, workers and multiple configs possible. - One blueprint per bounded context (
auth,orders,billing), not per file. - Extensions initialised in the factory, bound to
app.extensions, never as import-time singletons. - Config is an object with typed fields; secrets come from the environment.
Decision 2 — Layering inside a WSGI app
wsgi.py create_app()
blueprints/ routes: parse, validate, status codes
services/ use-cases (no flask imports)
repositories/ DB access
models/ SQLAlchemy or plain dataclasses
- A service function never imports
request,g, orcurrent_app. - Validation happens at the blueprint edge; services take typed arguments.
gis per-request scratch space, not a container for business objects.
Decision 3 — Contexts and error handling
- Application context for startup resources; request context for request data. Do not stash request state on the app object.
- One
register_error_handlerper error class; return the same envelope shape everywhere. - 404/405/500 handled explicitly — a default HTML traceback is a security leak.
- Teardown hooks close sessions/connections deterministically.
Decision 4 — Concurrency and deployment
- WSGI = one request per worker at a time. Scale with worker processes.
- Blocking external calls need timeouts; without them a slow upstream consumes the worker.
- Shared state (rate limits, caches) belongs outside the process; memory dies with the worker and is not shared.
- Behind a proxy: trust exactly one hop of
X-Forwarded-*(ProxyFix), and set secure cookie flags.
Failure modes at scale
- Module-level
app+ import-time extension init → can't test, can't scale. - Business logic inside view functions → duplicated across blueprints.
app.configused as a global registry for runtime state.- One worker configuration for CPU-bound and I/O-bound paths.
- Sessions/cookies used as a data store.
Verification receipts
- App created twice in one process (tests) without shared state.
- Error handlers verified for 400/404/405/500 with a consistent envelope.
- Load test at expected concurrency: worker saturation and queue time visible.
- Teardown test: connections closed, no leaked sessions.
- Config audit: no secret in code, debug off in production.
04 同仓库更多 Skills
interaction-patterns-architect
Architect-level interaction design in code — choosing established patterns over invented ones, feedback and latency behaviour, destructive-action safeguards, navigation and overlay conventions, and the state model behind every interactive surface. Use when a screen has to behave, not just look.
design-system-ops-architect
Architect-level operation of a design system in code — token pipelines and versioning, component API and variant policy, the catalogue as the contract, adoption metrics, and the governance that stops a system from forking into three. Use when a component library must survive several teams.
design-handoff-architect
Architect-level design handoff — what must be specified before implementation starts, tokens over raw values, responsive and content-limit contracts, state matrices, and the review loop that catches drift between design and code. Use when a design is about to become code.
content-microcopy-architect
Architect-level UI content — where strings live, voice and terminology consistency, error and empty-state copy as part of the interface, translation-ready authoring, and the content model a product needs before it multiplies screens. Use when the words in the interface matter as much as the pixels.
ui-ux-implementation-architect
Architect-level direction for turning a design into working UI — the handoff contract, component ownership versus screen-level layout, interaction and state conventions, design QA gates, and the review habits that keep an implementation faithful without frozen pixels. Use before any specific UI implementation skill.
test-strategy-architect
Architect-level test strategy — allocating assertions across unit, integration, contract and end-to-end layers, designing for testability through dependency boundaries, fixture and data strategy, and the flake and coverage policies that keep a suite trustworthy. Use when defining how a codebase is tested.