name: 010110-clean-architecture
description: Clean Architecture layer ordering and strict inward dependency flow for web applications. Domain → Application → Infrastructure → Actions → UI.
license: MIT
Clean Architecture
Core Principle
Dependencies flow inward. Inner layers know nothing about outer layers.
Layer Order (Outer to Inner)
- UI/Components — Presentation components
- Hooks — React hooks (if applicable)
- App/Pages — Route pages and layouts
- Actions — Entry points (Server Actions, controllers)
- Infrastructure — External integrations (DB, cache, APIs)
- Application — Use cases and services
- Domain — Business entities (pure, no dependencies)
Layer Responsibilities
Domain Layer (Innermost)
- Pure business logic
- No external dependencies
- Entities, value objects, interfaces
- Zero imports from any other layer
Application Layer
- Use cases and service orchestration
- Depends only on domain interfaces (ports)
- DTOs for data transfer
- No framework or infrastructure imports
Infrastructure Layer
- Implements application interfaces (adapters)
- Database clients, external API clients, cache, file storage
- Vendor SDKs live here
- Cookie I/O, authentication providers
Actions Layer
- Entry points: Server Actions, API route handlers, CLI commands
- Validate authentication and authorization
- Call application services
- Thin — no business logic
UI Layer (Outermost)
- Components, pages, layouts
- Calls actions (not services/repositories directly)
- Read-only data fetching via dedicated hooks
Clean Architecture Checklist
- [ ] Domain has no imports from infrastructure or UI
- [ ] Application uses interfaces (ports), not concrete implementations
- [ ] Infrastructure implements application interfaces (adapters)
- [ ] Actions call services, not repositories directly
- [ ] All external dependencies are in infrastructure layer
- [ ] UI calls actions, not services or repositories
- [ ] Dependency direction: UI → Actions → App → Infra → Domain
- [ ] No circular dependencies between layers
Migration Pattern
For legacy modules without clear layering:
- Identify module boundaries
- Create domain entities first (pure types + logic)
- Extract infrastructure concerns
- Define application service interfaces
- Wire up actions as entry points
- Remove legacy code when migration is complete
Quick Reference
| Layer | Can import from | Cannot import from |
|---|
| Domain | Nothing | Everything |
| Application | Domain | Infrastructure, UI |
| Infrastructure | Domain | UI, Actions |
| Actions | App, Infra, Domain | UI |
| UI | Actions | Domain (directly), Infrastructure |
References