$npx -y skills add jackspace/ClaudeSkillz --skill backend-dev-guidelines_diet103Comprehensive 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
| 1 | # Backend Development Guidelines |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | Establish consistency and best practices across backend microservices (blog-api, auth-service, notifications-service) using modern Node.js/Express/TypeScript patterns. |
| 6 | |
| 7 | ## When to Use This Skill |
| 8 | |
| 9 | Automatically activates when working on: |
| 10 | - Creating or modifying routes, endpoints, APIs |
| 11 | - Building controllers, services, repositories |
| 12 | - Implementing middleware (auth, validation, error handling) |
| 13 | - Database operations with Prisma |
| 14 | - Error tracking with Sentry |
| 15 | - Input validation with Zod |
| 16 | - Configuration management |
| 17 | - Backend testing and refactoring |
| 18 | |
| 19 | --- |
| 20 | |
| 21 | ## Quick Start |
| 22 | |
| 23 | ### New Backend Feature Checklist |
| 24 | |
| 25 | - [ ] **Route**: Clean definition, delegate to controller |
| 26 | - [ ] **Controller**: Extend BaseController |
| 27 | - [ ] **Service**: Business logic with DI |
| 28 | - [ ] **Repository**: Database access (if complex) |
| 29 | - [ ] **Validation**: Zod schema |
| 30 | - [ ] **Sentry**: Error tracking |
| 31 | - [ ] **Tests**: Unit + integration tests |
| 32 | - [ ] **Config**: Use unifiedConfig |
| 33 | |
| 34 | ### New Microservice Checklist |
| 35 | |
| 36 | - [ ] Directory structure (see [architecture-overview.md](architecture-overview.md)) |
| 37 | - [ ] instrument.ts for Sentry |
| 38 | - [ ] unifiedConfig setup |
| 39 | - [ ] BaseController class |
| 40 | - [ ] Middleware stack |
| 41 | - [ ] Error boundary |
| 42 | - [ ] Testing framework |
| 43 | |
| 44 | --- |
| 45 | |
| 46 | ## Architecture Overview |
| 47 | |
| 48 | ### Layered Architecture |
| 49 | |
| 50 | ``` |
| 51 | HTTP Request |
| 52 | ↓ |
| 53 | Routes (routing only) |
| 54 | ↓ |
| 55 | Controllers (request handling) |
| 56 | ↓ |
| 57 | Services (business logic) |
| 58 | ↓ |
| 59 | Repositories (data access) |
| 60 | ↓ |
| 61 | Database (Prisma) |
| 62 | ``` |
| 63 | |
| 64 | **Key Principle:** Each layer has ONE responsibility. |
| 65 | |
| 66 | See [architecture-overview.md](architecture-overview.md) for complete details. |
| 67 | |
| 68 | --- |
| 69 | |
| 70 | ## Directory Structure |
| 71 | |
| 72 | ``` |
| 73 | service/src/ |
| 74 | ├── config/ # UnifiedConfig |
| 75 | ├── controllers/ # Request handlers |
| 76 | ├── services/ # Business logic |
| 77 | ├── repositories/ # Data access |
| 78 | ├── routes/ # Route definitions |
| 79 | ├── middleware/ # Express middleware |
| 80 | ├── types/ # TypeScript types |
| 81 | ├── validators/ # Zod schemas |
| 82 | ├── utils/ # Utilities |
| 83 | ├── tests/ # Tests |
| 84 | ├── instrument.ts # Sentry (FIRST IMPORT) |
| 85 | ├── app.ts # Express setup |
| 86 | └── server.ts # HTTP server |
| 87 | ``` |
| 88 | |
| 89 | **Naming Conventions:** |
| 90 | - Controllers: `PascalCase` - `UserController.ts` |
| 91 | - Services: `camelCase` - `userService.ts` |
| 92 | - Routes: `camelCase + Routes` - `userRoutes.ts` |
| 93 | - Repositories: `PascalCase + Repository` - `UserRepository.ts` |
| 94 | |
| 95 | --- |
| 96 | |
| 97 | ## Core Principles (7 Key Rules) |
| 98 | |
| 99 | ### 1. Routes Only Route, Controllers Control |
| 100 | |
| 101 | ```typescript |
| 102 | // ❌ NEVER: Business logic in routes |
| 103 | router.post('/submit', async (req, res) => { |
| 104 | // 200 lines of logic |
| 105 | }); |
| 106 | |
| 107 | // ✅ ALWAYS: Delegate to controller |
| 108 | router.post('/submit', (req, res) => controller.submit(req, res)); |
| 109 | ``` |
| 110 | |
| 111 | ### 2. All Controllers Extend BaseController |
| 112 | |
| 113 | ```typescript |
| 114 | export class UserController extends BaseController { |
| 115 | async getUser(req: Request, res: Response): Promise<void> { |
| 116 | try { |
| 117 | const user = await this.userService.findById(req.params.id); |
| 118 | this.handleSuccess(res, user); |
| 119 | } catch (error) { |
| 120 | this.handleError(error, res, 'getUser'); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | ``` |
| 125 | |
| 126 | ### 3. All Errors to Sentry |
| 127 | |
| 128 | ```typescript |
| 129 | try { |
| 130 | await operation(); |
| 131 | } catch (error) { |
| 132 | Sentry.captureException(error); |
| 133 | throw error; |
| 134 | } |
| 135 | ``` |
| 136 | |
| 137 | ### 4. Use unifiedConfig, NEVER process.env |
| 138 | |
| 139 | ```typescript |
| 140 | // ❌ NEVER |
| 141 | const timeout = process.env.TIMEOUT_MS; |
| 142 | |
| 143 | // ✅ ALWAYS |
| 144 | import { config } from './config/unifiedConfig'; |
| 145 | const timeout = config.timeouts.default; |
| 146 | ``` |
| 147 | |
| 148 | ### 5. Validate All Input with Zod |
| 149 | |
| 150 | ```typescript |
| 151 | const schema = z.object({ email: z.string().email() }); |
| 152 | const validated = schema.parse(req.body); |
| 153 | ``` |
| 154 | |
| 155 | ### 6. Use Repository Pattern for Data Access |
| 156 | |
| 157 | ```typescript |
| 158 | // Service → Repository → Database |
| 159 | const users = await userRepository.findActive(); |
| 160 | ``` |
| 161 | |
| 162 | ### 7. Comprehensive Testing Required |
| 163 | |
| 164 | ```typescript |
| 165 | describe('UserService', () => { |
| 166 | it('should create user', async () => { |
| 167 | expect(user).toBeDefined(); |
| 168 | }); |
| 169 | }); |
| 170 | ``` |
| 171 | |
| 172 | --- |
| 173 | |
| 174 | ## Common Imports |
| 175 | |
| 176 | ```typescript |
| 177 | // Express |
| 178 | import express, { Request, Response, NextFunction, Router } from 'express'; |
| 179 | |
| 180 | // Validation |
| 181 | import { z } from 'zod'; |
| 182 | |
| 183 | // Database |
| 184 | import { PrismaClient } from '@prisma/client'; |
| 185 | import type { Prisma } from '@prisma/client'; |
| 186 | |
| 187 | // Sentry |
| 188 | import * as Sentry from '@sentry/node'; |
| 189 | |
| 190 | // Config |
| 191 | import { config } from './config/unifiedConfig'; |
| 192 | |
| 193 | // Middleware |
| 194 | import { SSOMid |