# abeyakilesh/optimus architecture

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

- Interactive diagram: https://gitdiagram.com/abeyakilesh/optimus
- Repository: https://github.com/abeyakilesh/optimus

## Overview

#### Purpose and entry points
This repository combines a Next.js landing surface with a local-first “kernel” for orchestrating autonomous work toward a pull request. The primary web entry point is `app/page.tsx`, composed under `app/layout.tsx`; CLI/kernel execution begins at `kernel/cli.ts`. Architecture decisions indicate bring-your-own-key inference and a hosted surface that does not host the execution kernel (`docs/adr/0002-byok-not-hosted-inference.md`, `docs/adr/0005-vercel-hosts-the-surface-never-the-kernel.md`).

#### Web surface
The `app/` tree is a presentation-only Next.js application: global styling and document shell reside in `app/globals.css` and `app/layout.tsx`, while `app/page.tsx` assembles the landing experience. Landing sections are independently represented in `components/landing/Hero.tsx`, `components/landing/Features.tsx`, and `components/landing/CTA.tsx`. This boundary should remain separate from kernel execution and credentials.

#### Kernel orchestration
`kernel/harness.ts` is the likely top-level execution harness coordinating a mission/run. `kernel/scheduler.ts` controls work sequencing, while `kernel/broker.ts` mediates requests or dispatch among execution participants. Shared contracts belong in `kernel/types.ts`; event-based progress and observability flow through `kernel/events.ts`. Together these form the central control plane from CLI invocation to scheduled work and emitted lifecycle events.

#### Capability, permissions, and built-ins
`kernel/builtin.ts` defines built-in capabilities/adapters available to the kernel. `kernel/permissions.ts` is the policy boundary governing which capabilities or operations a run may perform. The local-first ports-and-adapters direction is explicit in `docs/adr/0003-local-first-ports-and-adapters.md`; external model providers should therefore be invoked through replaceable boundaries rather than embedded in web components or scheduler logic.

#### Durable outputs and recovery
`kernel/artifacts.ts` owns materialized run outputs, likely including files or evidence required to produce/review a PR. `kernel/rollback.ts` provides failure recovery or reversal semantics. The important flow is: scheduled work produces events and artifacts; permissions constrain actions; rollback restores a safe state when a stage fails or is rejected. These boundaries are central to trustworthy automated repository modification.

#### Rules and analysis inputs
Repository-specific static-analysis rules are maintained under `rules/`, including `rules/typescript/security/` and `rules/javascript/security/`. They are inputs to security or quality stages rather than application runtime code. `sgconfig.yml` likely configures their scanner integration. This creates a policy/checking boundary between kernel-generated changes and repository acceptance requirements.

#### Runtime, infrastructure, and validation
The browser surface uses Next.js/React (`next.config.ts`, `app/`), while kernel code is TypeScript running through its CLI/runtime (`kernel/cli.ts`, `tsconfig.json`). Vercel is intended to host only the surface, not the kernel (`docs/adr/0005-vercel-hosts-the-surface-never-the-kernel.md`). CI separates build, unit, end-to-end, performance, security, and supply-chain checks through `.github/workflows/_build.yml`, `.github/workflows/_e2e.yml`, and `.github/workflows/_static-security.yml`. Kernel behavior is validated directly in `tests/kernel/orchestration.test.ts` and `tests/kernel/acceptance.test.ts`.

