Living reference repository for Darkmatter's engineering, toolchain, and operational conventions.
This repository (darkmatter/template, workspace effect-agent-harness-demo)
encodes how Darkmatter structures, builds, tests, secures, and deploys software.
Instead of maintaining an unverified style guide or empty starter boilerplate,
every convention is applied here to a small, working polyglot system—an Effect
agent harness, a Waku web app, a Tauri desktop shell, and a Rust process
supervisor—and gated end-to-end in CI.
The example domain is deliberately small and honest about its boundaries: no model credentials are required to run or test the repo, AI providers sit behind adapter layers at the composition roots, and the Rust worker is a bounded process supervisor rather than a security sandbox. Copy or slice the structure, toolchain, and boundaries; replace the example domain with your own.
- Conventions applied and why
- Repository root and the
ops/boundary - Deep modules and enforced package boundaries
- One TypeScript toolchain: Bun, tsgo, and Vite+
- Effect-native core with adapters at composition roots
- Rust at sharp runtime boundaries
- Declarative infrastructure with Alchemy, Waku, and Postgres
- Checked-in encrypted secrets with SOPS and age
- Hermetic Nix environments, layered entrypoints, and multi-stack CI
- Durable context ownership:
AGENTS.mdand ADRs
- Repository root and the
- Repository layout
- Install
- Usage
- Verification
- Contributing
- License
- Applied in:
ops/,ops/policies/repo-root/allowed,.config/, ADR 0001 - Convention:
ops/owns the operational life of the repository: operator commands (ops/bin/), container recipes (ops/container/), local Compose stacks (ops/compose/), dependency configs (ops/config/), deployment primitives (ops/deploy/), environment assembly (ops/environments/), encrypted secrets (ops/secrets/), observability (ops/observability/), machine Nix profiles (ops/nix/), and automated guardrails (ops/policies/). Source-adjacent configuration (package.json,tsconfig.json,waku.config.ts,alchemy.run.ts, schemas) stays beside the app or package that consumes it.ops/policies/repo-root/allowed(bun run lint:root) allowlists top-level files; tool configs that do not require the root live in.config/. - Why: Repositories accumulate operational files across environments long after the source layout settles. Separating "what configures the code" from "what operates the system" gives humans and agents a single routing rule and prevents both app directories and the repo root from turning into a junk drawer.
- Applied in:
.config/dependency-cruiser.cjs,packages/tooling/src/organization.ts,packages/agent-core/src/index.ts, ADR 0008 - Convention: Every workspace under
packages/*is a deep module whose sole public surface issrc/index.ts(exported as.). Apps (apps/*), sibling packages, and even a package's owntest/suite import packages exclusively through their entry points—neversrc/internals.dependency-cruiserruns insidebun run checkto enforce the graph: nothing outsideapps/importsapps/,internalpackages (sandbox-client,web-core) cannot depend onservicepackages (agent-*,infra), thetoolingleaf depends on no workspace package,test/fixtures stay private to tests, and circular dependencies fail the build. Intra-package imports use#*("./src/*") instead of../, and Oxlint enforces role-based file casing (PascalCaseinmodels/,services/,adapters/,components/;kebab-caseinworkflows/,policies/,utils/). - Why: Architectural boundaries that exist only in documentation decay.
Enforcing entry-point privacy and dependency direction in
bun run checkkeeps interfaces narrow, lets internals change without cascading edits, and forces tests to exercise observable public behavior rather than private helpers.
- Applied in:
package.json,vite.config.ts,packages/tooling/src/tsconfig.json, ADR 0002, ADR 0010 - Convention: Bun (
packageManagerpinned inpackage.json) manages workspaces, installs, and script execution. Shared dependency versions are pinned once at the workspace root (withoverridesaligning peer-coupled@effect/*,vite, andvitestpackages across transitive trees), while internal packages link viaworkspace:*(@repo/*). Typechecking uses TypeScript 7 (tsgo) patched with@effect/tsgoviabun run prepare.vite.config.tsis the single configuration file for linting (vp lint/ Oxlint), formatting (vp fmt/ Oxfmt at 80 columns with sortedpackage.jsonkeys), and testing (vp test run/ Vitest—neverbun test). - Why: Native Go and Rust tooling keeps typecheck, lint, and format passes
fast enough for humans and agents to run continuously. Consolidating Oxlint,
Oxfmt, and Vitest into
vite.config.tseliminates three drifting config files and ensures new repositories scaffolded withvp creatematch what CI validates here.
- Applied in:
packages/agent-core/,packages/agent-demo/,packages/agent-testkit/,apps/harnessd/src/orpc.ts,docs/10-effect-solutions.md, ADR 0005, ADR 0006, ADR 0012 - Convention: Domain packages use
Effectv4:Schema.ClassandSchema.TaggedClassfor data and wire contracts,Context.Servicewith package-qualified identifiers for capabilities, lowercase static layers (layer,layerMemory), andConfigproviders (node/no-process-envis an error invite.config.ts). Layers capture their dependencies once so public operations exposeR = never. Agents are built on@yielded/agent(Agent.make,AgentRuntime, and nativeeffect/aiTool,Toolkit, andLanguageModel) rather than hand-rolled model loops, and typed RPC surfaces useeffect-orpc(eos+ORPCTaggedError). Provider SDKs, HTTP servers, CLI parsing, and UI callbacks stay atapps/*composition roots (BunRuntime.runMainfor CLI and daemon; one lifecycle-boundManagedRuntimefor Tauri and Waku), all consuming the sharedDemoHarnessLayer. Tests run real Effects via@effect/vitest(it.effect) and swap layers (ScriptedModel) without module mocks. - Why: Modeling capabilities, configuration, and recoverable errors in Effect turns architectural seams into compiler-checked contracts without leaking environment requirements to callers. Quarantining SDKs and I/O runtimes at the edges lets CLI, HTTP, desktop, and deterministic tests execute the exact same core logic without live credentials or network access.
- Applied in:
crates/agent-sandboxd/,packages/sandbox-client/, ADR 0007 - Convention: Subprocess execution lives in a focused Rust crate
(
agent-sandboxd) behind a tagged NDJSON schema contract owned bypackages/sandbox-client. The daemon enforces wall-clock deadlines, retains bounded stdout/stderr prefixes, and kills Unix process groups cleanly—and is named and documented as a process supervisor, not a security sandbox. - Why: Unbounded child output, orphaned subprocesses, and Unix process-group teardown are sharp OS edges better handled in Rust, while TypeScript keeps a typed protocol boundary. Stating the non-goal (isolation belongs in an outer sandbox) keeps security assumptions honest.
- Applied in:
apps/web/alchemy.run.ts,packages/infra/alchemy.run.ts,ops/README.md, ADR 0004, ADR 0011 - Convention: Deployable infrastructure is declared in TypeScript with
Alchemy as a resource composition root, never inside
application domain code. Shared harness resources live in
packages/infra, whileapps/webowns an independentCloudflare.Website.Wakustack beside its source and builds the same Waku app through its Node adapter for self-hosted Bun, Nix, Docker, and Kubernetes targets. Postgres (kysely+pgor@effect/sql-pg; shared dev cluster via Bytebase, dedicated CloudNativePG in production) is the default application data store; D1 inpackages/infrais strictly a Cloudflare-local demo resource. - Why: App-owned Alchemy stacks keep
alchemy devfast and deployments independent without provisioning unrelated queues or Workers. Running one Waku codebase across Cloudflare Workers and self-hosted containers avoids maintaining two web servers, and defaulting to Postgres avoids coupling application persistence to edge-only SQLite constraints.
- Applied in:
.sops.yaml,ops/secrets/,apps/web/src/worker-env.ts, ADR 0003 - Convention: Deploy-time and bootstrap secrets are committed encrypted in
ops/secrets/using SOPS andagerecipients declared in.sops.yaml(encrypted_regexencrypts secret fields while keeping keys reviewable). Plaintext.env*files, decrypted outputs, and*.agekeyprivate keys are gitignored. Composition roots resolve secrets at deploy or startup time (viaalchemy-sopsfor Workers or KSOPS in Kubernetes) and never expose decrypted values in domain code or status payloads. - Why: Every repository should run and deploy from git without out-of-band
.envhandoffs, while keeping credentials encrypted at rest, diffable in pull requests, and confined to application edges.
- Applied in:
flake.nix,nix/bun.nix,nix/prelude.nix,justfile,ops/container/web/image.nix,.github/workflows/ci.yaml, ADR 0002, ADR 0009 - Convention:
flake.nix(flake-parts) provides the hermetic devshell,nix/bun.nix(bun2nix) locks Bun dependencies for offline Nix builds, andops/container/web/image.nixstreams the production OCI image without a Docker daemon. It is the only image recipe: the local Compose stacks run the same image, loaded withjust container-image.package.jsonscripts are the canonical non-interactive command surface for CI and agents; Prelude (x) andjustwrap those exact scripts for interactive discovery and devshell enforcement. CI installs with--frozen-lockfile --ignore-scripts, runs explicitbun run prepare, and validates TypeScript, Rust,nix flake check(including template slices and an end-to-end web smoke test), and Compose config on every change. - Why: Keeping
package.jsonas the single command contract with thin human wrappers prevents drift between interactive shells, headless agents, and CI. Disabling lifecycle scripts during install makes patching explicit, and checking every stack on every PR ensures Rust, Nix, containers, and flake slices never rot behind a green TypeScript test run.
- Applied in:
AGENTS.md,docs/adr/,docs/architecture.md - Convention: Always-on operational rules for agents and contributors stay
concise in
AGENTS.md. Cross-cutting architectural, security, and toolchain choices live as numbered, append-mostly records indocs/adr/, superseded explicitly (see ADR 0011 and ADR 0012) rather than silently rewritten when conventions change. - Why: Agents need short, high-signal rules in every session, while humans and future maintainers need the durable "why" behind non-obvious constraints so settled trade-offs are not repeatedly re-litigated.
| Path | Purpose |
|---|---|
apps/cli/ |
Effect CLI entrypoint and terminal rendering boundary |
apps/harnessd/ |
Typed HTTP API, OpenAPI server, and effect-orpc example on Bun |
apps/native/ |
Tauri desktop shell with one lifecycle-managed Effect runtime |
apps/web/ |
Waku status/metrics app with its own Cloudflare Alchemy stack |
packages/agent-core/ |
@yielded/agent definition, run schemas, and AgentHarness |
packages/agent-demo/ |
Deterministic, credential-free model and tool layer for apps |
packages/agent-runtime/ |
Supervised Shell tool and harness layer for provider runs |
packages/agent-testkit/ |
ScriptedModel and deterministic Echo tool test layers |
packages/infra/ |
Shared Cloudflare resource graph composed with Alchemy |
packages/sandbox-client/ |
Effect Schema NDJSON contract shared with the Rust supervisor |
packages/web-core/ |
Framework-independent config, status, and Prometheus helpers |
packages/tooling/ |
Shared tsconfig, Oxc config, and filename organization rules |
crates/agent-sandboxd/ |
Bounded Rust NDJSON process supervisor |
crates/alloy-web3-example/ |
Alloy HTTP provider and sol! contract interface example |
crates/cloudflare-worker-example/ |
Rust (workers-rs) Cloudflare Worker deployed by packages/infra |
contracts/ |
Foundry Solidity project with Counter contract and forge tests |
flake.nix, nix/ |
Flake-parts outputs, Prelude menu (x), bun2nix lock, slices |
ops/ |
Containers, Compose, K8s overlays, SOPS secrets, observability |
docs/ |
Architecture guide, Effect/Alchemy notes, and ADRs |
AGENTS.md |
Always-on contributor and coding-agent rules for this repository |
To trace the Effect and boundary conventions in code, start with
packages/agent-core/src/services/HarnessAgent.ts
and
packages/agent-core/src/services/AgentHarness.ts,
then read
packages/agent-testkit/test/agent-harness.test.ts.
The test is the shortest executable explanation of the design.
Enter the pinned Nix devshell (or run direnv allow) and install workspace
dependencies:
nix develop
bun installTo scaffold a new repository from a maintained library slice without copying demo apps or deployment stacks, run in an empty directory:
nix flake init -t github:darkmatter/template#nix-ts-lib
# Or: #nix-rust-lib / #nix-polyglot-lib| Template | Source slice |
|---|---|
nix-ts-lib (default) |
agent-core, agent-demo, agent-runtime, agent-testkit, sandbox-client, web-core, and shared tooling packages |
nix-rust-lib |
Workspace Cargo.toml/Cargo.lock and the Rust crates under crates/ |
nix-polyglot-lib |
Both slices above |
nix/templates.nix selects tracked paths directly from
this repository rather than maintaining duplicate template copies, and
nix/flake/default.nix adapts the devshell to the
languages present (omitting apps/ and app-only Prelude commands such as x
and bun run dev). Stage the files first so Nix and ops/policies/repo-root
can see them, then verify the slice you chose:
git init && git add .
nix develop
# TypeScript / polyglot slices:
bun install --frozen-lockfile --ignore-scripts && bun run prepare
bun run check && bun run test && bun run lint && bun run fmt:check
# Rust / polyglot slices:
cargo check --workspace && cargo test --workspaceTo audit or bring an existing repository up to these conventions, invoke the
darkmatter-repo-setup agent skill, which reads darkmatter/template as its
canonical reference.
Inside nix develop, run x for the interactive Prelude command picker (just
wraps the same commands from outside or inside the shell):
x devx dev runs alchemy dev for apps/web, serving the Waku app locally in
workerd on http://localhost:3000 with /api/status and /api/metrics
(first run prompts for alchemy login). To build and run the same app on Bun
without a Cloudflare profile—matching the container and Kubernetes path—run:
bun run webRun the deterministic agent harness from the CLI:
bun run cli run --events "Explain the harness boundaries"Or start the long-lived HTTP daemon and submit the same run over its schema-validated API (OpenAPI spec at http://127.0.0.1:4319/openapi.json):
bun run harnessd
curl -sS http://127.0.0.1:4319/runs \
-H 'content-type: application/json' \
-d '{"goal":"Explain the harness boundaries"}'To layer encrypted configuration into apps/web after replacing the throwaway
recipient in .sops.yaml with your team age key (see
ops/secrets/README.md):
export APP_SOPS_FILE="$PWD/ops/secrets/demo.sops.yaml"
bun run devRun the full check suite across TypeScript, Rust, Solidity, Nix, and Compose before claiming changes work:
bun run check
bun run lint:root
bun run test
bun run lint
bun run fmt:check
cargo check --workspace
cargo test --workspace
cargo fmt --all -- --check
forge test --root contracts
nix flake check
docker compose -f ops/compose/local.yaml configAfter changing package.json dependencies, regenerate nix/bun.nix
with bun run generate:bun-nix.
Changes to template change the baseline that new and audited Darkmatter
repositories inherit:
- Update the working code, automated check or policy, and
AGENTS.mdtogether when a convention changes. - Record durable cross-cutting decisions in
docs/adr/; supersede accepted ADRs rather than rewriting history in place. - Never commit decrypted SOPS files, plaintext
.envfiles, orageprivate keys.
UNLICENSED — Private Darkmatter reference repository.