Design a Scalable Flask Blueprint Structure for Modular Applications

Generate a modular Flask blueprint architecture with factory pattern, service layers, and production-ready structure.

๐Ÿ“ The Prompt

Design a complete Flask blueprint structure for a [APPLICATION_TYPE] application with the following modules: [MODULE_1], [MODULE_2], and [MODULE_3]. **Project Structure Requirements:** 1. **Directory Layout**: Generate the full folder tree showing: - Application factory pattern in `app/__init__.py` - Each blueprint in its own package under `app/[module]/` - Separate files for `routes.py`, `models.py`, `schemas.py`, and `services.py` within each blueprint - Shared utilities in `app/common/` (decorators, error handlers, middleware) - Configuration classes in `config.py` for [ENVIRONMENTS] (development, testing, production) 2. **Application Factory**: Implement `create_app(config_name)` that: - Loads environment-specific configuration - Initializes extensions (SQLAlchemy, Migrate, [ADDITIONAL_EXTENSIONS]) - Registers all blueprints with URL prefixes `/api/v1/[module]` - Sets up global error handlers returning JSON responses - Configures structured logging with [LOG_LEVEL] 3. **Blueprint Implementation**: For the [MODULE_1] blueprint, provide complete code for: - Blueprint registration with `url_prefix` - At least 3 routes: list (GET), create (POST), detail (GET /<id>) - A service layer class that encapsulates business logic separate from routes - Request validation using [VALIDATION_LIBRARY] (e.g., Marshmallow, Pydantic) 4. **Cross-Cutting Concerns**: - Authentication decorator using [AUTH_METHOD] - A `before_request` hook for request logging - Database session management and teardown 5. **Testing Setup**: Include a `conftest.py` with fixtures for the test client, database setup/teardown, and an authenticated user session. Provide every file with complete, runnable code and comments explaining architectural decisions.

๐Ÿ’ก Tips for Better Results

Specify your database (PostgreSQL, SQLite, MySQL) and ORM preference so models are generated correctly. Mention if you need async support with Quart or stick with synchronous Flask. Include your preferred auth method (JWT, session, OAuth) for accurate decorator implementation.

๐ŸŽฏ Use Cases

Python backend developers use this when starting a new Flask project that needs a clean, maintainable modular architecture that scales beyond a single-file app.

๐Ÿ”— Related Prompts

๐Ÿ’ป Coding beginner

Explain Code Like Im a Beginner

Get any code explained in plain English with line-by-line breakdowns, analogies, and learning suggestions.

๐Ÿ’ป Coding beginner

Debug My Code and Explain the Fix

Get your code debugged with clear explanations of what went wrong and why, plus the corrected version.

๐Ÿ’ป Coding intermediate

Write Unit Tests for My Code

Generate thorough unit tests covering edge cases, error handling, and both positive and negative scenarios.

๐Ÿ’ป Coding intermediate

Convert Code Between Languages

Convert code between any programming languages while maintaining idiomatic patterns and best practices.

๐Ÿ’ป Coding intermediate

Write a REST API Endpoint

Generate production-ready REST API endpoints with validation, error handling, and documentation.

๐Ÿ’ป Coding advanced

Create a GitHub Actions CI/CD Workflow for Automated Testing and Deployment

Generate a complete GitHub Actions CI/CD workflow with build, test, deploy, and notification jobs for your project.