# relmarrakchy/llm-lab architecture

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

- Interactive diagram: https://gitdiagram.com/relmarrakchy/llm-lab
- Repository: https://github.com/relmarrakchy/llm-lab

## Overview

LLM Lab is a browser-based environment for testing a LangChain agent: a user submits a chat message, the frontend records request details and sends the query to the NestJS API, which invokes the configured Ollama-backed agent and returns a reply. The frontend displays the conversation and an in-memory request log with status and latency summaries. The README documents the Ollama integration and prompt/model configuration; unsampled files are represented only where the tree or documentation supports their role.

Main entry points: [`frontend/app/page.tsx`](https://github.com/relmarrakchy/llm-lab/blob/master/frontend/app/page.tsx) (Chat App State), [`backend/src/agents/agents.controller.ts`](https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/agents.controller.ts) (Chat Endpoint), [`backend/src/agents/blueprint/agent.ts`](https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/blueprint/agent.ts) (LangChain Agent), [`backend/src/agents/agents.module.ts`](https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/agents.module.ts) (Agents Module)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Chat Interface"]
  node_home["Chat App State<br/>[page.tsx]"]
  node_chat["Chat Composer<br/>[ChatSection.tsx]"]
  node_message["Message Display<br/>[MessageBubble.tsx]"]
  node_logs["Log Summary<br/>[LogsSection.tsx]"]
  node_logentry["Log Details<br/>[LogEntry.tsx]"]
end

subgraph group_api["Backend API"]
  node_controller["Chat Endpoint"]
  node_dto["Chat Request DTO<br/>[chat-agent.dto.ts]"]
  node_service["Agent Service<br/>[agents.service.ts]"]
  node_appmodule["Root Module<br/>[app.module.ts]"]
  node_agentsmodule["Agents Module<br/>[agents.module.ts]"]
end

subgraph group_agent["Agent Inference"]
  node_agent["LangChain Agent<br/>[agent.ts]"]
  node_config["Model Selection<br/>[config.ts]"]
  node_prompt["System Prompt<br/>[system.md]"]
end

node_user(("User"))
node_ollama["Ollama Model"]

node_user -->|"submits query"| node_chat
node_home -->|"renders"| node_chat
node_home -->|"renders logs"| node_logs
node_chat -->|"sends input"| node_home
node_home -->|"posts query"| node_controller
node_controller -->|"accepts body"| node_dto
node_controller -->|"invokes"| node_service
node_service -->|"invokes"| node_agent
node_agent -->|"uses model"| node_config
node_agent -->|"loads prompt"| node_prompt
node_agent -->|"runs inference"| node_ollama
node_appmodule -->|"imports"| node_agentsmodule
node_agentsmodule -->|"registers"| node_controller
node_agentsmodule -->|"provides"| node_service
node_home -->|"displays replies"| node_message
node_logs -->|"renders entries"| node_logentry
node_controller -->|"returns response"| node_home
node_home -->|"records status and latency"| node_logs

click node_home "https://github.com/relmarrakchy/llm-lab/blob/master/frontend/app/page.tsx"
click node_chat "https://github.com/relmarrakchy/llm-lab/blob/master/frontend/app/components/ChatSection.tsx"
click node_message "https://github.com/relmarrakchy/llm-lab/blob/master/frontend/app/components/MessageBubble.tsx"
click node_logs "https://github.com/relmarrakchy/llm-lab/blob/master/frontend/app/components/LogsSection.tsx"
click node_logentry "https://github.com/relmarrakchy/llm-lab/blob/master/frontend/app/components/LogEntry.tsx"
click node_controller "https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/agents.controller.ts"
click node_dto "https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/dto/chat-agent.dto.ts"
click node_service "https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/agents.service.ts"
click node_appmodule "https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/app.module.ts"
click node_agentsmodule "https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/agents.module.ts"
click node_agent "https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/blueprint/agent.ts"
click node_config "https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/blueprint/config.ts"
click node_prompt "https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/blueprint/prompts/system.md"

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_home,node_chat,node_message,node_logs,node_logentry,node_user toneBlue
class node_controller,node_dto,node_service,node_appmodule,node_agentsmodule toneAmber
class node_agent,node_config,node_prompt toneMint
class node_ollama toneIndigo
```

## Components

### Chat Interface

- [Chat App State](https://github.com/relmarrakchy/llm-lab/blob/master/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Chat Composer](https://github.com/relmarrakchy/llm-lab/blob/master/frontend/app/components/ChatSection.tsx): `frontend/app/components/ChatSection.tsx`
- [Message Display](https://github.com/relmarrakchy/llm-lab/blob/master/frontend/app/components/MessageBubble.tsx): `frontend/app/components/MessageBubble.tsx`
- [Log Summary](https://github.com/relmarrakchy/llm-lab/blob/master/frontend/app/components/LogsSection.tsx): `frontend/app/components/LogsSection.tsx`
- [Log Details](https://github.com/relmarrakchy/llm-lab/blob/master/frontend/app/components/LogEntry.tsx): `frontend/app/components/LogEntry.tsx`

### Backend API

- [Chat Endpoint](https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/agents.controller.ts): `backend/src/agents/agents.controller.ts`
- [Chat Request DTO](https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/dto/chat-agent.dto.ts): `backend/src/agents/dto/chat-agent.dto.ts`
- [Agent Service](https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/agents.service.ts): `backend/src/agents/agents.service.ts`
- [Root Module](https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/app.module.ts): `backend/src/app.module.ts`
- [Agents Module](https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/agents.module.ts): `backend/src/agents/agents.module.ts`

### Agent Inference

- [LangChain Agent](https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/blueprint/agent.ts): `backend/src/agents/blueprint/agent.ts`
- [Model Selection](https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/blueprint/config.ts): `backend/src/agents/blueprint/config.ts`
- [System Prompt](https://github.com/relmarrakchy/llm-lab/blob/master/backend/src/agents/blueprint/prompts/system.md): `backend/src/agents/blueprint/prompts/system.md`

### Other components

- **User**
- **Ollama Model**

## Connections

- User → Chat Composer: submits query (evidence: `README.md`)
- Chat App State → Chat Composer: renders (evidence: `frontend/app/page.tsx`)
- Chat App State → Log Summary: renders logs (evidence: `frontend/app/page.tsx`)
- Chat Composer → Chat App State: sends input (evidence: `frontend/app/page.tsx`)
- Chat App State → Chat Endpoint: posts query (evidence: `frontend/app/page.tsx`)
- Chat Endpoint → Chat Request DTO: accepts body (evidence: `backend/src/agents/agents.controller.ts`)
- Chat Endpoint → Agent Service: invokes (evidence: `backend/src/agents/agents.controller.ts`)
- Agent Service → LangChain Agent: invokes (evidence: `backend/src/agents/agents.service.ts`)
- LangChain Agent → Model Selection: uses model (evidence: `backend/src/agents/blueprint/agent.ts`)
- LangChain Agent → System Prompt: loads prompt (evidence: `backend/src/agents/blueprint/agent.ts`)
- LangChain Agent → Ollama Model: runs inference (evidence: `README.md`)
- Root Module → Agents Module: imports (evidence: `backend/src/app.module.ts`)
- Agents Module → Chat Endpoint: registers (evidence: `backend/src/agents/agents.module.ts`)
- Agents Module → Agent Service: provides (evidence: `backend/src/agents/agents.module.ts`)
- Chat App State → Message Display: displays replies
- Log Summary → Log Details: renders entries (evidence: `frontend/app/components/LogsSection.tsx`)
- Chat Endpoint → Chat App State: returns response (evidence: `README.md`)
- Chat App State → Log Summary: records status and latency (evidence: `frontend/app/page.tsx`)
