AGENT SKILL
clean-architecture
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-07-20
- Stars
- ★ 0
- Forks
- 0
03 SKILL.md 正文
Clean Architecture Skill
Layer Hierarchy
utils/ → config/ → core/ → infrastructure/ → ai/ → application/ → presentation/
Inner layers have ZERO knowledge of outer layers. Outer layers depend on inner layers through imports.
Dependency Rule
The fundamental invariant: source-code dependencies always point inward.
| Layer | Location | Responsibility | Dependencies |
|---|---|---|---|
utils/ |
backend/src/<project_slug>/utils/ |
Enums, validators, types, retry policies | stdlib only |
config/ |
backend/src/<project_slug>/config/ |
Frozen dataclass configurations | utils/ |
core/ |
backend/src/<project_slug>/core/ |
ORM models, Pydantic models, registry | utils/, config/ |
infrastructure/ |
backend/src/<project_slug>/infrastructure/ |
Azure OpenAI, external API clients | config/, utils/, core/ |
ai/ |
backend/src/<project_slug>/ai/ |
RAG pipeline, embeddings, LangGraph | config/, utils/, core/ |
application/ |
backend/src/<project_slug>/application/ |
Use cases, orchestration, services | ai/, infrastructure/, core/, config/, utils/ |
presentation/ |
backend/src/<project_slug>/presentation/ |
FastAPI routes, middleware, DI | ALL layers |
Boundary Rules
Config Layer
- ALL config objects:
@dataclass(frozen=True, slots=True) - Config values from Azure Key Vault or environment variables
- Never hardcode connection strings or secrets
Core Layer
- ORM: SQLAlchemy 2.0+ with
Mappedandmapped_column - Pydantic:
Annotated[type, Field(...)]withdescriptionandexamples - Registry:
registry_constants.pygenerated fromregistry/naming_registry.json - Never hardcode field names — always use registry constants
DI Wiring
presentation/api/dependencies.pyis the SINGLE wiring point- Application services receive dependencies through constructor injection
- Never instantiate services directly in route handlers
Adding a New Layer Component
- Create module in the correct layer directory
- Import only from allowed layers (see table above)
- Add type hints, docstrings, and registry constants
- Wire dependencies in
dependencies.pyif needed - Create tests in
tests/unit/mirroring source structure
Common Violations
| Violation | Example | Fix |
|---|---|---|
| Outward import | utils/ imports from application/ |
Move shared code to utils/ |
| Circular import | A ↔ B | Extract shared interface to lower layer |
| Hardcoded DI | service = MyService() in route |
Use Depends() from dependencies.py |
| Mutable config | @dataclass without frozen=True |
Add frozen=True, slots=True |
| Hardcoded names | "claim_id" string literal |
Use ORM.Claim.id from registry |
04 同仓库更多 Skills
ui-ux-frontend
Frontend UX, accessibility, responsive layout, and Storybook interaction quality standards.
★ 0
testing-conventions
暂无简介
★ 0
tdd
暂无简介
★ 0
shadcn-ui
shadcn/ui component conventions and composition patterns
★ 0
sdd
暂无简介
★ 0
quality-gate
暂无简介
★ 0