Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Map

Summary: how the repository and the Rust crates are laid out, which crate may depend on which, and where to make a change.
Key terms: formats, flows, adapters, crate, feature, no_std, dependency rule.
Related: Interfaces · Data · AGENTS.md

The Rust code has three layers. Formats parse and verify signatures, keys and tokens. Flows apply the authentication rules to the rows they read and return decisions; they do no I/O. Adapters connect the flows to a database, a web framework and the system clock. Dependencies point downward only, so every rule can be tested without a database or a network.

The picture as text
flowchart TB
    subgraph adapters [Adapters: all I/O]
        axum[axum: HTTP API]
        sqlite[sqlite]
        postgres[postgres]
        seaorm[sea-orm]
    end
    subgraph flows [Flows: decisions, no I/O]
        signup
        passkey
        session
        device
        recovery
        more[tenant, place, provider, oidc, e2ee, api-key]
    end
    subgraph formats [Formats: parse and check]
        core
        webauthn
        dpop
        jose
        keys
    end
    adapters --> flows --> formats
    adapters --> formats

The repository

FolderContents
spec/The exact rules. Change it in the same commit as the behavior
schema/Reference SQL for SQLite and PostgreSQL: the core tables and each optional feature
docs/wiki/This wiki
docs/recipes/One page per task. Their Rust code compiles
docs/decisions/Decisions and their reasons
skills/Instructions for coding agents that add auth-chad to an application
rust/The Rust workspace
rust/loco/A separate workspace: the Loco adapter and an example

The crates

CrateLayerJob
auth-chad-coreformatShared types: IDs, rows and tables, writes and decisions, Authenticated, policies, errors, shared state (single-use marks, limits, leases), SQL text
auth-chad-keysformatES256, Ed25519 and RS256 keys, JWK, thumbprints
auth-chad-webauthnformatVerifies passkey registrations and assertions
auth-chad-joseformatA strict subset of JWS, JWK and JWT
auth-chad-dpopformatDPoP proofs and nonces
auth-chad-signupflowOpen, invite-only and external signup
auth-chad-passkeyflowRegister, log in, add and remove passkeys
auth-chad-sessionflowCookie or key-bound sessions, renewal, fresh login, logout, entering a tenant
auth-chad-tenantflowTenants and memberships
auth-chad-placeflowThe location of a tenant’s or user’s data
auth-chad-recoveryflowRecovery key, tenant owners, email
auth-chad-deviceflowDevice login (RFC 8628) and machine keys
auth-chad-api-keyflowAPI keys (optional, discouraged)
auth-chad-oidcflowIdentity proof from another provider
auth-chad-providerflowOAuth for first-party and connected apps
auth-chad-e2eeflowEnd-to-end encryption: identity secrets, envelopes, recovery
auth-chad-sqliteadapterStore on SQLite
auth-chad-postgresadapterStore on PostgreSQL
auth-chad-sea-ormadapterStore on the application’s SeaORM connection
auth-chad-axumadapterThe HTTP API, extractors, hooks, the worker, the browser script
auth-chadfacadeRe-exports the crates by feature. Applications depend on this crate
auth-chad-clientclientThe account API from a CLI, or from wasm in a browser (feature browser)
auth-chad-clitoolThe auth-chad command: schema, features, memberships, after-restore, doctor, docs
auth-chad-testingtestA memory store, a fake clock, fake random bytes, a software authenticator, storage tests
auth-chad-flow-teststestAll flows together
auth-chad-recipestestCompiles the Rust code in the recipes and in this wiki
example-minimalexampleA whole application with passkeys
auth-chad-locoadapterLoco integration (in rust/loco/)
example-locoexampleA Loco application with auth-chad (in rust/loco/)

Dependency rules

  1. formats depend on formats only. flows depend on formats. Adapters depend on both.
  2. A flow depends on no other flow, with these exceptions: signup and recovery use passkey; recovery and tenant use session to end sessions. Shared types are in core.
  3. formats and flows are no_std with alloc: no async runtime, clock, randomness or environment.
  4. Only adapters name a database, a web framework or an async runtime.
  5. No crate knows an application’s domain.

Features of the auth-chad crate

auth-chad = { git = "https://github.com/audiochad/auth-chad", rev = "<commit>", features = ["axum", "postgres"] }
FeatureAdds
passkey, session, signupThe default
tenant, place, recovery, device, provider, oidc, api-key, e2eeOne flow each
sqlite, postgres, sea-ormA store
axumThe HTTP API, with every flow it needs
clientThe Rust client
rs256-signRS256 ID tokens for the provider

Where to make a change

ChangePlace
A table or columnrust/formats/core/src/rows.rs, then AUTH_CHAD_BLESS=1 cargo test -p auth-chad-sqlite -p auth-chad-postgres
A limit or a policyrust/formats/core/src/{config,policy}.rs
A login, session or OAuth rulerust/flows/*
An HTTP route, extractor or hookrust/adapters/axum/src
A refusal coderust/formats/core/src/error.rs and rust/adapters/axum/src/error.rs
A task pagedocs/recipes/, and add it to rust/recipes/src/lib.rs

Code rules

  • Pure functions. Side effects go behind traits, used through generics instead of dyn.
  • Borrow before owning: &str before String.
  • No logging, no unsafe, no unwrap outside tests, no comments that repeat the code.
  • Tests run in parallel and need no network.
  • A new dependency needs a reason in the pull request. Never write cryptography.

Tests

TestCovers
Official vectors, Wycheproofformats
Unit and property tests with a fake clockEvery flow
Storage conformance (auth-chad-testing::conformance)Every store
HTTP tests (rust/adapters/axum/tests)Every route
Browser tests with a virtual authenticatorexample-minimal, the Loco example
Compiled recipes and wikiauth-chad-recipes

All crates share one version and release together. Before 1.0, an application pins a commit.