backend/scaffolding-flask/SKILL.md
Set up a Flask application using the app factory pattern with blueprints, extensions, and environment-specific configuration.
npx skillsauth add 7a336e6e/skills Scaffolding FlaskInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Create a well-structured Flask application using the app factory pattern, with modular blueprints, proper extension initialization, and environment-specific configuration classes.
Organize the project with clear separation of concerns:
project/
config.py
run.py
app/
__init__.py # App factory lives here
extensions.py # Extension instances
models/
__init__.py
user.py
routes/
__init__.py
auth.py
users.py
services/
__init__.py
user_service.py
tests/
conftest.py
migrations/
Define create_app() in app/__init__.py. This function builds and configures the application instance, registers extensions, and attaches blueprints.
from flask import Flask
from app.extensions import db, migrate, cors, login_manager
from config import config_by_name
def create_app(config_name=None):
"""Application factory for creating the Flask app."""
if config_name is None:
config_name = os.environ.get("APP_ENV", "development")
app = Flask(__name__)
app.config.from_object(config_by_name[config_name])
# Initialize extensions
db.init_app(app)
migrate.init_app(app, db)
cors.init_app(app)
login_manager.init_app(app)
# Register blueprints
from app.routes.auth import auth_bp
from app.routes.users import users_bp
app.register_blueprint(auth_bp, url_prefix="/api/v1/auth")
app.register_blueprint(users_bp, url_prefix="/api/v1/users")
return app
Declare extension instances in a dedicated app/extensions.py file. Do not bind them to an app at import time; instead, call init_app() inside the factory.
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_cors import CORS
from flask_login import LoginManager
db = SQLAlchemy()
migrate = Migrate()
cors = CORS()
login_manager = LoginManager()
Create a config.py at the project root with a base class and per-environment subclasses. See the full pattern in the config-patterns reference.
import os
class BaseConfig:
SECRET_KEY = os.environ.get("SECRET_KEY", "change-me")
SQLALCHEMY_TRACK_MODIFICATIONS = False
class DevelopmentConfig(BaseConfig):
DEBUG = True
SQLALCHEMY_DATABASE_URI = "sqlite:///dev.db"
class TestingConfig(BaseConfig):
TESTING = True
SQLALCHEMY_DATABASE_URI = "sqlite:///:memory:"
class ProductionConfig(BaseConfig):
DEBUG = False
SECRET_KEY = os.environ["SECRET_KEY"]
SQLALCHEMY_DATABASE_URI = os.environ["DATABASE_URL"]
config_by_name = {
"development": DevelopmentConfig,
"testing": TestingConfig,
"production": ProductionConfig,
}
Each domain gets its own blueprint. Register all blueprints inside create_app() with a versioned URL prefix. See the blueprint-patterns reference for conventions on when to split and how to organize blueprint internals.
Create a thin run.py entry point:
from app import create_app
app = create_app()
if __name__ == "__main__":
app.run()
create_app() function.init_app().run.py as a thin entry point that only calls create_app().extensions.py module.app = Flask(__name__) at module level.current_app if needed.When generating scaffolding, produce each file with its full relative path as a heading, followed by the complete file content. List all files created at the end as a summary.
.env files.development
Implement features using the Red-Green-Refactor cycle to ensure testability and correctness from the start.
data-ai
Manage the `tasks.md` ledger with strict locking and collision avoidance protocols to allow multiple agents to work in parallel safely.
development
The git-workflow skill defines branching conventions, commit message formats, and pull request standards that all agents must follow for consistent version control.
development
The environment-config skill standardizes how agents manage environment variables, secrets, and application configuration across local development and deployed environments.