Python Clean Architecture

Python Clean Architecture is a skill for Claude Code from MKToronto/python-clean-architecture. It costs 112 tokens per session (4,213 once invoked), scanned A, original, MIT.

A set of design and coding guidelines for Python projects built with FastAPI, a framework for creating web APIs. It uses Clean Architecture, which separates web requests, application logic, and database access.

In plain words
What is it for?
Use it to scaffold or refactor FastAPI projects, add endpoints, routers, operations, repositories, and models, and apply dependency injection and interface-based design.
Why use it?
It helps keep code easier to test, change, and extend by reducing unnecessary dependencies between its parts.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: mentions Claude Code.

Part of the python-clean-architecture plugin — 1 skill, 13 commands shipped together

Good fit Use it to scaffold or refactor FastAPI projects, add endpoints, routers, operations, repositories, and models, and apply dependency injection and interface-based design.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/mktoronto/python-clean-architecture/clean-architecture
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add MKToronto/python-clean-architecture --skill clean-architecture
Clone the repo
git clone --depth 1 https://github.com/MKToronto/python-clean-architecture

Made for: Claude Code.

Or install python-clean-architecture, the plugin that ships this one along with the rest of its 1 skill, 13 commands.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for Python Clean Architecture

README.md
[![agentmods](https://agentmods.dev/badge/skills/mktoronto/python-clean-architecture/clean-architecture/github.svg)](https://agentmods.dev/skills/mktoronto/python-clean-architecture/clean-architecture)
Your own site
<a href="https://agentmods.dev/skills/mktoronto/python-clean-architecture/clean-architecture"><img src="https://agentmods.dev/badge/skills/mktoronto/python-clean-architecture/clean-architecture/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for Python Clean Architecture

Your own site · 80×15
<a href="https://agentmods.dev/skills/mktoronto/python-clean-architecture/clean-architecture"><img src="https://agentmods.dev/badge/skills/mktoronto/python-clean-architecture/clean-architecture.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 112 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,213 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00112 $0.04213
Opus 5.5 $0.00045 $0.01685
Sonnet 5.5 $0.00022 $0.00843
Haiku 4.5 $0.00011 $0.00421

Measured 1mo ago against content hash 03fa5fe8f5ed, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

Python Clean Architecture scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

The scan reads SKILL.md. This mod also ships 21 executable files (examples/fastapi-hotel-api/db/__init__.py, examples/fastapi-hotel-api/db/database.py, examples/fastapi-hotel-api/db/db_interface.py, …), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/clean-architecture/SKILL.md · 270 lines

How it starts

The opening of the file, as written. The whole thing — 270 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Python Clean Architecture

Provide Clean Architecture guidance for Python projects, specifically FastAPI APIs. Based on seven core design principles, Pythonic implementations of classic patterns, and a three-layer architecture (Routers → Operations → Database).

Attribution: The principles, patterns, and architectural approach in this skill are inspired by and synthesized from Arjan Codes' courses: The Software Designer Mindset, Pythonic Patterns, and Complete Extension. The specific Pythonic framing (Protocol-based DI, functional pattern progression, three-layer FastAPI architecture) originates from his teaching. This plugin distills those principles into actionable guidance for Claude Code — it is not a reproduction of course content. See also: github.com/arjancodes | youtube.com/arjancodes.

When to Apply

  • Scaffolding new FastAPI projects with clean separation of concerns
  • Refactoring existing Python code to reduce coupling and increase cohesion
  • Adding new components (endpoints, operations, repositories, models)
  • Reviewing code for design quality and Pythonic idiom adherence
  • Making code testable through dependency injection and Protocol-based abstractions

Core Architecture: Three Layers

Every FastAPI project follows a strict three-layer dependency flow:

Routers (API layer)  →  Operations (business logic)  →  Database (persistence)

Each layer depends ONLY on the layer below it. Never skip layers.

Layer Responsibilities

Routers — HTTP interface. Accept requests, call operations, return responses. No business logic. Act as the composition root where concrete implementations are injected.

Operations — Business logic. Accept a DataInterface (Protocol) parameter for data access. Compute derived values, enforce rules, orchestrate workflows. Never import database modules directly.

Database — Persistence. Implement the DataInterface Protocol using SQLAlchemy, file storage, or any backend. Expose read_by_id, read_all, create, update, delete methods. Return DataObject = dict[str, Any] to decouple from ORM models.

Read the full file on GitHub · 270 lines

Files

What ships with it

60 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 270 lines · 112 tokens per session scan A 03fa5fe8f5ed

Subscribe to this mod's changes

Python Clean Architecture is a skill published in the GitHub repository MKToronto/python-clean-architecture (9 stars, last pushed 4mo ago), licensed MIT. It adds 112 tokens to every session and 4,213 once invoked, about $0.0004 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

python-patterns

Python backend patterns: layered architecture, async I/O, dependency injection, repository/service separation. TRIGGER when: creating routes, models, schemas, or services in a Python backend. SKIP: REST contract design (use api-design); schema/index tuning (use database-optimization). (Examples: FastAPI + SQLAlchemy +…

komluk/scaffolding · 73 tokens

python-backend

Production Python async patterns including asyncio TaskGroup, FastAPI dependency injection and middleware, SQLAlchemy 2.0 async sessions, and database connection pool tuning. Python 3.11+ runtime concerns such as ExceptionGroup, cancellation semantics, and session rollback. Use when building async services, wiring…

yonatangross/orchestkit · 82 tokens

cloudflare-workers-multi-lang

Multi-language Workers development with Rust, Python, and WebAssembly. Use when building Workers in languages other than JavaScript/TypeScript, or when integrating WASM modules for performance-critical code.

secondsky/claude-skills · 45 tokens

functions-development

Build serverless Go or Python functions for Falcon Foundry apps. TRIGGER when user asks to "create a function", "write a serverless function", "build backend logic", runs foundry functions create, or needs help with FDK handler patterns, function testing, or collection integration from functions. Also TRIGGER when…

CrowdStrike/foundry-skills · 195 tokens

python-services

Python patterns for CLI tools, async parallelism, and backend services. Use when building CLI apps, async/parallel Python, FastAPI services, background jobs, or configuring Python project tooling (uv, ruff, ty).

iliaal/whetstone · 48 tokens

litestar

Auto-activate for Litestar, Controller, Router, @get/@post, FromPath, MsgspecDTO, OpenAPIConfig, Provide, FromDishka, Guard, ASGIMiddleware, HTTPException, ChannelsPlugin, or WebSocket. Not for standalone libs.

litestar-org/litestar-skills · 58 tokens