design-layered-backend-architecture
Design or review a layered backend architecture (routes, controllers, services, repositories) for HTTP APIs and microservices.
Best use case
design-layered-backend-architecture is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Design or review a layered backend architecture (routes, controllers, services, repositories) for HTTP APIs and microservices.
Teams using design-layered-backend-architecture 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
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/design-layered-backend-architecture/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How design-layered-backend-architecture Compares
| Feature / Agent | design-layered-backend-architecture | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Design or review a layered backend architecture (routes, controllers, services, repositories) for HTTP APIs and microservices.
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
# Design Layered Backend Architecture ## Purpose Define a repeatable backend service structure that keeps HTTP concerns, business logic, and data access cleanly separated. ## When to use Use this skill when you are: - Starting a new backend service or module - Refactoring an existing codebase toward clearer boundaries - Reviewing architecture for maintainability and testability - Defining team-wide conventions for “where code goes” ## Inputs - Primary service responsibilities and domain boundaries - The external interfaces (HTTP endpoints, jobs, events) - Persistence model and integration points - Existing constraints (framework, ORM/query layer, deployment model) ## Outputs - A layering blueprint with clear responsibilities - A directory/module layout that supports the blueprint - A request lifecycle map (how a request flows through layers) - A list of architectural invariants to enforce in code review ## Core model A typical layered service uses four layers: 1. **Routes** - Define paths/methods - Register middleware - Delegate to controllers - MUST NOT implement business logic 2. **Controllers** - Validate and normalize inputs - Translate domain results to HTTP responses - Map errors to status codes and error shapes - SHOULD be thin and focused on HTTP 3. **Services** - Implement business rules and orchestration - Call repositories and other services - MUST NOT depend on HTTP objects 4. **Repositories** - Encapsulate persistence logic - Implement queries, transactions, and mappings - SHOULD hide ORM/query details from services ## Architectural invariants - Each layer MUST have a single primary responsibility. - Dependencies MUST flow inward: - routes → controllers → services → repositories - Services MUST be unit-testable without HTTP or database. - Data access SHOULD be testable via repository tests or integration tests. ## Decision checklist Use these decisions to avoid ambiguous boundaries. - **Do we need a repository layer?** - MAY be skipped for simple CRUD. - SHOULD be added once queries become non-trivial, transactional, or reused. - **Where do we validate input?** - SHOULD be at the controller boundary (closest to untrusted input). - **Where do we implement authorization?** - If the rule depends on HTTP context, keep enforcement in middleware/controller. - If the rule is domain-specific, enforce in services as well. ## Steps 1. Identify the public interfaces (endpoints/jobs/events). 2. Define domain services and responsibilities. 3. Define repository boundaries (per aggregate or per module). 4. Define controller responsibilities and error mapping contract. 5. Define route layout and middleware order. 6. Document the request lifecycle and verification checkpoints. 7. Add templates to standardize new modules. ## Verification - [ ] New endpoints follow the dependency direction (routes → controllers → services → repositories) - [ ] Controllers contain no data access queries - [ ] Routes contain no business logic - [ ] Services contain no HTTP concepts (`req`, `res`) - [ ] At least one service is unit-tested in isolation - [ ] Build passes after applying the architecture ## Boundaries - MUST NOT allow dependencies to flow outward (repositories calling controllers) - MUST NOT embed business logic in routes or controllers - MUST NOT introduce circular dependencies between layers - SHOULD NOT skip repository layer for non-trivial queries - SHOULD NOT mix multiple responsibilities in a single layer - SHOULD NOT bypass architectural invariants without documented justification ## Included assets - Examples: see `./examples/` for request lifecycle and module layout blueprints.
Related Skills
distinctive-frontend-design
Creates distinctive, production-grade frontend interfaces that avoid generic AI aesthetics. Guides bold aesthetic direction, typography, color, motion, and spatial composition for memorable UI. Use when building frontend components, pages, applications, or interfaces, or when the user asks for UI/UX design, styling, or visually striking interfaces.
developing-backend-services
Backend service development best practices. Use when designing, building, or reviewing backend services, REST APIs, gRPC services, microservices, webhooks, message queues, or server-side applications regardless of language or framework.
dev-swarm-stage-architecture
Design the complete system architecture including components, data flow, infrastructure, database schema, and API design. Use when starting stage 07 (architecture) or when user asks about system design, tech stack, or database schema.
dev-api-design
Production-grade API design patterns for REST, GraphQL, gRPC, and tRPC. Covers API architecture, OpenAPI/Swagger specs, versioning/deprecation, authentication/authorization, rate limiting, pagination, error models, contract testing, and developer documentation.
designing-databases
データベーススキーマ設計と最適化を支援します。正規化戦略、インデックス設計、パフォーマンス最適化を提供します。データモデル設計、データベース構造の最適化が必要な場合に使用してください。
designer-skills
Designer subsystem patterns for LlamaFarm. Covers React 18, TanStack Query, TailwindCSS, and Radix UI.
design-ui-ux-pro-max
UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 9 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind, shadcn/ui). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient. Integrations: shadcn/ui MCP for component search and examples.
design-tokens
Apply design token patterns using Tailwind CSS 4 @theme directive: CSS variables, semantic naming, color systems, typography scales, spacing, dark mode. Use when designing UI systems, reviewing design consistency, or establishing brand guidelines. Integrates with frontend-design skill for aesthetic execution.
design-taste-frontend
Senior UI/UX Engineer. Architect digital interfaces overriding default LLM biases. Enforces metric-based rules, strict component architecture, CSS hardware acceleration, and balanced design engineering.
design-microservices
マイクロサービス設計エージェント - ターゲットアーキテクチャ、変換計画、運用計画の策定。/design-microservices [対象パス] で呼び出し。
design-api
Triggered when user asks to design APIs, create API specifications, or plan API endpoints. Automatically delegates to the api-designer agent.
databases-architecture-skill
Master database design (SQL, NoSQL), system architecture, API design (REST, GraphQL), and building scalable systems. Learn PostgreSQL, MongoDB, system design patterns, and enterprise architectures.