2.7 KiB
2.7 KiB
Rust Workspace
All Rust code lives under crates/. The workspace is defined in Cargo.toml at the repo root.
Code Style
- Two spaces for indentation (not four)
- No minimum supported Rust version; use latest stable features freely
- Never use
println!oreprintln!outside of tests; uselogcrate macros instead - Use
anyhow::Result/AnyhowResultfor fallible functions in application code - Fields that are optional use the
maybe_prefix:maybe_creator_user_token - When two crates export the same type name, alias with a suffix:
use foo::Bar as BarFoo; - Prefer
useimports over inline fully-qualified paths; only qualify inline for true one-offs or std prelude collisions (Result,Option,Error)
File Layout
Organize for top-to-bottom reading. Important things first, details later.
- Constants at the top (after imports)
- Primary public type (the main struct/enum the file defines)
- Supporting types below the primary type
- API types in order: Request, Response, Error
implblocks after their type definitions- Constructors first, then public methods, then private helpers
- Callers above callees — follow the call chain downward
Test Layout
Within #[cfg(test)] mod tests { ... }:
- Imports
- Constants (test IDs, URLs, fixture data) — small context that tests reference
- Test functions or sub-modules grouped by category
- Helper functions (builders, pipeline runners, assertions)
Constants provide small context up front. Test cases come next so engineers see what is tested before how the helpers work.
Group related tests into sub-modules (mod pricing_tests { ... }) when a category has 2+
tests. Don't wrap a single test in its own module. Keep nesting to two levels max. Shared
helpers go in the parent mod tests so sub-modules can use super::*.
Building
- Most crates:
cargo check -p {crate_name}orcargo test -p {crate_name} - Crates using SQLx:
SQLX_OFFLINE=true cargo check -p {crate_name} storyteller-webandmysql_queriesrequireSQLX_OFFLINE=truestoryteller-webhas ~370 pre-existing warnings — check the last few lines for actual errors
Key Crates
storyteller_web— main HTTP API monolith (actix-web)artcraft_router— provider routing for image/video generation (Artcraft, Fal, KinoviWeb, Muapi)artcraft_api_defs— shared HTTP API type definitionskinovi_web_client— HTTP client for the Kinovi/KinoviWeb video generation serviceenums— database-backed enums stored as VARCHAR fieldstokens— primary key identifiers with Stripe-like prefixes (e.g.user_,mf_)mysql_queries— SQLx MySQL queries for the backend