modh-labs

route-architecture

0
0
# Install this skill:
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.ts or actions/ - Server actions
  • [ ] components/ - Route-specific components
  • [ ] loading.tsx - Skeleton matching UI layout
  • [ ] error.tsx - Error boundary using PageErrorBoundary from @/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.