Flask

Refactor Flask 3.x apps to an application factory with unbound extensions and blueprints.

1|Updated May 2, 2026
One-click install
npx skills add https://github.com/Levironexe/architect --skill flask-levironexe
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Flask
Source: https://github.com/Levironexe/architect/tree/main/skills/stacks/flask
Command: npx skills add https://github.com/Levironexe/architect --skill flask-levironexe

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Flask codebases often drift into circular imports, tangled extension setup, and routes that contain business logic, making refactors risky and tests difficult to write. This Skill guides your coding agent toward a reliable Flask 3.x structure using an application factory, unbound extensions, and blueprint-driven separation.

Core Features & Use Cases

  • Application factory structure: Enforces create_app() to create the Flask instance only inside the factory function, enabling environment-specific configuration and test isolation.
  • Unbound extension initialization: Instantiates extensions in app/extensions.py and binds them with init_app(app) inside create_app() to prevent circular imports.
  • Blueprint + service separation: Keeps routes.py thin (validation + response) while placing business logic in services.py, models in app/models/, and domain templates under blueprint namespaces.

Use Case: You inherit a Flask app where extensions and blueprints are imported at module load time, causing startup failures and brittle tests; you need a phased, safe refactor that preserves behavior while restructuring for maintainability.

Quick Start

Ask your agent: "Generate a Flask refactor plan for a project that uses blueprints, services, models, and an application factory, then apply the first phase to fix circular imports and extension initialization."

Frequently Asked Questions about Flask

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix circular imports in a Flask application?

Fix circular imports in Flask by moving extension instantiation to a separate module and binding them later using `extension.init_app(app)` inside the `create_app()` application factory function.

What is the application factory pattern in Flask 3.x?

The Flask application factory pattern uses a `create_app()` function to instantiate the Flask instance on demand, enabling environment-specific configuration selection and safe test isolation across development environments.

How do I separate business logic from routes in Flask blueprints?

To separate business logic from routes in Flask blueprints, keep `routes.py` files thin by handling only validation and responses, while moving all business logic into dedicated `services.py` modules within the blueprint structure.

Can I use pytest with a Flask application factory structure?

Yes, pytest works with a Flask application factory by calling `create_app()` within your test fixtures to generate isolated app instances, ensuring consistent test client setup and environment-specific configuration selection.

What is the best way to refactor a Flask app with tangled extension setup?

The best way to refactor a Flask app with tangled extension setup is a phased approach enforcing unbound extension initialization via `init_app(app)` and blueprint-driven separation to preserve behavior while restructuring for maintainability.