Repository navigation
20 Architecture
croft is a Rust workspace of focused crates, each one a bounded context. Cross-context types travel through value objects; no shared mutable state.
These shape every code change:
- SOLID. Single-responsibility crates; backends and runners depend on traits, not concretes; small, focused interfaces.
-
DDD. Bounded contexts split as crates:
config,runtime,container,hooks,agents,cache,tui. Cross-context types travel through well-defined value objects, not shared mutable state. -
Performance is a default, not an afterthought. Stream output,
don't buffer it. Prefer
&strandCow<'_, str>over owningStringwhere lifetimes allow. Avoid clone-happy code. No runtime reflection — TOML schemas are serde-derived at compile time. -
One source of truth per concern. A recipe is defined once.
The CLI runs it. The TUI runs it. Both go through
croft::runtime. -
No dead config. Every option in
croft.tomlmust change observable behaviour, or it doesn't ship.
Each top-level directory under src/ is a bounded context.
| Module | Bounded context |
|---|---|
croft::cli |
Binary; clap; subcommand dispatch. The only module that knows about clap. |
croft::config |
TOML / YAML parsing; schema; env resolution. No I/O orchestration. |
croft::runtime |
Recipe resolver; executor; output sinks; preflight. |
croft::container |
Backend trait; compose / docker / podman / null impls. |
croft::tui |
Embedded ratatui dashboard; stateful App; pure render fn. |
croft::cache |
Content-addressed git cache shared by hooks + agents. |
croft::hooks |
.pre-commit-config.yaml reader; native runner; git hook shim installer. |
croft::agents |
Upstream-sourced agent instructions / skills pipeline. |
src/
main.rs # thin wrapper → croft::cli::run
lib.rs # exposes every bounded-context module
cli/ # binary; clap; subcommand dispatch
config/ # TOML / YAML parsing; schema; env resolution
runtime/ # recipe resolution; supervision; preflight
container/ # Backend trait; compose / docker / podman impls
tui/ # ratatui app; panes; palette
cache/ # content-addressed git cache shared by hooks + agents
hooks/ # .pre-commit-config.yaml reader; git hook installer
agents/ # upstream-sourced agent instructions / skills pipeline
examples/ # runnable croft projects
docs/ # this wiki, synced via .github/workflows/wiki-sync.yml
The dependency graph between modules is a DAG (no cycles). From "leaves" to "trunk":
cache → hooks ↘
→ cli
cache → agents ↗
config → runtime → cli
↘ tui ↗
container → runtime
croft::cli is the only module that imports everything else. The
TUI and the CLI are different views of the same runtime, never two
implementations of the same logic.
The bounded contexts are enforced by directory + pub(crate) /
pub(super) visibility rather than crate boundaries — the project
ships as a single croft binary crate; the layering is a code-review
and refactor-discipline concern, not a compiler-enforced one.
Each context defines its own concrete types and exposes value
objects (no behaviour, no &mut self) for travel between contexts.
Example: croft::cache::RepoRef is the input shape both
croft::hooks and croft::agents translate their domain types
into; the cache module stays unaware of either consumer's Repo /
SourceSpec.
croft::container::Backend is the only abstraction croft::runtime
depends on. Implementations live in croft::container (compose,
docker, podman, null) and a custom backend in
croft::container::custom for [[services.systemd]] /
[[services.custom]] declarations.
croft::config::managed_block writes a marker-delimited section
into a file (used by the worktree dotenv writer and the
.croft/.gitignore writer). The block is replaced in place on
each write; user content above and below is preserved; identical
content is a no-op (mtime stays put).
After every code change, run the full verification ladder before committing:
cargo fmt --all
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspaceIf any step fails, fix the cause — don't suppress warnings, don't
#[allow] clippy lints without a written justification in the
commit body, and don't --no-verify past pre-commit hooks.
For UI / TUI changes specifically: also run a manual smoke test
(cargo run -- ui against the example project under examples/)
before reporting the change as complete.
- Default to fewer features, smaller surface area, sharper traits.
- A single integration test that runs against a real fixture beats five mocked unit tests.
- If a change makes
croftslower for the common case, it does not ship without a measurement. - Read
croft.tomlsemantics conservatively: silent inference is a bug.
- Contributing — verification ladder, commit conventions, how to add a new example.
croft is dual-licensed under MIT or Apache 2.0. Source: github.com/nsrosenqvist/croft. Back to Home.