/major-ai-skills:flaskfrom major-ai-skills
Ship Flask apps with application factories, blueprints, Alembic migrations, env-backed secrets, and gunicorn workers agents routinely miswire.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Flask is a WSGI microframework: explicit application factories, blueprints, and a request/app context stack. Extensions (db, migrate, CSRF) are constructed once and bound with init_app(app). Production traffic runs under gunicorn (or similar)—never flask run / app.run(). Agents fail closed on missing SECRET_KEY / DATABASE_URL in prod, push app_context() only when configuring, and keep Celery/RQ workers out of the request path.
┌─────────────────────────────────────────────────────────────┐
│ Flask factory → WSGI workers │
│ │
│ gunicorn "app:create_app()" / wsgi:app │
│ → create_app(config) │
│ ├── config from env (SECRET_KEY, DATABASE_URL) │
│ ├── extensions.init_app(app) │
│ ├── blueprints (api / web / admin) │
│ └── errorhandlers / CLI │
│ │
│ Request: app context + request context → view │
│ ├── SQLAlchemy / Alembic → @postgresql │
│ ├── sessions / rate limits → @redis (optional) │
│ └── background jobs → Celery/RQ worker │
└─────────────────────────────────────────────────────────────┘
Use when
Do not use when
@fastapi.@django.SECRET_KEY or ship the development server to prod → refuse.create_app() so tests/CLI/gunicorn construct isolated apps; avoid import-time global app for anything non-trivial.db = SQLAlchemy() then db.init_app(app) inside the factory; register blueprints after config.SECRET_KEY = os.environ["SECRET_KEY"] in production config—no "dev" fallback.current_app / g only in request/CLI; during setup use with app.app_context(): ….gunicorn -w 2-4 -b 0.0.0.0:$PORT "app:create_app()" (or wsgi:app); set proxy-fix headers when behind TLS LB.@redis; Flask async views exist but most extensions remain sync-first.app/extensions.py:
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_wtf import CSRFProtect
from sqlalchemy.orm import DeclarativeBase
class Base(DeclarativeBase):
pass
db = SQLAlchemy(model_class=Base)
migrate = Migrate()
csrf = CSRFProtect()
app/config.py:
import os
class Config:
SQLALCHEMY_TRACK_MODIFICATIONS = False
MAX_CONTENT_LENGTH = 5 * 1024 * 1024
class ProductionConfig(Config):
DEBUG = False
SECRET_KEY = os.environ["SECRET_KEY"]
SQLALCHEMY_DATABASE_URI = os.environ["DATABASE_URL"]
SESSION_COOKIE_SECURE = True
app/__init__.py:
import os
from flask import Flask, jsonify
from .extensions import db, migrate, csrf
from .config import ProductionConfig, Config
def create_app(config_object: type[Config] | None = None) -> Flask:
app = Flask(__name__)
cfg = config_object or (
ProductionConfig if os.environ.get("FLASK_ENV") == "production" else Config
)
app.config.from_object(cfg)
db.init_app(app)
migrate.init_app(app, db)
csrf.init_app(app)
from .blueprints.api import bp as api_bp
app.register_blueprint(api_bp, url_prefix="/api")
@app.get("/health")
def health():
return jsonify(ok=True)
return app
wsgi.py:
from app import create_app
app = create_app()
Commands:
export FLASK_APP="app:create_app"
flask db migrate -m "add items"
flask db upgrade
pytest -q
gunicorn -w 3 -b 0.0.0.0:${PORT:-8000} --timeout 60 wsgi:app
# or: gunicorn -w 3 -b 0.0.0.0:8000 "app:create_app()"
Blueprint validation sketch:
from flask import Blueprint, jsonify, request
from .extensions import db
from .models import Item
bp = Blueprint("api", __name__)
@bp.post("/items")
def create_item():
body = request.get_json(silent=True) or {}
sku = body.get("sku")
if not isinstance(sku, str) or not sku:
return jsonify(error="sku required"), 400
item = Item(sku=sku)
db.session.add(item)
db.session.commit()
return jsonify(id=item.id, sku=item.sku), 201
| Signature | Likely cause | Fix path |
|---|---|---|
Working outside of application context | Used current_app/db outside request/CLI | Move into view/CLI or with app.app_context() |
| Circular import on startup | Blueprint imports app/models at module top incorrectly | Late-import blueprints inside factory; extensions module |
| gunicorn can't find app with factory | Wrong callable string | wsgi:app or quoted "pkg:create_app()" |
| CSRF / session failures behind HTTPS proxy | Cookie Secure + missing proxy headers | SESSION_COOKIE_SECURE; ProxyFix / X-Forwarded-Proto |
| Schema drift / missing tables | Relying on db.create_all() in prod | Alembic upgrade in release pipeline |
SECRET_KEY weak or default in prod | Dev fallback left on | Fail closed with os.environ["SECRET_KEY"] |
| SQLite locks under gunicorn workers | File DB + multiple writers | Move to @postgresql; tune workers |
| Tests leak state between cases | Shared global app | create_app(TestingConfig) per test + fresh DB |
Development / Testing / Production; tests use in-memory SQLite or disposable Postgres.@docker); readiness may check DB ping separately.@fastapi better.db across conflicting configs without design.@fastapi — async-first alternative for OpenAPI-heavy APIs@postgresql — production database behind SQLAlchemy@redis — cache, sessions, Celery/RQ broker@docker — gunicorn image + Compose healthchecks@django — batteries-included alternative when admin/ORM conventions dominateMANDATORY: Use application factories +
init_app. Never hardcode productionSECRET_KEYor DB URLs. Schema changes go through Alembic in release jobs. Serve with gunicorn on0.0.0.0, not the Flask dev server. Fix context errors with proper request/CLI boundaries—not global app hacks.
gunicorn "pkg:create_app()" or wsgi:appWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.Other plugins' skills for the same job