# homanp/infinite-monitor architecture

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

- Interactive diagram: https://gitdiagram.com/homanp/infinite-monitor
- Repository: https://github.com/homanp/infinite-monitor

## Overview

1. **Overall shape**
   - This is a **Next.js App Router** application that serves both the dashboard editor UI and its backend API.
   - The product is an AI-powered “infinite canvas” dashboard builder where widgets are generated, deployed, and rendered live in isolated frames.

2. **Primary user surfaces**
   - The main editor lives at `src/app/page.tsx` and is built from the canvas and chat components in `src/components/`.
   - Shared/public viewing is split out into `src/app/share/[shareId]/page.tsx`, which uses dedicated shared-dashboard components for read-only or live shared viewing.

3. **Canvas/editor subsystem**
   - The dashboard editor is centered on an **infinite canvas** with drag/resize/zoom controls, widget cards, a grid, and layout management.
   - Key UI pieces here are `infinite-canvas`, `dashboard-grid`, `draggable-widget`, `zoom-controls`, `widget-card`, and `live-shared-dashboard-view`.

4. **AI chat and agent loop**
   - The chat sidebar drives widget creation and iteration via `src/app/api/chat/route.ts`.
   - The UI components under `src/components/ai-elements/` handle conversation rendering, prompt input, model selection, reasoning display, and code-block presentation.
   - `src/app/api/generate-title/route.ts` is a supporting endpoint for auto-titling dashboards or conversations.

5. **Model/provider abstraction**
   - The repo is designed for **bring-your-own-key** AI usage across multiple providers.
   - `src/lib/model-registry.ts`, `src/lib/create-model.ts`, and `src/lib/openrouter.ts` indicate a provider/model abstraction layer, with UI support for switching models in the chat.
   - Provider credentials are stored client-side in local storage, not persisted server-side.

6. **Widget runtime boundary**
   - Each widget is treated as a **separate React app** running in an iframe-like isolation boundary.
   - The runtime path appears to be: user prompt → AI-generated files → sandboxed build/run → served widget output.
   - `src/lib/widget-runner.ts` and the `/api/widgets/*` plus `/api/widget/*` routes are the main backend pieces for generating, building, and serving widget artifacts.

7. **Sandboxed build/execution**
   - Widget builds run in a secure execution environment rather than Docker, with the README explicitly calling out **Secure Exec / V8 isolate**.
   - `src/lib/durable-stream.ts` suggests long-running build/chat processes stream progress back to the UI.
   - `src/app/api/widgets/bootstrap/route.ts` and `src/app/api/widget/[id]/[[...path]]/route.ts` separate widget bootstrap from static asset serving.

8. **Persistence layer**
   - State is stored in **SQLite** through **Drizzle ORM** (`src/db/`, `drizzle.config.ts`).
   - `src/db/schema.ts` and `src/db/widgets.ts` are the core database definitions for widgets and related dashboard state.
   - The browser also keeps user settings and API keys in Zustand/localStorage via `src/store/settings-store.ts` and `src/store/widget-store.ts`.

9. **Sharing and live projection**
   - Sharing is a first-class subsystem, not just a URL copy feature.
   - `src/lib/share.ts`, `share-recorder.ts`, `share-projection.ts`, and `share-types.ts` indicate the app can record a dashboard state, project it into a shareable format, and serve it through `/api/share/[shareId]/bootstrap`.
   - The live view path is handled by `src/components/shared-dashboard-view.tsx` and `live-shared-dashboard-view.tsx`.

10. **External data access and safety**
   - Widget code can make outbound requests through a dedicated `/api/proxy` route, which acts as a server-side CORS/data access boundary.
   - `src/lib/web-search.ts` and `src/lib/brin.ts` show that the agent can search the web, but results and proxy requests are threat-scanned before use.
   - `src/lib/mcp-registry.ts` and `/api/mcp/test` suggest support for tool/MCP integrations, with a registry and test path for validating connectors.

11. **Templates and bootstrap flow**
   - The `src/templates/*.json` files provide prebuilt dashboard starting points for common domains.
   - `/api/templates` serves these templates, while bootstrap routes are used to initialize widget or share state into a runnable form.

12. **Operational boundary**
   - This repo is built and tested as a standard web app with CI, linting, and Vitest tests under `src/lib/__tests__` and `src/store/__tests__`.
   - Deployment is handled through Railway (`railway.toml`, GitHub deploy workflow), so the main runtime boundary is: browser UI + Next.js server + SQLite + external AI providers + sandboxed widget builds.

