← Back

DOCS

Документация

Architecture

Architecture

This note records the production-readiness shape that matters for DoD D.

Scope

  • Rust workspace for CLI, engine, router, providers, billing, and protocol.
  • Next.js web app for auth, stream API, usage, balance, and dashboard pages.
  • Shared canonical usage and cost math across Rust and TypeScript.
  • MoA / Self-MoA orchestration in the stream path.

Trust boundaries

  • Provider credentials stay in web-side env/config paths, not in crates/.
  • Cost reporting is derived from canonical usage, not from ad hoc UI totals.
  • Streaming and usage persistence are verified separately from billing math.
  • Offline evidence is accepted only when live provider creds are absent, and that assumption must be stated explicitly in the report artifact.

Cost and MoA path

  • web/lib/billing.ts and crates/plyrum-billing-client/src/cost.rs implement the canonical integer micro-RUB cost formula.
  • web/lib/moa.ts decides when MoA or Self-MoA activates.
  • The web/app/api/stream/run/route.ts path is the place where stream, lifecycle, and usage rows converge.
  • B6 evidence should compare MoA versus direct runs using the same offline harness assumptions when provider credentials are unavailable.

Router -> engine -> providers -> audit

  1. Router classifies a prompt into workload intent, risk, domains, and model candidates (crates/plyrum-router, web/lib/provider-catalog.ts).
  2. Engine executes the DAG or MoA-shaped plan and emits lifecycle frames through plyrum-protocol.
  3. Providers stream tokens and canonical usage through the provider registry; web adapters keep raw provider keys server-side.
  4. Billing normalizes token/cost data into micro-RUB usage records.
  5. Audit and transcript writers persist redacted JSONL records for CLI tool actions, lifecycle handoffs, and dashboard inspection.

Validation commands

  • cargo test -p plyrum-billing-client
  • pnpm -C web test
  • pnpm -C web exec tsc --noEmit --incremental false
  • cargo test -p plyrum-cli -- --test-threads=1
  • cargo test -p plyrum-cli auto_confirm
  • cargo test -p plyrum-cli working_system_creation
  • cargo test -p plyrum-cli persona_snapshots
  • cargo test -p plyrum-engine moa_pipeline
  • ./scripts/smoke.sh

DoD D notes

  • This repo now keeps the cost evidence in target/cost_report.json.
  • The report is intended to be machine-readable, reproducible, and reviewable without needing live provider access.