Skip to content

Commit 9ea843e

Browse files
author
Lasim
committed
feat: implement plugin route structure and registration system for enhanced security and isolation
1 parent 0b06feb commit 9ea843e

File tree

9 files changed

+563
-143
lines changed

9 files changed

+563
-143
lines changed

services/backend/API_DOCUMENTATION.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,48 @@ To extend API documentation:
316316
4. Include error response schemas (400, 401, 500, etc.)
317317
5. Add parameter validation schemas
318318

319+
## Plugin API Routes
320+
321+
### Plugin Route Structure
322+
323+
All plugin routes are automatically namespaced under `/api/plugin/<plugin-name>/` for security and isolation:
324+
325+
- **Core Routes**: `/api/auth/*`, `/api/users/*`, `/api/settings/*` (protected from plugins)
326+
- **Plugin Routes**: `/api/plugin/<plugin-name>/*` (isolated per plugin)
327+
328+
### Example Plugin Routes
329+
330+
For a plugin with ID `example-plugin`:
331+
332+
```
333+
GET /api/plugin/example-plugin/examples
334+
GET /api/plugin/example-plugin/examples/:id
335+
POST /api/plugin/example-plugin/examples
336+
PUT /api/plugin/example-plugin/examples/:id
337+
DELETE /api/plugin/example-plugin/examples/:id
338+
```
339+
340+
### Security Benefits
341+
342+
1. **Route Isolation**: Plugins cannot interfere with core routes or each other
343+
2. **Predictable Structure**: All plugin APIs follow the same pattern
344+
3. **Easy Identification**: Plugin ownership is clear from the URL
345+
4. **Automatic Namespacing**: No manual prefix management required
346+
347+
### Plugin Route Registration
348+
349+
Plugins register routes using the `PluginRouteManager`:
350+
351+
```typescript
352+
// In plugin's routes.ts file
353+
export async function registerRoutes(routeManager: PluginRouteManager, db: AnyDatabase | null) {
354+
// This becomes /api/plugin/my-plugin/data
355+
routeManager.get('/data', async () => {
356+
return { message: 'Hello from plugin!' };
357+
});
358+
}
359+
```
360+
319361
## Files Generated
320362

321363
- `api-spec.json` - Complete OpenAPI 3.0 specification in JSON format

0 commit comments

Comments
 (0)