Home › Flask › Flask 3 AGENTS.md

Flask 3 AGENTS.md

AGENTS.md for Flask 3 apps: app factory, blueprints, SQLAlchemy 2.0, and pytest with the test client.

AGENTS.mdFlask

How to use

Save this as AGENTS.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

AGENTS.mdDownload  
# AGENTS.md: Flask 3

## Commands
- Run: `flask --app app run --debug` · Test: `pytest -q` · Lint: `ruff check . && ruff format --check .`
- Migrations: `flask db migrate -m "msg"` then `flask db upgrade` (Flask-Migrate).

## Structure
- App factory `create_app(config=None)` in `app/__init__.py`; extensions created at module level and `init_app`'d in the factory.
- One blueprint per feature in `app/<feature>/routes.py`; logic in `app/<feature>/service.py`.
- SQLAlchemy 2.0 style: `db.session.execute(select(User).where(...)).scalars()`, typed models with `Mapped[...]` and `mapped_column`. No legacy `Model.query`.
- Validate input with a schema (marshmallow or pydantic, whatever the repo uses) before touching the DB.
- Config classes in `config.py` read from env; `SECRET_KEY` must come from env.
- Forms/HTML: Jinja autoescaping stays on; CSRF via Flask-WTF on every POST form.
- Return JSON errors from registered error handlers for API blueprints.

## Testing
- Fixtures: `app` (factory with test config, SQLite or a test Postgres), `client = app.test_client()`.
- Every new route gets a test for success and for bad input.

## Don't
- Don't use `app` as a global import inside blueprints; use `current_app`.
- Don't run with `debug=True` in production config.

More: all Flask rules · all AGENTS.md rules

Related rules

REST API design AGENTS.md

AGENTS.md for designing consistent HTTP/JSON APIs: resource naming, status codes, errors, pagination, and versioning.

AGENTS.mdAPI design

Deno 2 AGENTS.md

AGENTS.md for Deno 2 projects: deno.json tasks, JSR and npm imports, permissions, and built-in tooling.

AGENTS.mdDeno

Express 5 API AGENTS.md

AGENTS.md for Express 5 REST APIs in TypeScript with zod validation, error middleware, and supertest.

AGENTS.mdNode.js / TypeScript

Go stdlib HTTP service AGENTS.md

AGENTS.md for Go 1.27 services using only net/http, slog, and database/sql or pgx, with no web framework.

AGENTS.mdGo

Python FastAPI AGENTS.md

Universal AGENTS.md for Codex, Jules, Cursor and other agents working on a FastAPI + uv project.

AGENTS.mdPython / FastAPI

Stripe payments integration AGENTS.md

AGENTS.md for Stripe integrations: Checkout and Payment Intents, verified webhooks, idempotency, and test mode only.

AGENTS.mdStripe payments

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.