# munu-784/sop-agent architecture

> Architecture diagram of the GitHub repository munu-784/sop-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/munu-784/sop-agent
- Repository: https://github.com/munu-784/sop-agent

## Overview

SOP-Agent is a web application for user/admin access to SOPs, with a backend query endpoint and a separately represented AI/RAG subsystem. The visible workflow covers login, admin PDF upload and SOP management, and authenticated queries; the query handler currently returns a count-based placeholder and logs it. The README provides no capability detail, and the sampled query path does not invoke the AI services, so no connection to them is asserted.

Main entry points: [`frontend/src/App.jsx`](https://github.com/munu-784/sop-agent/blob/main/frontend/src/App.jsx) (Route application), [`backend/server.js`](https://github.com/munu-784/sop-agent/blob/main/backend/server.js) (HTTP server), [`backend/routes/sopRoutes.js`](https://github.com/munu-784/sop-agent/blob/main/backend/routes/sopRoutes.js) (SOP routes), [`backend/routes/queryRoutes.js`](https://github.com/munu-784/sop-agent/blob/main/backend/routes/queryRoutes.js) (Query routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_app["Route application<br/>[App.jsx]"]
  node_auth_ui["Login and signup"]
  node_admin_ui["Admin panel<br/>[AdminPanel.jsx]"]
  node_dashboard["SOP dashboard<br/>[Dashboard.jsx]"]
  node_upload_ui["SOP upload page<br/>[UploadSOP.jsx]"]
end

subgraph group_api["Backend API"]
  node_server["HTTP server<br/>[server.js]"]
  node_auth_routes["Auth routes<br/>[authRoutes.js]"]
  node_auth_controller["Auth controller<br/>[authController.js]"]
  node_auth_middleware["Access middleware<br/>[authMiddleware.js]"]
  node_sop_routes["SOP routes<br/>[sopRoutes.js]"]
  node_sop_controller["SOP controller<br/>[sopController.js]"]
  node_query_routes["Query routes<br/>[queryRoutes.js]"]
  node_query_controller["Query handler<br/>[queryController.js]"]
  node_pdf_upload["PDF upload filter<br/>[upload.js]"]
end

subgraph group_data["Application data"]
  node_db_config["Database connection<br/>[db.js]"]
  node_user_model[("User records<br/>[User.js]")]
  node_sop_model[("SOP records<br/>[SOP.js]")]
  node_log_model[("Query logs<br/>[Log.js]")]
  node_chat_model[("Chat records<br/>[Chat.js]")]
  node_embedding_model[("Embedding records<br/>[Embedding.js]")]
end

subgraph group_ai["AI pipeline"]
  node_embedding["Embedding generation<br/>[embedding.py]"]
  node_rag_pipeline["RAG pipeline<br/>[rag_pipeline.py]"]
  node_vector_index["Vector index<br/>[vector_index.py]"]
  node_embedding_service["Embedding service"]
  node_rag_service["RAG service<br/>[ragService.js]"]
  node_search_service["Vector search"]
  node_llm_service["Language model<br/>[llmService.js]"]
end

node_visitor(("User or admin"))

node_visitor -->|"opens"| node_app
node_app -->|"routes to"| node_auth_ui
node_app -->|"routes to"| node_admin_ui
node_app -->|"routes to"| node_dashboard
node_app -->|"routes to"| node_upload_ui
node_server -->|"connects"| node_db_config
node_server -->|"mounts"| node_auth_routes
node_server -->|"mounts"| node_sop_routes
node_server -->|"mounts"| node_query_routes
node_auth_routes -->|"dispatches to"| node_auth_controller
node_auth_controller -->|"reads and creates"| node_user_model
node_sop_routes -->|"protects routes"| node_auth_middleware
node_sop_routes -->|"accepts PDF"| node_pdf_upload
node_sop_routes -->|"dispatches to"| node_sop_controller
node_sop_controller -->|"reads and writes"| node_sop_model
node_query_routes -->|"protects route"| node_auth_middleware
node_query_routes -->|"dispatches to"| node_query_controller
node_query_controller -->|"reads"| node_sop_model
node_query_controller -->|"writes"| node_log_model
node_auth_middleware -->|"loads user"| node_user_model

click node_app "https://github.com/munu-784/sop-agent/blob/main/frontend/src/App.jsx"
click node_auth_ui "https://github.com/munu-784/sop-agent/tree/main/frontend/src/pages"
click node_admin_ui "https://github.com/munu-784/sop-agent/blob/main/frontend/src/pages/AdminPanel.jsx"
click node_dashboard "https://github.com/munu-784/sop-agent/blob/main/frontend/src/pages/Dashboard.jsx"
click node_upload_ui "https://github.com/munu-784/sop-agent/blob/main/frontend/src/pages/UploadSOP.jsx"
click node_server "https://github.com/munu-784/sop-agent/blob/main/backend/server.js"
click node_auth_routes "https://github.com/munu-784/sop-agent/blob/main/backend/routes/authRoutes.js"
click node_auth_controller "https://github.com/munu-784/sop-agent/blob/main/backend/controllers/authController.js"
click node_auth_middleware "https://github.com/munu-784/sop-agent/blob/main/backend/middleware/authMiddleware.js"
click node_sop_routes "https://github.com/munu-784/sop-agent/blob/main/backend/routes/sopRoutes.js"
click node_sop_controller "https://github.com/munu-784/sop-agent/blob/main/backend/controllers/sopController.js"
click node_query_routes "https://github.com/munu-784/sop-agent/blob/main/backend/routes/queryRoutes.js"
click node_query_controller "https://github.com/munu-784/sop-agent/blob/main/backend/controllers/queryController.js"
click node_pdf_upload "https://github.com/munu-784/sop-agent/blob/main/backend/utils/upload.js"
click node_db_config "https://github.com/munu-784/sop-agent/blob/main/backend/config/db.js"
click node_user_model "https://github.com/munu-784/sop-agent/blob/main/backend/models/User.js"
click node_sop_model "https://github.com/munu-784/sop-agent/blob/main/backend/models/SOP.js"
click node_log_model "https://github.com/munu-784/sop-agent/blob/main/backend/models/Log.js"
click node_chat_model "https://github.com/munu-784/sop-agent/blob/main/backend/models/Chat.js"
click node_embedding_model "https://github.com/munu-784/sop-agent/blob/main/backend/models/Embedding.js"
click node_embedding "https://github.com/munu-784/sop-agent/blob/main/ai-pipeline/embedding.py"
click node_rag_pipeline "https://github.com/munu-784/sop-agent/blob/main/ai-pipeline/rag_pipeline.py"
click node_vector_index "https://github.com/munu-784/sop-agent/blob/main/ai-pipeline/vector_index.py"
click node_embedding_service "https://github.com/munu-784/sop-agent/blob/main/backend/services/embeddingService.js"
click node_rag_service "https://github.com/munu-784/sop-agent/blob/main/backend/services/ragService.js"
click node_search_service "https://github.com/munu-784/sop-agent/blob/main/backend/services/vectorSearchService.js"
click node_llm_service "https://github.com/munu-784/sop-agent/blob/main/backend/services/llmService.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_auth_ui,node_admin_ui,node_dashboard,node_upload_ui,node_visitor toneBlue
class node_server,node_auth_routes,node_auth_controller,node_auth_middleware,node_sop_routes,node_sop_controller,node_query_routes,node_query_controller,node_pdf_upload toneAmber
class node_db_config,node_user_model,node_sop_model,node_log_model,node_chat_model,node_embedding_model toneMint
class node_embedding,node_rag_pipeline,node_vector_index,node_embedding_service,node_rag_service,node_search_service,node_llm_service toneRose
```

## Components

### Web interface

- [Route application](https://github.com/munu-784/sop-agent/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Login and signup](https://github.com/munu-784/sop-agent/tree/main/frontend/src/pages): `frontend/src/pages`
- [Admin panel](https://github.com/munu-784/sop-agent/blob/main/frontend/src/pages/AdminPanel.jsx): `frontend/src/pages/AdminPanel.jsx`
- [SOP dashboard](https://github.com/munu-784/sop-agent/blob/main/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [SOP upload page](https://github.com/munu-784/sop-agent/blob/main/frontend/src/pages/UploadSOP.jsx): `frontend/src/pages/UploadSOP.jsx`

### Backend API

- [HTTP server](https://github.com/munu-784/sop-agent/blob/main/backend/server.js): `backend/server.js`
- [Auth routes](https://github.com/munu-784/sop-agent/blob/main/backend/routes/authRoutes.js): `backend/routes/authRoutes.js`
- [Auth controller](https://github.com/munu-784/sop-agent/blob/main/backend/controllers/authController.js): `backend/controllers/authController.js`
- [Access middleware](https://github.com/munu-784/sop-agent/blob/main/backend/middleware/authMiddleware.js): `backend/middleware/authMiddleware.js`
- [SOP routes](https://github.com/munu-784/sop-agent/blob/main/backend/routes/sopRoutes.js): `backend/routes/sopRoutes.js`
- [SOP controller](https://github.com/munu-784/sop-agent/blob/main/backend/controllers/sopController.js): `backend/controllers/sopController.js`
- [Query routes](https://github.com/munu-784/sop-agent/blob/main/backend/routes/queryRoutes.js): `backend/routes/queryRoutes.js`
- [Query handler](https://github.com/munu-784/sop-agent/blob/main/backend/controllers/queryController.js): `backend/controllers/queryController.js`
- [PDF upload filter](https://github.com/munu-784/sop-agent/blob/main/backend/utils/upload.js): `backend/utils/upload.js`

### Application data

- [Database connection](https://github.com/munu-784/sop-agent/blob/main/backend/config/db.js): `backend/config/db.js`
- [User records](https://github.com/munu-784/sop-agent/blob/main/backend/models/User.js): `backend/models/User.js`
- [SOP records](https://github.com/munu-784/sop-agent/blob/main/backend/models/SOP.js): `backend/models/SOP.js`
- [Query logs](https://github.com/munu-784/sop-agent/blob/main/backend/models/Log.js): `backend/models/Log.js`
- [Chat records](https://github.com/munu-784/sop-agent/blob/main/backend/models/Chat.js): `backend/models/Chat.js`
- [Embedding records](https://github.com/munu-784/sop-agent/blob/main/backend/models/Embedding.js): `backend/models/Embedding.js`

### AI pipeline

- [Embedding generation](https://github.com/munu-784/sop-agent/blob/main/ai-pipeline/embedding.py): `ai-pipeline/embedding.py`
- [RAG pipeline](https://github.com/munu-784/sop-agent/blob/main/ai-pipeline/rag_pipeline.py): `ai-pipeline/rag_pipeline.py`
- [Vector index](https://github.com/munu-784/sop-agent/blob/main/ai-pipeline/vector_index.py): `ai-pipeline/vector_index.py`
- [Embedding service](https://github.com/munu-784/sop-agent/blob/main/backend/services/embeddingService.js): `backend/services/embeddingService.js`
- [RAG service](https://github.com/munu-784/sop-agent/blob/main/backend/services/ragService.js): `backend/services/ragService.js`
- [Vector search](https://github.com/munu-784/sop-agent/blob/main/backend/services/vectorSearchService.js): `backend/services/vectorSearchService.js`
- [Language model](https://github.com/munu-784/sop-agent/blob/main/backend/services/llmService.js): `backend/services/llmService.js`

### Other components

- **User or admin**

## Connections

- User or admin → Route application: opens (evidence: `frontend/src/App.jsx`)
- Route application → Login and signup: routes to (evidence: `frontend/src/App.jsx`)
- Route application → Admin panel: routes to (evidence: `frontend/src/App.jsx`)
- Route application → SOP dashboard: routes to (evidence: `frontend/src/App.jsx`)
- Route application → SOP upload page: routes to (evidence: `frontend/src/App.jsx`)
- HTTP server → Database connection: connects (evidence: `backend/server.js`)
- HTTP server → Auth routes: mounts (evidence: `backend/server.js`)
- HTTP server → SOP routes: mounts (evidence: `backend/server.js`)
- HTTP server → Query routes: mounts (evidence: `backend/server.js`)
- Auth routes → Auth controller: dispatches to (evidence: `backend/routes/authRoutes.js`)
- Auth controller → User records: reads and creates (evidence: `backend/controllers/authController.js`)
- SOP routes → Access middleware: protects routes (evidence: `backend/routes/sopRoutes.js`)
- SOP routes → PDF upload filter: accepts PDF (evidence: `backend/routes/sopRoutes.js`)
- SOP routes → SOP controller: dispatches to (evidence: `backend/routes/sopRoutes.js`)
- SOP controller → SOP records: reads and writes (evidence: `backend/controllers/sopController.js`)
- Query routes → Access middleware: protects route (evidence: `backend/routes/queryRoutes.js`)
- Query routes → Query handler: dispatches to (evidence: `backend/routes/queryRoutes.js`)
- Query handler → SOP records: reads (evidence: `backend/controllers/queryController.js`)
- Query handler → Query logs: writes (evidence: `backend/controllers/queryController.js`)
- Access middleware → User records: loads user (evidence: `backend/middleware/authMiddleware.js`)
