Codebase Orientation
Learn a Rust workspace by reading Cargo.toml boundaries, tracing the binary main path, and mapping where errors, config, and domain types live.
Recipe
# Workspace overview
cat Cargo.toml
cargo tree --depth 2
rg "^\[workspace\]" -l
# Entry points
fd main.rs
rg "#\[tokio::main\]" -l
# Public API surface
cargo doc --no-deps --openWhen to reach for this:
- First day on a new repo
- Before proposing architecture refactor
- After major workspace split
Working Example
Typical Axum service workspace layout:
billing/
Cargo.toml # workspace root
crates/
api/ # binary: HTTP server
src/main.rs
src/routes/
src/state.rs
domain/ # lib: business logic, no axum
infra/ # lib: sqlx, reqwest adapters
migrations/ # sqlx migrate
Reading order:
- Root
Cargo.tomlworkspace members and shared deps api/src/main.rs- startup, tracing, pool creationdomain/src/lib.rs- core types and traitsinfra- how DB and HTTP clients implement traitsmigrations/- schema truth
What this demonstrates:
- Binaries are thin; domain stays framework-agnostic
- Dependency direction:
api->domain<-infra - Migrations live outside hot code paths
Deep Dive
Questions to Answer in Hour One
| Question | Where to look |
|---|---|
| How is config loaded? | config.rs, main.rs |
| What error type crosses boundaries? | error.rs, domain |
| Where are integration tests? | tests/, api/tests/ |
| CI gates? | .github/workflows/ |
| MSRV? | rust-toolchain.toml, rust-version |
Navigation Tools
rg "struct AppState"- shared handler statecargo doc- rustdoc on public itemsrust-analyzergoto-def across crates
Gotchas
- Starting in wrong crate - missing workspace context. Fix: always root
Cargo.tomlfirst. - Ignoring feature flags - code "missing" in IDE. Fix: check
Cargo.toml[features]. - Assuming single binary - workspace has many. Fix:
cargo metadata | jq '.packages[].targets'. - Docs only in README - stale. Fix: trust
cargo docandarchitecture/ADRs. - Skipping migrations - wrong mental model of entities. Fix: read SQL schema early.
Alternatives
| Alternative | Use When | Don't Use When |
|---|---|---|
| Architecture ADR index | Documented system | Greenfield chaos |
| Onboarding video | Large legacy | Repo has good docs |
| Pairing tour | Complex domain | Solo time-boxed orientation |
FAQs
Monorepo vs multirepo?
Workspace Cargo.toml signals monorepo; clone once, build with --workspace.
Generated code?
Check build.rs, OUT_DIR, and sqlx prepare artifacts - do not hand-edit.
Related
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.