# shivtejg236/nemoforge architecture

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

- Interactive diagram: https://gitdiagram.com/shivtejg236/nemoforge
- Repository: https://github.com/shivtejg236/nemoforge

## Overview

#### Purpose and Entry Points
NemoForge is an AI-assisted web-research platform: it browses a requested target, extracts cleaned page content, and asks NVIDIA’s Llama model to answer the user’s prompt from that content. The backend process starts at `backend/src/index.ts`; the React SPA starts at `frontend/src/main.tsx` and composes its application shell in `frontend/src/App.tsx`. Local startup is automated by `scripts/launch.sh`.

#### Frontend Interaction Layer
The frontend is a Vite/React application with Zustand client state. It provides agent creation, live execution visibility, stored-result exploration, and settings through:
- `frontend/src/pages/AgentBuilder.tsx`
- `frontend/src/pages/ResultsExplorer.tsx`
- `frontend/src/store/useStore.ts`

It calls the backend through configured REST and WebSocket endpoints in `frontend/src/config.ts`. The key real-time UI boundary is the backend’s stream of execution logs and base64 browser screenshots.

#### HTTP, Authentication, and Session Boundary
The Node backend combines Express REST routes with a WebSocket server. Authentication is JWT-based middleware, separating protected agent/session operations from login/token issuance:
- `backend/src/index.ts`
- `backend/src/routes/auth.ts`
- `backend/src/middleware/auth.ts`

The REST/API layer accepts work requests and exposes persisted agent data; WebSockets deliver in-progress browser-agent events rather than requiring polling.

#### Agent Orchestration Pipeline
`backend/src/agent/orchestrator.ts` is the primary workflow coordinator. It receives the user prompt and target, emits lifecycle/log/screenshot events, invokes browser execution, converts the page to cleaned DOM text, and sends that text plus the original prompt to NVIDIA NIM. Its final Markdown analysis becomes the completed result.

The pipeline deliberately separates web acquisition from AI interpretation: browser automation determines what page data is collected; the LLM interprets already-collected DOM context instead of driving brittle selector logic.

#### Asynchronous Execution
Agent runs are queued and executed by a BullMQ-based worker layer:
- `backend/src/agent/queue.ts`
- `backend/src/agent/worker.ts`
- `backend/src/agent/orchestrator.ts`

This boundary keeps potentially long browser/LLM work outside the request path and enables queued status transitions and live event broadcasting. Redis is implied by BullMQ as material queue infrastructure, although no Redis deployment artifact is present in the tree.

#### Browser Acquisition and Stealth
Browser setup is isolated in `backend/src/agent/stealth.ts`, which selects among local Chromium modes and Bright Data’s remote Scraping Browser WebSocket endpoint. Ghost Cursor supplies human-like Bézier mouse behavior during Puppeteer-driven navigation. External web targets are therefore accessed through either local Chrome or Bright Data’s residential/anti-bot browser infrastructure, not directly by the frontend.

#### Persistence and Deployment
SQLite persistence stores session history, logs, and results through:
- `backend/src/db/database.ts`
- `backend/nemoforge.sqlite-wal`

Runtime configuration includes the database path, JWT secret, NVIDIA NIM key, and Bright Data endpoints via `.env.example`. The intended production split is Docker/Render for the backend (`backend/Dockerfile`, `render.yaml`) and Vercel for the frontend (`frontend/vercel.json`). NVIDIA NIM’s chat-completions API and Bright Data’s browser/proxy services are the central external dependencies.

