backend-dev-guidelines · diet103 — Claude Code skill: Express backend rules
A skill that lays out layered architecture for Node.js/Express/TypeScript services: routes, controllers, services, repositories. It activates on its own when the agent touches backend code.
npx skills add diet103/claude-code-infrastructure-showcase --skill backend-dev-guidelines -a claude-codeWhat backend-dev-guidelines does
Seven rules shape how the agent writes and edits backend code here. Routes stay thin and hand off to controllers, and every controller extends BaseController. Failures go to Sentry, request bodies get checked with Zod schemas, database calls sit behind repositories, and settings come from unifiedConfig rather than process.env.
You also get checklists for a new feature and a new microservice, the service/src/ directory layout with file naming conventions, an HTTP status table, and a list of anti-patterns. Separate reference files cover routing, services and repositories, validation, middleware, Prisma access, configuration, async handling, and testing. Blog API and Auth Service serve as templates.
The skill assumes Node.js/Express/TypeScript with Prisma and Sentry. On another stack you port the architectural principles yourself, following CLAUDE_INTEGRATION_GUIDE.md at the repo root. Worth a look before installing if your project runs Fastify with Drizzle, for instance.
What it helps with
- split an Express route into controller, service and repository
- get business logic out of route handlers
- wire Sentry into service-level error handling
- validate a request body with a Zod schema
- move environment reads into unifiedConfig
Example prompts for the agent
- Build a
POST /usersendpoint in layers: route, controller extendingBaseController, service, repository - Add Zod validation to the request body and report failures to Sentry
- Refactor this Express route to follow the skill's rules and pull the logic out of the route
How to install backend-dev-guidelines
1Skills CLI (Vercel)
npx skills add diet103/claude-code-infrastructure-showcase --skill backend-dev-guidelines -a claude-code2Manually: put the files in place
~/.claude/skills/backend-dev-guidelines/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/backend-dev-guidelines/
1Skills CLI (Vercel)
npx skills add diet103/claude-code-infrastructure-showcase --skill backend-dev-guidelines -a codex2Manually: put the files in place
.agents/skills/backend-dev-guidelines/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add diet103/claude-code-infrastructure-showcase --skill backend-dev-guidelines -a cursor2Manually: put the files in place
.cursor/skills/backend-dev-guidelines/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install diet103/claude-code-infrastructure-showcase backend-dev-guidelines2Manually: put the files in place
.github/skills/backend-dev-guidelines/SKILL.md1Skills CLI (Vercel)
npx skills add diet103/claude-code-infrastructure-showcase --skill backend-dev-guidelines -a gemini-cli2Platform CLI
gemini skills install https://github.com/diet103/claude-code-infrastructure-showcase --path .claude/skills/backend-dev-guidelinesManually: put the files in place
.devin/skills/backend-dev-guidelines/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add diet103/claude-code-infrastructure-showcase --skill backend-dev-guidelines -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about backend-dev-guidelines
How do I install backend-dev-guidelines in Claude Code?
Run npx skills add diet103/claude-code-infrastructure-showcase --skill backend-dev-guidelines -a claude-code. The skill file lands at ~/.claude/skills/backend-dev-guidelines/SKILL.md.
What does backend-dev-guidelines do?
It sets the conventions for layered Node.js/Express/TypeScript backends: routes, controllers, services and repositories, plus Prisma access, Sentry tracking, Zod validation and unifiedConfig.
Does it work with a different stack?
It is written for Express with Prisma and Sentry. The architectural principles carry over, but you adapt them yourself — the repo includes CLAUDE_INTEGRATION_GUIDE.md for that.
Source text
SKILL.md · MIT
---
name: backend-dev-guidelines
description: Comprehensive backend development guide for Node.js/Express/TypeScript microservices. Use when creating routes, controllers, services, repositories, middleware, or working with Express APIs, Prisma database access, Sentry error tracking, Zod validation, unifiedConfig, dependency injection, or async patterns. Covers layered architecture (routes → controllers → services → repositories), BaseController pattern, error handling, performance monitoring, testing strategies, and migration from legacy patterns.
---
# Backend Development Guidelines
## Purpose
Establish consistency and best practices across backend services using modern Node.js/Express/TypeScript patterns.
Written for Node.js/Express/TypeScript with Prisma and Sentry. Different stack? Adapt the architectural principles - see CLAUDE_INTEGRATION_GUIDE.md in the repo root.
## When to Use This Skill
Automatically activates when working on:
- Creating or modifying routes, endpoints, APIs
- Building controllers, services, repositories
- Implementing middleware (auth, validation, error handling)
- Database operations with Prisma
- Error tracking with Sentry
- Input validation with Zod
- Configuration management
- Backend testing and refactoring
---
## Quick Start
### New Backend Feature Checklist
- [ ] **Route**: Clean definition, delegate to controller
- [ ] **Controller**: Extend BaseController
- [ ] **Service**: Business logic with DI
- [ ] **Repository**: Database access (if complex)
- [ ] **Validation**: Zod schema
- [ ] **Sentry**: Error tracking
- [ ] **Tests**: Unit + integration tests
- [ ] **Config**: Use unifiedConfig
### New Microservice Checklist
- [ ] Directory structure (see [architecture-overview.md](architecture-overview.md))
- [ ] instrument.ts for Sentry
- [ ] unifiedConfig setup
- [ ] BaseController class
- [ ] Middleware stack
- [ ] Error boundary
- [ ] Testing framework
---
## Architecture Overview
### Layered Architecture
```
HTTP Request
↓
Routes (routing only)
↓
Controllers (request handling)
↓
Services (business logic)
↓
Repositories (data access)
↓
Database (Prisma)
```
**Key Principle:** Each layer has ONE responsibility.
See [architecture-overview.md](architecture-overview.md) for complete details.
---
## Directory Structure
```
service/src/
├── config/ # UnifiedConfig
├── controllers/ # Request handlers
├── services/ # Business logic
├── repositories/ # Data access
├── routes/ # Route definitions
├── middleware/ # Express middleware
├── types/ # TypeScript types
├── validators/ # Zod schemas
├── utils/ # Utilities
├── tests/ # Tests
├── instrument.ts # Sentry (FIRST IMPORT)
├── app.ts # Express setup
└── server.ts # HTTP server
```
**Naming Conventions:**
- Controllers: `PascalCase` - `UserController.ts`
- Services: `camelCase` - `userService.ts`
- Routes: `camelCase + Routes` - `userRoutes.ts`
- Repositories: `PascalCase + Repository` - `UserRepository.ts`
---
## Core Principles (7 Key Rules)
### 1. Routes Only Route, Controllers Control
```typescript
// ❌ NEVER: Business logic in routes
router.post('/submit', async (req, res) => {
// 200 lines of logic
});
// ✅ ALWAYS: Delegate to controller
router.post('/submit', (req, res) => controller.submit(req, res));
```
### 2. All Controllers Extend BaseController
```typescript
export class UserController extends BaseController {
async getUser(req: Request, res: Response): Promise<void> {
try {
const user = await this.userService.findById(req.params.id);
this.handleSuccess(res, user);
} catch (error) {
this.handleError(error, res, 'getUser');
}
}
}
```
### 3. All Errors to Sentry
```typescript
try {
await operation();
} catch (error) {
Sentry.captureException(error);
throw error;
}
```
### 4. Use unifiedConfig, NEVER process.env
```typescript
// ❌ NEVER
const timeout = process.env.TIMEOUT_MS;
// ✅ ALWAYS
import { config } from './config/unifiedConfig';
const timeout = config.timeouts.default;
```
### 5. Validate All Input with Zod
```typescript
const schema = z.object({ email: z.string().email() });
const validated = schema.parse(req.body);
```
### 6. Use Repository Pattern for Data Access
```typescript
// Service → Repository → Database
const users = await userRepository.findActive();
```
### 7. Comprehensive Testing Required
```typescript
describe('UserService', () => {
it('should create user', async () => {
expect(user).toBeDefined();
});
});
```
---
## Common Imports
```typescript
// Express
import express, { Request, Response, NextFunction, Router } from 'express';
// Validation
import { z } from 'zod';
// Database
import { PrismaClient } from '@prisma/client';
import type { Prisma } from '@prisma/client';
// Sentry
import * as Sentry from '@sentry/node';
// Config
import { config } from './config/unifiedConfig';
// Middleware
import { SSOMiddlewareClient } from './middleware/SSOMiddleware';
import { asyncErrorWrapper } from './middleware/errorBoundary';
```
---
## Quick Reference
### HTTP Status Codes
| Code | Use Case |
|------|----------|
| 200 | Success |
| 201 | Created |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 500 | Server Error |
### Service Templates
**Blog API** (✅ Mature) - Use as template for REST APIs
**Auth Service** (✅ Mature) - Use as template for authentication patterns
---
## Anti-Patterns to Avoid
❌ Business logic in routes
❌ Direct process.env usage
❌ Missing error handling
❌ No input validation
❌ Direct Prisma everywhere
❌ console.log instead of Sentry
---
## Navigation Guide
| Need to... | Read this |
|------------|-----------|
| Understand architecture | [architecture-overview.md](architecture-overview.md) |
| Create routes/controllers | [routing-and-controllers.md](routing-and-controllers.md) |
| Organize business logic | [services-and-repositories.md](services-and-repositories.md) |
| Validate input | [validation-patterns.md](validation-patterns.md) |
| Add error tracking | [sentry-and-monitoring.md](sentry-and-monitoring.md) |
| Create middleware | [middleware-guide.md](middleware-guide.md) |
| Database access | [database-patterns.md](database-patterns.md) |
| Manage config | [configuration.md](configuration.md) |
| Handle async/errors | [async-and-errors.md](async-and-errors.md) |
| Write tests | [testing-guide.md](testing-guide.md) |
| See examples | [complete-examples.md](complete-examples.md) |
---
## Resource Files
### [architecture-overview.md](architecture-overview.md)
Layered architecture, request lifecycle, separation of concerns
### [routing-and-controllers.md](routing-and-controllers.md)
Route definitions, BaseController, error handling, examples
### [services-and-repositories.md](services-and-repositories.md)
Service patterns, DI, repository pattern, caching
### [validation-patterns.md](validation-patterns.md)
Zod schemas, validation, DTO pattern
### [sentry-and-monitoring.md](sentry-and-monitoring.md)
Sentry init, error capture, performance monitoring
### [middleware-guide.md](middleware-guide.md)
Auth, audit, error boundaries, AsyncLocalStorage
### [database-patterns.md](database-patterns.md)
PrismaService, repositories, transactions, optimization
### [configuration.md](configuration.md)
UnifiedConfig, environment configs, secrets
### [async-and-errors.md](async-and-errors.md)
Async patterns, custom errors, asyncErrorWrapper
### [testing-guide.md](testing-guide.md)
Unit/integration tests, mocking, coverage
### [complete-examples.md](complete-examples.md)
Full examples, refactoring guide
---
## Related Skills
- **database-verification** - Verify column names and schema consistency
- **error-tracking** - Sentry integration patterns
- **skill-developer** - Meta-skill for creating and managing skills
---
**Skill Status**: COMPLETE ✅
**Line Count**: < 500 ✅
**Progressive Disclosure**: 11 resource files ✅
© diet103 · MIT · diet103/claude-code-infrastructure-showcase
Similar skills
All skills for Backend and APIs →backend-dev-guidelines by other authors comes first.