# ntatarinov/sai architecture

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

- Interactive diagram: https://gitdiagram.com/ntatarinov/sai
- Repository: https://github.com/ntatarinov/sai

## Overview

Sai is a local virtual-team product: an owner submits a business goal, the team plans and runs role-based agent work, checks results, records project state, and presents progress through a web page or terminal. The repository also contains the agent-development pipeline and Pixel Office, which visualizes its activity, plus a questionnaire picker. The graph emphasizes documented product stages and source-indexed calls; several internal modules are represented by their enclosing subsystem because their implementation was not excerpted.

Main entry points: [`tools/src/team/engine/engine.js`](https://github.com/ntatarinov/sai/blob/main/tools/src/team/engine/engine.js) (Project engine), [`tools/src/pixel-office/server.js`](https://github.com/ntatarinov/sai/blob/main/tools/src/pixel-office/server.js) (Office HTTP server), [`tools/src/team/store.js`](https://github.com/ntatarinov/sai/blob/main/tools/src/team/store.js) (Project state and journal), [`tools/src/web/server.js`](https://github.com/ntatarinov/sai/blob/main/tools/src/web/server.js) (Team web interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_team["Sai Team"]
  node_team_web["Team web interface<br/>[server.js]"]
  node_team_cli["Team commands<br/>[cli.js]"]
  node_team_engine["Project engine<br/>[engine.js]"]
  node_planning["Planning and review<br/>[plan.js]"]
  node_role_runner["Role task runner<br/>[runner.js]"]
  node_executor["Agent executors<br/>[executor.js]"]
  node_project_state[("Project state and journal<br/>[store.js]")]
  node_project_rules["State and event rules<br/>[reducer.js]"]
  node_project_files["Project data home<br/>[home.js]"]
end

subgraph group_pipeline["Agent Pipeline"]
  node_handoffs["Agent handoffs"]
  node_trace_checks["Trace checks"]
end

subgraph group_office["Pixel Office"]
  node_office_server["Office HTTP server<br/>[server.js]"]
  node_office_journal[("Event journal<br/>[journal.js]")]
  node_office_mask["Secret masking<br/>[mask.js]"]
  node_office_state["Office state directory<br/>[state-dir.js]"]
  node_office_page["Live office page<br/>[app.js]"]
end

subgraph group_picker["Questionnaire Picker"]
  node_picker_page["Questionnaire interface<br/>[app.js]"]
  node_picker_server["Questionnaire server<br/>[server.js]"]
  node_picker_engine["Questionnaire engine<br/>[engine.js]"]
end

node_owner(("Business owner"))

node_owner -->|"submits goal"| node_team_web
node_owner -->|"starts work"| node_team_cli
node_team_web -->|"starts projects"| node_team_engine
node_team_engine -->|"plans and checks"| node_planning
node_team_engine -->|"runs tasks"| node_role_runner
node_team_engine -->|"reads project"| node_project_state
node_team_engine -->|"records progress"| node_project_state
node_role_runner -->|"dispatches work"| node_executor
node_project_state -->|"reduces events"| node_project_rules
node_project_state -->|"uses project paths"| node_project_files
node_team_engine -.->|"creates handoffs"| node_handoffs
node_handoffs -->|"checks traces"| node_trace_checks
node_office_server -->|"records events"| node_office_journal
node_office_server -->|"masks content"| node_office_mask
node_office_server -->|"reads secrets"| node_office_state
node_office_page -->|"fetches events"| node_office_server
node_team_engine -->|"masks agent data"| node_office_mask
node_owner -.->|"answers questions"| node_picker_page
node_picker_page -->|"requests questionnaire"| node_picker_server
node_picker_server -->|"evaluates answers"| node_picker_engine

click node_team_web "https://github.com/ntatarinov/sai/blob/main/tools/src/web/server.js"
click node_team_cli "https://github.com/ntatarinov/sai/blob/main/tools/src/team/cli.js"
click node_team_engine "https://github.com/ntatarinov/sai/blob/main/tools/src/team/engine/engine.js"
click node_planning "https://github.com/ntatarinov/sai/blob/main/tools/src/team/engine/plan.js"
click node_role_runner "https://github.com/ntatarinov/sai/blob/main/tools/src/team/runner.js"
click node_executor "https://github.com/ntatarinov/sai/blob/main/tools/src/team/executor.js"
click node_project_state "https://github.com/ntatarinov/sai/blob/main/tools/src/team/store.js"
click node_project_rules "https://github.com/ntatarinov/sai/blob/main/tools/src/team/reducer.js"
click node_project_files "https://github.com/ntatarinov/sai/blob/main/tools/src/team/home.js"
click node_handoffs "https://github.com/ntatarinov/sai/tree/main/tools/src/handoffs"
click node_trace_checks "https://github.com/ntatarinov/sai/tree/main/tools/src/traces"
click node_office_server "https://github.com/ntatarinov/sai/blob/main/tools/src/pixel-office/server.js"
click node_office_journal "https://github.com/ntatarinov/sai/blob/main/tools/src/pixel-office/journal.js"
click node_office_mask "https://github.com/ntatarinov/sai/blob/main/tools/src/pixel-office/mask.js"
click node_office_state "https://github.com/ntatarinov/sai/blob/main/tools/src/pixel-office/state-dir.js"
click node_office_page "https://github.com/ntatarinov/sai/blob/main/tools/src/pixel-office/public/app.js"
click node_picker_page "https://github.com/ntatarinov/sai/blob/main/tools/src/picker/public/app.js"
click node_picker_server "https://github.com/ntatarinov/sai/blob/main/tools/src/picker/server.js"
click node_picker_engine "https://github.com/ntatarinov/sai/blob/main/tools/src/picker/engine.js"

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_team_web,node_team_cli,node_team_engine,node_planning,node_role_runner,node_executor,node_project_state,node_project_rules,node_project_files toneBlue
class node_handoffs,node_trace_checks toneAmber
class node_office_server,node_office_journal,node_office_mask,node_office_state,node_office_page toneMint
class node_picker_page,node_picker_server,node_picker_engine toneRose
class node_owner toneIndigo
```

## Components

### Sai Team

- [Team web interface](https://github.com/ntatarinov/sai/blob/main/tools/src/web/server.js): `tools/src/web/server.js`
- [Team commands](https://github.com/ntatarinov/sai/blob/main/tools/src/team/cli.js): `tools/src/team/cli.js`
- [Project engine](https://github.com/ntatarinov/sai/blob/main/tools/src/team/engine/engine.js): `tools/src/team/engine/engine.js`
- [Planning and review](https://github.com/ntatarinov/sai/blob/main/tools/src/team/engine/plan.js): `tools/src/team/engine/plan.js`
- [Role task runner](https://github.com/ntatarinov/sai/blob/main/tools/src/team/runner.js): `tools/src/team/runner.js`
- [Agent executors](https://github.com/ntatarinov/sai/blob/main/tools/src/team/executor.js): `tools/src/team/executor.js`
- [Project state and journal](https://github.com/ntatarinov/sai/blob/main/tools/src/team/store.js): `tools/src/team/store.js`
- [State and event rules](https://github.com/ntatarinov/sai/blob/main/tools/src/team/reducer.js): `tools/src/team/reducer.js`
- [Project data home](https://github.com/ntatarinov/sai/blob/main/tools/src/team/home.js): `tools/src/team/home.js`

### Agent Pipeline

- [Agent handoffs](https://github.com/ntatarinov/sai/tree/main/tools/src/handoffs): `tools/src/handoffs`
- [Trace checks](https://github.com/ntatarinov/sai/tree/main/tools/src/traces): `tools/src/traces`

### Pixel Office

- [Office HTTP server](https://github.com/ntatarinov/sai/blob/main/tools/src/pixel-office/server.js): `tools/src/pixel-office/server.js`
- [Event journal](https://github.com/ntatarinov/sai/blob/main/tools/src/pixel-office/journal.js): `tools/src/pixel-office/journal.js`
- [Secret masking](https://github.com/ntatarinov/sai/blob/main/tools/src/pixel-office/mask.js): `tools/src/pixel-office/mask.js`
- [Office state directory](https://github.com/ntatarinov/sai/blob/main/tools/src/pixel-office/state-dir.js): `tools/src/pixel-office/state-dir.js`
- [Live office page](https://github.com/ntatarinov/sai/blob/main/tools/src/pixel-office/public/app.js): `tools/src/pixel-office/public/app.js`

### Questionnaire Picker

- [Questionnaire interface](https://github.com/ntatarinov/sai/blob/main/tools/src/picker/public/app.js): `tools/src/picker/public/app.js`
- [Questionnaire server](https://github.com/ntatarinov/sai/blob/main/tools/src/picker/server.js): `tools/src/picker/server.js`
- [Questionnaire engine](https://github.com/ntatarinov/sai/blob/main/tools/src/picker/engine.js): `tools/src/picker/engine.js`

### Other components

- **Business owner**

## Connections

- Business owner → Team web interface: submits goal (evidence: `README.md`)
- Business owner → Team commands: starts work (evidence: `README.md`)
- Team web interface → Project engine: starts projects
- Project engine → Planning and review: plans and checks (evidence: `tools/src/team/engine/engine.js`)
- Project engine → Role task runner: runs tasks (evidence: `tools/src/team/engine/engine.js`)
- Project engine → Project state and journal: reads project (evidence: `tools/src/team/engine/engine.js`)
- Project engine → Project state and journal: records progress (evidence: `tools/src/team/engine/engine.js`)
- Role task runner → Agent executors: dispatches work (evidence: `tools/src/team/runner.js`)
- Project state and journal → State and event rules: reduces events (evidence: `tools/src/team/store.js`)
- Project state and journal → Project data home: uses project paths (evidence: `tools/src/team/store.js`)
- Project engine → Agent handoffs: creates handoffs (evidence: `README.md`)
- Agent handoffs → Trace checks: checks traces (evidence: `tools/src/handoffs/close.js`)
- Office HTTP server → Event journal: records events (evidence: `tools/src/pixel-office/server.js`)
- Office HTTP server → Secret masking: masks content (evidence: `tools/src/pixel-office/server.js`)
- Office HTTP server → Office state directory: reads secrets (evidence: `tools/src/pixel-office/server.js`)
- Live office page → Office HTTP server: fetches events (evidence: `README.md`)
- Project engine → Secret masking: masks agent data
- Business owner → Questionnaire interface: answers questions
- Questionnaire interface → Questionnaire server: requests questionnaire (evidence: `tools/src/picker/public/app.js`)
- Questionnaire server → Questionnaire engine: evaluates answers (evidence: `tools/src/picker/server.js`)
