# toreleon/openagent architecture

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

- Interactive diagram: https://gitdiagram.com/toreleon/openagent
- Repository: https://github.com/toreleon/openagent

## Overview

OpenAgent is a Next.js agent-app template. Its main workflow is an authenticated user turn: the chat route persists conversation state and streams an agent response to the browser, where the chat UI renders it. Distinct product branches add research, tools, artifacts, project context, and workspace editing; other branches provide publishing, schedules, connectors, and account features. Several relationships below come from the README rather than sampled implementation; unsampled subsystems are included where the README documents them.

Main entry points: [`src/app/api/chat/route.ts`](https://github.com/toreleon/openagent/blob/main/src/app/api/chat/route.ts) (Chat route), [`src/lib/agent.ts`](https://github.com/toreleon/openagent/blob/main/src/lib/agent.ts) (Agent runtime), [`src/lib/tools/index.ts`](https://github.com/toreleon/openagent/blob/main/src/lib/tools/index.ts) (Agent tools), [`src/components/chat/ChatApp.tsx`](https://github.com/toreleon/openagent/blob/main/src/components/chat/ChatApp.tsx) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_conversation["Conversation experience"]
  node_chat_ui["Chat interface<br/>[ChatApp.tsx]"]
  node_chat_api["Chat route<br/>[route.ts]"]
  node_chat_store["Chat state<br/>[chat.ts]"]
  node_conversation_api["Conversations<br/>[route.ts]"]
end

subgraph group_agent["Agent capabilities"]
  node_agent_runtime["Agent runtime<br/>[agent.ts]"]
  node_openai{{"OpenAI-compatible API"}}
  node_research["Deep research<br/>[orchestrator.ts]"]
  node_tools["Agent tools<br/>[index.ts]"]
  node_subagents["Parallel subagents<br/>[runner.ts]"]
  node_browser["Browser control<br/>[browser.ts]"]
  node_plugins["Plugins and skills<br/>[context.ts]"]
end

subgraph group_content["Content and workspace"]
  node_artifacts[("Artifact versions<br/>[artifacts.ts]")]
  node_artifact_ui["Artifact viewers<br/>[ArtifactPanel.tsx]"]
  node_projects["Project context<br/>[prompt.ts]"]
  node_workspace["Coding workspace<br/>[snapshot.ts]"]
  node_uploads["File uploads<br/>[storage.ts]"]
end

subgraph group_sites["Sites and automation"]
  node_sites[("Site lifecycle<br/>[sites.ts]")]
  node_site_public["Public site serving<br/>[route.ts]"]
  node_site_backend["Site backend API<br/>[route.ts]"]
  node_schedules["Scheduled runs<br/>[runner.ts]"]
end

subgraph group_platform["Identity and connectors"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_db[("Prisma database<br/>[db.ts]")]
  node_mcp["MCP connectors<br/>[client.ts]"]
  node_settings["Settings and controls<br/>[SettingsModal.tsx]"]
end

node_user(("User"))

node_user -->|"sends turn"| node_chat_ui
node_chat_ui -->|"posts turn"| node_chat_api
node_chat_api -->|"checks session"| node_auth
node_chat_api -->|"persists messages"| node_db
node_chat_api -->|"streams turn"| node_agent_runtime
node_agent_runtime -->|"requests response"| node_openai
node_chat_api -->|"streams SSE"| node_chat_store
node_chat_store -->|"updates view"| node_chat_ui
node_user -->|"manages chats"| node_conversation_api
node_conversation_api -->|"reads and writes"| node_db
node_chat_api -->|"runs research"| node_research
node_research -->|"uses completions"| node_agent_runtime
node_agent_runtime -->|"registers tools"| node_tools
node_tools -.->|"dispatches workers"| node_subagents
node_tools -.->|"offers browser tools"| node_browser
node_chat_api -->|"loads skill context"| node_plugins
node_agent_runtime -->|"builds prompt context"| node_plugins
node_chat_api -->|"applies artifact commands"| node_artifacts
node_artifact_ui -->|"browses versions"| node_artifacts
node_chat_api -->|"loads instructions"| node_projects
node_agent_runtime -->|"uses project context"| node_projects
node_chat_api -->|"snapshots turn"| node_workspace
node_user -->|"attaches files"| node_uploads
node_user -->|"publishes site"| node_sites
node_sites -->|"serves deployed site"| node_site_public
node_site_public -->|"enables backend"| node_site_backend
node_user -->|"configures runs"| node_schedules
node_schedules -.->|"starts agent run"| node_chat_api
node_user -->|"signs in"| node_auth
node_auth -->|"uses Prisma adapter"| node_db
node_user -->|"connects server"| node_mcp
node_agent_runtime -->|"loads MCP servers"| node_mcp
node_user -->|"personalizes account"| node_settings

click node_chat_ui "https://github.com/toreleon/openagent/blob/main/src/components/chat/ChatApp.tsx"
click node_chat_api "https://github.com/toreleon/openagent/blob/main/src/app/api/chat/route.ts"
click node_chat_store "https://github.com/toreleon/openagent/blob/main/src/store/chat.ts"
click node_conversation_api "https://github.com/toreleon/openagent/blob/main/src/app/api/conversations/route.ts"
click node_agent_runtime "https://github.com/toreleon/openagent/blob/main/src/lib/agent.ts"
click node_research "https://github.com/toreleon/openagent/blob/main/src/lib/research/orchestrator.ts"
click node_tools "https://github.com/toreleon/openagent/blob/main/src/lib/tools/index.ts"
click node_subagents "https://github.com/toreleon/openagent/blob/main/src/lib/subagents/runner.ts"
click node_browser "https://github.com/toreleon/openagent/blob/main/src/lib/tools/browser.ts"
click node_plugins "https://github.com/toreleon/openagent/blob/main/src/lib/plugins/context.ts"
click node_artifacts "https://github.com/toreleon/openagent/blob/main/src/lib/artifacts.ts"
click node_artifact_ui "https://github.com/toreleon/openagent/blob/main/src/components/artifacts/ArtifactPanel.tsx"
click node_projects "https://github.com/toreleon/openagent/blob/main/src/lib/projects/prompt.ts"
click node_workspace "https://github.com/toreleon/openagent/blob/main/src/lib/workspace/snapshot.ts"
click node_uploads "https://github.com/toreleon/openagent/blob/main/src/lib/storage.ts"
click node_sites "https://github.com/toreleon/openagent/blob/main/src/lib/sites.ts"
click node_site_public "https://github.com/toreleon/openagent/blob/main/src/app/s/%5Bslug%5D/route.ts"
click node_site_backend "https://github.com/toreleon/openagent/blob/main/src/app/s/%5Bslug%5D/api/%5B...path%5D/route.ts"
click node_schedules "https://github.com/toreleon/openagent/blob/main/src/lib/schedule/runner.ts"
click node_auth "https://github.com/toreleon/openagent/blob/main/src/lib/auth.ts"
click node_db "https://github.com/toreleon/openagent/blob/main/src/lib/db.ts"
click node_mcp "https://github.com/toreleon/openagent/blob/main/src/lib/mcp/client.ts"
click node_settings "https://github.com/toreleon/openagent/blob/main/src/components/settings/SettingsModal.tsx"

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_chat_ui,node_chat_api,node_chat_store,node_conversation_api,node_user toneBlue
class node_agent_runtime,node_openai,node_research,node_tools,node_subagents,node_browser,node_plugins toneAmber
class node_artifacts,node_artifact_ui,node_projects,node_workspace,node_uploads toneMint
class node_sites,node_site_public,node_site_backend,node_schedules toneRose
class node_auth,node_db,node_mcp,node_settings toneIndigo
```

## Components

### Conversation experience

- [Chat interface](https://github.com/toreleon/openagent/blob/main/src/components/chat/ChatApp.tsx): `src/components/chat/ChatApp.tsx`
- [Chat route](https://github.com/toreleon/openagent/blob/main/src/app/api/chat/route.ts): `src/app/api/chat/route.ts`
- [Chat state](https://github.com/toreleon/openagent/blob/main/src/store/chat.ts): `src/store/chat.ts`
- [Conversations](https://github.com/toreleon/openagent/blob/main/src/app/api/conversations/route.ts): `src/app/api/conversations/route.ts`

### Agent capabilities

- [Agent runtime](https://github.com/toreleon/openagent/blob/main/src/lib/agent.ts): `src/lib/agent.ts`
- **OpenAI-compatible API**
- [Deep research](https://github.com/toreleon/openagent/blob/main/src/lib/research/orchestrator.ts): `src/lib/research/orchestrator.ts`
- [Agent tools](https://github.com/toreleon/openagent/blob/main/src/lib/tools/index.ts): `src/lib/tools/index.ts`
- [Parallel subagents](https://github.com/toreleon/openagent/blob/main/src/lib/subagents/runner.ts): `src/lib/subagents/runner.ts`
- [Browser control](https://github.com/toreleon/openagent/blob/main/src/lib/tools/browser.ts): `src/lib/tools/browser.ts`
- [Plugins and skills](https://github.com/toreleon/openagent/blob/main/src/lib/plugins/context.ts): `src/lib/plugins/context.ts`

### Content and workspace

- [Artifact versions](https://github.com/toreleon/openagent/blob/main/src/lib/artifacts.ts): `src/lib/artifacts.ts`
- [Artifact viewers](https://github.com/toreleon/openagent/blob/main/src/components/artifacts/ArtifactPanel.tsx): `src/components/artifacts/ArtifactPanel.tsx`
- [Project context](https://github.com/toreleon/openagent/blob/main/src/lib/projects/prompt.ts): `src/lib/projects/prompt.ts`
- [Coding workspace](https://github.com/toreleon/openagent/blob/main/src/lib/workspace/snapshot.ts): `src/lib/workspace/snapshot.ts`
- [File uploads](https://github.com/toreleon/openagent/blob/main/src/lib/storage.ts): `src/lib/storage.ts`

### Sites and automation

- [Site lifecycle](https://github.com/toreleon/openagent/blob/main/src/lib/sites.ts): `src/lib/sites.ts`
- [Public site serving](https://github.com/toreleon/openagent/blob/main/src/app/s/%5Bslug%5D/route.ts): `src/app/s/[slug]/route.ts`
- [Site backend API](https://github.com/toreleon/openagent/blob/main/src/app/s/%5Bslug%5D/api/%5B...path%5D/route.ts): `src/app/s/[slug]/api/[...path]/route.ts`
- [Scheduled runs](https://github.com/toreleon/openagent/blob/main/src/lib/schedule/runner.ts): `src/lib/schedule/runner.ts`

### Identity and connectors

- [Authentication](https://github.com/toreleon/openagent/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [Prisma database](https://github.com/toreleon/openagent/blob/main/src/lib/db.ts): `src/lib/db.ts`
- [MCP connectors](https://github.com/toreleon/openagent/blob/main/src/lib/mcp/client.ts): `src/lib/mcp/client.ts`
- [Settings and controls](https://github.com/toreleon/openagent/blob/main/src/components/settings/SettingsModal.tsx): `src/components/settings/SettingsModal.tsx`

### Other components

- **User**

## Connections

- User → Chat interface: sends turn
- Chat interface → Chat route: posts turn
- Chat route → Authentication: checks session (evidence: `src/app/api/chat/route.ts`)
- Chat route → Prisma database: persists messages (evidence: `src/app/api/chat/route.ts`)
- Chat route → Agent runtime: streams turn (evidence: `src/app/api/chat/route.ts`)
- Agent runtime → OpenAI-compatible API: requests response
- Chat route → Chat state: streams SSE
- Chat state → Chat interface: updates view
- User → Conversations: manages chats
- Conversations → Prisma database: reads and writes (evidence: `src/app/api/conversations/route.ts`)
- Chat route → Deep research: runs research (evidence: `src/app/api/chat/route.ts`)
- Deep research → Agent runtime: uses completions (evidence: `src/lib/research/orchestrator.ts`)
- Agent runtime → Agent tools: registers tools (evidence: `src/lib/agent.ts`)
- Agent tools → Parallel subagents: dispatches workers
- Agent tools → Browser control: offers browser tools
- Chat route → Plugins and skills: loads skill context (evidence: `src/app/api/chat/route.ts`)
- Agent runtime → Plugins and skills: builds prompt context (evidence: `src/lib/agent.ts`)
- Chat route → Artifact versions: applies artifact commands (evidence: `src/app/api/chat/route.ts`)
- Artifact viewers → Artifact versions: browses versions
- Chat route → Project context: loads instructions (evidence: `src/app/api/chat/route.ts`)
- Agent runtime → Project context: uses project context (evidence: `src/lib/agent.ts`)
- Chat route → Coding workspace: snapshots turn (evidence: `src/app/api/chat/route.ts`)
- User → File uploads: attaches files
- User → Site lifecycle: publishes site
- Site lifecycle → Public site serving: serves deployed site (evidence: `src/app/s/[slug]/route.ts`)
- Public site serving → Site backend API: enables backend (evidence: `src/app/s/[slug]/route.ts`)
- User → Scheduled runs: configures runs
- Scheduled runs → Chat route: starts agent run
- User → Authentication: signs in
- Authentication → Prisma database: uses Prisma adapter (evidence: `src/lib/auth.ts`)
- User → MCP connectors: connects server
- Agent runtime → MCP connectors: loads MCP servers (evidence: `src/lib/agent.ts`)
- User → Settings and controls: personalizes account
