Skip to content

Commit 0ae4dd7

Browse files
committed
feat(api): create knowledge graph API routes (SSC-11)
Add Express routes for knowledge graph endpoints: - Concept CRUD: POST/GET/PUT/DELETE /concepts - Relationship CRUD: POST/PUT/DELETE /relationships - AI extraction: POST /extract (with rate limiting) - Semantic search: POST /search (with rate limiting) - Visualization: GET /graph, /strengths, /stats
1 parent 1c684ff commit 0ae4dd7

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { Router, Request, Response, NextFunction } from 'express';
2+
import { rateLimit } from 'express-rate-limit';
3+
import { knowledgeGraphController } from '../controllers/knowledgeGraph.controller';
4+
import { authenticateToken } from '../middleware/auth.middleware';
5+
6+
const router = Router();
7+
8+
// Rate limiting for AI extraction (more restrictive due to API costs)
9+
const extractionLimiter = rateLimit({
10+
windowMs: 15 * 60 * 1000, // 15 minutes
11+
max: 10, // 10 extraction requests per window
12+
message: { error: 'Too many extraction requests, please try again later' },
13+
standardHeaders: true,
14+
legacyHeaders: false,
15+
});
16+
17+
// Rate limiting for semantic search
18+
const searchLimiter = rateLimit({
19+
windowMs: 1 * 60 * 1000, // 1 minute
20+
max: 30, // 30 search requests per minute
21+
message: { error: 'Too many search requests, please try again later' },
22+
standardHeaders: true,
23+
legacyHeaders: false,
24+
});
25+
26+
// All routes require authentication
27+
router.use(authenticateToken);
28+
29+
// ============================================
30+
// CONCEPTS
31+
// ============================================
32+
33+
// POST /api/knowledge-graph/concepts - Create a new concept
34+
router.post('/concepts', (req: Request, res: Response, next: NextFunction) =>
35+
knowledgeGraphController.createConcept(req, res, next)
36+
);
37+
38+
// GET /api/knowledge-graph/concepts - Get all concepts for current user
39+
router.get('/concepts', (req: Request, res: Response, next: NextFunction) =>
40+
knowledgeGraphController.getConcepts(req, res, next)
41+
);
42+
43+
// GET /api/knowledge-graph/concepts/:id - Get a specific concept
44+
router.get('/concepts/:id', (req: Request, res: Response, next: NextFunction) =>
45+
knowledgeGraphController.getConcept(req, res, next)
46+
);
47+
48+
// PUT /api/knowledge-graph/concepts/:id - Update a concept
49+
router.put('/concepts/:id', (req: Request, res: Response, next: NextFunction) =>
50+
knowledgeGraphController.updateConcept(req, res, next)
51+
);
52+
53+
// DELETE /api/knowledge-graph/concepts/:id - Delete a concept
54+
router.delete('/concepts/:id', (req: Request, res: Response, next: NextFunction) =>
55+
knowledgeGraphController.deleteConcept(req, res, next)
56+
);
57+
58+
// GET /api/knowledge-graph/concepts/:id/similar - Find similar concepts
59+
router.get('/concepts/:id/similar', (req: Request, res: Response, next: NextFunction) =>
60+
knowledgeGraphController.findSimilar(req, res, next)
61+
);
62+
63+
// ============================================
64+
// RELATIONSHIPS
65+
// ============================================
66+
67+
// POST /api/knowledge-graph/relationships - Create a relationship
68+
router.post('/relationships', (req: Request, res: Response, next: NextFunction) =>
69+
knowledgeGraphController.createRelationship(req, res, next)
70+
);
71+
72+
// PUT /api/knowledge-graph/relationships/:id - Update a relationship
73+
router.put('/relationships/:id', (req: Request, res: Response, next: NextFunction) =>
74+
knowledgeGraphController.updateRelationship(req, res, next)
75+
);
76+
77+
// DELETE /api/knowledge-graph/relationships/:id - Delete a relationship
78+
router.delete('/relationships/:id', (req: Request, res: Response, next: NextFunction) =>
79+
knowledgeGraphController.deleteRelationship(req, res, next)
80+
);
81+
82+
// ============================================
83+
// AI EXTRACTION
84+
// ============================================
85+
86+
// POST /api/knowledge-graph/extract - Extract concepts from an upload
87+
router.post(
88+
'/extract',
89+
extractionLimiter,
90+
(req: Request, res: Response, next: NextFunction) =>
91+
knowledgeGraphController.extractFromUpload(req, res, next)
92+
);
93+
94+
// ============================================
95+
// SEMANTIC SEARCH
96+
// ============================================
97+
98+
// POST /api/knowledge-graph/search - Semantic search across concepts
99+
router.post(
100+
'/search',
101+
searchLimiter,
102+
(req: Request, res: Response, next: NextFunction) =>
103+
knowledgeGraphController.semanticSearch(req, res, next)
104+
);
105+
106+
// ============================================
107+
// VISUALIZATION & STATISTICS
108+
// ============================================
109+
110+
// GET /api/knowledge-graph/graph - Get graph data for visualization
111+
router.get('/graph', (req: Request, res: Response, next: NextFunction) =>
112+
knowledgeGraphController.getGraph(req, res, next)
113+
);
114+
115+
// GET /api/knowledge-graph/strengths - Get concept strength scores
116+
router.get('/strengths', (req: Request, res: Response, next: NextFunction) =>
117+
knowledgeGraphController.getConceptStrengths(req, res, next)
118+
);
119+
120+
// GET /api/knowledge-graph/stats - Get knowledge graph statistics
121+
router.get('/stats', (req: Request, res: Response, next: NextFunction) =>
122+
knowledgeGraphController.getStats(req, res, next)
123+
);
124+
125+
export default router;

0 commit comments

Comments
 (0)