Files
MoShiro/backend
justme e014a19554
ci/woodpecker/push/main-amd64-build Pipeline was successful
docs: reorganize into design, security, api, ops and dev; drop stale designs; refresh the diagrams [CI]
- Group docs by category with an index (docs/README.md); fix every link,
  code comment and the protocol conformance test that read docs/protocol.md.
- access.md and security.md rewritten to what is implemented: removed the
  unadopted member-proof chain, roles and recovery key that do not exist,
  the old implementation order and the budgets; gaps now carry a status.
- enrollment, deployment, api: the install flow is the static, hash-checked
  script with environment variables; no default admin.
- README and architecture: new topology and update-flow diagrams (operator
  passkey, CI signing, registry feed, auth and trust modules).
2026-10-08 19:37:56 +08:00
..
2026-10-04 21:46:39 +08:00

Backend

Backend 是 MoShiro 的控制面和数据服务,负责 Agent 注册与连接、任务编排、原始测量数据持久化、指标分析,以及供前端使用的 REST API 和 SSE 实时数据流。

组件

路径 职责
src/MoShiro.Backend/ 应用入口与依赖组合
src/MoShiro.Backend.Api/ Public、Admin API 和 OpenAPI
src/MoShiro.Backend.Gateway/ Fleet RPC、节点状态与测量数据接收
src/MoShiro.Backend.Application/ 业务用例、查询、任务和后台服务
src/MoShiro.Backend.Analysis/ 指标计算、累加器和服务模型
src/MoShiro.Backend.Storage.Sqlite/ 段文件与 SQLite 存储
fleet/ 通用节点身份、注册和连接框架
shared/ 测量引擎、协议和数据格式
tests/ 集成测试和测试支持代码

环境要求

使用 .NET SDK 10。仓库根目录的 global.json 指定所需 SDK 版本及滚动策略。

构建与测试

在 backend/ 目录运行:

cd backend
dotnet build MoShiro.slnx -c Release
dotnet test --solution MoShiro.slnx

发布当前平台的 NativeAOT Backend:

dotnet publish src/MoShiro.Backend -c Release -r <RID> -p:PublishAot=true

例如 <RID> 可为 win-x64、linux-x64 或 linux-arm64。NativeAOT 发布需要对应平台的 C/C++ 工具链。仓库根目录的 scripts/publish.sh backend <RID> 可构建单个平台的 Backend 可执行文件;容器发布由 Woodpecker tag 流水线完成,详见 ../docs/ops/deployment.md。

正式发布通过 Woodpecker tag 流水线生成 Linux/amd64 与 Linux/arm64 OCI 镜像,容器内监听 8080,数据写入挂载的 /data 卷。Agent 与 Probe 的多平台二进制包单独发布,不包含在 Backend 镜像中。

本地运行

在 backend/ 目录启动服务:

cd backend
dotnet run --project src/MoShiro.Backend -- --urls http://localhost:5000

没有默认管理员:第一次打开面板时按页面引导自己创建管理员、注册 passkey、建立信任根,页面要的认领码写在后端日志里(或用 MoShiro__ClaimCode 指定)。MoShiro__InitialAdminUser / MoShiro__InitialAdminPassword 只给自动化用。数据目录、公开地址、Cookie 和 CORS 等设置通过 MoShiro 配置节传入;完整配置说明见 ../docs/ops/deployment.md。站点默认需要登录,可在管理端修改公开设置。

OpenAPI 文档由构建生成到 openapi/v1.json。API 设计和端点说明见 ../docs/api/api.md;项目总览见仓库根目录的 README.md。