Main entry points: [`src/lib/widget-runner.ts`](https://github.com/homanp/infinite-monitor/blob/main/src/lib/widget-runner.ts) (Widget runner), [`src/lib/create-model.ts`](https://github.com/homanp/infinite-monitor/blob/main/src/lib/create-model.ts) (Model layer), [`src/app/page.tsx`](https://github.com/homanp/infinite-monitor/blob/main/src/app/page.tsx) (Editor page), [`src/components/infinite-canvas.tsx`](https://github.com/homanp/infinite-monitor/blob/main/src/components/infinite-canvas.tsx) (Infinite canvas)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Next.js app"]
  node_app_page["Editor page<br/>app route<br/>[page.tsx]"]
  node_share_page["Shared page<br/>app route<br/>[page.tsx]"]
  node_chat_api["Chat API<br/>api route<br/>[route.ts]"]
  node_widget_api["Widget API<br/>api route<br/>[route.ts]"]
  node_widgets_api["Widgets bootstrap<br/>api route<br/>[route.ts]"]
  node_share_api["Share bootstrap<br/>api route<br/>[route.ts]"]
  node_templates_api["Templates API<br/>api route<br/>[route.ts]"]
  node_proxy_api["Proxy API<br/>api route<br/>[route.ts]"]
end

subgraph group_ui["UI system"]
  node_canvas["Infinite canvas<br/>editor canvas"]
  node_grid["Dashboard grid<br/>layout grid<br/>[dashboard-grid.tsx]"]
  node_widget_card["Widget card<br/>widget shell<br/>[widget-card.tsx]"]
  node_chat_ui["Chat sidebar<br/>conversation ui<br/>[chat-sidebar.tsx]"]
  node_ai_elements["AI elements<br/>chat components<br/>[conversation.tsx]"]
  node_shared_view["Shared view<br/>view components"]
  node_live_view["Live projection<br/>view component"]
end

subgraph group_runtime["Widget runtime"]
  node_runner{{"Widget runner<br/>sandbox runtime<br/>[widget-runner.ts]"}}
  node_durable_stream["Durable stream<br/>streaming runtime<br/>[durable-stream.ts]"]
end

subgraph group_data["Data layer"]
  node_db_layer[("SQLite layer<br/>persistence<br/>[index.ts]")]
  node_schema["DB schema<br/>[schema.ts]"]
  node_stores["Client stores<br/>state store<br/>[widget-store.ts]"]
end

subgraph group_ai["AI and tools"]
  node_model_layer["Model layer<br/>provider abstraction<br/>[create-model.ts]"]
  node_registry["Model registry<br/>provider catalog<br/>[model-registry.ts]"]
  node_openrouter["OpenRouter<br/>provider adapter<br/>[openrouter.ts]"]
  node_search_mcp["Search and MCP<br/>tooling<br/>[web-search.ts]"]
end

subgraph group_share["Sharing"]
  node_share_core["Share core<br/>share engine<br/>[share.ts]"]
end

node_app_page -->|"renders"| node_canvas
node_app_page -->|"renders"| node_chat_ui
node_canvas -->|"uses"| node_grid
node_canvas -->|"hosts"| node_widget_card
node_chat_ui -->|"uses"| node_ai_elements
node_chat_api -->|"selects"| node_model_layer
node_model_layer -->|"consults"| node_registry
node_model_layer -->|"adapts"| node_openrouter
node_chat_api -->|"triggers"| node_runner
node_runner -->|"streams"| node_durable_stream
node_widget_api -->|"serves"| node_runner
node_widgets_api -->|"boots"| node_runner
node_runner -->|"persists"| node_db_layer
node_db_layer -->|"defined by"| node_schema
node_app_page -->|"reads"| node_stores
node_share_api -->|"uses"| node_share_core
node_share_page -->|"renders"| node_shared_view
node_shared_view -->|"extends"| node_live_view
node_share_core -->|"reads"| node_db_layer
node_templates_api -->|"loads"| node_schema
node_proxy_api -->|"guards"| node_search_mcp
node_search_mcp -->|"feeds"| node_model_layer

click node_app_page "https://github.com/homanp/infinite-monitor/blob/main/src/app/page.tsx"
click node_share_page "https://github.com/homanp/infinite-monitor/blob/main/src/app/share/[shareId]/page.tsx"
click node_chat_api "https://github.com/homanp/infinite-monitor/blob/main/src/app/api/chat/route.ts"
click node_widget_api "https://github.com/homanp/infinite-monitor/blob/main/src/app/api/widget/[id]/[[...path]]/route.ts"
click node_widgets_api "https://github.com/homanp/infinite-monitor/blob/main/src/app/api/widgets/bootstrap/route.ts"
click node_share_api "https://github.com/homanp/infinite-monitor/blob/main/src/app/api/share/[shareId]/bootstrap/route.ts"
click node_templates_api "https://github.com/homanp/infinite-monitor/blob/main/src/app/api/templates/route.ts"
click node_proxy_api "https://github.com/homanp/infinite-monitor/blob/main/src/app/api/proxy/route.ts"
click node_canvas "https://github.com/homanp/infinite-monitor/blob/main/src/components/infinite-canvas.tsx"
click node_grid "https://github.com/homanp/infinite-monitor/blob/main/src/components/dashboard-grid.tsx"
click node_widget_card "https://github.com/homanp/infinite-monitor/blob/main/src/components/widget-card.tsx"
click node_chat_ui "https://github.com/homanp/infinite-monitor/blob/main/src/components/chat-sidebar.tsx"
click node_ai_elements "https://github.com/homanp/infinite-monitor/blob/main/src/components/ai-elements/conversation.tsx"
click node_shared_view "https://github.com/homanp/infinite-monitor/blob/main/src/components/shared-dashboard-view.tsx"
click node_live_view "https://github.com/homanp/infinite-monitor/blob/main/src/components/live-shared-dashboard-view.tsx"
click node_runner "https://github.com/homanp/infinite-monitor/blob/main/src/lib/widget-runner.ts"
click node_durable_stream "https://github.com/homanp/infinite-monitor/blob/main/src/lib/durable-stream.ts"
click node_model_layer "https://github.com/homanp/infinite-monitor/blob/main/src/lib/create-model.ts"
click node_registry "https://github.com/homanp/infinite-monitor/blob/main/src/lib/model-registry.ts"
click node_openrouter "https://github.com/homanp/infinite-monitor/blob/main/src/lib/openrouter.ts"
click node_search_mcp "https://github.com/homanp/infinite-monitor/blob/main/src/lib/web-search.ts"
click node_share_core "https://github.com/homanp/infinite-monitor/blob/main/src/lib/share.ts"
click node_db_layer "https://github.com/homanp/infinite-monitor/blob/main/src/db/index.ts"
click node_schema "https://github.com/homanp/infinite-monitor/blob/main/src/db/schema.ts"
click node_stores "https://github.com/homanp/infinite-monitor/blob/main/src/store/widget-store.ts"

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_app_page,node_share_page,node_chat_api,node_widget_api,node_widgets_api,node_share_api,node_templates_api,node_proxy_api toneBlue
class node_canvas,node_grid,node_widget_card,node_chat_ui,node_ai_elements,node_shared_view,node_live_view toneAmber
class node_runner,node_durable_stream toneMint
class node_db_layer,node_schema,node_stores toneRose
class node_model_layer,node_registry,node_openrouter,node_search_mcp toneIndigo
class node_share_core toneTeal
```

## Components

### Next.js app

Browser entry points and API routes

- [Editor page](https://github.com/homanp/infinite-monitor/blob/main/src/app/page.tsx): app route · Main dashboard editor shell · `src/app/page.tsx`
- [Shared page](https://github.com/homanp/infinite-monitor/blob/main/src/app/share/[shareId]/page.tsx): app route · Read-only/live shared dashboard view · `src/app/share/[shareId]/page.tsx`
- [Chat API](https://github.com/homanp/infinite-monitor/blob/main/src/app/api/chat/route.ts): api route · Agent loop for widget creation and iteration · `src/app/api/chat/route.ts`
- [Widget API](https://github.com/homanp/infinite-monitor/blob/main/src/app/api/widget/[id]/[[...path]]/route.ts): api route · Serve widget artifacts from the isolated runtime · `src/app/api/widget/[id]/[[...path]]/route.ts`
- [Widgets bootstrap](https://github.com/homanp/infinite-monitor/blob/main/src/app/api/widgets/bootstrap/route.ts): api route · Initialize widget runtime state · `src/app/api/widgets/bootstrap/route.ts`
- [Share bootstrap](https://github.com/homanp/infinite-monitor/blob/main/src/app/api/share/[shareId]/bootstrap/route.ts): api route · Bootstrap shared dashboard state · `src/app/api/share/[shareId]/bootstrap/route.ts`
- [Templates API](https://github.com/homanp/infinite-monitor/blob/main/src/app/api/templates/route.ts): api route · Serves starter dashboard templates · `src/app/api/templates/route.ts`
- [Proxy API](https://github.com/homanp/infinite-monitor/blob/main/src/app/api/proxy/route.ts): api route · Server-side outbound request boundary · `src/app/api/proxy/route.ts`

### UI system

Dashboard editor, chat, and shared views

- [Infinite canvas](https://github.com/homanp/infinite-monitor/blob/main/src/components/infinite-canvas.tsx): editor canvas · Main layout and interaction surface · `src/components/infinite-canvas.tsx`
- [Dashboard grid](https://github.com/homanp/infinite-monitor/blob/main/src/components/dashboard-grid.tsx): layout grid · Canvas positioning and layout layer · `src/components/dashboard-grid.tsx`
- [Widget card](https://github.com/homanp/infinite-monitor/blob/main/src/components/widget-card.tsx): widget shell · Per-widget presentation and controls · `src/components/widget-card.tsx`
- [Chat sidebar](https://github.com/homanp/infinite-monitor/blob/main/src/components/chat-sidebar.tsx): conversation ui · Prompting and iteration surface · `src/components/chat-sidebar.tsx`
- [AI elements](https://github.com/homanp/infinite-monitor/blob/main/src/components/ai-elements/conversation.tsx): chat components · Conversation, prompt, model, and reasoning UI · `src/components/ai-elements/conversation.tsx`
- [Shared view](https://github.com/homanp/infinite-monitor/blob/main/src/components/shared-dashboard-view.tsx): view components · Shared dashboard rendering components · `src/components/shared-dashboard-view.tsx`
- [Live projection](https://github.com/homanp/infinite-monitor/blob/main/src/components/live-shared-dashboard-view.tsx): view component · Live shared dashboard presentation · `src/components/live-shared-dashboard-view.tsx`

### Widget runtime

Generation, sandboxed execution, and serving

- [Widget runner](https://github.com/homanp/infinite-monitor/blob/main/src/lib/widget-runner.ts): sandbox runtime · Build/run boundary for isolated widgets · `src/lib/widget-runner.ts`
- [Durable stream](https://github.com/homanp/infinite-monitor/blob/main/src/lib/durable-stream.ts): streaming runtime · Streams long-running build and chat progress · `src/lib/durable-stream.ts`

### Data layer

SQLite persistence and client state

- [SQLite layer](https://github.com/homanp/infinite-monitor/blob/main/src/db/index.ts): persistence · Drizzle-backed database access · `src/db/index.ts`
- [DB schema](https://github.com/homanp/infinite-monitor/blob/main/src/db/schema.ts): schema · Widget and dashboard tables · `src/db/schema.ts`
- [Client stores](https://github.com/homanp/infinite-monitor/blob/main/src/store/widget-store.ts): state store · Local settings and widget state in browser storage · `src/store/widget-store.ts`

### AI and tools

Model abstraction, search, and MCP integration

- [Model layer](https://github.com/homanp/infinite-monitor/blob/main/src/lib/create-model.ts): provider abstraction · Provider selection and model creation · `src/lib/create-model.ts`
- [Model registry](https://github.com/homanp/infinite-monitor/blob/main/src/lib/model-registry.ts): provider catalog · Available models and providers · `src/lib/model-registry.ts`
- [OpenRouter](https://github.com/homanp/infinite-monitor/blob/main/src/lib/openrouter.ts): provider adapter · External model gateway integration · `src/lib/openrouter.ts`
- [Search and MCP](https://github.com/homanp/infinite-monitor/blob/main/src/lib/web-search.ts): tooling · Web search, threat scanning, and connector registry · `src/lib/web-search.ts`

### Sharing

Recording, projection, and shared delivery

- [Share core](https://github.com/homanp/infinite-monitor/blob/main/src/lib/share.ts): share engine · Share recording, projection, and types · `src/lib/share.ts`

## Connections

- Editor page → Infinite canvas: renders · Editor page composes the canvas shell and workspace
- Editor page → Chat sidebar: renders · Editor page includes the chat sidebar
- Infinite canvas → Dashboard grid: uses · Canvas positions widgets on the dashboard grid
- Infinite canvas → Widget card: hosts · Canvas renders widget cards as movable units
- Chat sidebar → AI elements: uses · Chat sidebar is built from AI conversation controls
- Chat API → Model layer: selects · Chat API invokes the chosen model/provider
- Model layer → Model registry: consults · Model creation is driven by the registry
- Model layer → OpenRouter: adapts · One provider path goes through OpenRouter
- Chat API → Widget runner: triggers · Agent output can produce widget builds and runs
- Widget runner → Durable stream: streams · Build/run progress is streamed back to the UI
- Widget API → Widget runner: serves · Widget serving boundary is backed by the runner
- Widgets bootstrap → Widget runner: boots · Bootstrap endpoint initializes widget runtime state
- Widget runner → SQLite layer: persists · Widget artifacts and state are stored server-side
- SQLite layer → DB schema: defined by · Drizzle database uses the schema definitions
- Editor page → Client stores: reads · Editor UI relies on client-side settings and widget state
- Share bootstrap → Share core: uses · Shared bootstrap is produced by the share engine
- Shared page → Shared view: renders · Shared page uses the shared dashboard view
- Shared view → Live projection: extends · Live shared viewing is a specialized presentation
- Share core → SQLite layer: reads · Share recording and projection are backed by persisted state
- Templates API → DB schema: loads · Templates initialize dashboard state and content
- Proxy API → Search and MCP: guards · Outbound access and tool use are mediated through safety layers
- Search and MCP → Model layer: feeds · Tooling supports the AI agent loop
