# reference clean architecture

> Implement Clean Architecture and hexagonal patterns to decouple business logic from frameworks and databases.

reference clean architecture is a free AI agent skill on Agensi by kktestdev, in APIs & Backend. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [kktestdev](https://www.agensi.io/creators/supakit-kitjanabumrungsak)
- Category: [APIs & Backend](https://www.agensi.io/skills/apis-backend)
- Uses: 3
- Version: 1.0
- Last updated: 2026-10-20
- Security: scan passed (2026-10-20); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/reference-clean-architecture
- Tags: api, code-review, python, typescript, backend

## About this skill

When backend services grow, they often collapse into "fat controllers" and spaghetti logic that is impossible to test or refactor. This skill provides a strict blueprint for implementing Clean Architecture, hexagonal design, and ports-and-adapters patterns to decouple business logic from frameworks and databases.

### What it does
- **Enforce Layering Rules** by defining strict dependency directions between Entities, Use Cases, Repositories, and Adapters.
- **Implement Unit of Work** patterns to manage database transactions at the use-case boundary rather than the repository level.
- **Design Boundary Enforcement** strategies using stack-specific tools like import-linter, ArchUnit, or eslint-plugin-boundaries to prevent architectural drift.
- **Scaffold New Services** with consistent naming conventions and directory structures for Python, TypeScript, Java, and Go.
- **Migrate Legacy Code** using the strangler-fig pattern to incrementally move logic out of monolithic files without risky rewrites.

### How it works
1. **Layer Assignment** starts by placing every new or existing file into one of the four architectural layers based on its imports and responsibilities.
2. **Boundary Tooling** setup involves configuring automated CI checks that fail if an inner layer (like an Entity) attempts to import an outer layer (like an ORM).
3. **Transaction Mapping** moves commit logic from repositories to a Unit of Work context manager called by the Use Case.
4. **Consistency Audit** verifies that naming conventions for Entities, Repositories, and DTOs match the domain model.

### Frameworks & tools
Language-agnostic logic with specific implementation guides for Python (FastAPI, SQLAlchemy), TypeScript (NestJS, TypeORM), Java (Spring Boot), and Go. Uses import-linter, dependency-cruiser, and ArchUnit for automated enforcement.

### Why this beats prompting it yourself
Most LLMs default to "active record" patterns and "fat controllers" because that is what appears most in public training data. This skill forces a professional, decoupled architecture that stays maintainable as the project scales, preventing the common trap of leaking database details into business rules.

### Use cases
- Decoupling a core business engine from a specific framework like FastAPI or Express.
- Adding a CLI or Cron entry point to a service that was originally built only for HTTP.
- Breaking down a 2000-line "fat router" file into testable, single-purpose use cases.
- Establishing architectural standards for a new monorepo that multiple teams will contribute to.

### Known limitations
Not suitable for small scripts, single-file CLI utilities, or throwaway prototypes where layering overhead exceeds the benefits. Requires manual configuration of third-party linter tools in CI.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the reference clean architecture skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### What specific architectural problems does this skill solve for my backend services?

This skill solves the 'spaghetti code' problem by enforcing strict separation between business rules and external tools like databases or APIs, making your codebase significantly easier to test, maintain, and swap out frameworks later.

### Which programming languages and frameworks are compatible with this architectural blueprint?

The skill provides implementation guides for Python (FastAPI), TypeScript (NestJS), Java (Spring Boot), and Go, and it can be adapted to any language that supports object-oriented or functional programming patterns.

### How does this skill prevent my architecture from reverting to 'fat controllers' over time?

Unlike general prompts that often default to simple 'Active Record' patterns, this skill is specifically tuned to resist architectural drift by configuring automated enforcement tools like ArchUnit or import-linter in your CI/CD pipeline.

### What assets are included in the purchase of the 'reference clean architecture' skill?

You will receive a complete set of architectural templates, directory structure blueprints, configuration files for boundary-enforcement tools, and step-by-step migration strategies for legacy code.

### Are there any manual setup steps required outside of the AI agent's output?

While this skill handles the logic and structure, you will need to manually install and configure the recommended third-party linting tools (such as dependency-cruiser or ArchUnit) within your specific environment to enable automated enforcement.

### When should I avoid using this specific architectural pattern?

This skill is designed for complex, long-lived backend services; it is not recommended for simple scripts, prototypes, or single-purpose CLI tools where the overhead of multiple layers would outweigh the benefits.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
