Skip to content

Commit 712b8a6

Browse files
author
Lasim
committed
feat: Add comprehensive documentation for UI Design System, GitHub Integration, MCP Catalog, and user roles
- Introduced a new UI Design System guide detailing design principles, component patterns, and accessibility guidelines. - Created a GitHub Application Integration document explaining the process of integrating GitHub with DeployStack for MCP server creation. - Added a GitHub Integration guide outlining synchronization, OAuth configuration, and repository management features. - Developed an MCP Server Catalog documentation to facilitate server discovery, management, and deployment processes. - Updated roles documentation to include specific permissions related to the MCP Catalog and server management capabilities. - Enhanced team documentation to clarify MCP server settings and GitHub integration for team-specific deployments.
1 parent ee6fce8 commit 712b8a6

16 files changed

Lines changed: 4304 additions & 1004 deletions

docs/deploystack/development/backend/api-pagination.mdx

Lines changed: 667 additions & 0 deletions
Large diffs are not rendered by default.

docs/deploystack/development/backend/api-security.mdx

Lines changed: 473 additions & 0 deletions
Large diffs are not rendered by default.

docs/deploystack/development/backend/api.mdx

Lines changed: 130 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ The DeployStack Backend uses Fastify with Swagger plugins to automatically gener
1515
- **Postman Integration**: JSON/YAML specs that can be imported into Postman
1616
- **Automated Generation**: Specifications are generated from actual route code
1717

18+
## 🔒 Security First
19+
20+
**IMPORTANT**: Before developing any protected API endpoints, read the [API Security Best Practices](./api-security.mdx) documentation. It covers critical security patterns including:
21+
22+
- **Authorization Before Validation**: Why `preValidation` must be used instead of `preHandler` for authorization
23+
- **Proper Error Responses**: Ensuring unauthorized users get 403 Forbidden, not validation errors
24+
- **Security Testing**: How to test authorization properly
25+
- **Common Pitfalls**: Security anti-patterns to avoid
26+
27+
**Key Rule**: Always use `preValidation` for authorization checks to prevent information disclosure to unauthorized users.
28+
1829
## Available Commands
1930

2031
### 1. Generate Complete API Specification
@@ -99,6 +110,8 @@ When the server is running (`npm run dev`), you can access:
99110
2. **Directory Organization**: Group related routes in directories (e.g., `/auth/`, `/users/`, `/health/`)
100111
3. **Import Pattern**: Routes are imported and registered in `src/routes/index.ts`
101112
4. **Consistent Naming**: Use descriptive names that match the route purpose
113+
5. **Modular Approach**: **Keep route files small and focused** - aim for 1-3 related methods per file maximum
114+
6. **Maintainability**: Avoid large monolithic route files that become difficult to maintain
102115

103116
### Correct File Structure
104117

