# sathwikgampa/smart-lab-ai- architecture

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

- Interactive diagram: https://gitdiagram.com/sathwikgampa/smart-lab-ai-
- Repository: https://github.com/sathwikgampa/smart-lab-ai-

## Overview

SmartLab AI is an offline-first laboratory knowledge and operations assistant. Researchers ask questions or upload documents and images; the interface sends requests to Flask, which retrieves cited SOP evidence or routes work to laboratory services. The product also supports inventory, experiments and review, datasets, collaboration, literature, safety, troubleshooting, simulation, and training. The graph includes documented capabilities whose implementation was not sampled; those links are dashed where source-level wiring was not shown.

Main entry points: [`backend/app/rag/engine.py`](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/rag/engine.py) (RAG and citations), [`frontend/src/lib/api.js`](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/frontend/src/lib/api.js) (REST client), [`backend/app/services`](https://github.com/sathwikgampa/smart-lab-ai-/tree/main/backend/app/services) (Domain services), [`backend/app/vision/analyzer.py`](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/vision/analyzer.py) (Image analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Researcher interface"]
  node_app["Application shell<br/>[App.jsx]"]
  node_ask["Ask SmartLab<br/>[AskView.jsx]"]
  node_documents_ui["Document library<br/>[DocumentsView.jsx]"]
  node_evidence_ui["Evidence panel<br/>[EvidencePanel.jsx]"]
  node_api_client["REST client<br/>[api.js]"]
  node_operations_ui["Lab workspace views"]
end

subgraph group_knowledge["Knowledge and evidence"]
  node_rag["RAG and citations<br/>[engine.py]"]
  node_pdf["PDF extraction<br/>[pdf_extractor.py]"]
  node_embeddings["Text embeddings<br/>[embeddings.py]"]
  node_vector_store[("Vector index<br/>[vector_store.py]")]
  node_guardrails["Safety guardrails<br/>[guardrails.py]"]
  node_vision["Image analysis<br/>[analyzer.py]"]
  node_llm["Optional Claude<br/>[llm.py]"]
end

subgraph group_operations["Lab operations"]
  node_inventory["Reagent inventory<br/>[inventory.py]"]
  node_troubleshooting["Verified troubleshooting<br/>[troubleshooting.py]"]
  node_other_services["Domain services"]
end

subgraph group_platform["API and persistence"]
  node_rag_api["Chat and documents API<br/>[chat.py]"]
  node_documents_api["Document governance API<br/>[documents.py]"]
  node_search_api["Unified search API<br/>[search.py]"]
  node_other_apis["Operations APIs"]
  node_database[("SQLite records<br/>[db.py]")]
end

node_researcher(("Researcher"))

node_researcher -->|"uses"| node_app
node_app -->|"routes to"| node_ask
node_ask -->|"requests answers"| node_api_client
node_documents_ui -->|"manages documents"| node_api_client
node_ask -->|"opens citations"| node_evidence_ui
node_api_client -.->|"calls chat"| node_rag_api
node_api_client -.->|"uploads and queries"| node_documents_api
node_rag_api -.->|"retrieves answers"| node_rag
node_documents_api -.->|"indexes documents"| node_rag
node_rag -->|"extracts pages"| node_pdf
node_rag -->|"embeds text"| node_embeddings
node_rag -.->|"searches index"| node_vector_store
node_rag -->|"synthesizes answers"| node_llm
node_rag -->|"screens queries"| node_guardrails
node_vision -->|"sanitizes output"| node_guardrails
node_vision -->|"retrieves SOPs"| node_rag
node_vision -->|"describes images"| node_llm
node_researcher -->|"uses workspace"| node_operations_ui
node_operations_ui -.->|"sends operations requests"| node_api_client
node_api_client -.->|"calls domain APIs"| node_other_apis
node_other_apis -.->|"dispatches operations"| node_other_services
node_search_api -->|"retrieves documents"| node_rag
node_search_api -->|"searches reagents"| node_inventory
node_search_api -->|"matches fixes"| node_troubleshooting
node_other_services -.->|"includes inventory"| node_inventory
node_other_services -.->|"includes fixes"| node_troubleshooting
node_rag -.->|"reads document chunks"| node_database
node_inventory -.->|"reads and writes stock"| node_database
node_other_services -.->|"persists workspace data"| node_database

click node_app "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/frontend/src/App.jsx"
click node_ask "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/frontend/src/views/AskView.jsx"
click node_documents_ui "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/frontend/src/views/DocumentsView.jsx"
click node_evidence_ui "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/frontend/src/components/EvidencePanel.jsx"
click node_api_client "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/frontend/src/lib/api.js"
click node_rag_api "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/api/chat.py"
click node_documents_api "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/api/documents.py"
click node_rag "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/rag/engine.py"
click node_pdf "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/rag/pdf_extractor.py"
click node_embeddings "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/rag/embeddings.py"
click node_vector_store "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/rag/vector_store.py"
click node_guardrails "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/guardrails.py"
click node_vision "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/vision/analyzer.py"
click node_llm "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/services/llm.py"
click node_operations_ui "https://github.com/sathwikgampa/smart-lab-ai-/tree/main/frontend/src/views"
click node_search_api "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/api/search.py"
click node_inventory "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/services/inventory.py"
click node_troubleshooting "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/services/troubleshooting.py"
click node_other_services "https://github.com/sathwikgampa/smart-lab-ai-/tree/main/backend/app/services"
click node_other_apis "https://github.com/sathwikgampa/smart-lab-ai-/tree/main/backend/app/api"
click node_database "https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/db.py"

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_ask,node_documents_ui,node_evidence_ui,node_api_client,node_operations_ui toneBlue
class node_rag,node_pdf,node_embeddings,node_vector_store,node_guardrails,node_vision,node_llm toneAmber
class node_inventory,node_troubleshooting,node_other_services toneMint
class node_rag_api,node_documents_api,node_search_api,node_other_apis,node_database toneRose
class node_researcher toneIndigo
```

## Components

### Researcher interface

- [Application shell](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Ask SmartLab](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/frontend/src/views/AskView.jsx): `frontend/src/views/AskView.jsx`
- [Document library](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/frontend/src/views/DocumentsView.jsx): `frontend/src/views/DocumentsView.jsx`
- [Evidence panel](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/frontend/src/components/EvidencePanel.jsx): `frontend/src/components/EvidencePanel.jsx`
- [REST client](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/frontend/src/lib/api.js): `frontend/src/lib/api.js`
- [Lab workspace views](https://github.com/sathwikgampa/smart-lab-ai-/tree/main/frontend/src/views): `frontend/src/views`

### Knowledge and evidence

- [RAG and citations](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/rag/engine.py): `backend/app/rag/engine.py`
- [PDF extraction](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/rag/pdf_extractor.py): `backend/app/rag/pdf_extractor.py`
- [Text embeddings](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/rag/embeddings.py): `backend/app/rag/embeddings.py`
- [Vector index](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/rag/vector_store.py): `backend/app/rag/vector_store.py`
- [Safety guardrails](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/guardrails.py): `backend/app/guardrails.py`
- [Image analysis](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/vision/analyzer.py): `backend/app/vision/analyzer.py`
- [Optional Claude](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/services/llm.py): `backend/app/services/llm.py`

### Lab operations

- [Reagent inventory](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/services/inventory.py): `backend/app/services/inventory.py`
- [Verified troubleshooting](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/services/troubleshooting.py): `backend/app/services/troubleshooting.py`
- [Domain services](https://github.com/sathwikgampa/smart-lab-ai-/tree/main/backend/app/services): `backend/app/services`

### API and persistence

- [Chat and documents API](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/api/chat.py): `backend/app/api/chat.py`
- [Document governance API](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/api/documents.py): `backend/app/api/documents.py`
- [Unified search API](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/api/search.py): `backend/app/api/search.py`
- [Operations APIs](https://github.com/sathwikgampa/smart-lab-ai-/tree/main/backend/app/api): `backend/app/api`
- [SQLite records](https://github.com/sathwikgampa/smart-lab-ai-/blob/main/backend/app/db.py): `backend/app/db.py`

### Other components

- **Researcher**

## Connections

- Researcher → Application shell: uses (evidence: `README.md`)
- Application shell → Ask SmartLab: routes to (evidence: `frontend/src/App.jsx`)
- Ask SmartLab → REST client: requests answers (evidence: `frontend/src/views/AskView.jsx`)
- Document library → REST client: manages documents (evidence: `frontend/src/views/DocumentsView.jsx`)
- Ask SmartLab → Evidence panel: opens citations (evidence: `frontend/src/App.jsx`)
- REST client → Chat and documents API: calls chat
- REST client → Document governance API: uploads and queries
- Chat and documents API → RAG and citations: retrieves answers
- Document governance API → RAG and citations: indexes documents
- RAG and citations → PDF extraction: extracts pages (evidence: `backend/app/rag/engine.py`)
- RAG and citations → Text embeddings: embeds text (evidence: `backend/app/rag/engine.py`)
- RAG and citations → Vector index: searches index
- RAG and citations → Optional Claude: synthesizes answers (evidence: `backend/app/rag/engine.py`)
- RAG and citations → Safety guardrails: screens queries (evidence: `backend/app/rag/engine.py`)
- Image analysis → Safety guardrails: sanitizes output (evidence: `backend/app/vision/analyzer.py`)
- Image analysis → RAG and citations: retrieves SOPs (evidence: `backend/app/vision/analyzer.py`)
- Image analysis → Optional Claude: describes images (evidence: `backend/app/vision/analyzer.py`)
- Researcher → Lab workspace views: uses workspace (evidence: `README.md`)
- Lab workspace views → REST client: sends operations requests (evidence: `frontend/src/views/LiteratureView.jsx`)
- REST client → Operations APIs: calls domain APIs
- Operations APIs → Domain services: dispatches operations (evidence: `backend/app/api/search.py`)
- Unified search API → RAG and citations: retrieves documents (evidence: `backend/app/api/search.py`)
- Unified search API → Reagent inventory: searches reagents (evidence: `backend/app/api/search.py`)
- Unified search API → Verified troubleshooting: matches fixes (evidence: `backend/app/api/search.py`)
- Domain services → Reagent inventory: includes inventory
- Domain services → Verified troubleshooting: includes fixes
- RAG and citations → SQLite records: reads document chunks
- Reagent inventory → SQLite records: reads and writes stock (evidence: `backend/app/services/inventory.py`)
- Domain services → SQLite records: persists workspace data (evidence: `backend/app/services/inventory.py`)
