Refine Rust architecture boundaries
This commit is contained in:
@@ -39,6 +39,28 @@ MCP client
|
||||
Input mapping переводит MCP arguments в REST request. Output mapping переводит
|
||||
REST response в MCP tool result.
|
||||
|
||||
## Rust boundaries
|
||||
|
||||
В Community-коде закреплены следующие границы:
|
||||
|
||||
- `crank-core::domain` — доменные типы: operations, agents, users, secrets, observability, ids.
|
||||
- `crank-core::ports` — интерфейсы внешних зависимостей: policy, audit, identity, protocol adapters, cache stores, metering.
|
||||
- `crank-registry::records` — read/write records, которые возвращает storage layer.
|
||||
- `crank-registry::requests` — request-структуры для persistence операций.
|
||||
- `crank-registry::infrastructure` — PostgreSQL registry facade, pool config и extension migrations.
|
||||
- `apps/admin-api/src/dto.rs` — HTTP payloads и view models. Service layer не должен владеть DTO-типами.
|
||||
- `apps/admin-api/src/service/*` — application use-cases. Эти модули не импортируют `axum`.
|
||||
- `crates/crank-community-mcp/src/transport.rs` — MCP Streamable HTTP transport: headers, accept negotiation, session id, JSON/SSE responses.
|
||||
- `RuntimeExecutionRequest` — единая точка расширения runtime execution parameters. Новые auth/context/cache/metring параметры добавляются туда, а не через новые `execute_with_*` методы.
|
||||
|
||||
Границы проверяются скриптами:
|
||||
|
||||
```text
|
||||
scripts/check-rust-boundaries.sh
|
||||
scripts/check-rust-module-boundaries.sh
|
||||
scripts/check-rust-code-health.sh
|
||||
```
|
||||
|
||||
## Хранилище
|
||||
|
||||
PostgreSQL хранит:
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
- `cargo clippy --workspace --all-targets --all-features -- -D warnings` — локальные ошибки, smell-и и часть API-антипаттернов.
|
||||
- `cargo test --workspace --all-targets` — unit и integration-style тесты.
|
||||
- `scripts/check-rust-code-health.sh` — локальный repo-level gate для размера Rust-файлов.
|
||||
- `scripts/check-rust-boundaries.sh` — crate-level dependency direction и module-level import rules.
|
||||
- `scripts/check-rust-module-boundaries.sh` — запрет на опасные imports внутри слоев.
|
||||
|
||||
Что можно добавить позже:
|
||||
|
||||
@@ -39,16 +41,21 @@
|
||||
- выделять route/service/runtime helper в отдельный модуль;
|
||||
- оставлять рядом с production-кодом только короткие unit-тесты приватной логики.
|
||||
|
||||
Текущие крупные файлы:
|
||||
Текущие крупные production-файлы считаются debt baseline. Они не должны расти, а при изменении их нужно постепенно разбирать:
|
||||
|
||||
- `apps/admin-api/src/service.rs`
|
||||
- `apps/admin-api/src/app.rs`
|
||||
- `apps/mcp-server/src/main.rs`
|
||||
- `crates/crank-runtime/src/executor.rs`
|
||||
- `crates/crank-registry/src/postgres/mod.rs`
|
||||
- `crates/crank-community-mcp/src/app.rs`
|
||||
- `crates/crank-registry/src/postgres/operation.rs`
|
||||
|
||||
Уже выделенные направления:
|
||||
|
||||
- `apps/admin-api/src/dto.rs` содержит HTTP payloads и view models.
|
||||
- `crates/crank-registry/src/postgres/pool_config.rs` содержит env parsing и validation pool settings.
|
||||
- `crates/crank-registry/src/postgres/connection.rs` содержит connection/migration wiring.
|
||||
- `crates/crank-community-mcp/src/transport.rs` содержит Streamable HTTP transport helpers.
|
||||
- `crates/crank-runtime::RuntimeExecutionRequest` является основным способом передавать execution параметры.
|
||||
|
||||
## Правила тестов
|
||||
|
||||
Рядом с кодом допустимы:
|
||||
@@ -88,3 +95,11 @@ crank-core -> no app crates
|
||||
```
|
||||
|
||||
Если потребуется строгая автоматическая проверка границ, добавим отдельный script на основе `cargo metadata` или `cargo-guppy`.
|
||||
|
||||
Module-level правила уже проверяются:
|
||||
|
||||
- `apps/admin-api/src/service*` не импортирует `axum`;
|
||||
- `apps/admin-api/src/routes*` не импортирует `crank_runtime`;
|
||||
- `crank-core/src` не импортирует framework/storage/network runtime crates;
|
||||
- `crank-registry/src` не импортирует HTTP framework/client crates;
|
||||
- `crank-runtime/src` не импортирует HTTP framework или SQL storage crates.
|
||||
|
||||
Reference in New Issue
Block a user