# codewithmubasher/nightcode architecture

> Architecture diagram of the GitHub repository codewithmubasher/nightcode, 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/codewithmubasher/nightcode
- Repository: https://github.com/codewithmubasher/nightcode

## Overview

NightCode is a workspace-oriented AI coding assistant. A user selects a workspace and chats; the frontend sends chat requests to the Go API, which streams a model-driven agent run. The agent builds workspace-aware context, requests model responses, executes tools, and returns events for the chat UI; chat and artifact data are persisted. The tree also shows provider choices, workspace management, and MCP connectors as significant capabilities. The README is empty and several backend excerpts are partial, so uncertain internal wiring is omitted.

Main entry points: [`Backend/internal/api/handler.go`](https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/api/handler.go) (API handler), [`Frontend/src/components/chat-view.tsx`](https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/components/chat-view.tsx) (Chat view), [`Backend/internal/agent/loop.go`](https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/agent/loop.go) (Agent loop), [`Frontend/src/lib/backend-runtime.ts`](https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/lib/backend-runtime.ts) (Backend client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Chat interface"]
  node_app["Application shell<br/>[App.tsx]"]
  node_router["Page router<br/>[router.tsx]"]
  node_chatview["Chat view<br/>[chat-view.tsx]"]
  node_chatstate["Chat state<br/>[chat-context.tsx]"]
  node_runtime["Backend client<br/>[backend-runtime.ts]"]
end

subgraph group_api["API and orchestration"]
  node_server["HTTP server<br/>[main.go]"]
  node_handler["API handler<br/>[handler.go]"]
  node_reverse["Message reversal<br/>[reverse.go]"]
  node_store[("SQLite store<br/>[sqlite.go]")]
end

subgraph group_agent["Agent runtime"]
  node_loop["Agent loop<br/>[loop.go]"]
  node_context["Workspace context<br/>[context_manager.go]"]
  node_workspace["Workspace tools<br/>[workspace.go]"]
  node_registry["Tool registry<br/>[registry.go]"]
  node_tools["File and shell tools"]
end

subgraph group_integrations["Providers and connectors"]
  node_provider["Model providers"]
  node_mcpmanager["MCP connectors<br/>[handler.go]"]
  node_mcpclient["MCP client<br/>[client.go]"]
end

node_user(("User"))
node_modelservice{{"Model services"}}
node_mcpservers{{"MCP server processes"}}

node_user -->|"uses"| node_app
node_app -->|"renders routes"| node_router
node_router -->|"opens chat"| node_chatview
node_chatview -->|"updates messages"| node_chatstate
node_chatview -->|"sends requests"| node_runtime
node_chatstate -->|"loads chats"| node_runtime
node_runtime -->|"HTTP requests"| node_server
node_server -->|"dispatches"| node_handler
node_handler -->|"starts runs"| node_loop
node_handler -->|"persists chat data"| node_store
node_handler -->|"reverses messages"| node_reverse
node_handler -->|"registers connectors"| node_mcpmanager
node_handler -->|"selects provider"| node_provider
node_loop -->|"builds prompt"| node_context
node_context -->|"reads workspace"| node_workspace
node_loop -->|"requests completion"| node_provider
node_provider -.->|"streams responses"| node_modelservice
node_loop -->|"dispatches tools"| node_registry
node_registry -->|"executes tool"| node_tools
node_mcpmanager -->|"creates clients"| node_mcpclient
node_mcpclient -.->|"JSON-RPC"| node_mcpservers
node_chatview -->|"streams results"| node_user

click node_app "https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/App.tsx"
click node_router "https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/router.tsx"
click node_chatview "https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/components/chat-view.tsx"
click node_chatstate "https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/context/chat-context.tsx"
click node_runtime "https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/lib/backend-runtime.ts"
click node_server "https://github.com/codewithmubasher/nightcode/blob/main/Backend/cmd/server/main.go"
click node_handler "https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/api/handler.go"
click node_reverse "https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/api/reverse.go"
click node_store "https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/store/sqlite.go"
click node_loop "https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/agent/loop.go"
click node_context "https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/context/context_manager.go"
click node_workspace "https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/tools/workspace.go"
click node_registry "https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/tools/registry.go"
click node_tools "https://github.com/codewithmubasher/nightcode/tree/main/Backend/internal/tools"
click node_provider "https://github.com/codewithmubasher/nightcode/tree/main/Backend/internal/provider"
click node_mcpmanager "https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/api/handler.go"
click node_mcpclient "https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/mcp/client.go"

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_router,node_chatview,node_chatstate,node_runtime,node_user toneBlue
class node_server,node_handler,node_reverse,node_store toneAmber
class node_loop,node_context,node_workspace,node_registry,node_tools,node_mcpservers toneMint
class node_provider,node_mcpmanager,node_mcpclient toneRose
class node_modelservice toneIndigo
```

## Components

### Chat interface

- [Application shell](https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/App.tsx): `Frontend/src/App.tsx`
- [Page router](https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/router.tsx): `Frontend/src/router.tsx`
- [Chat view](https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/components/chat-view.tsx): `Frontend/src/components/chat-view.tsx`
- [Chat state](https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/context/chat-context.tsx): `Frontend/src/context/chat-context.tsx`
- [Backend client](https://github.com/codewithmubasher/nightcode/blob/main/Frontend/src/lib/backend-runtime.ts): `Frontend/src/lib/backend-runtime.ts`

### API and orchestration

- [HTTP server](https://github.com/codewithmubasher/nightcode/blob/main/Backend/cmd/server/main.go): `Backend/cmd/server/main.go`
- [API handler](https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/api/handler.go): `Backend/internal/api/handler.go`
- [Message reversal](https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/api/reverse.go): `Backend/internal/api/reverse.go`
- [SQLite store](https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/store/sqlite.go): `Backend/internal/store/sqlite.go`

### Agent runtime

- [Agent loop](https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/agent/loop.go): `Backend/internal/agent/loop.go`
- [Workspace context](https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/context/context_manager.go): `Backend/internal/context/context_manager.go`
- [Workspace tools](https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/tools/workspace.go): `Backend/internal/tools/workspace.go`
- [Tool registry](https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/tools/registry.go): `Backend/internal/tools/registry.go`
- [File and shell tools](https://github.com/codewithmubasher/nightcode/tree/main/Backend/internal/tools): `Backend/internal/tools`

### Providers and connectors

- [Model providers](https://github.com/codewithmubasher/nightcode/tree/main/Backend/internal/provider): `Backend/internal/provider`
- [MCP connectors](https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/api/handler.go): `Backend/internal/api/handler.go`
- [MCP client](https://github.com/codewithmubasher/nightcode/blob/main/Backend/internal/mcp/client.go): `Backend/internal/mcp/client.go`

### Other components

- **User**
- **Model services**
- **MCP server processes**

## Connections

- User → Application shell: uses
- Application shell → Page router: renders routes
- Page router → Chat view: opens chat
- Chat view → Chat state: updates messages
- Chat view → Backend client: sends requests
- Chat state → Backend client: loads chats
- Backend client → HTTP server: HTTP requests
- HTTP server → API handler: dispatches
- API handler → Agent loop: starts runs
- API handler → SQLite store: persists chat data
- API handler → Message reversal: reverses messages
- API handler → MCP connectors: registers connectors
- API handler → Model providers: selects provider
- Agent loop → Workspace context: builds prompt
- Workspace context → Workspace tools: reads workspace
- Agent loop → Model providers: requests completion
- Model providers → Model services: streams responses
- Agent loop → Tool registry: dispatches tools
- Tool registry → File and shell tools: executes tool
- MCP connectors → MCP client: creates clients
- MCP client → MCP server processes: JSON-RPC
- Chat view → User: streams results
