一键导入
backend-architecture-flask-python
Application Factory, Blueprints, SQLAlchemy, and config separation for Flask
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Application Factory, Blueprints, SQLAlchemy, and config separation for Flask
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | backend-architecture-flask-python |
| description | Application Factory, Blueprints, SQLAlchemy, and config separation for Flask |
project/
├── app/
│ ├── __init__.py # Application Factory (create_app)
│ ├── config.py # Configuration classes (Dev, Prod, Test)
│ ├── extensions.py # Flask extensions (db, migrate, login)
│ ├── blueprints/
│ │ ├── auth/
│ │ │ ├── __init__.py # Blueprint creation
│ │ │ ├── routes.py # Route definitions
│ │ │ └── forms.py # WTForms schemas
│ │ └── users/
│ │ ├── __init__.py
│ │ └── routes.py
│ ├── models/ # SQLAlchemy models
│ │ ├── __init__.py
│ │ └── user.py
│ ├── services/ # Business logic
│ │ └── user_service.py
│ └── templates/ # Jinja2 templates (if server-rendered)
├── tests/
│ ├── conftest.py # Pytest fixtures (app, client, db)
│ ├── test_auth.py
│ └── test_users.py
├── .env # Local environment variables
├── requirements.txt
└── run.py # Entry point
| Artifact | Convention | Example |
|---|---|---|
| Files/Directories | snake_case | user_service.py |
| Classes | PascalCase | UserService |
| Functions/Methods | snake_case | get_user_by_id |
| Variables | snake_case | current_user |
| Blueprint names | plural nouns | users |
| Route prefixes | plural kebab-case | /api/users |
| Environment variables | UPPER_SNAKE_CASE | DATABASE_URL |
Use create_app(config_name) in app/__init__.py to build the Flask instance. This allows creating different app instances for development, testing, and production without global state.
def create_app(config_name="development"):
app = Flask(__name__)
app.config.from_object(config_map[config_name])
register_extensions(app)
register_blueprints(app)
return app
Organize routes into Blueprints. Each feature domain gets its own Blueprint. Never define routes directly on the app instance outside of a Blueprint.
users_bp = Blueprint("users", __name__, url_prefix="/api/users")
models/ package, not in routes.py.backref sparingly — prefer explicit relationship definitions.Create a config.py with at least three classes: Config (base), DevelopmentConfig, ProductionConfig, TestingConfig. Load the correct one via environment variable or default.
requirements.txt..venv/ or __pycache__/ to version control.| Layer | Test Type | Framework | File Naming |
|---|---|---|---|
| Service | Unit | Pytest | test_user_service.py |
| Route / View | Integration | Pytest + Flask test client | test_auth_routes.py |
| Model | Unit | Pytest | test_user_model.py |
pytest as the test runner (not unittest).conftest.py to define shared fixtures (app instance, test client, database session).Syncs Telegram supergroup topics into local task files and GitHub issues, using embedded Python scripts for deterministic JSON state management. Preserves raw bilingual messages verbatim, injects refactored prompts, and correlates codebase context.
100% Jetpack Compose, MVI (UDF), Hilt, and SQLDelight for token-efficient, zero-hallucination Android development.
NestJS, Prisma ORM, Vertical Slice Architecture, and Strict TypeScript for zero-hallucination backend development.
Expo Managed Workflow, Expo Router, NativeWind, and Strict TypeScript for zero-hallucination cross-platform apps.
Automatically generates decentralized task files based on manager instructions.
Idiomatic Go, Clean Architecture, and Gin routing best practices