architecture-patterns

Applies Robota's architecture patterns — functional core/imperative shell, ports-and-adapters, and DI-based composition. Use when designing module boundaries, separating domain from infrastructure, or improving testability.

16 stars

Best use case

architecture-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Applies Robota's architecture patterns — functional core/imperative shell, ports-and-adapters, and DI-based composition. Use when designing module boundaries, separating domain from infrastructure, or improving testability.

Teams using architecture-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/architecture-patterns/SKILL.md --create-dirs "https://raw.githubusercontent.com/woojubb/robota/main/.agents/skills/architecture-patterns/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/architecture-patterns/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How architecture-patterns Compares

Feature / Agentarchitecture-patternsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Applies Robota's architecture patterns — functional core/imperative shell, ports-and-adapters, and DI-based composition. Use when designing module boundaries, separating domain from infrastructure, or improving testability.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Architecture Patterns

## Rule Anchor
- `AGENTS.md` > "Development Patterns"
- `AGENTS.md` > "Type System (Strict)"
- `AGENTS.md` > "Execution Safety"

## Use This Skill When
- Domain logic is mixed with API calls, storage, or logging.
- Building or refactoring class-based services.
- Reducing coupling between domain logic and infrastructure.
- Replacing infrastructure should not rewrite core business logic.
- Tests are slow because every case touches real side effects.

## Core Principles

### Functional Core, Imperative Shell
1. **Pure core**: business rules as pure functions (same input, same output).
2. **Thin shell**: perform I/O at the outer boundary only.
3. **Explicit data flow**: pass dependencies and inputs explicitly.
4. **Visible decisions**: keep side-effect decisions in the orchestration layer.

### Ports and Adapters (Hexagonal)
5. **Domain independence**: domain core depends on nothing external.
6. **Port interfaces**: define required capabilities as interfaces owned by core/application.
7. **Adapter implementations**: concrete technology lives in adapters only.
8. **Composition root**: wire ports to adapters at a single entry point.

### Dependency Injection and Composition
9. **Composition over inheritance**: prefer object composition.
10. **Constructor injection**: inject dependencies through constructors, not global imports.
11. **Narrow responsibilities**: keep class responsibilities explicit and focused.
12. **Strategy extension**: model extension points with interfaces and strategy objects.

## Layer Map
- **Domain**: entities, value objects, domain services, pure rules.
- **Application**: use cases orchestrating domain operations.
- **Ports**: interfaces for repositories, gateways, message buses.
- **Adapters**: implementations (SQL, HTTP, queue, file, SDK).
- **Shell**: thin orchestration — prepare data → call pure core → persist/output.

## Workflow
1. Identify the use case entrypoint (controller, handler, command).
2. Classify current responsibilities: domain logic vs I/O concerns.
3. Extract pure transformation rules into separate functions.
4. Define minimal interfaces for external collaborators (ports).
5. Move API/DB/time/random/logger access into boundary adapters.
6. Inject implementations via constructor defaults or factories.
7. Keep application service thin and explicit.
8. Wire dependencies only at composition root.
9. Test core with table-driven tests; test shell with integration tests.

## Reference Skeletons

### Functional Core + Imperative Shell
```ts
type TOrderDecision =
  | { approved: true }
  | { approved: false; reason: 'INVALID_TOTAL' | 'HIGH_RISK' };

function evaluateOrder(input: IOrderInput): TOrderDecision {
  if (input.total <= 0) return { approved: false, reason: 'INVALID_TOTAL' };
  if (input.riskScore > 80) return { approved: false, reason: 'HIGH_RISK' };
  return { approved: true };
}

async function processOrder(input: IOrderInput, deps: IProcessDeps): Promise<void> {
  const decision = evaluateOrder(input);
  await deps.repository.saveDecision(input.id, decision);
  if (!decision.approved) await deps.notifier.sendRejection(input.id, decision.reason);
}
```

### Constructor DI with Strategy
```ts
interface IUserRepository {
  save(user: IUser): Promise<void>;
}

interface IPasswordHasher {
  hash(password: string): Promise<string>;
}

class UserRegistrationService {
  constructor(
    private readonly repo: IUserRepository,
    private readonly hasher: IPasswordHasher
  ) {}

  async register(input: IRegisterInput): Promise<IUser> {
    const hashed = await this.hasher.hash(input.password);
    const user = { ...input, password: hashed };
    await this.repo.save(user);
    return user;
  }
}
```

## Checklist
- [ ] Business rules exist as pure functions.
- [ ] Side effects are performed only in boundary layer.
- [ ] Pure logic has no direct logger, DB, network, env access.
- [ ] Domain layer imports no infrastructure package.
- [ ] Ports are owned by core/application, not adapters.
- [ ] Adapters implement ports without leaking transport details.
- [ ] Composition root is the only place with concrete wiring.
- [ ] Class has one clear responsibility.
- [ ] External systems are abstracted behind interfaces.
- [ ] Constructor receives all required collaborators.
- [ ] Unit tests cover pure logic without mocks.
- [ ] Integration tests validate boundary wiring.

## Anti-Patterns
- Hidden I/O inside utility functions labeled as "pure".
- Passing framework objects deep into domain functions.
- Mixing orchestration and validation logic in one large function.
- "Hexagonal" folders with real logic still inside adapters.
- Adapter-driven interfaces that leak vendor details.
- Framework DTOs passed directly through domain models.
- Fat service classes that orchestrate everything.
- Inheritance chains for simple behavior reuse.
- Static/global state used as implicit dependency injection.
- Interface explosion without clear ownership or usage.

Related Skills

vercel-composition-patterns

16
from woojubb/robota

React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component libraries, or designing reusable APIs. Triggers on tasks involving compound components, render props, context providers, or component architecture. Includes React 19 API changes.

ddd-tactical-patterns

16
from woojubb/robota

Applies Domain-Driven Design tactical patterns (Aggregate, Bounded Context, Value Object, Domain Event) to structure domain models with clear transactional boundaries. Use when designing domain objects, deciding ownership, or separating contexts.

async-concurrency-patterns

16
from woojubb/robota

Manages concurrent async operations with execution limits, cancellation propagation, and backpressure in TypeScript. Use when running parallel tasks, coordinating multiple agents, or handling streaming responses with rate limits.

architecture-decision-records

16
from woojubb/robota

Records architectural decisions with context, alternatives, and consequences using the ADR format. Use when making or reviewing significant design choices that affect multiple modules or packages.

web-design-guidelines

16
from woojubb/robota

Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".

vitest-testing-strategy

16
from woojubb/robota

Defines a practical testing strategy for TypeScript and JavaScript using Vitest across unit, integration, and type-level tests. Use when adding features, refactoring, or preventing regressions with fast feedback loops.

version-management

16
from woojubb/robota

All packages must have the same version. Use changesets for coordinated version bumps. Never version packages independently.

vercel-react-native-skills

16
from woojubb/robota

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

vercel-react-best-practices

16
from woojubb/robota

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

user-request-gate

16
from woojubb/robota

Use immediately when the user requests any implementation, code change, feature addition, fix, or modification. Gates code writing behind a backlog draft document. Read-only exploration is always permitted.

type-boundary-and-ssot

16
from woojubb/robota

Applies Robota's preferred workflow for trust-boundary validation, strict typing, quality gates, and owner-based SSOT reuse. Use when adding or reviewing type contracts, boundary parsing, shared contract ownership, or running quality checks.

tdd-red-green-refactor

16
from woojubb/robota

Kent Beck's TDD workflow. Use when writing new code or modifying existing behavior. Enforces the Red-Green-Refactor cycle with small, verifiable steps.