AI chat application with a graph-based conversation UI. Every message is a node in a tree — branch off at any point, explore multiple approaches simultaneously, and switch AI models on the fly.
Traditional AI chat interfaces are linear — once you go down a path, going back means losing context. ChatGraph fixes this:
- Branch conversations from any message to explore different directions
- Switch AI models mid-conversation and compare responses side-by-side
- Visualize conversation structure as an interactive graph with the chat panel alongside it
- Navigate freely — click any node in the graph to jump to that point in the conversation
[System Prompt]
└── [User: "Explain recursion"]
├── [GPT-4: "Recursion is..."]
│ └── [User: "Give me an example"]
│ └── [GPT-4: "Here's factorial..."]
└── [Claude: "Think of recursion as..."] ← branch with different model
└── [User: "Compare to iteration"]
Core
- Tree-based conversation model with branching and navigation
- Real-time streaming responses via SSE (Server-Sent Events)
- Model switching per message via OpenRouter
- Split-pane UI — chat panel + interactive graph visualization
- Markdown rendering with syntax highlighting, LaTeX, and tables
- Regenerate responses and edit+resend messages
- Dark mode
Graph & Visualization
- Interactive node graph powered by React Flow with dagre layout
- Collapse/expand subtrees, zoom-to-fit, vertical/horizontal layout toggle
- Conversation heatmap overlay and fog-of-war minimap
- Node pinning, color labels, and freeform annotations
- Time-travel conversation replay
- Label filtering and saved viewport positions
AI & Analytics
- Multi-model tournament mode — compare responses from different models
- AI-powered auto-titling for conversations
- Smart summarization nodes with context pruning controls
- Context window visualizer with auto-summarize suggestions
- Token & cost dashboard with real pricing data
- Historical spending charts and CSV export
- Per-node token contribution breakdown and real-time cost ticker
Productivity
- Toast notification system and desktop notifications
- Activity feed event log
- Response quality tracking (thumbs up/down)
- Daily budget alerts
- Mermaid diagram rendering and HTML/CSS/JS live preview
- Node.js >= 18
- PostgreSQL 16 — running locally or in Docker
- OpenRouter API key — get one at openrouter.ai
git clone https://github.com/your-username/ChatGraph.git
cd ChatGraphnpm installThis installs dependencies for both the client and server workspaces.
Start a PostgreSQL instance. If using Docker:
docker run -d \
--name chatgraph-postgres \
-e POSTGRES_USER=chatgraph \
-e POSTGRES_PASSWORD=localdev \
-e POSTGRES_DB=chatgraph \
-p 5432:5432 \
postgres:16cp .env.example packages/server/.envEdit packages/server/.env if your database connection differs from the defaults:
DATABASE_URL=postgresql://chatgraph:localdev@localhost:5432/chatgraph
PORT=3002
NODE_ENV=development
cd packages/server
npx prisma migrate dev
cd ../..npm run devThis starts both the frontend (http://localhost:5173) and backend (http://localhost:3002) concurrently.
Open the app in your browser and go to Settings. Enter your OpenRouter API key and test the connection. The key is stored server-side in the database — not in environment variables.
ChatGraph/
├── packages/
│ ├── client/ # React frontend (Vite, port 5173)
│ │ ├── src/
│ │ │ ├── components/ # chat/, graph/, layout/, settings/, shared/
│ │ │ ├── hooks/ # useConversation, useCompletion, useActivePath
│ │ │ ├── stores/ # Zustand stores (conversation, ui, settings)
│ │ │ ├── services/ # api.ts (REST), stream.ts (SSE)
│ │ │ ├── types/
│ │ │ └── utils/ # tree.ts, layout.ts (dagre)
│ │ └── vite.config.ts # Proxy /api → backend
│ └── server/ # Express backend (port 3002)
│ ├── src/
│ │ ├── routes/ # REST API endpoints
│ │ ├── services/ # Business logic
│ │ ├── middleware/ # Error handling, Zod validation
│ │ └── utils/
│ └── prisma/
│ └── schema.prisma # Database schema
├── docs/ # Specifications and architecture docs
├── package.json # Root workspace config
└── .env.example
| Command | Description |
|---|---|
npm run dev |
Start client + server in dev mode |
npm run build |
Build both packages |
npm run lint |
Lint all packages |
npm run typecheck |
Type-check all packages |
npm test |
Run tests |
npx prisma studio |
Open Prisma database browser (run from packages/server) |
npx prisma migrate dev |
Run database migrations (run from packages/server) |
| Layer | Technology |
|---|---|
| Monorepo | npm workspaces |
| Frontend | React 18, TypeScript, Vite 6 |
| Graph UI | React Flow (v12) + dagre |
| Styling | Tailwind CSS 4 |
| State | Zustand 5 |
| Backend | Node.js, Express 4, TypeScript |
| ORM | Prisma 6 |
| Validation | Zod |
| Database | PostgreSQL 16 |
| AI API | OpenRouter (SSE streaming) |
The backend exposes a RESTful API under /api/v1:
GET/POST/DELETE /api/v1/conversations— manage conversationsPOST /api/v1/conversations/:id/complete— send a completion request (SSE streaming)POST /api/v1/conversations/:id/nodes— create nodesPATCH/DELETE /api/v1/nodes/:id— edit or delete nodesGET /api/v1/models— list available OpenRouter modelsGET/PUT /api/v1/settings— app settingsGET /api/v1/usage— token usage statisticsGET /api/v1/analytics— conversation analytics
MIT