# sunil8521/gpt-clone-langgraph architecture

> Architecture diagram of the GitHub repository sunil8521/gpt-clone-langgraph, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sunil8521/gpt-clone-langgraph
- Repository: https://github.com/sunil8521/gpt-clone-langgraph

## Overview

The product is a cookie-session authenticated AI chat application. Users sign in or create an account, open or create a conversation, send messages, and view conversation history; the chat agent uses Gemini and MongoDB-backed checkpoint memory. The sampled sources establish client authentication and chat API calls plus server startup and auth behavior. Chat-route and agent internals were not sampled, so their links reflect only the documented architecture and the repository’s exact paths.

Main entry points: [`server/src/routes/chat.ts`](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/routes/chat.ts) (Chat routes), [`client/src/App.tsx`](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/client/src/App.tsx) (App routing), [`server/src/routes/auth.ts`](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/routes/auth.ts) (Auth routes), [`server/src/agent.ts`](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/agent.ts) (Conversation agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app["App routing<br/>[App.tsx]"]
  node_authpage["Sign in / sign up<br/>[Auth.tsx]"]
  node_chatpage["Chat interface<br/>[Chat.tsx]"]
  node_authstore["Auth state<br/>[useAuthStore.ts]"]
  node_chatstore["Chat state<br/>[useChatStore.ts]"]
end

subgraph group_api["API and auth"]
  node_server["Express server<br/>[index.ts]"]
  node_authroutes["Auth routes<br/>[auth.ts]"]
  node_authmiddleware["Session guard<br/>[auth.ts]"]
end

subgraph group_chat["Chat and agent"]
  node_chatroutes["Chat routes<br/>[chat.ts]"]
  node_agent["Conversation agent<br/>[agent.ts]"]
  node_gemini{{"Gemini model"}}
end

subgraph group_persistence["Persistence"]
  node_userdb[("User records<br/>[User.ts]")]
  node_chatdb[("Chat records<br/>[Chat.ts]")]
  node_checkpoints[("Agent checkpoints<br/>[agent.ts]")]
end

node_user(("User"))
node_mongodb[("MongoDB")]

node_user -->|"uses"| node_app
node_app -->|"checks session"| node_authstore
node_app -->|"routes to"| node_authpage
node_app -->|"routes to"| node_chatpage
node_authpage -->|"submits credentials"| node_authstore
node_authstore -->|"calls auth API"| node_authroutes
node_chatpage -->|"uses chat state"| node_chatstore
node_chatstore -->|"calls chat API"| node_chatroutes
node_server -->|"mounts"| node_authroutes
node_server -->|"mounts"| node_chatroutes
node_server -->|"initializes"| node_agent
node_authroutes -->|"reads / writes"| node_userdb
node_authroutes -->|"stores sessions"| node_mongodb
node_chatroutes -->|"guards requests"| node_authmiddleware
node_chatroutes -->|"reads / writes"| node_chatdb
node_chatroutes -->|"invokes"| node_agent
node_agent -->|"generates replies"| node_gemini
node_agent -->|"persists memory"| node_checkpoints
node_chatdb -->|"persists records"| node_mongodb
node_checkpoints -->|"stores checkpoints"| node_mongodb

click node_app "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/client/src/App.tsx"
click node_authpage "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/client/src/pages/Auth.tsx"
click node_chatpage "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/client/src/pages/Chat.tsx"
click node_authstore "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/client/src/store/useAuthStore.ts"
click node_chatstore "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/client/src/store/useChatStore.ts"
click node_server "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/index.ts"
click node_authroutes "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/routes/auth.ts"
click node_authmiddleware "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/middleware/auth.ts"
click node_chatroutes "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/routes/chat.ts"
click node_agent "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/agent.ts"
click node_userdb "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/models/User.ts"
click node_chatdb "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/models/Chat.ts"
click node_checkpoints "https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/agent.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,node_authpage,node_chatpage,node_authstore,node_chatstore,node_user toneBlue
class node_server,node_authroutes,node_authmiddleware,node_mongodb toneAmber
class node_chatroutes,node_agent,node_gemini toneMint
class node_userdb,node_chatdb,node_checkpoints toneRose
```

## Components

### Web client

- [App routing](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/client/src/App.tsx): `client/src/App.tsx`
- [Sign in / sign up](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/client/src/pages/Auth.tsx): `client/src/pages/Auth.tsx`
- [Chat interface](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/client/src/pages/Chat.tsx): `client/src/pages/Chat.tsx`
- [Auth state](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/client/src/store/useAuthStore.ts): `client/src/store/useAuthStore.ts`
- [Chat state](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/client/src/store/useChatStore.ts): `client/src/store/useChatStore.ts`

### API and auth

- [Express server](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/index.ts): `server/src/index.ts`
- [Auth routes](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/routes/auth.ts): `server/src/routes/auth.ts`
- [Session guard](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/middleware/auth.ts): `server/src/middleware/auth.ts`

### Chat and agent

- [Chat routes](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/routes/chat.ts): `server/src/routes/chat.ts`
- [Conversation agent](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/agent.ts): `server/src/agent.ts`
- **Gemini model**

### Persistence

- [User records](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/models/User.ts): `server/src/models/User.ts`
- [Chat records](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/models/Chat.ts): `server/src/models/Chat.ts`
- [Agent checkpoints](https://github.com/sunil8521/gpt-clone-langgraph/blob/main/server/src/agent.ts): `server/src/agent.ts`

### Other components

- **User**
- **MongoDB**

## Connections

- User → App routing: uses
- App routing → Auth state: checks session
- App routing → Sign in / sign up: routes to
- App routing → Chat interface: routes to
- Sign in / sign up → Auth state: submits credentials
- Auth state → Auth routes: calls auth API
- Chat interface → Chat state: uses chat state
- Chat state → Chat routes: calls chat API
- Express server → Auth routes: mounts
- Express server → Chat routes: mounts
- Express server → Conversation agent: initializes
- Auth routes → User records: reads / writes
- Auth routes → MongoDB: stores sessions
- Chat routes → Session guard: guards requests
- Chat routes → Chat records: reads / writes
- Chat routes → Conversation agent: invokes
- Conversation agent → Gemini model: generates replies
- Conversation agent → Agent checkpoints: persists memory
- Chat records → MongoDB: persists records
- Agent checkpoints → MongoDB: stores checkpoints
