Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/content/docs/graphql/explanation/architecture.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar:

import { Aside } from '@astrojs/starlight/components';

This solution is loosely based on Clean Architecture. It's by no means perfect, so we prefer to call it **Lean Mean Clean Architecture**. The inspiration is [Jason Taylor's Clean Architecture template](https://github.com/jasontaylordev/CleanArchitecture), with some ideas taken further and others scaled back.
This solution is loosely based on Clean Architecture. It's by no means perfect, so we prefer to call it **Lean Mean Clean Architecture**. The inspiration is [Jason Taylor's Clean Architecture template](https://github.com/jasontaylordev/CleanArchitecture), with some ideas taken further and others scaled back. [Not your uncle's Clean](/not-your-uncles-clean/) lays it side by side with textbook Clean Architecture, and explains how it ended up this way.

## Dependencies point inwards

Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/lambda/explanation/architecture.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar:

import { Aside } from '@astrojs/starlight/components';

This solution is loosely based on Clean Architecture. It's by no means perfect, so we prefer to call it **Lean Mean Clean Architecture**. The inspiration is [Jason Taylor's Clean Architecture template](https://github.com/jasontaylordev/CleanArchitecture), with some ideas taken further and others scaled back.
This solution is loosely based on Clean Architecture. It's by no means perfect, so we prefer to call it **Lean Mean Clean Architecture**. The inspiration is [Jason Taylor's Clean Architecture template](https://github.com/jasontaylordev/CleanArchitecture), with some ideas taken further and others scaled back. [Not your uncle's Clean](/not-your-uncles-clean/) lays it side by side with textbook Clean Architecture, and explains how it ended up this way.

## Dependencies point inwards

Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/mcp/explanation/architecture.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar:

import { Aside } from '@astrojs/starlight/components';

This solution is loosely based on Clean Architecture. It's by no means perfect, so we prefer to call it **Lean Mean Clean Architecture**. The inspiration is [Jason Taylor's Clean Architecture template](https://github.com/jasontaylordev/CleanArchitecture), with some ideas taken further and others scaled back.
This solution is loosely based on Clean Architecture. It's by no means perfect, so we prefer to call it **Lean Mean Clean Architecture**. The inspiration is [Jason Taylor's Clean Architecture template](https://github.com/jasontaylordev/CleanArchitecture), with some ideas taken further and others scaled back. [Not your uncle's Clean](/not-your-uncles-clean/) lays it side by side with textbook Clean Architecture, and explains how it ended up this way.

## Dependencies point inwards

Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/minimalapi/explanation/architecture.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar:

import { Aside } from '@astrojs/starlight/components';

This solution is loosely based on Clean Architecture. It's by no means perfect, so we prefer to call it **Lean Mean Clean Architecture**. The inspiration is [Jason Taylor's Clean Architecture template](https://github.com/jasontaylordev/CleanArchitecture), with some ideas taken further and others scaled back.
This solution is loosely based on Clean Architecture. It's by no means perfect, so we prefer to call it **Lean Mean Clean Architecture**. The inspiration is [Jason Taylor's Clean Architecture template](https://github.com/jasontaylordev/CleanArchitecture), with some ideas taken further and others scaled back. [Not your uncle's Clean](/not-your-uncles-clean/) lays it side by side with textbook Clean Architecture, and explains how it ended up this way.

## Dependencies point inwards

Expand Down
166 changes: 166 additions & 0 deletions src/content/docs/not-your-uncles-clean.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
---
title: "Not your uncle's Clean"
description: "How Lean Mean Clean Architecture compares with textbook Clean Architecture, how it got this way, and the seams we kept on purpose."
template: splash
---

The five templates are loosely based on Clean Architecture, the one Uncle Bob made famous. "Loosely" is doing a lot of work in that sentence. It's not as clean as your uncle's, and that's on purpose.

## Where it came from

This didn't start as an exercise in Clean Architecture. It started with one question: what's a good way to put different front doors on what is basically the same system? An HTTP API, a GraphQL schema, an MCP server for AI clients and an AWS Lambda function, all serving the same movie reviews with the same rules.

What popped out was one shared middle and a thin outside you can swap. It looked a lot like Clean Architecture, minus the parts that didn't earn their keep. We call it Lean Mean Clean Architecture, or clean-ish when nobody's listening.

## Side by side

<svg class="cl-diagram cl-diagram-wide" viewBox="0 0 760 440" role="img" aria-label="Textbook Clean Architecture has four stacked projects: Web, Application, Domain and Infrastructure, with an interface for most classes. Lean Mean Clean has five front doors, one per template, over one shared Application project and one Infrastructure project, with three interfaces in total.">
<defs>
<marker id="cl-uncle-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0,0 L10,5 L0,10 z" fill="#6E9A43" /></marker>
</defs>
<text x="20" y="26" font-size="15" font-weight="800" letter-spacing="1.5" fill="currentColor">TEXTBOOK</text>
<g fill="none" stroke="currentColor" stroke-opacity="0.45" stroke-width="2" stroke-dasharray="6 5">
<rect x="20" y="44" width="330" height="70" rx="14" />
<rect x="20" y="136" width="330" height="70" rx="14" />
<rect x="20" y="228" width="330" height="70" rx="14" />
<rect x="20" y="320" width="330" height="70" rx="14" />
</g>
<g fill="currentColor">
<text x="40" y="72" font-size="15" font-weight="700">Web</text>
<text x="40" y="95" font-size="13" opacity="0.75">Controllers, DTOs, mapping profiles</text>
<text x="40" y="164" font-size="15" font-weight="700">Application</text>
<text x="40" y="187" font-size="13" opacity="0.75">IThingService, IDateTime, IUnitOfWork...</text>
<text x="40" y="256" font-size="15" font-weight="700">Domain</text>
<text x="40" y="279" font-size="13" opacity="0.75">Value objects, events, specifications</text>
<text x="40" y="348" font-size="15" font-weight="700">Infrastructure</text>
<text x="40" y="371" font-size="13" opacity="0.75">IRepository&lt;T&gt; and a unit of work on DbSet&lt;T&gt;</text>
</g>
<g stroke="#6E9A43" stroke-width="3" marker-end="url(#cl-uncle-arrow)">
<line x1="185" y1="116" x2="185" y2="132" />
<line x1="185" y1="208" x2="185" y2="224" />
<line x1="185" y1="318" x2="185" y2="302" />
</g>
<text x="20" y="424" font-size="13" fill="currentColor" opacity="0.75">Four or five projects, an interface per class</text>
<g transform="translate(390 0)">
<text x="20" y="26" font-size="15" font-weight="800" letter-spacing="1.5" fill="currentColor">LEAN MEAN CLEAN</text>
<g font-size="11" font-weight="700" text-anchor="middle" fill="#0B132A">
<rect x="20" y="44" width="62" height="52" rx="12" fill="#10B981" /><text x="51" y="74">Minimal</text>
<rect x="87" y="44" width="62" height="52" rx="12" fill="#8B5CF6" /><text x="118" y="74">MCP</text>
<rect x="154" y="44" width="62" height="52" rx="12" fill="#EC4899" /><text x="185" y="74">GraphQL</text>
<rect x="221" y="44" width="62" height="52" rx="12" fill="#3B82F6" /><text x="252" y="74">Web API</text>
<rect x="288" y="44" width="62" height="52" rx="12" fill="#F59E0B" /><text x="319" y="74">Lambda</text>
</g>
<text x="20" y="118" font-size="13" fill="currentColor" opacity="0.75">Presentation: one front door per template</text>
<rect x="20" y="136" width="330" height="162" rx="14" fill="#6E9A43" />
<g fill="#FBFAF8">
<text x="40" y="166" font-size="15" font-weight="700">Application, the same in all five</text>
<text x="40" y="194" font-size="13">Feature folders, one folder per use case</text>
<text x="40" y="216" font-size="13">Command, handler and validator together</text>
<text x="40" y="238" font-size="13">Plain records, no Domain project</text>
<text x="40" y="260" font-size="13">No services, TimeProvider for time</text>
<text x="40" y="282" font-size="13">Three repository interfaces</text>
</g>
<rect x="20" y="320" width="330" height="70" rx="14" fill="#FBFAF8" stroke="#0B132A" stroke-opacity="0.2" />
<g fill="#0B132A">
<text x="40" y="348" font-size="15" font-weight="700">Infrastructure, the same in all five</text>
<text x="40" y="371" font-size="13" opacity="0.8">One class, LINQ straight on the DbContext</text>
</g>
<g stroke="#6E9A43" stroke-width="3" marker-end="url(#cl-uncle-arrow)">
<line x1="320" y1="108" x2="320" y2="132" />
<line x1="320" y1="318" x2="320" y2="302" />
</g>
<text x="20" y="424" font-size="13" fill="currentColor" opacity="0.75">Three projects, three interfaces</text>
</g>
</svg>

<svg class="cl-diagram cl-diagram-narrow" viewBox="0 0 370 880" role="img" aria-label="Textbook Clean Architecture has four stacked projects: Web, Application, Domain and Infrastructure, with an interface for most classes. Lean Mean Clean has five front doors, one per template, over one shared Application project and one Infrastructure project, with three interfaces in total.">
<defs>
<marker id="cl-uncle-arrow-narrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0,0 L10,5 L0,10 z" fill="#6E9A43" /></marker>
</defs>
<text x="20" y="26" font-size="15" font-weight="800" letter-spacing="1.5" fill="currentColor">TEXTBOOK</text>
<g fill="none" stroke="currentColor" stroke-opacity="0.45" stroke-width="2" stroke-dasharray="6 5">
<rect x="20" y="44" width="330" height="70" rx="14" />
<rect x="20" y="136" width="330" height="70" rx="14" />
<rect x="20" y="228" width="330" height="70" rx="14" />
<rect x="20" y="320" width="330" height="70" rx="14" />
</g>
<g fill="currentColor">
<text x="40" y="72" font-size="15" font-weight="700">Web</text>
<text x="40" y="95" font-size="13" opacity="0.75">Controllers, DTOs, mapping profiles</text>
<text x="40" y="164" font-size="15" font-weight="700">Application</text>
<text x="40" y="187" font-size="13" opacity="0.75">IThingService, IDateTime, IUnitOfWork...</text>
<text x="40" y="256" font-size="15" font-weight="700">Domain</text>
<text x="40" y="279" font-size="13" opacity="0.75">Value objects, events, specifications</text>
<text x="40" y="348" font-size="15" font-weight="700">Infrastructure</text>
<text x="40" y="371" font-size="13" opacity="0.75">IRepository&lt;T&gt; and a unit of work on DbSet&lt;T&gt;</text>
</g>
<g stroke="#6E9A43" stroke-width="3" marker-end="url(#cl-uncle-arrow-narrow)">
<line x1="185" y1="116" x2="185" y2="132" />
<line x1="185" y1="208" x2="185" y2="224" />
<line x1="185" y1="318" x2="185" y2="302" />
</g>
<text x="20" y="424" font-size="13" fill="currentColor" opacity="0.75">Four or five projects, an interface per class</text>
<g transform="translate(0 440)">
<text x="20" y="26" font-size="15" font-weight="800" letter-spacing="1.5" fill="currentColor">LEAN MEAN CLEAN</text>
<g font-size="11" font-weight="700" text-anchor="middle" fill="#0B132A">
<rect x="20" y="44" width="62" height="52" rx="12" fill="#10B981" /><text x="51" y="74">Minimal</text>
<rect x="87" y="44" width="62" height="52" rx="12" fill="#8B5CF6" /><text x="118" y="74">MCP</text>
<rect x="154" y="44" width="62" height="52" rx="12" fill="#EC4899" /><text x="185" y="74">GraphQL</text>
<rect x="221" y="44" width="62" height="52" rx="12" fill="#3B82F6" /><text x="252" y="74">Web API</text>
<rect x="288" y="44" width="62" height="52" rx="12" fill="#F59E0B" /><text x="319" y="74">Lambda</text>
</g>
<text x="20" y="118" font-size="13" fill="currentColor" opacity="0.75">Presentation: one front door per template</text>
<rect x="20" y="136" width="330" height="162" rx="14" fill="#6E9A43" />
<g fill="#FBFAF8">
<text x="40" y="166" font-size="15" font-weight="700">Application, the same in all five</text>
<text x="40" y="194" font-size="13">Feature folders, one folder per use case</text>
<text x="40" y="216" font-size="13">Command, handler and validator together</text>
<text x="40" y="238" font-size="13">Plain records, no Domain project</text>
<text x="40" y="260" font-size="13">No services, TimeProvider for time</text>
<text x="40" y="282" font-size="13">Three repository interfaces</text>
</g>
<rect x="20" y="320" width="330" height="70" rx="14" fill="#FBFAF8" stroke="#0B132A" stroke-opacity="0.2" />
<g fill="#0B132A">
<text x="40" y="348" font-size="15" font-weight="700">Infrastructure, the same in all five</text>
<text x="40" y="371" font-size="13" opacity="0.8">One class, LINQ straight on the DbContext</text>
</g>
<g stroke="#6E9A43" stroke-width="3" marker-end="url(#cl-uncle-arrow-narrow)">
<line x1="320" y1="108" x2="320" y2="132" />
<line x1="320" y1="318" x2="320" y2="302" />
</g>
<text x="20" y="424" font-size="13" fill="currentColor" opacity="0.75">Three projects, three interfaces</text>
</g>
</svg>

## What's different

| | Textbook | Lean Mean Clean | Why |
| --- | --- | --- | --- |
| Projects | Web, Application, Domain, Infrastructure, sometimes a shared kernel | Presentation, Application, Infrastructure | Fewer "does this go in Domain or Application?" debates. |
| Folders | By layer and type: `Services`, `Interfaces`, `Dtos` | By feature, then use case: `Reviews/Commands/CreateReview` | Everything one change touches sits in one folder. |
| Entities | A rich domain model in its own project | Plain records next to the use cases that return them | The rules live in validators and handlers, and there isn't enough domain to fill a project. |
| Services | An `IThingService` and `ThingService` for each area | None | Each use case has one handler, and the handler is the service. |
| Interfaces | One for nearly every class | Three, all repository interfaces | See the seams below. |
| Data access | A generic repository and unit of work wrapped around `DbSet<T>` | One class implements all three repository interfaces with LINQ on the DbContext | EF Core already is a repository and a unit of work. |
| Time | An `IDateTime` of your own | `TimeProvider` | It's been in the box since .NET 8. |
| Dependency rule | Presentation never references Infrastructure | Presentation references it to wire up dependency injection, and everything else in Infrastructure is `internal` | Saves a project whose only job is to call two methods. |

## The seams we kept

Some abstractions did earn their keep. Here's what's left, and why.

- **Three repository interfaces, one implementation.** Yes, that's the bit critics point at, and they're not wrong about most apps. These stay because Application is identical in five templates and has no idea which front door it's behind, and because handler tests run against NSubstitute instead of a database.
- **Separate database models.** Infrastructure keeps its own EF Core models and maps them to the Application records with [Mapperly](https://mapperly.riok.app), so navigation properties and database config never leak into what clients see. It costs a mapper, and Mapperly writes that at build time.
- **[Mediator](https://github.com/martinothamar/Mediator).** Every front door sends the same commands and queries through one pipeline, so validation, logging and a trace span per use case are written once. It's free and source-generated, so there's no reflection on the way through.

## When to fold it away

If you'll only ever have one front door, you could fold Application and Infrastructure into the host, drop the repository interfaces and query the DbContext straight from the handlers. That's a perfectly good shape. These templates show the version with five front doors, so they keep the seam.

Pick the template with the front door you need, and delete whatever you don't. We won't take it personally.

- [Clean Minimal API](/minimalapi/explanation/architecture/)
- [Clean Model Context Protocol](/mcp/explanation/architecture/)
- [Clean GraphQL API](/graphql/explanation/architecture/)
- [Clean Web API](/webapi/explanation/architecture/)
- [Clean Lambda Function](/lambda/explanation/architecture/)
2 changes: 1 addition & 1 deletion src/content/docs/webapi/explanation/architecture.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar:

import { Aside } from '@astrojs/starlight/components';

This solution is loosely based on Clean Architecture. It's by no means perfect, so we prefer to call it **Lean Mean Clean Architecture**. The inspiration is [Jason Taylor's Clean Architecture template](https://github.com/jasontaylordev/CleanArchitecture), with some ideas taken further and others scaled back.
This solution is loosely based on Clean Architecture. It's by no means perfect, so we prefer to call it **Lean Mean Clean Architecture**. The inspiration is [Jason Taylor's Clean Architecture template](https://github.com/jasontaylordev/CleanArchitecture), with some ideas taken further and others scaled back. [Not your uncle's Clean](/not-your-uncles-clean/) lays it side by side with textbook Clean Architecture, and explains how it ended up this way.

## Dependencies point inwards

Expand Down
15 changes: 15 additions & 0 deletions src/styles/docs/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,18 @@ pre {
font-family: var(--lmca-font-display);
color: var(--sl-color-white);
}

/* A wide diagram with a stacked twin for narrow screens, so its labels stay readable on a phone. */
.cl-diagram-narrow {
display: none;
}

@media (max-width: 40rem) {
.cl-diagram-wide {
display: none;
}

.cl-diagram-narrow {
display: block;
}
}