agentleFS
ai-enhanced-engineerai-enhanced-engineer/aiee-skills/skills/arch-ddd/SKILL.md

arch-ddd

Skill4 starsChanged 5 months agoMITView on GitHub

Tactical DDD patterns for clean Python architecture including Domain Model, Repository, Service Layer, Unit of Work, and Aggregates. Use for backend architecture decisions, implementing data access layers, separating business logic from infrastructure, or reviewing code separation.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When deciding where to place new features, domain ownership typically outweighs infrastructure convenience.

    line 79

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Domain-Driven Architecture

Architectural patterns for building maintainable Python applications with clean separation between business logic and infrastructure.

Core Principle

"Behavior should drive storage, not the reverse." Focus on what the system does, not just its data model.

The Four Pillars

1. Domain Model Pattern

The heart of your application - pure business logic, no infrastructure dependencies.

  • Entities: Objects with long-lived identity (User, Order)
  • Value Objects: Immutable, defined by attributes (Money, Address)
  • Domain Services: Logic spanning multiple entities

2. Repository Pattern

Abstraction over persistent storage with simple interface.

  • Decouple domain from data access
  • Enable testing with fake implementations
  • Hide persistence complexity

3. Service Layer Pattern

Orchestrates use cases and defines application boundaries.

  • Thin orchestration, not business logic
  • Handles transaction boundaries
  • Clear API for use cases

4. Unit of Work Pattern

Atomic operations and transaction lifecycle management.

  • Explicit transaction boundaries
  • Single entry point to repositories
  • Ensures consistency

Aggregate Pattern

Consistency boundaries - clusters of objects that must remain consistent together.

  • One aggregate = one repository
  • Modify one aggregate per transaction — spanning several in one transaction couples their consistency boundaries and complicates rollback
  • Reference other aggregates by ID, not object reference — cross-boundary object references trigger unintended cascade loads

The Dependency Rule

Dependencies point inward:

Entrypoints → Service Layer → Domain Model
     ↓              ↓
  Adapters ← ← ← ← ←

When to Apply

ScenarioPattern
Complex business rulesDomain Model
Multiple data sourcesRepository
Multiple entry pointsService Layer
Transaction managementUnit of Work
Complex invariantsAggregates

Multi-Service Architecture

Service Placement Decision Framework

When deciding where to place new features, domain ownership typically outweighs infrastructure convenience.

Decision criteria (priority order):

  1. Domain Ownership - Which service owns the business capability?
  2. Data Ownership - Which service owns the authoritative data?
  3. Infrastructure Reuse - Which service has needed infrastructure already?
  4. Deployment Coupling - Which choice minimizes cross-service deployments?

Example:

OptionDomainDataInfrastructureDecision
gateway-serviceNo (real-time)NoYes (has DB)Reject
migrations-serviceNo (schemas)NoYes (has batch)Reject
analytics-serviceYes (analytics)Yes (owns data)No (needs new)Accept

Trade-off: Infrastructure setup is one-time cost; wrong service boundaries compound over time.

Aggregate Write Boundaries — Client Side

Splitting an aggregate root + children across two requests re-introduces the failure class the boundary prevents: failed child → orphaned parent; retry without checking → duplicate parent. Prefer the single transactional nested-create endpoint. Verify the contract exists before assuming split endpoints are required; a retry id-guard treats the symptom, not the disease.

See reference.md § "Aggregate Write Boundaries — Client Side" for failure modes and retry-guard analysis. See arch-decision-records § "API Consumption Patterns" for the client-side consumption rule.

See reference.md for detailed explanations and examples.md for implementations.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.