# arpitve560/codepilot architecture

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

- Interactive diagram: https://gitdiagram.com/arpitve560/codepilot
- Repository: https://github.com/arpitve560/codepilot

## Overview

AI Pair Programmer is a browser-based coding workspace: users sign in, edit code in Monaco, ask an AI for streamed help that can be applied to the editor, and optionally collaborate in private or link-accessible rooms. Room edits and presence sync live over Socket.IO; room documents persist in MongoDB. The tree also includes a code-execution service and routes, though the README marks execution as next, so its detailed provider behavior is not established here. Connections for unsampled client and collaboration internals follow the README; uncertain provider wiring is omitted.

Main entry points: [`server/src/index.js`](https://github.com/arpitve560/codepilot/blob/main/server/src/index.js) (HTTP server), [`server/src/controllers/ai.controller.js`](https://github.com/arpitve560/codepilot/blob/main/server/src/controllers/ai.controller.js) (Chat controller), [`client/src/App.jsx`](https://github.com/arpitve560/codepilot/blob/main/client/src/App.jsx) (App gate), [`client/src/Workspace.jsx`](https://github.com/arpitve560/codepilot/blob/main/client/src/Workspace.jsx) (Workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Coding workspace"]
  node_app["App gate<br/>[App.jsx]"]
  node_authui["Auth interface<br/>[AuthPage.jsx]"]
  node_authstate["Auth state<br/>[AuthProvider.jsx]"]
  node_workspace["Workspace<br/>[Workspace.jsx]"]
  node_editor["Monaco editor<br/>[EditorPane.jsx]"]
  node_chat["AI chat<br/>[ChatPanel.jsx]"]
  node_chatinput["Chat input<br/>[ChatInput.jsx]"]
end

subgraph group_identity["Accounts and rooms"]
  node_roomui["Room controls<br/>[RoomsMenu.jsx]"]
  node_collabhook["Collaboration client<br/>[useCollab.js]"]
  node_authcontroller["Auth controller<br/>[auth.controller.js]"]
  node_userstore[("User records<br/>[User.js]")]
  node_roomcontroller["Room management<br/>[room.controller.js]"]
  node_roomstore[("Room records<br/>[Room.js]")]
  node_socket["Socket gateway<br/>[socket.js]"]
  node_roomdocs["Room documents<br/>[rooms.js]"]
end

subgraph group_ai["AI assistance"]
  node_usechat["Chat client<br/>[useChat.js]"]
  node_parse["Reply parser<br/>[parseMessage.js]"]
  node_codeblock["Code blocks<br/>[CodeBlock.jsx]"]
  node_aicontroller["Chat controller<br/>[ai.controller.js]"]
  node_prompt["Prompt builder<br/>[pairProgrammer.js]"]
  node_groqservice["Groq stream client<br/>[groq.service.js]"]
end

subgraph group_server["Application backend"]
  node_api["API client<br/>[api.js]"]
  node_authroutes["Auth routes<br/>[auth.routes.js]"]
  node_roomroutes["Room routes<br/>[room.routes.js]"]
  node_airoutes["AI route<br/>[ai.routes.js]"]
  node_runroutes["Run routes<br/>[run.routes.js]"]
  node_runcontroller["Run controller<br/>[run.controller.js]"]
  node_execution["Execution dispatcher<br/>[index.js]"]
  node_serverentry["HTTP server<br/>[index.js]"]
end

node_developer(("Developer"))
node_groq{{"Groq model API"}}
node_runner{{"Execution provider"}}
node_mongo[("MongoDB")]
node_collaborator(("Collaborator"))

node_developer -->|"opens"| node_app
node_app -->|"checks session"| node_authstate
node_app -->|"shows signed out"| node_authui
node_app -->|"opens signed in"| node_workspace
node_authui -->|"submits credentials"| node_authstate
node_authstate -->|"sends requests"| node_api
node_workspace -->|"hosts editor"| node_editor
node_workspace -->|"hosts chat"| node_chat
node_chat -->|"collects prompt"| node_chatinput
node_chatinput -->|"submits chat"| node_usechat
node_usechat -->|"posts chat"| node_api
node_api -->|"requests"| node_airoutes
node_airoutes -->|"dispatches"| node_aicontroller
node_aicontroller -->|"builds context"| node_prompt
node_aicontroller -->|"streams completion"| node_groqservice
node_groqservice -->|"requests stream"| node_groq
node_aicontroller -->|"SSE tokens"| node_usechat
node_usechat -->|"parses reply"| node_parse
node_parse -->|"extracts code"| node_codeblock
node_codeblock -->|"applies edits"| node_editor
node_workspace -->|"manages rooms"| node_roomui
node_roomui -->|"room requests"| node_api
node_roomui -->|"joins room"| node_collabhook
node_collabhook -->|"syncs document"| node_socket
node_collaborator -->|"edits document"| node_collabhook
node_socket -->|"updates room document"| node_roomdocs
node_roomdocs -->|"persists snapshots"| node_mongo
node_serverentry -->|"attaches socket"| node_socket
node_serverentry -->|"mounts routes"| node_authroutes
node_serverentry -->|"mounts routes"| node_roomroutes
node_serverentry -->|"mounts routes"| node_airoutes
node_serverentry -->|"mounts routes"| node_runroutes
node_authroutes -->|"dispatches"| node_authcontroller
node_authcontroller -->|"reads and writes"| node_userstore
node_roomroutes -->|"dispatches"| node_roomcontroller
node_roomcontroller -->|"reads and writes"| node_roomstore
node_roomcontroller -->|"looks up invitee"| node_userstore
node_authcontroller -->|"stores users"| node_mongo
node_roomstore -->|"persists rooms"| node_mongo
node_airoutes -->|"dispatches"| node_aicontroller
node_runroutes -->|"dispatches"| node_runcontroller
node_runcontroller -->|"requests execution"| node_execution
node_execution -.->|"runs code"| node_runner

click node_app "https://github.com/arpitve560/codepilot/blob/main/client/src/App.jsx"
click node_authui "https://github.com/arpitve560/codepilot/blob/main/client/src/auth/AuthPage.jsx"
click node_authstate "https://github.com/arpitve560/codepilot/blob/main/client/src/auth/AuthProvider.jsx"
click node_workspace "https://github.com/arpitve560/codepilot/blob/main/client/src/Workspace.jsx"
click node_editor "https://github.com/arpitve560/codepilot/blob/main/client/src/components/editor/EditorPane.jsx"
click node_chat "https://github.com/arpitve560/codepilot/blob/main/client/src/components/chat/ChatPanel.jsx"
click node_chatinput "https://github.com/arpitve560/codepilot/blob/main/client/src/components/chat/ChatInput.jsx"
click node_usechat "https://github.com/arpitve560/codepilot/blob/main/client/src/hooks/useChat.js"
click node_parse "https://github.com/arpitve560/codepilot/blob/main/client/src/lib/parseMessage.js"
click node_codeblock "https://github.com/arpitve560/codepilot/blob/main/client/src/components/chat/CodeBlock.jsx"
click node_api "https://github.com/arpitve560/codepilot/blob/main/client/src/lib/api.js"
click node_roomui "https://github.com/arpitve560/codepilot/blob/main/client/src/components/rooms/RoomsMenu.jsx"
click node_collabhook "https://github.com/arpitve560/codepilot/blob/main/client/src/hooks/useCollab.js"
click node_authroutes "https://github.com/arpitve560/codepilot/blob/main/server/src/routes/auth.routes.js"
click node_authcontroller "https://github.com/arpitve560/codepilot/blob/main/server/src/controllers/auth.controller.js"
click node_userstore "https://github.com/arpitve560/codepilot/blob/main/server/src/models/User.js"
click node_roomroutes "https://github.com/arpitve560/codepilot/blob/main/server/src/routes/room.routes.js"
click node_roomcontroller "https://github.com/arpitve560/codepilot/blob/main/server/src/controllers/room.controller.js"
click node_roomstore "https://github.com/arpitve560/codepilot/blob/main/server/src/models/Room.js"
click node_socket "https://github.com/arpitve560/codepilot/blob/main/server/src/collab/socket.js"
click node_roomdocs "https://github.com/arpitve560/codepilot/blob/main/server/src/collab/rooms.js"
click node_airoutes "https://github.com/arpitve560/codepilot/blob/main/server/src/routes/ai.routes.js"
click node_aicontroller "https://github.com/arpitve560/codepilot/blob/main/server/src/controllers/ai.controller.js"
click node_prompt "https://github.com/arpitve560/codepilot/blob/main/server/src/prompts/pairProgrammer.js"
click node_groqservice "https://github.com/arpitve560/codepilot/blob/main/server/src/services/groq.service.js"
click node_runroutes "https://github.com/arpitve560/codepilot/blob/main/server/src/routes/run.routes.js"
click node_runcontroller "https://github.com/arpitve560/codepilot/blob/main/server/src/controllers/run.controller.js"
click node_execution "https://github.com/arpitve560/codepilot/blob/main/server/src/services/execution/index.js"
click node_serverentry "https://github.com/arpitve560/codepilot/blob/main/server/src/index.js"

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_authui,node_authstate,node_workspace,node_editor,node_chat,node_chatinput toneBlue
class node_roomui,node_collabhook,node_authcontroller,node_userstore,node_roomcontroller,node_roomstore,node_socket,node_roomdocs,node_mongo toneAmber
class node_usechat,node_parse,node_codeblock,node_aicontroller,node_prompt,node_groqservice,node_groq toneMint
class node_api,node_authroutes,node_roomroutes,node_airoutes,node_runroutes,node_runcontroller,node_execution,node_serverentry toneRose
class node_developer,node_runner,node_collaborator toneIndigo
```

## Components

### Coding workspace

- [App gate](https://github.com/arpitve560/codepilot/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Auth interface](https://github.com/arpitve560/codepilot/blob/main/client/src/auth/AuthPage.jsx): `client/src/auth/AuthPage.jsx`
- [Auth state](https://github.com/arpitve560/codepilot/blob/main/client/src/auth/AuthProvider.jsx): `client/src/auth/AuthProvider.jsx`
- [Workspace](https://github.com/arpitve560/codepilot/blob/main/client/src/Workspace.jsx): `client/src/Workspace.jsx`
- [Monaco editor](https://github.com/arpitve560/codepilot/blob/main/client/src/components/editor/EditorPane.jsx): `client/src/components/editor/EditorPane.jsx`
- [AI chat](https://github.com/arpitve560/codepilot/blob/main/client/src/components/chat/ChatPanel.jsx): `client/src/components/chat/ChatPanel.jsx`
- [Chat input](https://github.com/arpitve560/codepilot/blob/main/client/src/components/chat/ChatInput.jsx): `client/src/components/chat/ChatInput.jsx`

### Accounts and rooms

- [Room controls](https://github.com/arpitve560/codepilot/blob/main/client/src/components/rooms/RoomsMenu.jsx): `client/src/components/rooms/RoomsMenu.jsx`
- [Collaboration client](https://github.com/arpitve560/codepilot/blob/main/client/src/hooks/useCollab.js): `client/src/hooks/useCollab.js`
- [Auth controller](https://github.com/arpitve560/codepilot/blob/main/server/src/controllers/auth.controller.js): `server/src/controllers/auth.controller.js`
- [User records](https://github.com/arpitve560/codepilot/blob/main/server/src/models/User.js): `server/src/models/User.js`
- [Room management](https://github.com/arpitve560/codepilot/blob/main/server/src/controllers/room.controller.js): `server/src/controllers/room.controller.js`
- [Room records](https://github.com/arpitve560/codepilot/blob/main/server/src/models/Room.js): `server/src/models/Room.js`
- [Socket gateway](https://github.com/arpitve560/codepilot/blob/main/server/src/collab/socket.js): `server/src/collab/socket.js`
- [Room documents](https://github.com/arpitve560/codepilot/blob/main/server/src/collab/rooms.js): `server/src/collab/rooms.js`

### AI assistance

- [Chat client](https://github.com/arpitve560/codepilot/blob/main/client/src/hooks/useChat.js): `client/src/hooks/useChat.js`
- [Reply parser](https://github.com/arpitve560/codepilot/blob/main/client/src/lib/parseMessage.js): `client/src/lib/parseMessage.js`
- [Code blocks](https://github.com/arpitve560/codepilot/blob/main/client/src/components/chat/CodeBlock.jsx): `client/src/components/chat/CodeBlock.jsx`
- [Chat controller](https://github.com/arpitve560/codepilot/blob/main/server/src/controllers/ai.controller.js): `server/src/controllers/ai.controller.js`
- [Prompt builder](https://github.com/arpitve560/codepilot/blob/main/server/src/prompts/pairProgrammer.js): `server/src/prompts/pairProgrammer.js`
- [Groq stream client](https://github.com/arpitve560/codepilot/blob/main/server/src/services/groq.service.js): `server/src/services/groq.service.js`

### Application backend

- [API client](https://github.com/arpitve560/codepilot/blob/main/client/src/lib/api.js): `client/src/lib/api.js`
- [Auth routes](https://github.com/arpitve560/codepilot/blob/main/server/src/routes/auth.routes.js): `server/src/routes/auth.routes.js`
- [Room routes](https://github.com/arpitve560/codepilot/blob/main/server/src/routes/room.routes.js): `server/src/routes/room.routes.js`
- [AI route](https://github.com/arpitve560/codepilot/blob/main/server/src/routes/ai.routes.js): `server/src/routes/ai.routes.js`
- [Run routes](https://github.com/arpitve560/codepilot/blob/main/server/src/routes/run.routes.js): `server/src/routes/run.routes.js`
- [Run controller](https://github.com/arpitve560/codepilot/blob/main/server/src/controllers/run.controller.js): `server/src/controllers/run.controller.js`
- [Execution dispatcher](https://github.com/arpitve560/codepilot/blob/main/server/src/services/execution/index.js): `server/src/services/execution/index.js`
- [HTTP server](https://github.com/arpitve560/codepilot/blob/main/server/src/index.js): `server/src/index.js`

### Other components

- **Developer**
- **Groq model API**
- **Execution provider**
- **MongoDB**
- **Collaborator**

## Connections

- Developer → App gate: opens
- App gate → Auth state: checks session
- App gate → Auth interface: shows signed out
- App gate → Workspace: opens signed in
- Auth interface → Auth state: submits credentials
- Auth state → API client: sends requests
- Workspace → Monaco editor: hosts editor
- Workspace → AI chat: hosts chat
- AI chat → Chat input: collects prompt
- Chat input → Chat client: submits chat
- Chat client → API client: posts chat
- API client → AI route: requests
- AI route → Chat controller: dispatches
- Chat controller → Prompt builder: builds context
- Chat controller → Groq stream client: streams completion
- Groq stream client → Groq model API: requests stream
- Chat controller → Chat client: SSE tokens
- Chat client → Reply parser: parses reply
- Reply parser → Code blocks: extracts code
- Code blocks → Monaco editor: applies edits
- Workspace → Room controls: manages rooms
- Room controls → API client: room requests
- Room controls → Collaboration client: joins room
- Collaboration client → Socket gateway: syncs document
- Collaborator → Collaboration client: edits document
- Socket gateway → Room documents: updates room document
- Room documents → MongoDB: persists snapshots
- HTTP server → Socket gateway: attaches socket
- HTTP server → Auth routes: mounts routes
- HTTP server → Room routes: mounts routes
- HTTP server → AI route: mounts routes
- HTTP server → Run routes: mounts routes
- Auth routes → Auth controller: dispatches
- Auth controller → User records: reads and writes
- Room routes → Room management: dispatches
- Room management → Room records: reads and writes
- Room management → User records: looks up invitee
- Auth controller → MongoDB: stores users
- Room records → MongoDB: persists rooms
- AI route → Chat controller: dispatches
- Run routes → Run controller: dispatches
- Run controller → Execution dispatcher: requests execution
- Execution dispatcher → Execution provider: runs code
