Skip to content

Architecture

matthew edited this page Aug 29, 2026 · 1 revision

Architecture

How the codebase is laid out and the two invariants every change must respect. The mechanisms that make a feature a deletable plug-in are on Runtime seams.

Code is clean if it can be read, and enhanced by a developer other than its original author. Every line must justify its existence through clear naming and thorough documentation of why it exists.

1. Stack at a glance

  • Angular 22, standalone + zoneless. Signals are the reactive model; there is no Zone.js. A @Service() decorator (= @Injectable({ providedIn: 'root' })) marks DI singletons.
  • Electron, main + preload written in TypeScript and esbuild-bundled (not tsc-emitted); tsc --noEmit type-checks them.
  • Vitest for tests; ESLint (typed rules) + Prettier (printWidth: 100) enforce the house style mechanically.
  • Node is pinned via .nvmrc (currently 24.16.0) — run nvm use before working.

2. Repository architecture — feature-first

src/ contains exactly two subdirectories:

src/features/<feature>/{angular,electron,api}   ← recipes: compose shared parts
src/shared/{angular,api,app,electron}           ← kitchen: runtime + reusable parts

The eight features are workspace (the directory tab), repository (source-control), code, markdown, terminal, agent, settings, and welcome. settings and welcome are leaf consumers of shared infra modelled as features for uniformity.

The two invariants (non-negotiable)

  1. No feature code lands in shared. shared/{angular,api,electron} must not name or import any feature. (shared/app — the assembler — is the sole exception; see below.)
  2. Features are isolated like plugins. Everything a feature needs lives under src/features/<feature>/; a feature imports only @shared/* and @features/*, never a sibling feature's internals by relative path. Removing a feature's folder removes the feature — the only permitted straggler is one line in src/shared/app/config.ts.

Enforced, not just documented. INV2 is mechanically checked by ESLint. eslint.config.js generates a per-feature @typescript-eslint/no-restricted-imports rule that bans importing a sibling @features/<other>/* — a feature may import only @shared/* and its own @features/<self>/*. A cross-feature import fails npm run lint. The fix is always to promote the shared surface to @shared, never to add a cross-import (precedent: MarkdownCommands → @shared/angular/services/markdown-commands, CommitDetail → @shared/angular/components/panels/commit-detail).

Kitchen vs recipe

shared is a kitchen stocked with reusable capability components, framework, atoms, cross-cutting services, and the generic IPC transport. Features are recipes: a leaf view composes shared parts plus its own ribbon / commands / status glue and its own api/electron surface.

shared/app — the assembler

src/shared/app is a deliberately tiny sibling of angular/api/electron. It is the only code allowed to name features, because it is the composition root:

  • config.ts — the feature enumeration (seven provide<F>Feature() calls; welcome is mounted directly by root). This is the one place that lists features; delete a feature = delete its folder
    • remove its line here.
  • root/ — the app-root component that mounts the shell chrome + the active tab's view.
  • main.ts — the Angular bootstrap. global.d.ts — the ambient Window.bridge/host types. index.html — the HTML entry.

3. Shared capability wrappers — the load-bearing contract

The kitchen's capability components are thin wrappers around exactly one engine each — no splitter, no side panels, no ribbon, no embedded agent:

Wrapper Wraps Backing plumbing (also in shared)
<app-terminal> xterm (node-pty backend) pty api contract + electron terminal-manager + terminal-bridge
<app-text-editor> Monaco monaco service + Editors (model-URI → document registry)
<app-markdown-editor> Milkdown / ProseMirror milkdown service + plugins
<app-agent> the agent chat UI agent-runtime / ai-auth / agent-sessions + the ai bridge

Because a shared wrapper depends on its plumbing, the plumbing is shared too — so the terminal feature owns little-to-no unique electron/api; it composes the shared capability.

Feature views are leaves that compose the shared panel layout with these wrappers:

terminal-view = layout{ main: <app-terminal>,        side: <app-agent> }
code-view     = layout{ main: <app-text-editor>,     sides: <app-terminal>, <app-agent> }
markdown-view = layout{ main: <app-markdown-editor>, sides: outline/review/reader, <app-agent> }

Do not sub-divide a capability wrapper or "improve" it while touching it. It is the kitchen.

Clone this wiki locally