agentsclimarketplace

Clean architecture

Skill G1Joshi/Agent-Skills/skills/architecture/clean-architecture

Clean Architecture layered design. Use for maintainable code.From its SKILL.md

Install
npx -y skills add G1Joshi/Agent-Skills --skill clean-architecture

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 10 stars10 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

3.6 KB, 753 tokens by cl100k_base, as published. Nobody here has run it

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

// 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

ErrorCauseSolution
Circular DependencyViolating the dependency rule.Use Dependency Inversion (Interfaces) to break the cycle.
Boilerplate OverloadCreating strict layers for simple CRUD.Consider "Vertical Slice Architecture" or Modular Monolith for simpler domains.

References

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,851. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.