Skip to content

docs(architecture): name the gateway module in the src/ module table - #427

Merged
argszero merged 1 commit into
mainfrom
docs/architecture-name-the-gateway-module
Oct 21, 2026
Merged

argszero merged 1 commit into
mainfrom
docs/architecture-name-the-gateway-module

Conversation

@argszero

Copy link
Copy Markdown
Owner

Summary

docs/architecture.md §3 ("模块(src/)") lists nine modules and gateway.rs is not one of them — the whole document does not contain the string once (grep -i gateway → 0 hits).

What was left out is the largest production module in the tree and the place a request actually lands:

fact reading
declared production module src/main.rs:19 — mod gateway; (not one of the #[cfg(test)] gate modules)
size 3136 lines — protocol.rs 2141, sse.rs 2709, billing.rs 931
handlers it holds chat_completions:863, anthropic_messages:878, responses:893, models:916, plans:932, v1_models:962
its own map module doc, line 1: //! 网关兼容端点(architecture §6 API 一览)

Why this is an omission, not a different way of summarising

Two readings inside the same document say so:

  1. §4「数据流(一次调用)」 walks one call step by step: endpoint → auth check → balance pre-check → key routing → upstream request → settle. Every one of those steps but the first has a row in §3: auth.rs, billing.rs, router.rs, sse.rs. The module that receives the request is the single one missing, so a reader following §4 into src/ has nowhere to go for step one.
  2. The routes/ row enumerates the API surface it serves ("认证 / 钱包 / 交易 / 仪表盘 / 共享 / 管理 / 运营者 API") and does not include the three gateway endpoints — which exist in src/routes/mod.rs's router but are handled in gateway.rs. That is a gap in the enumeration, not a scope decision.

Changes

  • One row added to §3, placed next to routes/ — the two are the parallel HTTP layers (platform API versus model calls), and keeping them adjacent preserves the table's existing grouping (infrastructure first, HTTP last)
  • No config or data-structure change, so no example file to sync
| `gateway.rs` | 网关三条端点(`/v1/chat/completions`、`/v1/responses`、`/anthropic/v1/messages`):取 model → 路由选 key → 按 plan 端点定出站协议(跨协议转换交 `protocol.rs` / `sse.rs`)→ 转发上游 → 解析 usage 交 `billing.rs` 计费;模型 / 套餐列表端点亦在此 |

The wording follows the modules' actual division of labour rather than restating §4: router.rs chooses the key, protocol.rs / sse.rs do the cross-protocol conversion, billing.rs prices and settles, and this row says that gateway.rs is the entry point that ties them together.

Deliberately not touched: config.rs, main.rs and i18n_pack.rs are also production modules the document never names (grep -c → 0 each), but §4's flow does not pass through them, so this reading does not cover them. One defect per change.

Tests

  • cargo test — 579 passed / 0 failed
  • cargo fmt --check — clean
  • cargo clippy --all-targets — clean
  • No new unit test: no gate reads docs/architecture.md. Every include_str! target in the tree is README.md, README.en.md, CHANGELOG.md, ui/README.md, ui/index.html, ui/js/*.js, ui/css/style.css, config/config.example.toml, Cargo.toml, Dockerfile, docker-compose.yml, .dockerignore, and docs/prototype/aitokenpool-console.html (the prototype, not this document). So the change is unguarded by design — this repository's standing rule for prose assertions is to correct the data rather than pin one wording in a gate.

Checklist

  • Branch name follows the convention (docs/)
  • Commit message uses Conventional Commits (docs(architecture): ...)
  • Single purpose, minimal diff — one line added

Section 3 lists nine modules, and gateway.rs is not one of them -- the
whole document does not contain the string once. It is declared in
src/main.rs:19 and is the largest production module in the tree (3136
lines; protocol.rs 2141, sse.rs 2709, billing.rs 931), and it holds the
six handlers a request actually lands in: chat_completions,
anthropic_messages, responses, models, plans and v1_models. Its own
module doc opens with "网关兼容端点(architecture §6 API 一览)", so it
treats this document as its map.

The omission is visible from inside the document, twice over:

- Section 4 walks one call step by step -- endpoint, auth, balance
  pre-check, key routing, upstream, settle -- and every step but the
  first has a row in section 3 (auth.rs, billing.rs, router.rs, sse.rs).
  The module that receives the request is the one missing.
- The routes/ row names the platform APIs it serves and does not
  include the three gateway endpoints, which are registered in
  src/routes/mod.rs and handled in gateway.rs.

One row added, next to routes/ (the two are the parallel HTTP layers:
platform API versus model calls). The other production modules that the
document never names -- config.rs, main.rs, i18n_pack.rs -- are left
alone: section 4's flow does not pass through them, so this reading
does not cover them.

Tests: cargo test 579 passed / 0 failed; cargo fmt --check and cargo
clippy --all-targets clean. No gate reads docs/architecture.md, so this
change is unguarded by design -- the axis' standing rule is to correct
the data, not to pin one wording.
@argszero
argszero merged commit 159c0df into main Oct 21, 2026
2 checks passed
@argszero
argszero deleted the docs/architecture-name-the-gateway-module branch October 21, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant