Skip to content

Commit 12a4565

Browse files
author
Lasim
committed
feat(api-docs): add guidelines for shared schemas in CRUD modules to enhance consistency and maintainability
1 parent 4aeb664 commit 12a4565

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

docs/development/backend/api.mdx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,53 @@ services/backend/src/routes/mcp/
245245
- **Clear Responsibility**: Each file has a single, clear purpose
246246
- **Reduced Complexity**: Avoid hundreds of lines in single files
247247

248+
### Shared Schemas for CRUD Modules (Mandatory)
249+
250+
**MANDATORY PATTERN**: For route directories that implement complete CRUD operations on a single entity (Create, Read, Update, Delete), you **must** create a shared `schemas.ts` file to eliminate duplication and ensure consistency.
251+
252+
#### When to Create Shared Schemas
253+
254+
Create a `schemas.ts` file when your route directory contains:
255+
- **Multiple endpoints** operating on the same core entity
256+
- **Duplicate schema definitions** across route files
257+
- **Common response structures** (error responses, entity objects)
258+
- **Shared parameter validation** (ID parameters, common fields)
259+
260+
#### What to Include in Shared Schemas
261+
262+
**Always Share:**
263+
- **Error response schemas** that appear in multiple files
264+
- **Core entity object schemas** used in responses
265+
- **Common parameter schemas** (ID validation, shared fields)
266+
- **Shared TypeScript interfaces** for consistent typing
267+
268+
**Keep Endpoint-Specific:**
269+
- **Request body schemas** with different requirements (create vs. update)
270+
- **Endpoint-specific success response wrappers**
271+
- **Unique validation rules** specific to individual operations
272+
273+
#### Implementation Requirements
274+
275+
1. **File Naming**: Use `schemas.ts` in the route directory
276+
2. **Export Pattern**: Export const schemas and TypeScript interfaces
277+
3. **Import Pattern**: Import shared components into individual route files
278+
4. **Documentation**: Include clear comments explaining shared vs. specific schemas
279+
280+
#### Benefits of Shared Schemas
281+
282+
- **Single Source of Truth**: Entity structure defined once
283+
- **Elimination of Duplication**: Removes copy-pasted schema definitions
284+
- **Improved Maintainability**: Changes happen in one place
285+
- **Enhanced Consistency**: All endpoints use identical shared structures
286+
- **Better Type Safety**: Shared interfaces prevent type drift
287+
288+
#### Module Examples Requiring Shared Schemas
289+
290+
- `/mcp/categories/` - Complete category management CRUD
291+
- `/mcp/servers/` - Server management operations
292+
- `/teams/` - Team management functionality
293+
- Any directory with 3+ routes operating on the same entity
294+
248295
### Route File Template
249296

250297
Each route file should follow this **recommended pattern**:

0 commit comments

Comments
 (0)