Best use case
clean-architecture is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Clean Architecture layered design. Use for maintainable code.
Teams using clean-architecture should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/clean-architecture/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How clean-architecture Compares
| Feature / Agent | clean-architecture | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Clean Architecture layered design. Use for maintainable code.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Clean Architecture
Clean Architecture, popularized by Robert C. Martin (Uncle Bob), separates software into layers to ensure independence from frameworks, databases, and UIs. The core principle is the **Dependency Rule**: source code dependencies can only point inwards.
## When to Use
- Building enterprise applications with complex business logic.
- Long-lived projects where frameworks/databases might change over time.
- Large teams requiring clear separation of concerns to work in parallel.
## Quick Start
```typescript
// 1. Entity (Enterprise Logic) - Inner Layer
class User {
constructor(
public id: string,
public name: string,
) {
if (name.length < 2) throw new Error("Name too short");
}
}
// 2. Use Case (Application Logic)
class CreateUserUseCase {
constructor(private userRepository: UserRepository) {} // Depends on interface
async execute(name: string): Promise<User> {
const user = new User(crypto.randomUUID(), name);
await this.userRepository.save(user);
return user;
}
}
// 3. Interface Adapter (Repository Interface)
interface UserRepository {
save(user: User): Promise<void>;
}
// 4. Frameworks & Drivers (Implementation) - Outer Layer
class SqlUserRepository implements UserRepository {
async save(user: User): Promise<void> {
await db.query("INSERT INTO users ...", [user.id, user.name]);
}
}
```
## Core Concepts
### The Dependency Rule
Inner layers (Entities) know nothing about outer layers (Controllers, Presenters). Outer layers depend on inner layers.
### Entities
Enterprise-wide business rules. These are the least likely to change when something external changes (e.g., page navigation security).
### Application Business Rules (Use Cases)
Orchestrate the flow of data to and from the entities. They contain the specific business rules of the application (e.g., "Create Order").
## Common Patterns
### Dependency Injection
The glue that makes Clean Architecture possible. Outer layers inject concrete implementations (e.g., `SqlUserRepository`) into inner layers (which expect `UserRepository` interface).
### DTOs (Data Transfer Objects)
Use simple objects (DTOs) to cross boundaries. Do not pass Entities to the UI or Database rows to the Use Case.
## Best Practices
**Do**:
- Define **Interfaces** in the layer that uses them (Interface Segregation).
- Test **Use Cases** in isolation using mocks for repositories.
- Keep **Frameworks** (React, NestJS, Spring) at the outermost layer.
**Don't**:
- Don't let **database entities** (ORM models) leak into the inner layers. Map them to domain Entities.
- Don't skip layers "for speed" (e.g., Controller calling DB directly) in complex apps.
## Troubleshooting
| Error | Cause | Solution |
| :--------------------- | :-------------------------------------- | :------------------------------------------------------------------------------ |
| `Circular Dependency` | Violating the dependency rule. | Use Dependency Inversion (Interfaces) to break the cycle. |
| `Boilerplate Overload` | Creating strict layers for simple CRUD. | Consider "Vertical Slice Architecture" or Modular Monolith for simpler domains. |
## References
- [The Clean Architecture Blog](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
- [Clean Architecture vs. Hexagonal](https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together/)Related Skills
template
Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].
zsh
Zsh shell with oh-my-zsh. Use for terminal shell.
zed
Zed high-performance collaborative editor. Use for fast editing.
xcode
Xcode Apple development IDE with simulators. Use for iOS/macOS development.
webstorm
WebStorm JavaScript IDE with debugging. Use for web development.
webpack
Webpack module bundler with loaders and plugins. Use for bundling.
warp
Warp modern terminal with AI. Use for terminal work.
vscode
Visual Studio Code editor with extensions and debugging. Use for code editing.
vite
Vite fast build tool with HMR. Use for modern frontend builds.
visual-studio
Visual Studio IDE for Windows with debugging and profiling. Use for .NET development.
vim
Vim text editor with motions, macros, and plugins. Use for terminal editing.
turbopack
Turbopack Rust-powered bundler. Use for fast builds.