Use when adding new error messages to React, or seeing "unknown error code" warnings.
npx skills add modh-labs/ai-software-os --skill "route-architecture"
Install specific skill from multi-skill repository
# Description
Guide code organization, folder structure, and route architecture following your project's colocation patterns. Use when creating routes, deciding file placement, organizing imports, or discussing services vs repositories. Enforces 3+ routes threshold, actions folder pattern, and shared infrastructure conventions.
# SKILL.md
name: route-architecture
description: Guide code organization, folder structure, and route architecture following your project's colocation patterns. Use when creating routes, deciding file placement, organizing imports, or discussing services vs repositories. Enforces 3+ routes threshold, actions folder pattern, and shared infrastructure conventions.
allowed-tools: Read, Grep, Glob, Edit, Write
Route Architecture Skill
When This Skill Activates
This skill automatically activates when you:
- Create new routes or features
- Decide where to place new code
- Organize components, actions, or types
- Discuss services vs repositories
- Work with _shared/ directory
Core Philosophy
Colocation first, share when necessary.
Code lives with the route that uses it until it needs to be shared. The threshold for sharing is 3+ routes or 2 routes with clear expansion potential.
Directory Structure
app/
βββ (protected)/ # Authenticated routes
β βββ [route]/ # Example: calls, leads, dashboard
β βββ page.tsx # Server Component (data fetching)
β βββ actions.ts # Server actions (1-2 actions)
β βββ actions/ # Server actions folder (3+ actions)
β β βββ create-item.ts
β β βββ delete-item.ts
β βββ components/ # Route-specific components
β βββ loading.tsx # Skeleton (matches UI layout)
β βββ error.tsx # Error boundary with retry
β βββ CLAUDE.md # Route documentation
β
βββ (public)/ # Public routes
β
βββ api/webhooks/ # ONLY for external webhooks
β
βββ _shared/ # Shared code (3+ routes)
βββ components/ # Shared UI components
βββ lib/ # Utilities, clients
βββ repositories/ # Data access layer
βββ services/ # Business logic
βββ types/ # TypeScript types
βββ validation/ # Zod schemas
When to Use What
Repository vs Service vs Action
| Layer | Purpose | Location | When to Use |
|---|---|---|---|
| Repository | Database CRUD | _shared/repositories/ |
ALL database operations |
| Service | Business logic | _shared/services/ |
Complex multi-step operations |
| Server Action | Entry point | Route actions.ts |
User-triggered mutations |
User Click β Server Action β Service (if complex) β Repository β Database
Decision Tree
"Where should this code live?"
Is it a database query?
β _shared/repositories/[entity].repository.ts
Is it complex business logic (multi-step, external services)?
β _shared/services/[domain].service.ts
Is it a user-triggered mutation or fetch?
β Route's actions.ts or actions/
Is it a UI component?
β Used by 1-2 routes? β Route's components/
β Used by 3+ routes? β _shared/components/
Is it a type definition?
β Route-specific? β Route's types.ts
β Shared across routes? β _shared/types/
Is it validation?
β _shared/validation/[route].schema.ts
Full Pattern Examples
For complete code examples of all patterns (repository, service, action, component, types/validation, anti-patterns), see references/route-patterns.md.
Quick Reference
| What | Where | Rule |
|---|---|---|
| Database queries | _shared/repositories/ |
Always |
| Complex business logic | _shared/services/ |
3+ steps or external services |
| User mutations/fetches | Route actions.ts or actions/ |
Colocated with route |
| Route components | Route components/ |
Default |
| Shared components | _shared/components/ |
3+ routes threshold |
| Route-specific types | Route types.ts |
Single route use |
| Shared types | _shared/types/ |
Multiple route use |
| Validation schemas | _shared/validation/ |
Always |
Checklist for New Routes
- [ ]
page.tsx- Server Component for data fetching - [ ]
actions.tsoractions/- Server actions - [ ]
components/- Route-specific components - [ ]
loading.tsx- Skeleton matching UI layout - [ ]
error.tsx- Error boundary usingPageErrorBoundaryfrom@/app/_shared/components/PageErrorBoundary - [ ]
CLAUDE.md- Route documentation - [ ] Repository in
_shared/repositories/if new entity - [ ] Validation schema in
_shared/validation/
Reference
For complete audit checklist: @docs/patterns/route-audit.md
# Supported AI Coding Agents
This skill is compatible with the SKILL.md standard and works with all major AI coding agents:
Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.