From fdf2e6897c44840efefa5e46983138535e95fdf2 Mon Sep 17 00:00:00 2001 From: NanaKay007 Date: Sat, 31 Jan 2026 09:58:53 -0800 Subject: [PATCH 1/2] Fix architecture overview diagram accuracy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - React/Vite not Next.js, Express 5 not Next.js API - Same-origin HTTP + WebSocket, not separate HTTPS - MongoDB connected from Auth Service (users, sessions) and Chat Service (conversations, messages, pending actions), not just LangChain - LLM provider shows both Gemini and Claude πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- system-design.md | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/system-design.md b/system-design.md index f052bb2..0610895 100644 --- a/system-design.md +++ b/system-design.md @@ -5,7 +5,7 @@ ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Frontend (SPA) β”‚ -β”‚ React / Next.js (static export) β”‚ +β”‚ React 19 / Vite / Tailwind β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Auth View β”‚ β”‚ Calendar β”‚ β”‚ Chat Panel β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Dashboard β”‚ β”‚ (collapsible side β”‚ β”‚ @@ -15,25 +15,27 @@ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ approval UI) β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ - β”‚ HTTPS + β”‚ Same-origin HTTP + WebSocket β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Backend API β”‚ -β”‚ Node.js (Express / Next.js API) β”‚ +β”‚ Node.js / Express 5 β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Auth β”‚ β”‚ Calendar β”‚ β”‚ Agent / Chat β”‚ β”‚ β”‚ β”‚ Service β”‚ β”‚ Service β”‚ β”‚ Service (LangChain) β”‚ β”‚ -β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ -β””β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ - β”‚ β”‚ β”‚ - β–Ό β–Ό β–Ό -Google OAuth Google Calendar LangChain TS Agent - 2.0 API API + LLM Provider - (e.g. Gemini free tier) - β”‚ - β–Ό - MongoDB - (conversations, pending - actions, sessions) +β”‚ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ +β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β”‚ β”‚ β”‚ + β–Ό β–Ό β–Ό + Google OAuth Google Calendar LangChain TS Agent + 2.0 API API + LLM Provider + (Gemini / Claude) + β”‚ β”‚ + └───────────┐ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β–Ό β–Ό + MongoDB + (users, sessions, + conversations, messages, + pending actions) ``` ## Data Models From bd31e4b331c1a582b125f1c3255595aac0004902 Mon Sep 17 00:00:00 2001 From: NanaKay007 Date: Sat, 31 Jan 2026 10:02:37 -0800 Subject: [PATCH 2/2] Convert system-design diagrams to Mermaid where appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Architecture overview: Mermaid flowchart - Auth flow: Mermaid sequence diagram - Calendar viewing flow: Mermaid sequence diagram - Chat HITL flow: Mermaid sequence diagram - Production architecture: Mermaid flowchart - Conversation memory flow: kept as ASCII (multi-line box labels are more readable this way); fixed entry point from POST /api/chat to WS /ws πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- system-design.md | 201 ++++++++++++++++++++++------------------------- 1 file changed, 92 insertions(+), 109 deletions(-) diff --git a/system-design.md b/system-design.md index 0610895..a6c9161 100644 --- a/system-design.md +++ b/system-design.md @@ -2,40 +2,28 @@ ## Architecture Overview -``` -β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” -β”‚ Frontend (SPA) β”‚ -β”‚ React 19 / Vite / Tailwind β”‚ -β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ -β”‚ β”‚ Auth View β”‚ β”‚ Calendar β”‚ β”‚ Chat Panel β”‚ β”‚ -β”‚ β”‚ β”‚ β”‚ Dashboard β”‚ β”‚ (collapsible side β”‚ β”‚ -β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ panel / mobile β”‚ β”‚ -β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ full-screen β”‚ β”‚ -β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ overlay, HITL β”‚ β”‚ -β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ approval UI) β”‚ β”‚ -β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ -β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ - β”‚ Same-origin HTTP + WebSocket -β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” -β”‚ Backend API β”‚ -β”‚ Node.js / Express 5 β”‚ -β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ -β”‚ β”‚ Auth β”‚ β”‚ Calendar β”‚ β”‚ Agent / Chat β”‚ β”‚ -β”‚ β”‚ Service β”‚ β”‚ Service β”‚ β”‚ Service (LangChain) β”‚ β”‚ -β”‚ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ -β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ - β”‚ β”‚ β”‚ - β–Ό β–Ό β–Ό - Google OAuth Google Calendar LangChain TS Agent - 2.0 API API + LLM Provider - (Gemini / Claude) - β”‚ β”‚ - └───────────┐ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ - β–Ό β–Ό - MongoDB - (users, sessions, - conversations, messages, - pending actions) +```mermaid +graph TD + subgraph Frontend["Frontend (SPA) β€” React 19 / Vite / Tailwind"] + AuthView[Auth View] + CalendarDash[Calendar Dashboard] + ChatPanel["Chat Panel
(collapsible side panel /
mobile full-screen overlay,
HITL approval UI)"] + end + + Frontend -->|"Same-origin HTTP + WebSocket"| Backend + + subgraph Backend["Backend API β€” Node.js / Express 5"] + AuthSvc[Auth Service] + CalSvc[Calendar Service] + ChatSvc["Agent / Chat Service
(LangChain)"] + end + + AuthSvc --> GoogleOAuth[Google OAuth 2.0 API] + CalSvc --> GoogleCal[Google Calendar API] + ChatSvc --> LLM["LLM Provider
(Gemini / Claude)"] + + AuthSvc --> MongoDB + ChatSvc --> MongoDB["MongoDB
(users, sessions, conversations,
messages, pending actions)"] ``` ## Data Models @@ -174,75 +162,82 @@ The agent is built using **LangChain.js** with the following components: ### Authentication Flow -``` -User Frontend Backend Google - β”‚ β”‚ β”‚ β”‚ - │──click login─▢│ β”‚ β”‚ - β”‚ │──GET /auth/login──▢ β”‚ - β”‚ │◀─redirect URL──│ β”‚ - │◀──redirect────│ β”‚ β”‚ - │──consent──────────────────────────────────────▢│ - │◀─────────────────────auth code─────────────────│ - │──callback─────▢ β”‚ β”‚ - β”‚ │──GET /auth/callback?code=──────▢│ - β”‚ β”‚ │──exchange code─▢│ - β”‚ β”‚ │◀─tokens────────│ - β”‚ β”‚ β”‚ (store tokens) β”‚ - β”‚ │◀─session/JWT──│ β”‚ - │◀──logged in───│ β”‚ β”‚ +```mermaid +sequenceDiagram + actor User + participant Frontend + participant Backend + participant Google + + User->>Frontend: Click login + Frontend->>Backend: GET /auth/login + Backend-->>Frontend: Redirect URL + Frontend-->>User: Redirect to Google + User->>Google: Consent + Google-->>User: Auth code + User->>Frontend: Callback + Frontend->>Backend: GET /auth/callback?code= + Backend->>Google: Exchange code + Google-->>Backend: Tokens + Note over Backend: Store tokens in session + Backend-->>Frontend: Session cookie + Frontend-->>User: Logged in ``` ### Calendar Viewing Flow -``` -User Frontend Backend Google Calendar API - β”‚ β”‚ β”‚ β”‚ - │──view cals───▢│ β”‚ β”‚ - β”‚ │──GET /api/calendars─▢ β”‚ - β”‚ β”‚ │──list calendars───▢│ - β”‚ β”‚ │◀─calendar list─────│ - β”‚ │◀─calendars JSON─────│ β”‚ - │◀──render──────│ β”‚ β”‚ - β”‚ β”‚ β”‚ β”‚ - │──click cal───▢│ β”‚ β”‚ - β”‚ │──GET /api/calendars/{id}/events─────────▢│ - β”‚ β”‚ │──list events──────▢│ - β”‚ β”‚ │◀─events───────────│ - β”‚ │◀─events JSON────────│ β”‚ - │◀──render──────│ β”‚ β”‚ +```mermaid +sequenceDiagram + actor User + participant Frontend + participant Backend + participant GoogleCal as Google Calendar API + + User->>Frontend: View calendars + Frontend->>Backend: GET /api/calendars + Backend->>GoogleCal: List calendars + GoogleCal-->>Backend: Calendar list + Backend-->>Frontend: Calendars JSON + Frontend-->>User: Render calendar list + + User->>Frontend: Click calendar + Frontend->>Backend: GET /api/calendars/{id}/events + Backend->>GoogleCal: List events + GoogleCal-->>Backend: Events + Backend-->>Frontend: Events JSON + Frontend-->>User: Render calendar view ``` ### Chat with Human-In-The-Loop Flow -``` -User Frontend Backend LLM Google Cal API - β”‚ β”‚ β”‚ β”‚ β”‚ - │──"schedule β”‚ β”‚ β”‚ β”‚ - β”‚ meeting"────▢│ β”‚ β”‚ β”‚ - β”‚ │──WS send_message───▢ β”‚ β”‚ - β”‚ β”‚ │──prompt + ───────▢ β”‚ - β”‚ β”‚ β”‚ conversation β”‚ β”‚ - β”‚ β”‚ β”‚ history β”‚ β”‚ - β”‚ β”‚ │◀─tool call───────│ β”‚ - β”‚ β”‚ β”‚ (create_event) β”‚ β”‚ - β”‚ β”‚ β”‚ β”‚ β”‚ - β”‚ β”‚ β”‚ (save PendingAction) β”‚ - β”‚ │◀─reply + pending────│ β”‚ β”‚ - │◀──show action β”‚ action β”‚ β”‚ β”‚ - β”‚ for approvalβ”‚ β”‚ β”‚ β”‚ - β”‚ β”‚ β”‚ β”‚ β”‚ - │──approve─────▢│ β”‚ β”‚ β”‚ - β”‚ │──POST /api/actions/{id}/approve────────▢ β”‚ - β”‚ β”‚ │──create event────────────────────▢│ - β”‚ β”‚ │◀─event created───────────────────│ - β”‚ │◀─confirmation───────│ β”‚ β”‚ - │◀──"Done!"─────│ β”‚ β”‚ β”‚ +```mermaid +sequenceDiagram + actor User + participant Frontend + participant Backend + participant LLM + participant GoogleCal as Google Calendar API + + User->>Frontend: "Schedule meeting" + Frontend->>Backend: WS send_message + Backend->>LLM: Prompt + conversation history + LLM-->>Backend: Tool call (create_event) + Note over Backend: Save PendingAction to MongoDB + Backend-->>Frontend: Reply + pending action + Frontend-->>User: Show action for approval + + User->>Frontend: Approve + Frontend->>Backend: POST /api/actions/{id}/approve + Backend->>GoogleCal: Create event + GoogleCal-->>Backend: Event created + Backend-->>Frontend: Confirmation + Frontend-->>User: "Done!" ``` ### Conversation Memory Flow (LangChain) ``` -POST /api/chat +WS /ws (send_message) β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” @@ -304,25 +299,13 @@ POST /api/chat Single-service deployment on Railway β€” the Express backend serves the built React SPA as static files, eliminating cross-origin complexity. -``` -β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” -β”‚ Railway (Single Service) β”‚ -β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ -β”‚ β”‚ Express Backend β”‚ β”‚ -β”‚ β”‚ - API routes (/api/*) β”‚ β”‚ -β”‚ β”‚ - WebSocket (/ws) β”‚ β”‚ -β”‚ β”‚ - Static files (app/dist)β”‚ β”‚ -β”‚ β”‚ - SPA fallback β”‚ β”‚ -β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ -β”‚ β”‚ β”‚ -β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ - β”‚ - β–Ό - β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” - β”‚ MongoDB Atlas (M0) β”‚ - β”‚ Sessions, Users, β”‚ - β”‚ Conversations, etc. β”‚ - β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +```mermaid +graph TD + subgraph Railway["Railway (Single Service)"] + Express["Express Backend
β€’ API routes (/api/*)
β€’ WebSocket (/ws)
β€’ Static files (app/dist)
β€’ SPA fallback"] + end + + Express --> Mongo["MongoDB Atlas (M0)
Sessions, Users,
Conversations, Pending Actions"] ``` ### Production Configuration