Files
Nexus/.cursor/rules/nexus-tech-stack.mdc
T

46 lines
1.5 KiB
Plaintext
Raw Normal View History

---
alwaysApply: true
---
# Nexus 6.0 技术栈
## 架构分层(禁止跨层直连)
```
web/app/*.html → server/api/*.py → application/services → infrastructure/* → domain/models
```
- API 层:路由 + Pydantic 校验 + `Depends(get_current_admin)`,不写 SQL
- Service 层:业务编排,通过 Repository 访问数据
- InfrastructureDB/Redis/SSH/Telegram 实现细节
- DomainSQLAlchemy ORM 模型,无 FastAPI 依赖
## 启动模式
- 无 `.env` → **安装模式**:仅 `/api/install/` + `/app/install.html`
- 有 `.env` → 正常模式:`SECRET_KEY` / `API_KEY` / `ENCRYPTION_KEY` 缺一不可
## 配置三写(安装向导)
`web/data/config.php` + `.env``NEXUS_` 前缀)+ MySQL `settings` 表。
**不可从 DB 覆盖**`SECRET_KEY`、`API_KEY`、`ENCRYPTION_KEY`、`DATABASE_URL`。
## 数据流
Agent(60s) → Redis 实时 → 前端直读 → 10min → MySQL 历史。告警:WebSocket + Telegram。
## 后台任务(仅 primary worker
`heartbeat_flush`(10min) · `self_monitor`(30s) · `schedule_runner`(60s) · `retry_runner`(5min)
## HTTP / DB 会话
- 普通 API`DbSessionMiddleware` → `request.state.db`,禁止在 factory 里 `AsyncSessionLocal()` 后不 close
- WebSocket / `/api/install/`:不走 DB 中间件
## 相关规则文件
- `nexus-python-backend.mdc` — `server/**/*.py`
- `nexus-frontend.mdc` — `web/app/**`
- `nexus-security.mdc` — 安全与凭据
- `perfect-implementation.mdc` — 完美实现与文档纪律