python-clean-architecture

Scaffold FastAPI projects with a three-layer architecture and Protocol-based DI.

7|1|Updated Feb 21, 2026
One-click install
npx skills add https://github.com/MKToronto/python-clean-architecture-codex --skill python-clean-architecture
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-clean-architecture
Source: https://github.com/MKToronto/python-clean-architecture-codex/tree/main/.agents/skills/clean-architecture
Command: npx skills add https://github.com/MKToronto/python-clean-architecture-codex --skill python-clean-architecture

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides practical guidance for applying Clean Architecture to Python and FastAPI projects, helping teams achieve clear separation of concerns, protocol-based DI, and scalable architecture decisions.

Core Features & Use Cases

  • Scaffold new FastAPI projects with a strict three-layer structure (Routers → Operations → Database) and Protocol-based DI.
  • Help refactor existing Python code to reduce coupling, increase cohesion, and promote testability.
  • Support adding new components (endpoints, use cases, repositories, models) with consistent interfaces.
  • Assist in code quality reviews, architecture decisions, and Pythonic pattern adoption (Protocol, Callable, DI, data-first design).

Quick Start

Scaffold a FastAPI project with a three-layer architecture and Protocol-based DI to begin practical development.

Frequently Asked Questions about python-clean-architecture

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

FAQPage Schema
How do I structure a FastAPI project using clean architecture?

Structure a FastAPI project using clean architecture by adopting a strict three-layer structure: Routers → Operations → Database. This canonical layout enforces separation of concerns and uses Protocol-based dependency injection to keep code scalable and testable.

How does Protocol-based dependency injection work in Python?

Protocol-based dependency injection in Python uses structural subtyping to define interfaces without inheritance. Applying this in FastAPI decouples routers from concrete database operations, promoting testability and reducing coupling across architectural layers.

What is the best way to refactor existing Python code for better testability?

The best way to refactor existing Python code for testability is to apply clean architecture principles. Introduce Protocol-based dependency injection and migrate logic into a three-layer structure to reduce coupling, increase cohesion, and isolate business rules from infrastructure.

Can I use Python design patterns like Callable and Protocol to decouple FastAPI endpoints?

Yes, you can use Python design patterns like Protocol and Callable to decouple FastAPI endpoints. Defining use cases and repositories with Protocols enables data-first design and seamless dependency injection, keeping endpoint logic lightweight and isolated.

When should I not use a three-layer architecture for my Python application?

You should avoid a three-layer architecture for simple Python scripts or prototypes where strict separation of concerns introduces unnecessary boilerplate. Clean architecture patterns are designed for scalable, complex projects requiring long-term testability and maintainability.