# getcompanion-ai/feynman architecture

> Architecture diagram of the GitHub repository getcompanion-ai/feynman, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/getcompanion-ai/feynman
- Repository: https://github.com/getcompanion-ai/feynman

## Overview

1. **Top-level shape**
   - This repo is a **two-part product**: a **Node-based CLI application** at the root, and a separate **Astro documentation website** under `website/`.
   - The CLI is the runtime product; the website is the public docs/install portal and mirrors the same workflows, agents, and tool references.

2. **User-facing entry points**
   - The main executable is `bin/feynman.js`, which boots the CLI from `src/index.ts` and `src/cli.ts`.
   - The CLI surface is organized around research workflows like `deepresearch`, `lit`, `review`, `audit`, `replicate`, `compare`, `draft`, `autoresearch`, and `watch`, with slash-command style shortcuts reflected in `src/model/commands.ts` and `src/search/commands.ts`.

3. **Core runtime boundary: Pi**
   - The repository is built on **Pi** as the agent runtime. The `src/pi/` subtree contains the integration layer for launching Pi, configuring settings, packaging presets, and web access.
   - Several `scripts/lib/pi-*patch.*` files and `scripts/patch-embedded-pi.mjs` indicate the repo **vendors and patches embedded Pi dependencies** to control behavior like extension loading, subagents, legacy schema handling, and web-access hooks.

4. **Research workflow engine**
   - The research behavior is mostly defined as **skills and prompts**, not hardcoded application logic.
   - `skills/` contains the reusable skill library; `prompts/` contains workflow prompts; `.feynman/agents/` contains agent role definitions; and `extensions/research-tools/` provides tool-specific extensions used by those workflows.
   - The data flow is: user command → CLI command dispatch → Pi agent runtime → skill/prompt selection → tool-enabled research execution → generated artifact in `outputs/`.

5. **Agent roles**
   - The bundled roles are **Researcher**, **Reviewer**, **Writer**, and **Verifier**.
   - These are not separate services; they are instructions and policies that shape how the same runtime behaves for evidence gathering, peer-review simulation, drafting, and citation verification.

6. **Model and provider subsystem**
   - `src/model/` handles model cataloging, registry resolution, service tiers, and the model metadata consumed by the CLI/setup flow.
   - The README’s “custom provider” path shows the architecture supports **OpenAI-compatible local or remote model endpoints** via a base URL + API key model, which is how Ollama and similar providers can be plugged in.

7. **Search and source acquisition**
   - `src/web-search.ts` and the `extensions/research-tools/` layer provide the main external-source acquisition path.
   - The repo explicitly integrates **AlphaXiv**, web search, and session search; these are the main ingestion boundaries for source-grounded research outputs.
   - The important architectural boundary is that the CLI does not “own” the data sources; it orchestrates external retrieval tools and then synthesizes/cites them.

8. **Execution and compute extensions**
   - Compute-heavy workflows are handled via skills and tools, not by the CLI itself.
   - The repository supports **Docker**, **Modal**, and **RunPod** through dedicated skills, which means long-running or GPU-backed tasks are delegated to external execution environments rather than the local terminal process.

9. **Setup, bootstrap, and environment control**
   - `src/setup/` covers installation/doctor/preview/setup flows, while `src/bootstrap/` handles sync-related startup work.
   - `src/system/` contains OS and runtime adapters like executable discovery, Node version checks, URL opening, and promise polyfills.
   - These modules form the “environment boundary” around the CLI so it can reliably run across macOS/Linux/Windows and enforce the required Node/runtime constraints.

10. **Skill distribution and installation**
   - The repo treats skills as a distributable artifact. `scripts/install/` and `scripts/sync-website-installers.mjs` generate the public installer paths, while `skills-lock.json` pins what gets distributed.
   - The README distinguishes between a **full terminal app install** and a **skills-only install**, which is important architecturally: skills are portable content, while the CLI includes runtime, auth storage, and bundled Pi packages.

11. **Generated outputs and artifacts**
   - Research artifacts are written to `outputs/`, with supporting folders like `notes/`, `papers/`, and `experiments/` used as working areas.
   - This suggests a clear separation between **input sources**, **working state**, and **published/generated deliverables**.

12. **Website as documentation and installer host**
   - `website/` is a standalone Astro app that publishes the docs for commands, agents, tools, and workflows.
   - It also serves the public installer assets under `website/public/`, making the website part of the delivery pipeline for the CLI and skills distribution.

