Skip to content
This repository was archived by the owner on Oct 19, 2026. It is now read-only.

Commit 41ca003

Browse files
authored
refactor: migrate to ceres application/transport paths and centralize HTTP errors (#2139)
* refactor: enforce DTO boundaries and extract jupiter-migrate for faster builds Move mono HTTP DTOs into ceres/model (admin, webhook, bot, note, group) and route label/group logic through MonoApiService facades so mono no longer imports jupiter::model. Add CI guard for the DTO boundary, document the three-layer model rules in ceres/README, and relocate ProtocolError HTTP mapping to mono. Extract SeaORM migrations into jupiter-migrate with optional jupiter/migrate feature gating, fold context into mono/bootstrap, and slim common by removing axum. Update mono routers, storage init, and workspace deps accordingly. * update docs * refactor: thin mono routers with MonoAppServices facades and ceres domain modules Introduce MonoAppServices and TransportContext so mono routers stop calling storage directly, and split MonoApiService into domain modules (user, issue, conversation, code review, gpg, note, reviewer, cl_list, etc.). Move notification dispatch/triggers and webhook admin/delivery into ceres application, relocate pack helpers to infra, and extend CI guards for callisto, jupiter::service, transport/application, and router storage access. * refactor: migrate to ceres application/transport paths and centralize HTTP errors Deprecate ceres legacy re-exports (api_service, pack, protocol, build_trigger, code_edit) and switch mono/ceres call sites to application::* and transport::*. Add typed MegaError variants with shared HTTP status mapping in common, simplify mono ApiError, and improve Git SSH protocol error handling. Further thin group/tag/artifacts routers via MonoApiService facades and extend CI guards to block legacy ceres import paths in mono.
1 parent d9ccfba commit 41ca003

251 files changed

Lines changed: 3999 additions & 3287 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/copilot-instructions.md‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ cargo nextest run -p <crate> when suggesting fast local test runs
2626

2727
## Key Components (Modules)
2828

29-
This is a monorepo containing many components. Some key ones include:
30-
31-
* **`mono` / `ceres` / `jupiter` / `moon`**: These are various services and libraries within the monorepo, primarily written in Rust and TypeScript.
32-
* **`orion`**: Build orchestration and workspace management.
33-
* **`saturn`**: Policy and permission management.
34-
35-
**Note**: `scorpio` (FUSE filesystem) has been moved to its own repository at [scorpiofs](https://github.com/web3infra-foundation/scorpiofs).
29+
| Crate | Role |
30+
|-------|------|
31+
| `mono` | Server binary (HTTP REST, Git HTTP/SSH, Swagger) |
32+
| `ceres` | Domain library: transport, application, HTTP DTOs |
33+
| `jupiter` / `callisto` | Storage and SeaORM entities |
34+
| `jupiter-migrate` | Database migrations |
35+
| `orion` / `orion-server` / `orion-scheduler` | Build orchestration |
36+
| `saturn` | Cedar policy |
37+
| `vault` | Crypto and secrets |
38+
| `moon` | Frontend (TypeScript) |
39+
40+
See [docs/architecture.md](docs/architecture.md) for the full workspace map.
3641

3742
## Coding style & quality
3843

‎.github/workflows/base.yml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,45 @@ jobs:
8585
with:
8686
shared-key: base-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
8787
cache-on-failure: true
88+
- name: Enforce DTO boundary (mono must not import jupiter::model)
89+
run: |
90+
if rg -q 'jupiter::model' mono/; then
91+
echo "mono must not depend on jupiter::model; use ceres::model and MonoApiService facades"
92+
rg 'jupiter::model' mono/
93+
exit 1
94+
fi
95+
- name: Enforce module dependency boundaries
96+
run: |
97+
if rg -q 'use callisto::' mono/src/; then
98+
echo "mono/src must not import callisto directly; use ceres::model and MonoApiService facades"
99+
rg 'use callisto::' mono/src/
100+
exit 1
101+
fi
102+
if rg -q 'jupiter::service::' mono/src/; then
103+
echo "mono/src must not import jupiter::service directly; use MonoApiService facades"
104+
rg 'jupiter::service::' mono/src/
105+
exit 1
106+
fi
107+
if rg -q 'api_service::mono::MonoApiService' ceres/src/transport/; then
108+
echo "ceres transport must not depend on MonoApiService"
109+
rg 'api_service::mono::MonoApiService' ceres/src/transport/
110+
exit 1
111+
fi
112+
if rg -q 'use crate::(pack|transport)' ceres/src/application/; then
113+
echo "ceres application must not import transport/pack directly"
114+
rg 'use crate::(pack|transport)' ceres/src/application/
115+
exit 1
116+
fi
117+
if rg --glob '!lfs_router.rs' -q '\.storage\.|_stg\(\)' mono/src/api/router/; then
118+
echo "mono routers must use MonoApiService facades, not storage"
119+
rg --glob '!lfs_router.rs' '\.storage\.|_stg\(\)' mono/src/api/router/
120+
exit 1
121+
fi
122+
if rg -q 'ceres::(api_service|pack|protocol|build_trigger|code_edit)' mono/; then
123+
echo "mono must use ceres::application::* and ceres::transport::* instead of legacy re-exports"
124+
rg 'ceres::(api_service|pack|protocol|build_trigger|code_edit)' mono/
125+
exit 1
126+
fi
88127
- name: Run cargo clippy
89128
run: |
90129
sccache --start-server || true

‎Cargo.lock‎

Lines changed: 18 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ members = [
77
"ceres",
88
"clients/orion-client",
99
"common",
10-
"context",
1110
"io-orbit",
1211
"jupiter",
1312
"jupiter/callisto",
13+
"jupiter-migrate",
1414
"mono",
1515
"orion",
1616
"orion-scheduler",
@@ -19,7 +19,6 @@ members = [
1919
"vault",
2020
]
2121
default-members = ["mono", "orion", "orion-server", "orion-scheduler"]
22-
exclude = ["tools/artifacts-compose-e2e"]
2322
resolver = "3"
2423

2524

@@ -29,15 +28,14 @@ io-orbit = { path = "io-orbit" }
2928
mono = { path = "mono" }
3029
common = { path = "common" }
3130
jupiter = { path = "jupiter" }
31+
jupiter-migrate = { path = "jupiter-migrate" }
3232
ceres = { path = "ceres" }
3333
callisto = { path = "jupiter/callisto" }
3434
vault = { path = "vault" }
3535
saturn = { path = "saturn" }
3636
orion = { path = "orion" }
3737
orion-client = { path = "clients/orion-client" }
3838

39-
context = { path = "context" }
40-
4139
git-internal = "0.7.6"
4240
libvault-core = "0.1.0"
4341

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ Mega is evolving toward deeper AI-native capabilities:
5353

5454
To facilitate a rapid deployment and hands-on experience with the Mega service, the following instructions are derived from the project's [documentation](https://github.com/web3infra-foundation/mega/tree/main/docker).
5555

56+
- **Docker demo (recommended):** [docker/README.md](docker/README.md)
57+
- **Native development:** [docs/development.md](docs/development.md)
58+
- **Architecture:** [docs/architecture.md](docs/architecture.md)
59+
60+
Related projects: [Libra](https://github.com/web3infra-foundation/libra) (Git-compatible agent client), [ScorpioFS](https://github.com/web3infra-foundation/scorpiofs) (FUSE monorepo mount).
61+
5662
## Community
5763

5864
Discord Channel - https://discord.gg/HMFuu6pJmQ

‎ceres/Cargo.toml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ uuid = { workspace = true, features = ["v4"] }
3535
reqwest = { workspace = true, features = ["json", "stream"] }
3636
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "net", "process"] }
3737
tokio-stream = { workspace = true }
38-
axum = { workspace = true }
38+
axum-core = "0.5.6"
3939
async-recursion = { workspace = true }
4040
sysinfo = { workspace = true }
4141
utoipa = { workspace = true }
4242
regex = { workspace = true }
4343
tokio-util = { workspace = true }
4444
rkyv = { workspace = true }
4545

46+
[features]
47+
migrate = ["jupiter/migrate"]
48+
4649
[dev-dependencies]
50+
axum = { workspace = true }
51+
jupiter-migrate = { workspace = true }
4752
tempfile = { workspace = true }

‎ceres/README.md‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Monorepo domain library for Mega: Git transport, REST application logic, and sha
88
ceres/src/
99
├── lib.rs
1010
├── bus/ # Transport ↔ application event bus
11-
├── infra/ # Shared infrastructure (GitObjectCache)
11+
├── infra/ # Shared infrastructure (GitObjectCache, pack streams, decode errors)
1212
├── transport/
1313
│ ├── protocol/ # Smart HTTP/SSH Git protocol
1414
│ └── pack/ # receive-pack / upload-pack handlers
@@ -20,7 +20,9 @@ ceres/src/
2020
├── diff/, merge_checker/, lfs/
2121
```
2222

23-
Legacy paths (`ceres::protocol`, `ceres::pack`, `ceres::api_service`, etc.) remain as re-exports in `lib.rs` for compatibility with `mono`.
23+
`mono` uses `ceres::application::*` and `ceres::transport::*` for domain logic and Git transport.
24+
25+
`axum-core` is confined to `ceres/infra/pack_decode.rs` for `git-internal` pack decode stream errors until upstream accepts `std::io::Error`.
2426

2527
## Dependency rules
2628

@@ -31,6 +33,42 @@ Legacy paths (`ceres::protocol`, `ceres::pack`, `ceres::api_service`, etc.) rema
3133
| `bus` | Minimal shared types for events | `transport` / `application` implementations |
3234
| `mono` (binary) | Assembles `TransportRuntime` + injects handlers | — |
3335

36+
## Model boundary
37+
38+
Three DTO layers; keep imports aligned with this table:
39+
40+
| Layer | Crate / path | Role | Consumers |
41+
|-------|--------------|------|-----------|
42+
| Wire | `api-model` | mono ↔ orion cross-process protocol (buck2, artifacts, shared pagination wrappers) | `mono`, `orion`, `orion-client`, `ceres` (pagination only where needed) |
43+
| HTTP / OpenAPI | `ceres/model` | All mono REST request/response types + `utoipa` schemas | `mono` routers, `ceres` application |
44+
| Storage assembly | `jupiter/model` | Bundles of `callisto` entities from storage/services; no serde/utoipa | `jupiter` storage/service, `ceres` application only |
45+
46+
Rules:
47+
48+
- `mono` routers must **not** `use jupiter::model` — map via `ceres::model` and `MonoApiService` facades.
49+
- `mono/src` must **not** `use callisto::` or `jupiter::service::` — storage entities and service calls stay in `ceres` application layer.
50+
- `ceres/src/transport` must **not** reference `MonoApiService` (transport ↔ application boundary).
51+
- `api-model` is **not** mono HTTP schema (except shared wrappers like `CommonPage` / `Pagination`).
52+
- `ceres/model` is the mapping hub: `impl From<jupiter::model::*>` and `impl From<callisto::*>` live here.
53+
- `application/build_trigger/model` is a ceres subdomain API schema (build triggers); same HTTP rules as `ceres/model`, kept alongside orchestration until a later consolidation.
54+
55+
## Error type boundaries
56+
57+
| Layer | Error type | HTTP adapter (mono) |
58+
|-------|------------|---------------------|
59+
| `ceres/application`, `jupiter` | `MegaError` | `ApiError` (`mono/src/api/error.rs`) |
60+
| `ceres/transport`, Git Smart HTTP/SSH | `ProtocolError` | `protocol_error::into_response` |
61+
| Buck upload | `BuckError` (via `MegaError::Buck`) | `ApiError` |
62+
| Git LFS | `GitLFSError` | `map_lfs_error` in `lfs_router` |
63+
64+
Rules:
65+
66+
- REST routers and `MonoApiService` use `MegaError` only; `api_handler` resolves import vs mono handlers and returns `MegaError`.
67+
- `ProtocolError` is confined to Git client protocol paths; use `mega_to_protocol_error` at transport boundaries when mapping domain failures.
68+
- Do not use `ProtocolError` in REST handlers.
69+
70+
Long term: extract `ceres/model` → `mega-api-types` only if a non-mono consumer needs HTTP DTOs without ceres domain code.
71+
3472
## Git push event flow
3573

3674
```mermaid

‎ceres/src/application/api_service/blame_ops.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use git_internal::{
1717
};
1818

1919
use crate::{
20-
api_service::ApiHandler,
20+
application::api_service::ApiHandler,
2121
model::blame::{BlameBlock, BlameInfo, BlameQuery, BlameResult, Contributor},
2222
};
2323

@@ -182,7 +182,8 @@ pub async fn get_file_blame<T: ApiHandler + ?Sized>(
182182

183183
// Resolve starting commit from refs
184184
let start_commit =
185-
crate::api_service::commit_ops::resolve_start_commit(handler, ref_name).await?;
185+
crate::application::api_service::commit_ops::resolve_start_commit(handler, ref_name)
186+
.await?;
186187

187188
// Get file content and blob hash at start commit
188189
let (current_content, start_blob_hash) =

‎ceres/src/application/api_service/blob_ops.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use git_internal::{
1414
use sha1::{Digest, Sha1};
1515

1616
use crate::{
17-
api_service::{ApiHandler, tree_ops},
17+
application::api_service::{ApiHandler, tree_ops},
1818
model::git::DiffPreviewPayload,
1919
};
2020

‎ceres/src/application/api_service/commit_ops.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use jupiter::redis::AsyncCommands;
2121
use serde::{Deserialize, Serialize};
2222

2323
use crate::{
24-
api_service::{ApiHandler, history, tree_ops},
24+
application::api_service::{ApiHandler, history, tree_ops},
2525
model::{
2626
change_list::{DiffItemSchema, MuiTreeNode},
2727
commit::{CommitFilesChangedPage, CommitSummary, GpgStatus},

0 commit comments

Comments
 (0)