How the code is laid out and which import is allowed where. The reasoning is ADR-0026; this page is what to read before
adding a file or a library. The shared kernel and the rules are built, every domain (threads, settings, onboarding, update, chat,
review, files, session-tree, artifacts, terminal, agents) is a set of libraries, and the renderer app holds the shell only.
apps/
renderer/ Angular shell: app.config, app.ts/html, the shell store, the panel switcher, the toast host (the window has
no route table: one page, the panels are switched by UiStore) scope:app
desktop/ Electron main + preload scope:app
backend/ NestJS (folder per domain under src/, see Backend) scope:backend
cli/ the pi-kit command: service, update, login, open, remote, pair, desktop install scope:backend
backend-runtime/ esbuild bundles of pi, MCP, Needle and the native-module loaders for the packaged backend scope:backend
secret-cli/ pi-kit-secret, the keychain helper pi runs scope:backend
libs/
shared/ the shared kernel, never imports a domain
protocol/ zod schemas and types shared by backend and renderer @pi-kit/protocol type:util
design-system/ tokens, CSS, Angular primitives (pk-*, pkTip, pkItem, the code editor and its tokenizer) @pi-kit/design-system type:ui
ui/ what several domains show: the diff viewer, the context menu, models and thinking formatters,
the settings catalog, keys and shortcuts, onboarding helpers, PATH_DRAG_TYPE @pi-kit/ui type:util
i18n/ Transloco setup and the English and German translations @pi-kit/i18n type:util
api/ generated HTTP operations/models, authenticated transport, NDJSON framing @pi-kit/api type:api layer:transport
data-access/ store traits ([ADR-0024](adr/0024-ngrx-signal-store.md)), toast,
dialog, theme, view prefs, health, redaction, clock, provider usage, CONTEXT_POLICY,
UiStore (the switches between components) @pi-kit/data-access type:data
testing/ thread and graph-row fixtures, fakeThreads (specs only) @pi-kit/testing type:util
pi-adapter/ pi SDK events to AG-UI (backend kernel) @pi-kit/pi-adapter type:util
secret-store/ keychain and encrypted file store (backend kernel) @pi-kit/secret-store type:util
service-host/ backend spawning/watchdog, discovery, desktop host channel, owner and remote gateways, service/CLI helpers
@pi-kit/service-host (Node/Electron host code) type:util
threads/ the thread list, projects, worktrees, trust, the attendant's suggestions
api/ ThreadsStore, TrustStore, AttendantStore, WorktreeStore, CoordinationStore, threadLabel, the ports ThreadShell and WorktreeReview
data/ threads.store, trust.store, attendant.store, worktree.store, coordination.store, changed-count.store, outcome-menu.store, score.store, learn.store, learned.store (the record of learned skills), new-thread.store, ports
util/ thread-groups, thread-state, fork-meta, sidebar, outcome, learn, where (the Where row's plan, menus, sentences and request) (pure)
ui/ FocusSelect (the inline rename field)
feature-sidebar/ ThreadSidebar (the rail, quick actions, Needs you, project bands and thread rows) and TrustDialog (eager, part of the shell)
feature-worktree/ the Sync with base / Merge back / Hand off dialog (lazy chunk)
feature-new-thread/ the page of a thread without a message and its Where row (lazy chunk, provided to the chat page through two tokens of chat/data)
feature-learn/ the skill review dialog: read a drafted skill, Approve or Discard (lazy chunk)
settings/ the settings dialog and everything a person configures
api/ what other domains use: the stores, and the components onboarding shares
(GetModel, KeyWorkflow, LoginFlow) plus PkSetting, the row every section uses, the file editor dialog (FileEditorDialog: llama-swap YAML,
mcp.json and SKILL.md), and the local model runtime (LocalRuntimeWizard, LocalModelSettings, LocalInstallGuide, LlamaRuntimeUpdatesPanel)
data/ settings.store, secrets.store, connectors.store, composio.store, packages.store, provider-cards.store, project-page.store, computer-use.store,
litellm.store, local-runtime.store, local-model-catalog.store
util/ the connectors' states, the rows of the Providers and MCP lists, the two wizards' step machines, the server form, the project rows,
the package rows with the Add a package steps, the control-column alignment check (pure)
feature-settings/ SettingsDialog (the host) and SettingsWindow (lazy): nav, search; the General, Appearance, Voice and Computer use sections; the Versions block
feature-providers/ Providers (the list and its "+" Add a provider wizard, the LiteLLM connection) and Models sections
feature-connectors/ MCP servers (the connectors merged in, its "+" Add a server wizard, the server form, the edit dialog and "Edit here", and the optional
Composio dialog that adds one Composio app at a time)
feature-attendant/ Attendant section feature-keybindings/ Keybindings section
feature-projects-trust/ Projects section: the list, a project's page, its setup scripts and open worktrees
feature-advanced/ Advanced (with "Use previous release") and Extensions and skills (Packages with the Add a package wizard, Your skills, Your
extensions and prompts); pk-learned-skill and pk-learned-retired (the record of a learned skill under its row, and the Retired list)
onboarding/ the first-run flow
data/ onboarding.store, onboarding-launch (the only part in the initial bundle)
feature-onboarding/ the full-window cards and the strip above the chat page (lazy chunk)
update/ pi and pi-kit updates
api/ data/ UpdateStore
feature-update/ the progress toast and the restart toast
chat/ the conversation with pi
api/ `export *` of chat/data: ChatStore, VoiceStore, CommandRegistry, the types (used by settings, files, review, session-tree, the shell)
data/ ChatStore, CommandRegistry, ComposerExtensions, PaletteStore, UsageStore, VoiceStore, VoiceCapture, ThreadReplayAgent and
ThreadReplayCacheStore (the cached, delta-replayed thread log), the ports ChatTree and ChatConnectors, the slots
util/ transcript and turn models, composer parsing, usage and voice helpers, the model picker's sections, matcher and effort-flask levels, generative-UI labels (pure)
ui/ the model panel (the picker) and the effort flask, the skill chip, interrupt blocks, the markdown service, pk-prose (no store)
feature-chat/ ChatPage: the CopilotKit page, the transcript and its virtual viewport, the tool-row and activity registrations
feature-composer/ InputContainer (field, toolbar, model picker, queue bar, voice button and hint), ChatState, the agent's input container, ModelPicker (the composer chip and the header button), Palette, DialogHost
feature-interrupts/ the interrupts section of the transcript
feature-genui/ the A2UI catalog and loading component, genui-turn, the MCP Apps host and its registration
review/ review mode and the Changes panel
api/ data/ ChangesStore
util/ the review message built from a comment batch
feature-review/ ReviewView, ReviewTray, ChangesPanel
files/ the Files panel
data/ FilesStore (nothing outside the domain reads it: no api)
util/ rows, decoration, menus, names, sizes (pure)
feature-files/ FilesPanel
session-tree/ the session graph, the Entries inspector, branching
api/ data/ GraphStore
util/ ui/ graph layout and tree model; the graph list (PkSessionGraph)
feature-tree/ SessionPanel
artifacts/ the desktop browser shared by the user and agent ([ADR-0029](adr/0029-browser-artifacts.md))
data/ component-scoped BrowserStore, direct generated shared/api browser operations
feature-artifacts/ ArtifactsPanel: address bar, navigation, expand, native viewport layout
terminal/ the Terminal panel: data/ (TerminalStore), feature-terminal/ (TerminalPanel); no api, nothing else reads it
agents/ ([ADR-0033](adr/0033-durable-background-agents.md)) the background agents of a thread
api/ `export *` of agents/data: AgentsStore
data/ AgentsStore (component-scoped: the list from the SDK, every change from the status channel through ThreadsStore.onStatusEvent)
util/ agent states to labels and badges, durations, the Active and History lists (pure)
feature-agents/ AgentsPanel (Active, History, questions) and AgentTranscript (the chat domain's transcript on a ChatStore for the AG-UI agent `pi-bg`)
rooms/ rooms across paired instances and their playbooks ([ADR-0038](adr/0038-rooms-for-cross-machine-work.md))
api/ `export *` of rooms/data: RoomsStore (the start-room dialog of threads/feature-sidebar uses it, playbook picker included)
data/ RoomsStore, OpenRoomStore (events, tasks, the playbook's stages, drafts to approve and notebook, from the room stream)
feature-room/ RoomView: the timeline, consultants by role and machine, the stage list, the notebook and the draft cards
<domain>/ api/ feature-<name>/ ui/ data/ util/ (the shape every domain library follows)
packages/ pi packages that ship with the app (Nx projects scope:shared type:util, tested with vitest)
pi-kit-learn/ @pi-kit/learn: /learn, the analysis prompt; talks to pi-kit through the events of doc/docs/plugins.md
pi-kit-meat-proxy/ @pi-kit/meat-proxy: /score, the ledger, the attribution prompt and the score arithmetic; the plugin API's second consumer
pi-computer-use/ @pi-kit/computer-use: opt-in computer use through Cua Driver (`/computer-use on`); installed into pi once like the others,
and uses only the one-way `pi-kit:composer` event
tools/generators/domain-lib/ the generator below scope:tools
e2e/ end-to-end tests: Playwright driven by Node's test runner (`pnpm run e2e`; not an Nx project)
Nx project names: shared-<name> for the kernel (shared-protocol, shared-data-access, ...), <domain>-<type>[-<name>]
for domain libraries (threads-feature-sidebar, chat-data), and the app folder name for apps (renderer, backend).
The import alias is separate and stays short: @pi-kit/protocol, @pi-kit/data-access, and
@pi-kit/<domain>/<type>[-<name>] for domain libraries (@pi-kit/threads/feature-sidebar).
Every project carries one scope:* tag and, for libraries, one type:* tag. eslint.config.mjs holds the whole rule as
one depConstraints block (@nx/enforce-module-boundaries); a violation is a lint error.
| Scope | May depend on |
|---|---|
scope:shared |
scope:shared only |
scope:<domain> |
itself, scope:shared, and the type:api of other domains |
scope:backend |
scope:backend, scope:shared |
scope:app |
anything |
| Type | One line | May depend on (inside the scope rule above) |
|---|---|---|
type:api |
What other domains import: a facade over the domain's store, selected types | data, util, scope:shared |
type:feature |
Container components wired to stores; lazy entry points and eager shell features | feature, ui, data, util, scope:shared, other domains' api |
type:ui |
Presentational components: inputs and outputs only, no store, no HTTP | ui, util, scope:shared |
type:data |
SignalStores, direct generated operations, mappers | data, util, scope:shared, other domains' api |
type:util |
Pure functions of the domain | util, scope:shared |
Both rules apply at once: a scope:threads + type:ui library may use threads utils, shared code and nothing of
chat; it may not use chat/api either, because a ui library never touches a store. The check is on every import
that goes through a @pi-kit/* alias; a relative import out of a library is an error too. apps/renderer is
scope:app, so its own folders import each other freely until they become libraries.
One more tag, layer:transport (on shared/api only), limits that library to other layer:transport code, so the
transport never imports a store. tools/generators/domain-lib is scope:tools, outside the rule.
The scope rule needs one entry per domain: the domains list at the top of eslint.config.mjs (the generator adds a
new domain to it).
-
A new file goes in the domain that owns it. It goes to
libs/shared/*only when two domains need it (the "scope rule" of ADR-0026); until then it stays with its single user. -
A domain library is made with the generator, never by hand:
pnpm exec nx g ./tools/generators/domain-lib:lib --domain threads --type feature --name sidebar pnpm exec nx g ./tools/generators/domain-lib:lib --domain settings --type data--typeisapi | feature | ui | data | util; onlyfeaturetakes--name(one library per lazy entry, the others are one per domain).--testing angular|nodeoverrides the test setup (default:nodeforutil,angularfor the rest). Add--dry-runto see what it would write.It creates
libs/<domain>/<type>[-<name>]withproject.json(name<domain>-<type>[-<name>], tagsscope:<domain>andtype:<type>,lintandtesttargets),tsconfig.json,tsconfig.lib.json,tsconfig.spec.json,eslint.config.mjs(Angular rules, prefixpk),README.md,src/index.ts, apackage.jsonthat only says"sideEffects": false(see "Barrels and the bundle" below), and eithersrc/test-setup.ts(angular: the Angular unit-test builder with jsdom and vitest, likeshared-data-access) orvitest.config.mts(node: plain vitest with the@pi-kit/*aliases read fromtsconfig.base.json, likeshared-ui). It adds the@pi-kit/<domain>/<type>[-<name>]path totsconfig.base.jsonand the domain to thedomainslist. The generator's own test ispnpm exec nx test tools-domain-lib. -
Specs sit next to the code (
*.spec.ts).pnpm run checkrunsbuild,eslint:lintandtestfor every project, so a generated library is in the gate as soon as it exists. The Angular unit-test builder fails when a project has no spec at all, so a library without specs has notesttarget (delete it fromproject.jsonafter generating, add it back from a sibling when the first spec lands). -
To keep a feature lazy, load its entry through a
@deferblock inapps/renderer(or, for the settings window, in theSettingsDialoghost of its own library) or through a slot's dynamicimport()(below), and avoid other static imports of that entry. Not everyfeature-*library is lazy: the sidebar is part of the eager shell. -
Barrels and the bundle: write
src/index.tsof every library asexport * from './lib/x'(andexport * from '@pi-kit/<domain>/data'in anapi). The existing barrels use this form to preserve the lazy split. Do not assume that barrel syntax alone guarantees a chunk boundary: static imports and the application build determine what ships in each chunk. A lazy component that is the entry of its chunk (the settings window) is not exported from the barrel at all, because the barrel would import it statically; the host that@defers it imports it by relative path. Name clashes between a barrel'sexport *sources are a compile error (TS2308), which is how a state interface calledKeyWorkflowand a component of the same name were found. -
A domain library may not import the app, and the project graph may not have a cycle (
@nx/enforce-module-boundariesreports it:chat-data -> settings-api -> settings-data -> chat-api -> chat-data). When two domains really read each other, one side uses the other'sapiand the other side declares a port: an abstract class in itsdatathat it injects, whichapp.config.ts(the composition root) provides from the real store ({ provide: ChatTree, useExisting: GraphStore }). There are four:ThreadShell(the shell store lives in the app) andWorktreeReview(review reads the threads) inthreads/data,ChatTree(session tree) andChatConnectors(the connectors of Settings) inchat/data. A new port is a last resort: first see whether the dependency can point the other way. -
Two slots are the other way a lazy chunk of one domain reaches into another's page:
EMPTY_THREAD_PAGEandNEW_THREAD_COMPOSERinchat/dataare injection tokens whose value is a function that loads components (() => import('@pi-kit/threads/feature-new-thread'), provided inapp.config.ts). The transcript and the composer render what they load withNgComponentOutlet; nothing else imports the feature library, so it stays a lazy chunk, and the chat never imports the threads' feature code. The page and the row decide by themselves whether the open thread is a new one.
apps/renderer/src/appholdsapp.config.ts,app.ts/html,shell.store.ts,panel-switcher.ts(the header's side-panel toggles) andcore/toast-host.ts, with their specs. The toast host stays in the app: it is the window's toast stack, which happens to contain theupdatetoast, so it composes two domains.- Settings reads the chat through
chat/api(ChatStore.running,VoiceStore); the chat reads the connectors of Settings through the portChatConnectors, becausesettings/dataimportschat/apifirst (a chat that importssettings/apiback is a cycle). CoordinationStore(who else works in the folder, ADR-0020) is inthreads/data: the Files panel and review mode both show its chips.ChangedCountStore(the badge on the sidebar's "Working tree changes" button: git status of the folder in view) is inthreads/data, andThreadShell.answerWaitingis the port the "Needs you" strip answers a dialog through.PATH_DRAG_TYPE(the drag type of a Files row, read by the chat's drop target) is inshared/ui: two domains need it.- What left
shared/ui: composer logic, the transcript and turn models, usage, voice and generative-UI helpers (tochat/util), the files model (files/util), the review message (review/util), the graph layout and tree model (session-tree/util), the session graph component (session-tree/ui),forkMeta(threads/util). What stayed: the formatters inthinking.ts,models, the diff viewer and rows (chat and review), the context menu, the settings catalog, keys and shortcuts,onboarding(several domains read them). - Tailwind scans the domain folders through the
@sourcelines inapps/renderer/src/styles.css; a new domain whose templates use utility classes adds one. UiStoremoved fromcore/to@pi-kit/data-access: threads, settings and onboarding all read it (which dialog is open, the composer requests), and a library cannot import the app, so by the scope rule of ADR-0026 it is kernel code.- The
apilibraries re-export theirdatalibrary withexport *, so what other domains can use is whatdataexports. Thedatabarrels expose stores and domain contracts; HTTP operations come directly from the generated shared API.SecretsStoreis exported to the settings features and therefore visible throughsettings/api. settings/apialso hosts components and a directive-like row (GetModel,KeyWorkflow,LoginFlow,PkSetting,FileEditorDialog, the local runtime wizard). Anapimay depend on its owndataonly, so this is where components that other domains show (the provider cards in the onboarding) and that every section library uses can live without breaking the rule.- A section library is imported statically by the settings window, so all sections ship in the one lazy
settings-windowchunk. Making each section its own chunk would need@deferin the window's template. apps/renderer/src/app/core/keeps onlytoast-host.ts; everything else that was incore/is@pi-kit/data-access.- Linting runs through the inferred
eslint:linttarget of@nx/eslint/plugin, which every project has (the backend, desktop and Node projects included);pnpm run lintruns it alone andpnpm run checkruns it withbuildandtest. The renderer libraries also carry an explicitlinttarget, which the generator adds.pnpm run lint:toolingcoversscripts/,tools/andpackages/.
Generated HTTP API and configuration (ADR-0027)
shared/api owns the generated SDK and authenticated transport. Import operation
functions and ApiClient from @pi-kit/api; always pass client to the operation.
Stores call generated operations directly; do not add endpoint wrapper classes or *.api.ts proxies. Keep state, response mapping and orchestration in domain data/ libraries. The domain api/ folder
remains the public domain facade. Regenerate with pnpm run api:openapi; the full
check compares every generated file. The transport layer cannot import stores.
Data libraries use typed policy injection tokens for configurable runtime behavior (for example, THREADS_POLICY,
SETTINGS_POLICY and VOICE_POLICY); the naming and number of tokens vary by domain.
Use component inputs for instance behavior, tokens for application/domain defaults,
and reactive preference stores for user settings. CONTEXT_POLICY is shared by chat
and thread context indicators. Keep pure functions independent of DI by passing the
policy as a parameter. Protocol IDs and storage keys remain constants.
Chat and settings store implementation features live under data/src/lib/chat/ and
data/src/lib/settings/; their store files compose those features and retain the
public facade used by components.