Main entry points: [`kernel/scheduler.ts`](https://github.com/abeyakilesh/optimus/blob/main/kernel/scheduler.ts) (Work scheduler), [`kernel/harness.ts`](https://github.com/abeyakilesh/optimus/blob/main/kernel/harness.ts) (Run harness), [`kernel/artifacts.ts`](https://github.com/abeyakilesh/optimus/blob/main/kernel/artifacts.ts) (Run artifacts), [`app/layout.tsx`](https://github.com/abeyakilesh/optimus/blob/main/app/layout.tsx) (Document shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Hosted web surface"]
  node_layout["Document shell<br/>Next.js layout<br/>[layout.tsx]"]
  node_landing["Landing page<br/>Next.js page<br/>[page.tsx]"]
  node_sections["Landing sections<br/>React components<br/>[Hero.tsx]"]
  node_styles["Global styles<br/>CSS<br/>[globals.css]"]
end

subgraph group_kernel["Local execution kernel"]
  node_cli{{"Kernel CLI<br/>TypeScript CLI<br/>[cli.ts]"}}
  node_harness["Run harness<br/>orchestrator<br/>[harness.ts]"]
  node_scheduler["Work scheduler<br/>control plane<br/>[scheduler.ts]"]
  node_broker["Request broker<br/>dispatcher<br/>[broker.ts]"]
  node_contracts["Kernel contracts<br/>shared types<br/>[types.ts]"]
  node_events["Lifecycle events<br/>event stream<br/>[events.ts]"]
  node_permissions{{"Permissions policy<br/>policy boundary<br/>[permissions.ts]"}}
  node_builtins["Built-in capabilities<br/>adapter registry<br/>[builtin.ts]"]
  node_artifacts[("Run artifacts<br/>durable outputs<br/>[artifacts.ts]")]
  node_rollback["Rollback<br/>recovery<br/>[rollback.ts]"]
end

subgraph group_governance["Policy and delivery"]
  node_rules["Security rules<br/>static-analysis rules"]
  node_scanner["Scanner configuration<br/>analysis config<br/>[sgconfig.yml]"]
  node_ci["Validation CI<br/>GitHub Actions<br/>[_build.yml]"]
  node_deployment{{"Vercel deployment boundary<br/>hosting policy"}}
  node_byok["BYOK inference policy<br/>architecture decision"]
end

node_layout -->|"renders"| node_landing
node_layout -->|"applies"| node_styles
node_landing -->|"assembles"| node_sections
node_deployment -->|"hosts"| node_layout
node_deployment -.->|"excludes"| node_cli
node_cli -->|"starts run"| node_harness
node_harness -->|"coordinates"| node_scheduler
node_scheduler -->|"dispatches work"| node_broker
node_broker -->|"invokes"| node_builtins
node_harness -->|"uses"| node_contracts
node_scheduler -->|"emits"| node_events
node_scheduler -->|"produces"| node_artifacts
node_permissions -->|"authorizes"| node_builtins
node_permissions -->|"constrains"| node_scheduler
node_harness -->|"recovers via"| node_rollback
node_rollback -->|"restores safe state"| node_artifacts
node_scanner -->|"loads"| node_rules
node_rules -.->|"checks changes"| node_artifacts
node_ci -.->|"validates"| node_artifacts
node_byok -.->|"governs provider access"| node_builtins

click node_layout "https://github.com/abeyakilesh/optimus/blob/main/app/layout.tsx"
click node_landing "https://github.com/abeyakilesh/optimus/blob/main/app/page.tsx"
click node_sections "https://github.com/abeyakilesh/optimus/blob/main/components/landing/Hero.tsx"
click node_styles "https://github.com/abeyakilesh/optimus/blob/main/app/globals.css"
click node_cli "https://github.com/abeyakilesh/optimus/blob/main/kernel/cli.ts"
click node_harness "https://github.com/abeyakilesh/optimus/blob/main/kernel/harness.ts"
click node_scheduler "https://github.com/abeyakilesh/optimus/blob/main/kernel/scheduler.ts"
click node_broker "https://github.com/abeyakilesh/optimus/blob/main/kernel/broker.ts"
click node_contracts "https://github.com/abeyakilesh/optimus/blob/main/kernel/types.ts"
click node_events "https://github.com/abeyakilesh/optimus/blob/main/kernel/events.ts"
click node_permissions "https://github.com/abeyakilesh/optimus/blob/main/kernel/permissions.ts"
click node_builtins "https://github.com/abeyakilesh/optimus/blob/main/kernel/builtin.ts"
click node_artifacts "https://github.com/abeyakilesh/optimus/blob/main/kernel/artifacts.ts"
click node_rollback "https://github.com/abeyakilesh/optimus/blob/main/kernel/rollback.ts"
click node_scanner "https://github.com/abeyakilesh/optimus/blob/main/sgconfig.yml"
click node_ci "https://github.com/abeyakilesh/optimus/blob/main/.github/workflows/_build.yml"
click node_deployment "https://github.com/abeyakilesh/optimus/blob/main/docs/adr/0005-vercel-hosts-the-surface-never-the-kernel.md"
click node_byok "https://github.com/abeyakilesh/optimus/blob/main/docs/adr/0002-byok-not-hosted-inference.md"

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_layout,node_landing,node_sections,node_styles toneBlue
class node_cli,node_harness,node_scheduler,node_broker,node_contracts,node_events,node_permissions,node_builtins,node_artifacts,node_rollback toneAmber
class node_rules,node_scanner,node_ci,node_deployment,node_byok toneMint
```

## Components

### Hosted web surface

Presentation-only Next.js landing site.

- [Document shell](https://github.com/abeyakilesh/optimus/blob/main/app/layout.tsx): Next.js layout · `app/layout.tsx`
- [Landing page](https://github.com/abeyakilesh/optimus/blob/main/app/page.tsx): Next.js page · `app/page.tsx`
- [Landing sections](https://github.com/abeyakilesh/optimus/blob/main/components/landing/Hero.tsx): React components · Hero, features, and CTA compose the landing experience. · `components/landing/Hero.tsx`
- [Global styles](https://github.com/abeyakilesh/optimus/blob/main/app/globals.css): CSS · `app/globals.css`

### Local execution kernel

CLI-driven control plane for autonomous repository work.

- [Kernel CLI](https://github.com/abeyakilesh/optimus/blob/main/kernel/cli.ts): TypeScript CLI · Local entry point for a mission or run. · `kernel/cli.ts`
- [Run harness](https://github.com/abeyakilesh/optimus/blob/main/kernel/harness.ts): orchestrator · Coordinates a mission from invocation through completion. · `kernel/harness.ts`
- [Work scheduler](https://github.com/abeyakilesh/optimus/blob/main/kernel/scheduler.ts): control plane · `kernel/scheduler.ts`
- [Request broker](https://github.com/abeyakilesh/optimus/blob/main/kernel/broker.ts): dispatcher · Mediates dispatch among execution participants. · `kernel/broker.ts`
- [Kernel contracts](https://github.com/abeyakilesh/optimus/blob/main/kernel/types.ts): shared types · `kernel/types.ts`
- [Lifecycle events](https://github.com/abeyakilesh/optimus/blob/main/kernel/events.ts): event stream · Progress and observability for runs. · `kernel/events.ts`
- [Permissions policy](https://github.com/abeyakilesh/optimus/blob/main/kernel/permissions.ts): policy boundary · Constrains capabilities and operations available to a run. · `kernel/permissions.ts`
- [Built-in capabilities](https://github.com/abeyakilesh/optimus/blob/main/kernel/builtin.ts): adapter registry · Replaceable local-first capability adapters, including provider access. · `kernel/builtin.ts`
- [Run artifacts](https://github.com/abeyakilesh/optimus/blob/main/kernel/artifacts.ts): durable outputs · Materialized changes and evidence for review or PR creation. · `kernel/artifacts.ts`
- [Rollback](https://github.com/abeyakilesh/optimus/blob/main/kernel/rollback.ts): recovery · Restores a safe state after failure or rejection. · `kernel/rollback.ts`

### Policy and delivery

Acceptance rules, deployment boundaries, and CI.

- **Security rules**: static-analysis rules · Repository acceptance inputs for generated changes.
- [Scanner configuration](https://github.com/abeyakilesh/optimus/blob/main/sgconfig.yml): analysis config · `sgconfig.yml`
- [Validation CI](https://github.com/abeyakilesh/optimus/blob/main/.github/workflows/_build.yml): GitHub Actions · Build, end-to-end, static security, performance, and supply-chain checks. · `.github/workflows/_build.yml`
- [Vercel deployment boundary](https://github.com/abeyakilesh/optimus/blob/main/docs/adr/0005-vercel-hosts-the-surface-never-the-kernel.md): hosting policy · Hosts only the web surface, never the execution kernel. · `docs/adr/0005-vercel-hosts-the-surface-never-the-kernel.md`
- [BYOK inference policy](https://github.com/abeyakilesh/optimus/blob/main/docs/adr/0002-byok-not-hosted-inference.md): architecture decision · Inference credentials remain user-provided rather than hosted. · `docs/adr/0002-byok-not-hosted-inference.md`

## Connections

- Document shell → Landing page: renders
- Document shell → Global styles: applies
- Landing page → Landing sections: assembles
- Vercel deployment boundary → Document shell: hosts
- Vercel deployment boundary → Kernel CLI: excludes
- Kernel CLI → Run harness: starts run
- Run harness → Work scheduler: coordinates
- Work scheduler → Request broker: dispatches work
- Request broker → Built-in capabilities: invokes
- Run harness → Kernel contracts: uses
- Work scheduler → Lifecycle events: emits
- Work scheduler → Run artifacts: produces
- Permissions policy → Built-in capabilities: authorizes
- Permissions policy → Work scheduler: constrains
- Run harness → Rollback: recovers via
- Rollback → Run artifacts: restores safe state
- Scanner configuration → Security rules: loads
- Security rules → Run artifacts: checks changes
- Validation CI → Run artifacts: validates
- BYOK inference policy → Built-in capabilities: governs provider access
