| name | stack-architecture |
| version | 0.1.0 |
| description | Design stack-based systems using @outfitter/* packages. Use when planning new projects, choosing packages, designing handler architecture, or when "architecture", "design", "structure", "plan handlers", or "error taxonomy" are mentioned. |
| context | fork |
| agent | stacker |
| allowed-tools | Read Grep Glob |
Stack Architecture Design
Design transport-agnostic handler systems with proper Result types and error taxonomy.
Process
Step 1: Understand Requirements
Gather information about:
- Transport surfaces โ CLI, MCP, HTTP, or all?
- Domain operations โ What actions does the system perform?
- Failure modes โ What can go wrong? (maps to error taxonomy)
- External dependencies โ APIs, databases, file system?
Step 2: Design Handler Layer
For each domain operation:
- Define input type (Zod schema)
- Define output type
- Identify possible error types (from taxonomy)
- Write handler signature:
Handler<Input, Output, Error1 | Error2>
Example:
const CreateUserInputSchema = z.object({
email: z.string().email(),
name: z.string().min(1),
});
interface User {
id: string;
email: string;
name: string;
}
const createUser: Handler<unknown, User, ValidationError | ConflictError>;
Step 3: Map Errors to Taxonomy
Map domain errors to the 10 categories:
| Domain Error | Stack Category | Error Class |
|---|
| Not found | not_found | NotFoundError |
| Invalid input | validation | ValidationError |
| Already exists | conflict | ConflictError |
| No permission | permission | PermissionError |
| Auth required | auth | AuthError |
| Timed out | timeout | TimeoutError |
| Connection failed | network | NetworkError |
| Limit exceeded | rate_limit | RateLimitError |
| Bug/unexpected | internal | InternalError |
| User cancelled | cancelled | CancelledError |
Step 4: Choose Packages
Packages are organized into three tiers:
Package Tiers
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TOOLING TIER โ
โ Build-time, dev-time, test-time packages โ
โ @outfitter/testing โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โฒ
โ depends on
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ RUNTIME TIER โ
โ Application-specific packages for different deployment targets โ
โ @outfitter/cli @outfitter/mcp @outfitter/daemon โ
โ @outfitter/config @outfitter/logging @outfitter/file-ops โ
โ @outfitter/state โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โฒ
โ depends on
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FOUNDATION TIER โ
โ Zero-runtime-dependency core packages โ
โ @outfitter/contracts @outfitter/types โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Tier | Packages | Dependency Rule |
|---|
| Foundation | contracts, types | No @outfitter/* deps |
| Runtime | cli, mcp, daemon, config, logging, file-ops, state | May depend on Foundation |
| Tooling | testing | May depend on Foundation + Runtime |
Package Selection
| Package | Purpose | When to Use |
|---|
@outfitter/contracts | Result types, errors, Handler contract | Always (foundation) |
@outfitter/types | Type utilities, collection helpers | Type manipulation |
@outfitter/cli | CLI commands, output modes, formatting | CLI applications |
@outfitter/mcp | MCP server, tool registration | AI agent tools |
@outfitter/config | XDG paths, config loading | Configuration needed |
@outfitter/logging | Structured logging, redaction | Logging needed |
@outfitter/daemon | Background services, IPC | Long-running services |
@outfitter/file-ops | Secure paths, atomic writes, locking | File operations |
@outfitter/state | Pagination, cursor state | Paginated data |
@outfitter/testing | Test harnesses, fixtures | Testing |
Selection criteria:
- All projects need
@outfitter/contracts (foundation)
- CLI applications add
@outfitter/cli (includes UI components)
- MCP servers add
@outfitter/mcp
- File operations need both
@outfitter/config (paths) and @outfitter/file-ops (safety)
Step 5: Design Context Flow
Determine:
- Entry points โ Where is context created? (CLI main, MCP server, HTTP handler)
- Context contents โ Logger, config, signal, workspaceRoot
- Tracing โ How requestId flows through operations
Output Templates
Architecture Overview
Project: {PROJECT_NAME}
Transport Surfaces: {CLI | MCP | HTTP | ...}
Directory Structure:
โโโ src/
โ โโโ handlers/ # Transport-agnostic business logic
โ โ โโโ {handler-1}.ts
โ โ โโโ {handler-2}.ts
โ โโโ commands/ # CLI adapter (if CLI)
โ โโโ tools/ # MCP adapter (if MCP)
โ โโโ index.ts # Entry point
โโโ tests/
โโโ handlers/ # Handler tests
Dependencies:
โโโ @outfitter/contracts # Foundation (always)
โโโ @outfitter/{package-2} # {reason}
โโโ @outfitter/{package-3} # {reason}
Handler Inventory
| Handler | Input | Output | Errors | Description |
|---|
getUser | GetUserInput | User | NotFoundError | Fetch user by ID |
createUser | CreateUserInput | User | ValidationError, ConflictError | Create new user |
deleteUser | DeleteUserInput | void | NotFoundError, PermissionError | Remove user |
Error Strategy
Domain Errors โ Stack Taxonomy:
{domain-error-1} โ {stack-category} ({ErrorClass})
- When: {condition}
- Exit code: {code}
{domain-error-2} โ {stack-category} ({ErrorClass})
- When: {condition}
- Exit code: {code}
Implementation Order
- Foundation โ Install packages, create types
- Core handlers โ Implement business logic with tests
- Transport adapters โ Wire up CLI/MCP/HTTP
- Testing โ Integration tests across transports
Constraints
Always:
- Recommend Result types over exceptions
- Map domain errors to taxonomy categories
- Design handlers as pure functions (input, context) โ Result
- Consider all transport surfaces upfront
- Include error types in handler signatures
Never:
- Suggest throwing exceptions
- Design transport-specific logic in handlers
- Recommend hardcoded paths
- Skip error type planning
- Couple handlers to specific transports
Related Skills
outfitter-stack:stack-patterns โ Reference for all patterns
outfitter:tdd โ TDD implementation methodology
outfitter-stack:stack-templates โ Templates for components