Main entry points: [`backend/src/index.ts`](https://github.com/shivtejg236/nemoforge/blob/main/backend/src/index.ts) (Express + WebSocket server), [`backend/src/agent/orchestrator.ts`](https://github.com/shivtejg236/nemoforge/blob/main/backend/src/agent/orchestrator.ts) (Research orchestrator), [`frontend/src/App.tsx`](https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/App.tsx) (Application shell), [`backend/src/agent/queue.ts`](https://github.com/shivtejg236/nemoforge/blob/main/backend/src/agent/queue.ts) (Run queue)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React frontend"]
  node_spa_entry["SPA entry<br/>Vite React entry<br/>[main.tsx]"]
  node_app_shell["Application shell<br/>React app<br/>[App.tsx]"]
  node_agent_builder["Agent Builder<br/>React page<br/>[AgentBuilder.tsx]"]
  node_results_explorer["Results Explorer<br/>React page"]
  node_client_store["Client state<br/>Zustand store<br/>[useStore.ts]"]
  node_endpoint_config["API endpoint config<br/>frontend config<br/>[config.ts]"]
  node_frontend_deploy["Frontend deployment<br/>Vercel config<br/>[vercel.json]"]
end

subgraph group_backend["Backend runtime"]
  node_server["Express + WebSocket server<br/>Node entrypoint<br/>[index.ts]"]
  node_auth_routes["Login and token routes<br/>Express routes<br/>[auth.ts]"]
  node_jwt_auth["JWT protection<br/>Express middleware<br/>[auth.ts]"]
  node_database[("Session and result store<br/>SQLite access layer<br/>[database.ts]")]
  node_sqlite_wal[("SQLite WAL<br/>database journal")]
  node_backend_deploy["Backend deployment<br/>Docker / Render"]
end

subgraph group_agent["Agent execution"]
  node_queue["Run queue<br/>BullMQ queue<br/>[queue.ts]"]
  node_worker["Queue worker<br/>BullMQ worker<br/>[worker.ts]"]
  node_orchestrator["Research orchestrator<br/>agent workflow<br/>[orchestrator.ts]"]
  node_browser_stealth["Browser acquisition<br/>Puppeteer stealth setup<br/>[stealth.ts]"]
end

subgraph group_external["Infrastructure &amp; services"]
  node_redis[("Redis<br/>queue infrastructure")]
  node_bright_data{{"Bright Data browser<br/>remote scraping browser"}}
  node_web_targets{{"Target websites<br/>external web"}}
  node_nvidia_nim{{"NVIDIA NIM<br/>LLM API"}}
end

node_launch["Local launcher<br/>shell script<br/>[launch.sh]"]

node_launch -->|"starts"| node_spa_entry
node_launch -->|"starts"| node_server
node_spa_entry -->|"renders"| node_app_shell
node_app_shell -->|"hosts"| node_agent_builder
node_app_shell -->|"hosts"| node_results_explorer
node_agent_builder -->|"updates"| node_client_store
node_results_explorer -->|"reads"| node_client_store
node_endpoint_config -->|"REST + WebSocket"| node_server
node_server -->|"serves"| node_auth_routes
node_server -->|"applies"| node_jwt_auth
node_jwt_auth -->|"authorizes runs"| node_queue
node_server -->|"reads and writes"| node_database
node_queue -->|"uses"| node_redis
node_queue -->|"dispatches jobs"| node_worker
node_worker -->|"executes"| node_orchestrator
node_orchestrator -->|"acquires page"| node_browser_stealth
node_browser_stealth -->|"navigates"| node_web_targets
node_browser_stealth -.->|"remote mode"| node_bright_data
node_orchestrator -->|"prompt + cleaned DOM"| node_nvidia_nim
node_orchestrator -->|"persists logs and result"| node_database
node_orchestrator -->|"live events"| node_server
node_database -->|"journals to"| node_sqlite_wal
node_backend_deploy -.->|"packages"| node_server
node_frontend_deploy -.->|"deploys"| node_spa_entry

click node_launch "https://github.com/shivtejg236/nemoforge/blob/main/scripts/launch.sh"
click node_spa_entry "https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/main.tsx"
click node_app_shell "https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/App.tsx"
click node_agent_builder "https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/pages/AgentBuilder.tsx"
click node_results_explorer "https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/pages/ResultsExplorer.tsx"
click node_client_store "https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/store/useStore.ts"
click node_endpoint_config "https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/config.ts"
click node_server "https://github.com/shivtejg236/nemoforge/blob/main/backend/src/index.ts"
click node_auth_routes "https://github.com/shivtejg236/nemoforge/blob/main/backend/src/routes/auth.ts"
click node_jwt_auth "https://github.com/shivtejg236/nemoforge/blob/main/backend/src/middleware/auth.ts"
click node_database "https://github.com/shivtejg236/nemoforge/blob/main/backend/src/db/database.ts"
click node_queue "https://github.com/shivtejg236/nemoforge/blob/main/backend/src/agent/queue.ts"
click node_worker "https://github.com/shivtejg236/nemoforge/blob/main/backend/src/agent/worker.ts"
click node_orchestrator "https://github.com/shivtejg236/nemoforge/blob/main/backend/src/agent/orchestrator.ts"
click node_browser_stealth "https://github.com/shivtejg236/nemoforge/blob/main/backend/src/agent/stealth.ts"
click node_sqlite_wal "https://github.com/shivtejg236/nemoforge/blob/main/backend/nemoforge.sqlite-wal"
click node_backend_deploy "https://github.com/shivtejg236/nemoforge/blob/main/backend/Dockerfile"
click node_frontend_deploy "https://github.com/shivtejg236/nemoforge/blob/main/frontend/vercel.json"

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_spa_entry,node_app_shell,node_agent_builder,node_results_explorer,node_client_store,node_endpoint_config,node_frontend_deploy toneBlue
class node_server,node_auth_routes,node_jwt_auth,node_database,node_sqlite_wal,node_backend_deploy toneAmber
class node_queue,node_worker,node_orchestrator,node_browser_stealth toneMint
class node_redis,node_bright_data,node_web_targets,node_nvidia_nim toneRose
class node_launch toneNeutral
```

## Components

### React frontend

- [SPA entry](https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/main.tsx): Vite React entry · `frontend/src/main.tsx`
- [Application shell](https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/App.tsx): React app · `frontend/src/App.tsx`
- [Agent Builder](https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/pages/AgentBuilder.tsx): React page · Creates browser research requests. · `frontend/src/pages/AgentBuilder.tsx`
- [Results Explorer](https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/pages/ResultsExplorer.tsx): React page · Explores stored completed results. · `frontend/src/pages/ResultsExplorer.tsx`
- [Client state](https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/store/useStore.ts): Zustand store · `frontend/src/store/useStore.ts`
- [API endpoint config](https://github.com/shivtejg236/nemoforge/blob/main/frontend/src/config.ts): frontend config · Defines REST and WebSocket endpoints. · `frontend/src/config.ts`
- [Frontend deployment](https://github.com/shivtejg236/nemoforge/blob/main/frontend/vercel.json): Vercel config · `frontend/vercel.json`

### Backend runtime

- [Express + WebSocket server](https://github.com/shivtejg236/nemoforge/blob/main/backend/src/index.ts): Node entrypoint · Serves REST APIs and broadcasts live agent events. · `backend/src/index.ts`
- [Login and token routes](https://github.com/shivtejg236/nemoforge/blob/main/backend/src/routes/auth.ts): Express routes · `backend/src/routes/auth.ts`
- [JWT protection](https://github.com/shivtejg236/nemoforge/blob/main/backend/src/middleware/auth.ts): Express middleware · Guards agent and session operations. · `backend/src/middleware/auth.ts`
- [Session and result store](https://github.com/shivtejg236/nemoforge/blob/main/backend/src/db/database.ts): SQLite access layer · Persists history, logs, and results. · `backend/src/db/database.ts`
- [SQLite WAL](https://github.com/shivtejg236/nemoforge/blob/main/backend/nemoforge.sqlite-wal): database journal · `backend/nemoforge.sqlite-wal`
- [Backend deployment](https://github.com/shivtejg236/nemoforge/blob/main/backend/Dockerfile): Docker / Render · `backend/Dockerfile`

### Agent execution

- [Run queue](https://github.com/shivtejg236/nemoforge/blob/main/backend/src/agent/queue.ts): BullMQ queue · Moves long-running work out of request handling. · `backend/src/agent/queue.ts`
- [Queue worker](https://github.com/shivtejg236/nemoforge/blob/main/backend/src/agent/worker.ts): BullMQ worker · `backend/src/agent/worker.ts`
- [Research orchestrator](https://github.com/shivtejg236/nemoforge/blob/main/backend/src/agent/orchestrator.ts): agent workflow · Coordinates acquisition, DOM cleaning, AI analysis, and lifecycle events. · `backend/src/agent/orchestrator.ts`
- [Browser acquisition](https://github.com/shivtejg236/nemoforge/blob/main/backend/src/agent/stealth.ts): Puppeteer stealth setup · Uses local Chromium or Bright Data remote browser with human-like cursor behavior. · `backend/src/agent/stealth.ts`

### Infrastructure & services

- **Redis**: queue infrastructure · BullMQ backing store implied by the worker layer.
- **Bright Data browser**: remote scraping browser · Provides remote residential anti-bot browser access.
- **Target websites**: external web
- **NVIDIA NIM**: LLM API · Produces Markdown analysis from prompt and cleaned DOM context.

### Other components

- [Local launcher](https://github.com/shivtejg236/nemoforge/blob/main/scripts/launch.sh): shell script · Starts the local frontend and backend. · `scripts/launch.sh`

## Connections

- Local launcher → SPA entry: starts
- Local launcher → Express + WebSocket server: starts
- SPA entry → Application shell: renders
- Application shell → Agent Builder: hosts
- Application shell → Results Explorer: hosts
- Agent Builder → Client state: updates
- Results Explorer → Client state: reads
- API endpoint config → Express + WebSocket server: REST + WebSocket · Sends requests and receives logs and screenshots.
- Express + WebSocket server → Login and token routes: serves
- Express + WebSocket server → JWT protection: applies
- JWT protection → Run queue: authorizes runs
- Express + WebSocket server → Session and result store: reads and writes
- Run queue → Redis: uses
- Run queue → Queue worker: dispatches jobs
- Queue worker → Research orchestrator: executes
- Research orchestrator → Browser acquisition: acquires page
- Browser acquisition → Target websites: navigates
- Browser acquisition → Bright Data browser: remote mode
- Research orchestrator → NVIDIA NIM: prompt + cleaned DOM
- Research orchestrator → Session and result store: persists logs and result
- Research orchestrator → Express + WebSocket server: live events · Emits lifecycle logs and screenshots.
- Session and result store → SQLite WAL: journals to
- Backend deployment → Express + WebSocket server: packages
- Frontend deployment → SPA entry: deploys
