Files
Edu/services/content/README.md
SpecialX 9850bfcfd1 feat(p4): content analysis service with Neo4j knowledge graph and ClickHouse analytics
P4 阶段交付物:
- services/content: 内容资源服务(NestJS)
  - textbooks: 教材 CRUD + 知识图谱绑定
  - config/neo4j.ts: Neo4j driver 单例
  - textbooks.service.ts: MySQL CRUD + Neo4j 知识图谱(createKnowledgeGraph/getPrerequisites)
  - package.json: 补充 @opentelemetry/sdk-node + exporter-trace-otlp-http
- services/data-ana: 数据分析服务(Python FastAPI)
  - main.py: FastAPI + /healthz + class_performance + student_weakness 骨架
  - clickhouse_client.py: ClickHouse 客户端封装
  - config.py: 环境变量配置
- packages/shared-proto/proto/content.proto: TextbookService + KnowledgeGraphService 契约
- packages/shared-proto/proto/analytics.proto: AnalyticsService 契约(class_performance/student_weakness)
2026-07-08 01:38:35 +08:00

66 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# content 内容资源服务
> 版本0.1P4 骨架)
> 端口3005
## 职责
内容资源限界上下文,管理 Textbook、Chapter、KnowledgePoint 聚合。
支持多存储MySQL教材/章节/知识点写模型)+ Neo4j知识图谱前置依赖+ Elasticsearch题库全文检索P4 后续补充)。
## 技术栈
- NestJS 10.x + TypeScript 5.6ESM
- Drizzle ORMMySQL
- neo4j-driver知识图谱
- Zod运行时校验
- pino日志+ prom-client指标+ OpenTelemetry追踪
## 开发
```bash
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 + GlobalErrorFilterCONTENT_* 前缀)
│ └─ observability/# logger、metrics、tracer
├─ textbooks/ # 教材/章节/知识点 + 知识图谱
├─ app.module.ts
└─ main.ts
```
## 关键端点
- `POST /textbooks` 创建教材
- `GET /textbooks` 教材列表
- `GET /textbooks/:id` 教材详情
- `TextbooksService.createKnowledgeGraph` 在 Neo4j 构建知识点前置依赖
- `TextbooksService.getPrerequisites` 查询知识点前置链路
## 对外契约
gRPC 服务 `TextbookService``KnowledgeGraphService` 定义见 `packages/shared-proto/proto/content.proto`