13. **Validation and release pipeline**
   - The tests under `tests/` cover config paths, model catalog behavior, Pi patches, node-version checks, URL opening, and skill paths, which are the main architecture seams most likely to break.
   - `.github/workflows/publish.yml` plus the build scripts indicate a release process that produces installable artifacts and likely the standalone bundled distribution referenced in the README.

14. **What to draw in an architecture diagram**
   - A good diagram would show: **User/terminal → CLI entrypoint → command dispatcher → Pi runtime + skills/prompts → external tools (search, AlphaXiv, session search, web, compute providers) → generated outputs**.
   - In parallel, show the **docs website** as a separate deployment that publishes documentation and installer scripts, and the **skills installer** path as a content-only distribution channel distinct from the full app.

Main entry points: [`src/pi/runtime.ts`](https://github.com/getcompanion-ai/feynman/blob/main/src/pi/runtime.ts) (Pi runtime), [`website/src/content/docs`](https://github.com/getcompanion-ai/feynman/tree/main/website/src/content/docs) (Docs content), [`src/cli.ts`](https://github.com/getcompanion-ai/feynman/blob/main/src/cli.ts) (Commands), [`extensions/research-tools.ts`](https://github.com/getcompanion-ai/feynman/blob/main/extensions/research-tools.ts) (Tools ext)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI runtime"]
  node_bin_entry["CLI entry<br/>entrypoint<br/>[feynman.js]"]
  node_cli_boot["App bootstrap<br/>cli bootstrap<br/>[index.ts]"]
  node_command_dispatch["Commands<br/>dispatcher<br/>[cli.ts]"]
  node_search_commands["Search cmds<br/>command registry<br/>[commands.ts]"]
  node_model_commands["Model cmds<br/>command registry<br/>[commands.ts]"]
  node_model_core["Model core<br/>model registry<br/>[catalog.ts]"]
  node_pi_runtime["Pi runtime<br/>agent runtime<br/>[runtime.ts]"]
  node_pi_launch["Pi launch<br/>runtime launcher<br/>[launch.ts]"]
  node_setup_env["Setup<br/>[setup.ts]"]
  node_system_adapters["System adapters<br/>platform boundary<br/>[executables.ts]"]
  node_web_search["Web search<br/>source acquisition<br/>[web-search.ts]"]
end

subgraph group_content["Research content"]
  node_agents["Agents<br/>roles<br/>[agents]"]
  node_skills["Skills"]
  node_prompts["Prompts"]
  node_research_tools["Tools ext<br/>tool extensions<br/>[research-tools.ts]"]
  node_pi_overrides["Pi patches<br/>vendor patches<br/>[vendor-overrides]"]
  node_outputs[("Outputs<br/>artifacts")]
  node_installers["Installers<br/>distribution"]
end

subgraph group_site["Docs website"]
  node_docs_site["Docs site<br/>astro site"]
  node_site_content["Docs content"]
  node_site_public["Public assets<br/>site assets"]
end

node_bin_entry -->|"starts"| node_cli_boot
node_cli_boot -->|"routes"| node_command_dispatch
node_command_dispatch -->|"uses"| node_model_commands
node_command_dispatch -->|"uses"| node_search_commands
node_command_dispatch -->|"orchestrates"| node_pi_runtime
node_pi_runtime -->|"launches"| node_pi_launch
node_pi_runtime -->|"selects models"| node_model_core
node_pi_runtime -->|"applies roles"| node_agents
node_pi_runtime -->|"executes"| node_skills
node_pi_runtime -->|"templates"| node_prompts
node_pi_runtime -->|"uses tools"| node_research_tools
node_research_tools -->|"retrieves"| node_web_search
node_research_tools -->|"writes"| node_outputs
node_setup_env -->|"checks"| node_system_adapters
node_setup_env -->|"configures"| node_model_core
node_pi_overrides -->|"patches"| node_pi_runtime
node_installers -->|"packages"| node_skills
node_installers -->|"publishes"| node_docs_site
node_docs_site -->|"renders"| node_site_content
node_docs_site -->|"serves"| node_site_public
node_site_content -->|"documents"| node_agents
node_site_content -->|"documents"| node_skills
node_site_content -->|"documents"| node_research_tools
node_site_content -->|"documents"| node_prompts

click node_bin_entry "https://github.com/getcompanion-ai/feynman/blob/main/bin/feynman.js"
click node_cli_boot "https://github.com/getcompanion-ai/feynman/blob/main/src/index.ts"
click node_command_dispatch "https://github.com/getcompanion-ai/feynman/blob/main/src/cli.ts"
click node_search_commands "https://github.com/getcompanion-ai/feynman/blob/main/src/search/commands.ts"
click node_model_commands "https://github.com/getcompanion-ai/feynman/blob/main/src/model/commands.ts"
click node_model_core "https://github.com/getcompanion-ai/feynman/blob/main/src/model/catalog.ts"
click node_pi_runtime "https://github.com/getcompanion-ai/feynman/blob/main/src/pi/runtime.ts"
click node_pi_launch "https://github.com/getcompanion-ai/feynman/blob/main/src/pi/launch.ts"
click node_setup_env "https://github.com/getcompanion-ai/feynman/blob/main/src/setup/setup.ts"
click node_system_adapters "https://github.com/getcompanion-ai/feynman/blob/main/src/system/executables.ts"
click node_web_search "https://github.com/getcompanion-ai/feynman/blob/main/src/web-search.ts"
click node_agents "https://github.com/getcompanion-ai/feynman/blob/main/.feynman/agents"
click node_skills "https://github.com/getcompanion-ai/feynman/tree/main/skills"
click node_prompts "https://github.com/getcompanion-ai/feynman/tree/main/prompts"
click node_research_tools "https://github.com/getcompanion-ai/feynman/blob/main/extensions/research-tools.ts"
click node_pi_overrides "https://github.com/getcompanion-ai/feynman/blob/main/.feynman/vendor-overrides"
click node_outputs "https://github.com/getcompanion-ai/feynman/tree/main/outputs"
click node_installers "https://github.com/getcompanion-ai/feynman/tree/main/scripts/install"
click node_docs_site "https://github.com/getcompanion-ai/feynman/tree/main/website"
click node_site_content "https://github.com/getcompanion-ai/feynman/tree/main/website/src/content/docs"
click node_site_public "https://github.com/getcompanion-ai/feynman/tree/main/website/public"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_bin_entry,node_cli_boot,node_command_dispatch,node_search_commands,node_model_commands,node_model_core,node_pi_runtime,node_pi_launch,node_setup_env,node_system_adapters,node_web_search toneBlue
class node_agents,node_skills,node_prompts,node_research_tools,node_pi_overrides,node_outputs,node_installers toneAmber
class node_docs_site,node_site_content,node_site_public toneMint
```

## Components

### CLI runtime

Node-based application that boots the terminal product and orchestrates research workflows.

- [CLI entry](https://github.com/getcompanion-ai/feynman/blob/main/bin/feynman.js): entrypoint · Main executable that starts the terminal app. · `bin/feynman.js`
- [App bootstrap](https://github.com/getcompanion-ai/feynman/blob/main/src/index.ts): cli bootstrap · CLI startup and top-level command wiring. · `src/index.ts`
- [Commands](https://github.com/getcompanion-ai/feynman/blob/main/src/cli.ts): dispatcher · Primary workflow command surface for research actions. · `src/cli.ts`
- [Search cmds](https://github.com/getcompanion-ai/feynman/blob/main/src/search/commands.ts): command registry · Slash-style search and source-acquisition commands. · `src/search/commands.ts`
- [Model cmds](https://github.com/getcompanion-ai/feynman/blob/main/src/model/commands.ts): command registry · Model-related command and setup surfaces. · `src/model/commands.ts`
- [Model core](https://github.com/getcompanion-ai/feynman/blob/main/src/model/catalog.ts): model registry · Catalog, registry, and service-tier resolution for models. · `src/model/catalog.ts`
- [Pi runtime](https://github.com/getcompanion-ai/feynman/blob/main/src/pi/runtime.ts): agent runtime · Integration layer for launching and configuring the embedded Pi agent runtime. · `src/pi/runtime.ts`
- [Pi launch](https://github.com/getcompanion-ai/feynman/blob/main/src/pi/launch.ts): runtime launcher · Startup and packaging path for Pi execution. · `src/pi/launch.ts`
- [Setup](https://github.com/getcompanion-ai/feynman/blob/main/src/setup/setup.ts): environment setup · Doctor, preview, and installation flows for local readiness. · `src/setup/setup.ts`
- [System adapters](https://github.com/getcompanion-ai/feynman/blob/main/src/system/executables.ts): platform boundary · OS/runtime helpers for executables, Node checks, and URL opening. · `src/system/executables.ts`
- [Web search](https://github.com/getcompanion-ai/feynman/blob/main/src/web-search.ts): source acquisition · External search and retrieval boundary for source-grounded research. · `src/web-search.ts`

### Research content

Reusable prompts, skills, agent roles, and tool extensions that define behavior.

- [Agents](https://github.com/getcompanion-ai/feynman/blob/main/.feynman/agents): roles · Researcher, reviewer, writer, and verifier role instructions. · `.feynman/agents`
- [Skills](https://github.com/getcompanion-ai/feynman/tree/main/skills): workflow skills · Reusable skill library that encodes research and compute workflows. · `skills`
- [Prompts](https://github.com/getcompanion-ai/feynman/tree/main/prompts): workflow prompts · Prompt templates for deep research, review, drafting, and related flows. · `prompts`
- [Tools ext](https://github.com/getcompanion-ai/feynman/blob/main/extensions/research-tools.ts): tool extensions · Research tool extensions for alphaxiv, discovery, session search, and helpers. · `extensions/research-tools.ts`
- [Pi patches](https://github.com/getcompanion-ai/feynman/blob/main/.feynman/vendor-overrides): vendor patches · Embedded Pi override layer for extension loading, web access, subagents, and schema compatibility. · `.feynman/vendor-overrides`
- [Outputs](https://github.com/getcompanion-ai/feynman/tree/main/outputs): artifacts · Generated research artifacts and working outputs. · `outputs`
- [Installers](https://github.com/getcompanion-ai/feynman/tree/main/scripts/install): distribution · Scripts and generated installers for full app and skills-only distribution. · `scripts/install`

### Docs website

Standalone Astro app that publishes documentation and installer assets.

- [Docs site](https://github.com/getcompanion-ai/feynman/tree/main/website): astro site · Standalone documentation and installer portal. · `website`
- [Docs content](https://github.com/getcompanion-ai/feynman/tree/main/website/src/content/docs): docs content · Published docs for commands, agents, tools, workflows, and setup. · `website/src/content/docs`
- [Public assets](https://github.com/getcompanion-ai/feynman/tree/main/website/public): site assets · Installer files and public downloadable assets served by the website. · `website/public`

## Connections

- CLI entry → App bootstrap: starts · Executable boots the application runtime.
- App bootstrap → Commands: routes · Top-level CLI dispatches user actions into workflows.
- Commands → Model cmds: uses · Model-related commands feed setup and resolution flows.
- Commands → Search cmds: uses · Search and slash commands expose source-acquisition actions.
- Commands → Pi runtime: orchestrates · CLI delegates workflow execution to the embedded agent runtime.
- Pi runtime → Pi launch: launches · Runtime startup and packaging are handled through the launch layer.
- Pi runtime → Model core: selects models · Agent runtime depends on model catalog and service-tier resolution.
- Pi runtime → Agents: applies roles · Runtime behavior is shaped by agent instructions and policies.
- Pi runtime → Skills: executes · Skills supply the reusable workflow behavior.
- Pi runtime → Prompts: templates · Prompts steer each research workflow.
- Pi runtime → Tools ext: uses tools · Tool extensions provide external capabilities and source access.
- Tools ext → Web search: retrieves · Search tools connect to web and source providers.
- Tools ext → Outputs: writes · Research workflows produce artifacts in the outputs area.
- Setup → System adapters: checks · Setup flows validate the host environment and runtime constraints.
- Setup → Model core: configures · Setup and doctor flows use model metadata.
- Pi patches → Pi runtime: patches · Vendor overrides modify embedded Pi behavior and compatibility.
- Installers → Skills: packages · Skill distribution is separated from the full runtime.
- Installers → Docs site: publishes · Installer assets are synced into the website delivery path.
- Docs site → Docs content: renders · Astro site publishes docs content.
- Docs site → Public assets: serves · Website hosts public install artifacts.
- Docs content → Agents: documents · Docs describe the bundled agent roles.
- Docs content → Skills: documents · Docs describe the skill workflows and usage.
- Docs content → Tools ext: documents · Docs cover the key tool integrations.
- Docs content → Prompts: documents · Docs explain the workflow prompts and commands.
