NestJS (6 services): implement @RequirePermission decorator with SetMetadata+Reflector, register APP_GUARD globally, fix as assertions to type guards, add explicit return types, fix import type for express, fix /metrics implicit any, replace native Error with ApplicationError, remove typeorm remnants, register LifecycleService. teacher-bff: add logger, ApplicationError, GlobalErrorFilter, forward real userId to downstream, log downstream failures, migrate health controller to shared/health. Go (2 services): interface to any, doc comments, CORS dev whitelist, JWT secret fail-fast, push-gateway internal API auth, metrics and readyz endpoints, remove dead code. Python (2 services): lifespan return type, dev_mode to bool, data-ana APIRouter, ai POST body model, ClickHouse async wrapping.
content 内容资源服务
版本:0.1(P4 骨架) 端口:3005
职责
内容资源限界上下文,管理 Textbook、Chapter、KnowledgePoint 聚合。 支持多存储:MySQL(教材/章节/知识点写模型)+ Neo4j(知识图谱前置依赖)+ Elasticsearch(题库全文检索,P4 后续补充)。
技术栈
- NestJS 10.x + TypeScript 5.6(ESM)
- Drizzle ORM(MySQL)
- neo4j-driver(知识图谱)
- Zod(运行时校验)
- pino(日志)+ prom-client(指标)+ OpenTelemetry(追踪)
开发
pnpm install
pnpm dev # 端口 3005
pnpm build
pnpm typecheck
pnpm lint
pnpm test
环境变量
| 变量 | 说明 |
|---|---|
PORT |
服务端口(默认 3005) |
DATABASE_URL |
MySQL 连接串 |
NEO4J_URL |
Neo4j Bolt 连接 URL |
NEO4J_PASSWORD |
Neo4j 密码 |
ES_URL |
Elasticsearch 地址 |
JWT_SECRET |
JWT 密钥 |
OTEL_EXPORTER_OTLP_ENDPOINT |
OpenTelemetry OTLP 端点(可选) |
模块结构
src/
├─ config/ # env、database(MySQL)、neo4j
├─ shared/
│ ├─ errors/ # ApplicationError + GlobalErrorFilter(CONTENT_* 前缀)
│ └─ observability/# logger、metrics、tracer
├─ textbooks/ # 教材/章节/知识点 + 知识图谱
├─ app.module.ts
└─ main.ts
关键端点
POST /textbooks创建教材GET /textbooks教材列表GET /textbooks/:id教材详情TextbooksService.createKnowledgeGraph在 Neo4j 构建知识点前置依赖TextbooksService.getPrerequisites查询知识点前置链路
健康检查
| 端点 | 用途 | 鉴权 |
|---|---|---|
GET /healthz |
存活探针(liveness),仅返回进程状态,不检查依赖 | 无 |
GET /readyz |
就绪探针(readiness),检查 DB 连接,失败返回 503 | 无 |
实现见 src/shared/health/health.controller.ts,5 个 NestJS 服务(iam/core-edu/content/msg/classes)一致。
对外契约
gRPC 服务 TextbookService、KnowledgeGraphService 定义见 packages/shared-proto/proto/content.proto。