@@ -120,6 +133,37 @@ services/backend/src/routes/
120133
└── index.ts # Team management endpoints
121134
```
122135

136+
### Modular Route Organization (Recommended)
137+
138+
For complex feature areas, break down routes into smaller, focused files:
139+
140+
```
141+
services/backend/src/routes/mcp/
142+
├── index.ts # Route registration only
143+
├── categories/
144+
│ ├── create.ts # POST /api/mcp/categories (1 method)
145+
│ ├── update.ts # PUT /api/mcp/categories/{id} (1 method)
146+
│ └── delete.ts # DELETE /api/mcp/categories/{id} (1 method)
147+
├── servers/
148+
│ ├── list.ts # GET /api/mcp/servers (1 method)
149+
│ ├── get.ts # GET /api/mcp/servers/{id} (1 method)
150+
│ ├── search.ts # GET /api/mcp/servers/search (1 method)
151+
│ ├── create-global.ts # POST /api/mcp/servers/global (1 method)
152+
│ ├── update-global.ts # PUT /api/mcp/servers/global/{id} (1 method)
153+
│ └── delete-global.ts # DELETE /api/mcp/servers/global/{id} (1 method)
154+
└── versions/
155+
├── list.ts # GET /api/mcp/servers/{id}/versions (1 method)
156+
├── create.ts # POST /api/mcp/servers/{id}/versions (1 method)
157+
└── update.ts # PUT /api/mcp/servers/{id}/versions/{versionId} (1 method)
158+
```
159+
160+
**Benefits of Modular Approach:**
161+
- **Easier Maintenance**: Small files are easier to understand and modify
162+
- **Better Testing**: Individual route files can be tested in isolation
163+
- **Team Collaboration**: Multiple developers can work on different routes without conflicts
164+
- **Clear Responsibility**: Each file has a single, clear purpose
165+
- **Reduced Complexity**: Avoid hundreds of lines in single files
166+
123167
### Route File Template
124168

125169
Each route file should follow this pattern:
@@ -210,6 +254,71 @@ export const registerRoutes = (server: FastifyInstance): void => {
210254
4. **Code Organization**: Related functionality is grouped together
211255
5. **Team Collaboration**: Multiple developers can work on different routes without conflicts
212256

257+
## Content-Type Header Requirements
258+
259+
### When to Include Content-Type Headers
260+
261+
**IMPORTANT**: The `Content-Type: application/json` header is required for specific HTTP methods when sending request body data.
262+
263+
#### ✅ ALWAYS Include Content-Type for:
264+
- **POST** requests with request body data
265+
- **PUT** requests with request body data
266+
- **PATCH** requests with request body data
267+
268+
#### ❌ NEVER Include Content-Type for:
269+
- **GET** requests (no request body)
270+
- **DELETE** requests (typically no request body)
271+
- **HEAD** requests (no request body)
272+
273+
#### Correct Client Implementation Pattern
274+
275+
```javascript
276+
function makeRequest(method, path, data = null, cookies = null) {
277+
const options = {
278+
method,
279+
headers: { 'Accept': 'application/json' }
280+
};
281+
282+
// Set Content-Type for methods that send request body data
283+
if (['POST', 'PUT', 'PATCH'].includes(method.toUpperCase()) && data !== null) {
284+
options.headers['Content-Type'] = 'application/json';
285+
}
286+
287+
// Rest of implementation...
288+
}
289+
```
290+
291+
#### ❌ Problematic Pattern (Avoid This)
292+
293+
```javascript
294+
// UNCLEAR: This doesn't indicate WHICH methods need Content-Type
295+
if (data) {
296+
options.headers['Content-Type'] = 'application/json';
297+
}
298+
```
299+
300+
### API Specification Content-Type Documentation
301+
302+
When defining route schemas, explicitly document Content-Type requirements for POST/PUT/PATCH endpoints:
303+
304+
```typescript
305+
// For endpoints that require Content-Type
306+
const routeSchema = {
307+
tags: ['Category'],
308+
summary: 'Create new item',
309+
description: 'Creates a new item. Requires Content-Type: application/json header when sending request body.',
310+
requestBody: {
311+
required: true,
312+
content: {
313+
'application/json': {
314+
schema: zodToJsonSchema(requestSchema, { $refStrategy: 'none', target: 'openApi3' })
315+
}
316+
}
317+
},
318+
// ... rest of schema
319+
};
320+
```
321+
213322
## Adding Documentation to Routes
214323

215324
To add OpenAPI documentation to your routes, define your request body and response schemas using Zod. Then, use the `zodToJsonSchema` utility to convert these Zod schemas into the JSON Schema format expected by Fastify.
@@ -246,12 +355,23 @@ const myErrorResponseSchema = z.object({
246355
const routeSchema = {
247356
tags: ['Category'], // Your API category
248357
summary: 'Brief description of your endpoint',
249-
description: 'Detailed description of what this endpoint does, its parameters, and expected outcomes.',
358+
description: 'Detailed description of what this endpoint does, its parameters, and expected outcomes. Requires Content-Type: application/json header when sending request body.',
250359
security: [{ cookieAuth: [] }], // Include if authentication is required
251360
body: zodToJsonSchema(myRequestBodySchema, {
252361
$refStrategy: 'none', // Keeps definitions inline, often simpler for Fastify
253362
target: 'openApi3' // Ensures compatibility with OpenAPI 3.0
254363
}),
364+
requestBody: {
365+
required: true,
366+
content: {
367+
'application/json': {
368+
schema: zodToJsonSchema(myRequestBodySchema, {
369+
$refStrategy: 'none',
370+
target: 'openApi3'
371+
})
372+
}
373+
}
374+
},
255375
response: {
256376
200: zodToJsonSchema(mySuccessResponseSchema.describe("Successful operation"), {
257377
$refStrategy: 'none',
@@ -301,6 +421,15 @@ fastify.post<{ Body: RequestBody }>(
301421
5. **Type Safety**: Handlers receive properly typed, validated data
302422
6. **Cleaner Code**: No redundant validation logic in handlers
303423

424+
### Why Both `body` and `requestBody` Properties?
425+
426+
**Important**: You need BOTH properties for complete functionality:
427+
428+
- **`body`**: Enables Fastify's automatic request validation using the Zod schema
429+
- **`requestBody`**: Ensures proper OpenAPI specification generation with Content-Type documentation
430+
431+
Without `body`, validation won't work. Without `requestBody`, your API specification won't properly document the `application/json` Content-Type requirement.
432+
304433
### What NOT to Do (Anti-patterns)
305434

306435
**Don't do manual validation in handlers:**

0 commit comments

Comments
 (0)