clean-architecture

Implement Clean Architecture layers with ports and adapters in Python/FastAPI projects.

3|Updated Oct 27, 2025
One-click install
npx skills add https://github.com/eco2-team/backend --skill clean-architecture-eco2-team
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clean-architecture
Source: https://github.com/eco2-team/backend/tree/main/.claude/skills/clean-architecture
Command: npx skills add https://github.com/eco2-team/backend --skill clean-architecture-eco2-team

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a structured blueprint to implement Clean Architecture (including hexagonal and ports-and-adapters patterns) in Python/FastAPI projects, enabling clear separation of concerns and scalable software design.

Core Features & Use Cases

  • Layered structure guidance: Domain, Application, Infrastructure, and Presentation layers with explicit responsibilities and allowed dependencies.
  • Port/Adapter patterns: Clear definitions for domain and application ports and concrete adapters to support easy swapping of technologies.
  • CQRS and testing conventions: Guidance on separating write and read models, plus testing strategies across domain, application, and infrastructure layers.

Quick Start

To begin, apply this guide to a Python/FastAPI project by: 1) delineating domain entities and value objects, 2) creating application use cases as interactor objects, 3) wiring ports to adapters in a DI setup, and 4) organizing code into domain/application/infrastructure/presentation folders.

Frequently Asked Questions about clean-architecture

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

FAQPage Schema
How do I implement Clean Architecture in a Python FastAPI project?

To implement Clean Architecture in a Python FastAPI project, separate your code into Domain, Application, Infrastructure, and Presentation layers. Define domain entities, create application use case interactors, and wire ports to adapters using dependency injection for scalable software design.

What is the difference between ports and adapters in hexagonal architecture?

In hexagonal architecture, ports define the interfaces for domain and application interactions, while adapters are concrete implementations that connect those ports to external technologies. This pattern allows you to easily swap infrastructure technologies without modifying core business logic.

How do I structure Domain and Application layers when applying DDD in Python?

Structure Domain layers by defining pure entities and value objects containing business rules. Structure Application layers by creating interactor objects that orchestrate use cases, ensuring dependencies point inward toward the domain without referencing external infrastructure frameworks.

Can I use CQRS with layered architecture in FastAPI applications?

Yes, you can apply CQRS in a FastAPI layered architecture by explicitly separating write and read models. This involves routing command operations through domain interactors for writes and designing optimized query handlers for read operations within the application layer.

What testing conventions should I follow for Clean Architecture in Python?

Follow testing conventions that isolate layers by testing domain entities as pure logic, application interactors with mocked ports, and infrastructure adapters with integration tests. This ensures strict separation of concerns across domain, application, and infrastructure layers.

When should I not use Clean Architecture for my FastAPI application?

Avoid Clean Architecture for small FastAPI applications or simple CRUD endpoints where the overhead of defining ports, adapters, and multiple layers outweighs the need for strict separation of concerns and long-term architectural scalability.