# huantian3365/ai-personal-agent architecture

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

- Interactive diagram: https://gitdiagram.com/huantian3365/ai-personal-agent
- Repository: https://github.com/huantian3365/ai-personal-agent

## Overview

This is an Electron desktop chat application with a React renderer, a main-process service layer, and a LangGraph-based conversational agent. The principal workflow is: a user works in the chat UI, renderer requests cross the preload IPC bridge, main-process handlers coordinate conversation execution, and the core streams agent events while persisting conversation state in SQLite. The graph preserves the workspace/conversation, settings, tools, and checkpoint subsystems. Some handler-to-runtime and renderer-to-IPC call sites were not excerpted, so those links are omitted rather than inferred.

Main entry points: [`src/main/index.ts`](https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/index.ts) (App Bootstrap), [`src/main/database/index.ts`](https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/database/index.ts) (SQLite Database), [`src/renderer/src/router/routers.tsx`](https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/router/routers.tsx) (Page Router), [`src/main/ipc/index.ts`](https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/ipc/index.ts) (IPC Registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Renderer UI"]
  node_renderer["Renderer App<br/>[main.tsx]"]
  node_router["Page Router<br/>[routers.tsx]"]
  node_chat["Chat Page<br/>[index.tsx]"]
  node_sidebar["Conversation Sidebar<br/>[Sidebar.tsx]"]
  node_settings["Settings Page<br/>[index.tsx]"]
  node_welcome["Welcome Page<br/>[index.tsx]"]
end

subgraph group_bridge["IPC Bridge"]
  node_preload["Preload API<br/>[mount.ts]"]
  node_preload_conversation["Conversation API<br/>[conversation.ts]"]
  node_ipc_contract["IPC Channels<br/>[ipc.ts]"]
end

subgraph group_main["Main Services"]
  node_main_boot["App Bootstrap<br/>[index.ts]"]
  node_ipc_registry["IPC Registry<br/>[index.ts]"]
  node_agent_handler["Agent Handler<br/>[agent.ts]"]
  node_conversation_handler["Conversation Handler<br/>[conversation.ts]"]
  node_config["Configuration<br/>[config.ts]"]
  node_database[("SQLite Database<br/>[index.ts]")]
  node_migrations["Schema Migrations<br/>[migrate.ts]"]
  node_sqlite_repository["SQLite Repository<br/>[index.ts]"]
end

subgraph group_core["Agent Core"]
  node_agent_loop["Agent Loop<br/>[loop.ts]"]
  node_agent_init["Agent Initialization<br/>[init.ts]"]
  node_agent_events["Event Emitter<br/>[emitter.ts]"]
  node_message_parse["Stream Parsing<br/>[parseStream.ts]"]
  node_message_history["Message History<br/>[historyMessage.ts]"]
  node_checkpoint[("Checkpoint Store<br/>[checkpoint.ts]")]
  node_graph_nodes["Graph Nodes<br/>[nodes.ts]"]
  node_tool_register["Tool Registration<br/>[register.ts]"]
  node_file_tool["File Tool<br/>[file.ts]"]
  node_shell_tool["Shell Tool<br/>[shell.ts]"]
  node_time_tool["Time Tool<br/>[time.ts]"]
  node_core_entry["Core Lifecycle<br/>[index.ts]"]
  node_core_log["Core Logging<br/>[log.ts]"]
end

node_user(("User"))

node_user -->|"uses"| node_renderer
node_renderer -->|"mounts"| node_router
node_router -->|"routes"| node_chat
node_router -->|"routes"| node_settings
node_router -->|"routes"| node_welcome
node_preload -->|"exposes"| node_preload_conversation
node_preload_conversation -->|"invokes channels"| node_ipc_contract
node_preload -->|"uses channels"| node_ipc_contract
node_main_boot -->|"mounts handlers"| node_ipc_registry
node_main_boot -->|"opens"| node_database
node_main_boot -->|"initializes"| node_config
node_main_boot -->|"initializes"| node_core_entry
node_main_boot -->|"loads window"| node_renderer
node_ipc_registry -->|"uses channels"| node_ipc_contract
node_ipc_registry -->|"registers"| node_agent_handler
node_ipc_registry -->|"registers"| node_conversation_handler
node_database -->|"migrates schema"| node_migrations
node_database -->|"creates repository"| node_sqlite_repository
node_migrations -->|"updates schema"| node_database
node_core_entry -->|"opens store"| node_checkpoint
node_core_entry -->|"configures"| node_core_log
node_checkpoint -->|"reads and writes"| node_database
node_agent_loop -->|"initializes"| node_agent_init
node_agent_loop -->|"emits events"| node_agent_events
node_agent_loop -->|"parses stream"| node_message_parse
node_message_history -->|"uses parser"| node_message_parse
node_agent_handler -.->|"dispatches"| node_agent_loop
node_conversation_handler -.->|"queries"| node_sqlite_repository
node_graph_nodes -.->|"uses tools"| node_tool_register
node_tool_register -.->|"registers"| node_file_tool
node_tool_register -.->|"registers"| node_shell_tool
node_tool_register -.->|"registers"| node_time_tool

click node_renderer "https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/main.tsx"
click node_router "https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/router/routers.tsx"
click node_chat "https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/pages/Chat/index.tsx"
click node_sidebar "https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/layouts/components/Sidebar.tsx"
click node_settings "https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/pages/Setting/index.tsx"
click node_welcome "https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/pages/Welcome/index.tsx"
click node_preload "https://github.com/huantian3365/ai-personal-agent/blob/main/src/preload/mount.ts"
click node_preload_conversation "https://github.com/huantian3365/ai-personal-agent/blob/main/src/preload/api/conversation.ts"
click node_ipc_contract "https://github.com/huantian3365/ai-personal-agent/blob/main/src/shared/ipc.ts"
click node_main_boot "https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/index.ts"
click node_ipc_registry "https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/ipc/index.ts"
click node_agent_handler "https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/ipc/impl/agent.ts"
click node_conversation_handler "https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/ipc/impl/conversation.ts"
click node_config "https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/config/file/config.ts"
click node_database "https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/database/index.ts"
click node_migrations "https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/database/init/migrate.ts"
click node_sqlite_repository "https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/database/service/impl/sqlite/index.ts"
click node_agent_loop "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/agent/loop.ts"
click node_agent_init "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/agent/init.ts"
click node_agent_events "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/agent/emitter.ts"
click node_message_parse "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/message/parseStream.ts"
click node_message_history "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/message/historyMessage.ts"
click node_checkpoint "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/graph/checkpoint.ts"
click node_graph_nodes "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/graph/nodes.ts"
click node_tool_register "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/tools/register.ts"
click node_file_tool "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/tools/impl/file.ts"
click node_shell_tool "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/tools/impl/shell.ts"
click node_time_tool "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/tools/impl/time.ts"
click node_core_entry "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/index.ts"
click node_core_log "https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/utils/log.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_renderer,node_router,node_chat,node_sidebar,node_settings,node_welcome,node_user toneBlue
class node_preload,node_preload_conversation,node_ipc_contract toneAmber
class node_main_boot,node_ipc_registry,node_agent_handler,node_conversation_handler,node_config,node_database,node_migrations,node_sqlite_repository toneMint
class node_agent_loop,node_agent_init,node_agent_events,node_message_parse,node_message_history,node_checkpoint,node_graph_nodes,node_tool_register,node_file_tool,node_shell_tool,node_time_tool,node_core_entry,node_core_log toneRose
```

## Components

### Renderer UI

- [Renderer App](https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/main.tsx): `src/renderer/src/main.tsx`
- [Page Router](https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/router/routers.tsx): `src/renderer/src/router/routers.tsx`
- [Chat Page](https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/pages/Chat/index.tsx): `src/renderer/src/pages/Chat/index.tsx`
- [Conversation Sidebar](https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/layouts/components/Sidebar.tsx): `src/renderer/src/layouts/components/Sidebar.tsx`
- [Settings Page](https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/pages/Setting/index.tsx): `src/renderer/src/pages/Setting/index.tsx`
- [Welcome Page](https://github.com/huantian3365/ai-personal-agent/blob/main/src/renderer/src/pages/Welcome/index.tsx): `src/renderer/src/pages/Welcome/index.tsx`

### IPC Bridge

- [Preload API](https://github.com/huantian3365/ai-personal-agent/blob/main/src/preload/mount.ts): `src/preload/mount.ts`
- [Conversation API](https://github.com/huantian3365/ai-personal-agent/blob/main/src/preload/api/conversation.ts): `src/preload/api/conversation.ts`
- [IPC Channels](https://github.com/huantian3365/ai-personal-agent/blob/main/src/shared/ipc.ts): `src/shared/ipc.ts`

### Main Services

- [App Bootstrap](https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/index.ts): `src/main/index.ts`
- [IPC Registry](https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/ipc/index.ts): `src/main/ipc/index.ts`
- [Agent Handler](https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/ipc/impl/agent.ts): `src/main/ipc/impl/agent.ts`
- [Conversation Handler](https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/ipc/impl/conversation.ts): `src/main/ipc/impl/conversation.ts`
- [Configuration](https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/config/file/config.ts): `src/main/config/file/config.ts`
- [SQLite Database](https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/database/index.ts): `src/main/database/index.ts`
- [Schema Migrations](https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/database/init/migrate.ts): `src/main/database/init/migrate.ts`
- [SQLite Repository](https://github.com/huantian3365/ai-personal-agent/blob/main/src/main/database/service/impl/sqlite/index.ts): `src/main/database/service/impl/sqlite/index.ts`

### Agent Core

- [Agent Loop](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/agent/loop.ts): `src/core/agent/loop.ts`
- [Agent Initialization](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/agent/init.ts): `src/core/agent/init.ts`
- [Event Emitter](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/agent/emitter.ts): `src/core/agent/emitter.ts`
- [Stream Parsing](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/message/parseStream.ts): `src/core/message/parseStream.ts`
- [Message History](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/message/historyMessage.ts): `src/core/message/historyMessage.ts`
- [Checkpoint Store](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/graph/checkpoint.ts): `src/core/graph/checkpoint.ts`
- [Graph Nodes](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/graph/nodes.ts): `src/core/graph/nodes.ts`
- [Tool Registration](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/tools/register.ts): `src/core/tools/register.ts`
- [File Tool](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/tools/impl/file.ts): `src/core/tools/impl/file.ts`
- [Shell Tool](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/tools/impl/shell.ts): `src/core/tools/impl/shell.ts`
- [Time Tool](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/tools/impl/time.ts): `src/core/tools/impl/time.ts`
- [Core Lifecycle](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/index.ts): `src/core/index.ts`
- [Core Logging](https://github.com/huantian3365/ai-personal-agent/blob/main/src/core/utils/log.ts): `src/core/utils/log.ts`

### Other components

- **User**

## Connections

- User → Renderer App: uses
- Renderer App → Page Router: mounts (evidence: `src/renderer/src/main.tsx`)
- Page Router → Chat Page: routes (evidence: `src/renderer/src/router/routers.tsx`)
- Page Router → Settings Page: routes (evidence: `src/renderer/src/router/routers.tsx`)
- Page Router → Welcome Page: routes (evidence: `src/renderer/src/router/routers.tsx`)
- Preload API → Conversation API: exposes (evidence: `src/preload/mount.ts`)
- Conversation API → IPC Channels: invokes channels (evidence: `src/preload/api/conversation.ts`)
- Preload API → IPC Channels: uses channels (evidence: `src/preload/mount.ts`)
- App Bootstrap → IPC Registry: mounts handlers (evidence: `src/main/index.ts`)
- App Bootstrap → SQLite Database: opens (evidence: `src/main/index.ts`)
- App Bootstrap → Configuration: initializes (evidence: `src/main/index.ts`)
- App Bootstrap → Core Lifecycle: initializes (evidence: `src/main/index.ts`)
- App Bootstrap → Renderer App: loads window (evidence: `src/main/index.ts`)
- IPC Registry → IPC Channels: uses channels (evidence: `src/main/ipc/index.ts`)
- IPC Registry → Agent Handler: registers (evidence: `src/main/ipc/index.ts`)
- IPC Registry → Conversation Handler: registers (evidence: `src/main/ipc/index.ts`)
- SQLite Database → Schema Migrations: migrates schema (evidence: `src/main/database/index.ts`)
- SQLite Database → SQLite Repository: creates repository (evidence: `src/main/database/index.ts`)
- Schema Migrations → SQLite Database: updates schema (evidence: `src/main/database/init/migrate.ts`)
- Core Lifecycle → Checkpoint Store: opens store (evidence: `src/core/index.ts`)
- Core Lifecycle → Core Logging: configures (evidence: `src/core/index.ts`)
- Checkpoint Store → SQLite Database: reads and writes (evidence: `src/core/graph/checkpoint.ts`)
- Agent Loop → Agent Initialization: initializes (evidence: `src/core/agent/loop.ts`)
- Agent Loop → Event Emitter: emits events (evidence: `src/core/agent/loop.ts`)
- Agent Loop → Stream Parsing: parses stream (evidence: `src/core/agent/loop.ts`)
- Message History → Stream Parsing: uses parser (evidence: `src/core/message/historyMessage.ts`)
- Agent Handler → Agent Loop: dispatches
- Conversation Handler → SQLite Repository: queries
- Graph Nodes → Tool Registration: uses tools
- Tool Registration → File Tool: registers
- Tool Registration → Shell Tool: registers
- Tool Registration → Time Tool: registers
