deno-ddd
Domain-Driven Design patterns and architecture for Deno TypeScript applications. Use when building complex business logic, implementing bounded contexts, or structuring large-scale Deno applications with clear separation of concerns.
What this skill does
# Domain-Driven Design in Deno
## When to Use This Skill
Use this skill when:
- Building applications with complex business logic
- Implementing hexagonal/clean architecture in Deno
- Structuring large-scale Deno applications
- Separating domain logic from infrastructure
- Working with bounded contexts and aggregates
- Need clear separation between layers
**Prerequisites:** Always read `deno-core.md` first for essential Deno configuration.
---
## Project Philosophy
> **Clean, Modern TypeScript**: Embrace Deno's vision of secure, modern JavaScript/TypeScript development without the baggage of Node.js legacy patterns.
> **Domain-Driven Design**: Follow DDD principles with clear separation between domain logic, application services, and infrastructure concerns.
> **TypeScript-First**: Leverage TypeScript's type system for safety and developer experience. No `any` types in production code.
---
## Core DDD Principles
### Ubiquitous Language
- Use domain terminology consistently in code, docs, and conversations
- Type names, method names, and variables should match business concepts
- Avoid technical jargon in domain layer
### Bounded Contexts
- Each context has its own models and language
- Clear boundaries between contexts
- Explicit translation between contexts
### Layered Architecture
1. **Domain Layer** - Pure business logic, no dependencies
2. **Application Layer** - Use cases, orchestration
3. **Infrastructure Layer** - External services, databases, APIs
4. **API Layer** - HTTP handlers, CLI, GraphQL resolvers
---
## Project Structure
### Recommended Directory Layout
```
src/
├── domain/ # Domain layer - core business logic
│ ├── entities/ # Domain entities (Memory, User, Order)
│ │ ├── user.ts
│ │ └── order.ts
│ ├── value-objects/ # Immutable values (Email, Money, Status)
│ │ ├── email.ts
│ │ ├── money.ts
│ │ └── order-status.ts
│ ├── aggregates/ # Consistency boundaries
│ │ └── order-aggregate.ts
│ ├── repositories/ # Repository interfaces (ports)
│ │ ├── user-repository.ts
│ │ └── order-repository.ts
│ ├── services/ # Domain services
│ │ └── pricing-service.ts
│ ├── events/ # Domain events
│ │ └── order-created.ts
│ └── errors/ # Domain-specific errors
│ ├── validation-error.ts
│ └── business-rule-error.ts
│
├── application/ # Application layer - use cases
│ ├── use-cases/ # Use case implementations
│ │ ├── create-order.ts
│ │ ├── update-user.ts
│ │ └── process-payment.ts
│ ├── services/ # Application services
│ ├── dto/ # Data transfer objects
│ │ ├── create-order-dto.ts
│ │ └── user-response-dto.ts
│ └── errors/ # Application-specific errors
│ ├── not-found-error.ts
│ └── unauthorized-error.ts
│
├── infrastructure/ # Infrastructure layer - technical details
│ ├── persistence/ # Database implementations
│ │ ├── postgres/
│ │ │ ├── user-repository-impl.ts
│ │ │ └── order-repository-impl.ts
│ │ └── migrations/
│ ├── external/ # External service integrations
│ │ ├── payment-gateway.ts
│ │ └── email-service.ts
│ ├── logging/ # Structured logging
│ │ └── logger.ts
│ ├── config/ # Configuration
│ │ └── database.ts
│ └── errors/ # Infrastructure errors
│ ├── database-error.ts
│ └── external-api-error.ts
│
├── web/ # Web/API layer - HTTP entry points
│ ├── controllers/ # Request handlers
│ │ ├── user-controller.ts
│ │ └── order-controller.ts
│ ├── middleware/ # HTTP middleware
│ │ ├── auth.ts
│ │ ├── validation.ts
│ │ ├── error-handler.ts
│ │ └── logging.ts
│ ├── routes/ # Route definitions
│ │ ├── user-routes.ts
│ │ └── order-routes.ts
│ └── server.ts # HTTP server setup
│
└── shared/ # Shared kernel
├── types/
│ └── result.ts
└── utils/
└── validation.ts
tests/
├── domain/ # Domain tests (unit)
│ ├── entities/
│ │ └── user.test.ts
│ └── value-objects/
│ └── email.test.ts
├── application/ # Application tests (integration)
│ └── use-cases/
│ └── create-order.test.ts
└── e2e/ # End-to-end tests
└── order-workflow.test.ts
```
### Import Map Configuration
Configure `deno.json` for clean imports across all layers:
```json
{
"imports": {
"@/": "./src/",
"@/domain/": "./src/domain/",
"@/application/": "./src/application/",
"@/infrastructure/": "./src/infrastructure/",
"@/web/": "./src/web/",
"@/shared/": "./src/shared/"
}
}
```
---
## Layer Dependencies
Understanding and enforcing layer dependencies is critical for maintaining a clean DDD architecture.
### Allowed Dependencies
- **`domain`** → (no external dependencies - pure business logic)
- **`application`** → `domain`
- **`infrastructure`** → `domain` + `application`
- **`web`** (or `api`) → `domain` + `application` + `infrastructure`
### Forbidden Dependencies
**NEVER allow these dependencies:**
- **`domain`** → `application`, `infrastructure`, `web`
- **`application`** → `infrastructure`, `web`
- **`infrastructure`** → `web`
### Dependency Flow Visualization
```
┌─────────────┐
│ web │ (HTTP handlers, routes, middleware)
└──────┬──────┘
│
┌──────▼──────┐
│infrastructure│ (Database, external APIs)
└──────┬──────┘
│
┌──────▼──────┐
│ application │ (Use cases, orchestration)
└──────┬──────┘
│
┌──────▼──────┐
│ domain │ (Entities, value objects, business rules)
└─────────────┘
```
**Key Principle:** Dependencies flow inward. Inner layers have no knowledge of outer layers.
---
## Domain Layer
### Entities
Entities have identity and lifecycle. Use classes with private constructors.
```typescript
// src/domain/entities/user.ts
import type { Email } from "@/domain/value-objects/email.ts";
import type { UserId } from "@/domain/value-objects/user-id.ts";
export class User {
private constructor(
private readonly id: UserId,
private name: string,
private email: Email,
private readonly createdAt: Date,
) {}
// Factory method - ensures valid construction
static create(name: string, email: Email): User {
if (name.trim().length === 0) {
throw new Error("User name cannot be empty");
}
return new User(
UserId.generate(),
name,
email,
new Date(),
);
}
// Reconstruct from persistence
static reconstitute(
id: UserId,
name: string,
email: Email,
createdAt: Date,
): User {
return new User(id, name, email, createdAt);
}
// Business logic methods
changeName(newName: string): void {
if (newName.trim().length === 0) {
throw new Error("User name cannot be empty");
}
this.name = newName;
}
// Getters
getId(): UserId { return this.id; }
getName(): string { return this.name; }
getEmail(): Email { return this.email; }
getCreatedAt(): Date { return this.createdAt; }
}
```
### Value Objects
Value objects have no identity, compared by value.
```typescript
// src/domain/value-objects/email.ts
export class Email {
private constructor(private readonly value: string) {}
static create(value: string): Email {
if (!Email.isValid(value)) {
throw new Error(`Invalid email: ${value}`);
}
return new Email(value.toLowerCase());
}
private static isValid(value: string): boolean {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(value);
}
getValue(): string { return this.value; }
equals(other: Email): boolean { return this.value === other.value; }
Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.