Skip to content

Building Block View

ontrack is one package (ADR-0003). Its building blocks are the files of src/: an entry point, one thin module per subcommand, and the domain modules that do the work. This section says what each module is responsible for.

Entry point and commands

bin/ontrack.ts is the executable. It passes the arguments and process to main and sets the exit code to what main returns.

src/cli.ts declares the command line with yargs, selects the subcommand, runs its handler and turns a thrown error into a message on standard error and exit code 1. It defines Io, the three things a command needs from the outside (current directory, standard output, standard error), so that tests call main without a process.

src/commands/ holds one module per subcommand: plan, apply, instructions, review, suggest, decide and check. Each exports its name, its description, its options and a handler. A handler calls domain modules, writes their formatted result to Io and returns the exit code. Only commands/apply.ts holds logic of its own: it orders the steps of an apply run (see Runtime View).

Domain modules

src/schemas.ts holds the zod models of everything ontrack reads from outside: the project’s package.json, a dependency’s package.json, the ontrack key of a track, and the frontmatter values revision and title.

src/tracks.ts lists the project’s tracks. It reads the project’s package.json, then the package.json of each installed dependency, and keeps those with an ontrack key. It returns, per track, the namespace (the npm alias) and the directory of its ADRs.

src/revision.ts reads the frontmatter of an ADR without a YAML parser: where it starts and ends, its revision: and its title:. It classifies a local copy against the track’s copy, and can set the revision: line of a file while leaving every other byte as it was.

src/plan.ts builds the plan: for each track, each ADR and its category (new, revised, removed, undetermined, unreadable, unchanged), and the files waiting to move out of a flat layout. It reads only. It also formats the plan as the text ontrack plan prints.

src/apply.ts turns a plan into actions (imported, moved, confirmed, pruned), checks all of them before any write, executes them, and formats the result. It is the only module that writes under docs/adr/. It runs git mv when the project is a git work tree.

src/links.ts finds the Markdown links a flat-layout migration breaks, in every Markdown file of the project. It reads only and imports no other module.

src/instructions.ts reads the ADRs the repository holds under docs/adr/, resolves which are in force (accepted and not superseded), refuses two ADRs that decide the same trait key, and formats the decided traits as the instructions block.

src/agents.ts compares the instructions block with what AGENTS.md holds between the two markers, reports its state, and writes it. It is the only module that writes AGENTS.md.

src/review.ts selects the ADRs to review and formats the three prompts: every proposed ADR in sequence, one proposed ADR, or the supersession of one accepted ADR.

src/suggest.ts formats the audit prompt: the ADRs the repository holds, those its tracks would import, and the steps an agent follows to find the decisions never recorded. It reuses review’s listing of the ADRs to import and its numbering sentence.

src/decide.ts formats the prompt that records one decision the user states. It reuses suggest’s lists of ADRs, its steps that read the rules and write the ADR, and review’s numbering sentence.

src/check.ts runs, through the shell, the check: command of each ADR in force and formats the outcome.

Direction of dependencies

Dependencies point one way: bin → cli → commands → domain modules, and no domain module imports a command. The commands import cli for the Io type only.

Module Imports
cli the seven commands, yargs, and package.json for the version
commands/plan plan, agents
commands/apply plan, apply, links, agents
commands/instructions instructions
commands/review review
commands/suggest suggest
commands/decide decide, suggest
commands/check check
apply plan, revision, and the Link type of links
plan tracks, revision
agents instructions
review instructions, plan
suggest instructions, review
decide suggest, review
check instructions
instructions plan (its listing of Markdown files), revision
tracks schemas, which imports zod
revision schemas
links, schemas no other module of src/

Two groups follow from the table. The modules that deal with tracks (tracks, plan, apply) are the only ones that read node_modules. The modules that deal with the repository’s own rulings (instructions, agents, check) read the project’s files only; review, suggest and decide also read the tracks, through plan, to name the ADRs to import or revised. Both groups rest on revision for frontmatter.

Diagram

This is the building-blocks view of the LikeC4 model in docs/architecture/model/. It is drawn on the documentation site only; elsewhere, read the model’s .c4 files.