# dwivedi1823/prodapi architecture

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

- Interactive diagram: https://gitdiagram.com/dwivedi1823/prodapi
- Repository: https://github.com/dwivedi1823/prodapi

## Overview

This repository is a web-based LLM chat assistant. Its main workflow runs from browser chat submission through API validation, input security checks, cache lookup, agent/model invocation on a miss, output checks, and response delivery; the API also records request metrics. A separate document-loading utility reads local text/PDF files and web pages, but the sampled code does not connect it to chat or retrieval. The README contains no readable capability details, so this map follows the source and tree; unsampled endpoint behavior is shown only where directly evident.

Main entry points: [`app/main.py`](https://github.com/dwivedi1823/prodapi/blob/main/app/main.py) (FastAPI app), [`app/agent.py`](https://github.com/dwivedi1823/prodapi/blob/main/app/agent.py) (LangGraph agent), [`document_loaders.py`](https://github.com/dwivedi1823/prodapi/blob/main/document_loaders.py) (Document loader), [`frontend/app.js`](https://github.com/dwivedi1823/prodapi/blob/main/frontend/app.js) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat client"]
  node_frontend["Chat interface<br/>[app.js]"]
  node_page["Chat page<br/>[index.html]"]
end

subgraph group_api["API workflow"]
  node_api_app["FastAPI app<br/>[main.py]"]
  node_schemas["Request models<br/>[models.py]"]
end

subgraph group_runtime["Assistant runtime"]
  node_security["Security pipeline<br/>[security.py]"]
  node_cache["Response cache<br/>[cache.py]"]
  node_agent["LangGraph agent<br/>[agent.py]"]
  node_config["Settings<br/>[config.py]"]
end

subgraph group_operations["Operations"]
  node_metrics["Metrics collector<br/>[monitoring.py]"]
end

subgraph group_ingestion["Document loading"]
  node_local_docs["Local documents"]
  node_loader["Document loader"]
end

node_user(("Chat user"))
node_primary_model["Primary model"]
node_fallback_model["Fallback model"]
node_web_docs["Web documents"]

node_user -->|"uses"| node_frontend
node_frontend -->|"posts chat"| node_api_app
node_api_app -->|"serves page"| node_page
node_api_app -->|"validates payload"| node_schemas
node_api_app -->|"checks input"| node_security
node_api_app -->|"looks up"| node_cache
node_api_app -->|"invokes on miss"| node_agent
node_agent -->|"invokes"| node_primary_model
node_agent -->|"falls back to"| node_fallback_model
node_api_app -->|"validates output"| node_security
node_api_app -->|"stores response"| node_cache
node_api_app -->|"records requests"| node_metrics
node_api_app -->|"loads settings"| node_config
node_agent -->|"loads settings"| node_config
node_loader -->|"reads"| node_local_docs
node_loader -->|"loads pages"| node_web_docs

click node_frontend "https://github.com/dwivedi1823/prodapi/blob/main/frontend/app.js"
click node_page "https://github.com/dwivedi1823/prodapi/blob/main/frontend/index.html"
click node_api_app "https://github.com/dwivedi1823/prodapi/blob/main/app/main.py"
click node_schemas "https://github.com/dwivedi1823/prodapi/blob/main/app/models.py"
click node_security "https://github.com/dwivedi1823/prodapi/blob/main/app/security.py"
click node_cache "https://github.com/dwivedi1823/prodapi/blob/main/app/cache.py"
click node_agent "https://github.com/dwivedi1823/prodapi/blob/main/app/agent.py"
click node_config "https://github.com/dwivedi1823/prodapi/blob/main/app/config.py"
click node_metrics "https://github.com/dwivedi1823/prodapi/blob/main/app/monitoring.py"
click node_local_docs "https://github.com/dwivedi1823/prodapi/tree/main/data"
click node_loader "https://github.com/dwivedi1823/prodapi/blob/main/document_loaders.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_frontend,node_page,node_user toneBlue
class node_api_app,node_schemas toneAmber
class node_security,node_cache,node_agent,node_config toneMint
class node_metrics toneRose
class node_local_docs,node_loader,node_primary_model,node_fallback_model,node_web_docs toneIndigo
```

## Components

### Chat client

- [Chat interface](https://github.com/dwivedi1823/prodapi/blob/main/frontend/app.js): `frontend/app.js`
- [Chat page](https://github.com/dwivedi1823/prodapi/blob/main/frontend/index.html): `frontend/index.html`

### API workflow

- [FastAPI app](https://github.com/dwivedi1823/prodapi/blob/main/app/main.py): `app/main.py`
- [Request models](https://github.com/dwivedi1823/prodapi/blob/main/app/models.py): `app/models.py`

### Assistant runtime

- [Security pipeline](https://github.com/dwivedi1823/prodapi/blob/main/app/security.py): `app/security.py`
- [Response cache](https://github.com/dwivedi1823/prodapi/blob/main/app/cache.py): `app/cache.py`
- [LangGraph agent](https://github.com/dwivedi1823/prodapi/blob/main/app/agent.py): `app/agent.py`
- [Settings](https://github.com/dwivedi1823/prodapi/blob/main/app/config.py): `app/config.py`

### Operations

- [Metrics collector](https://github.com/dwivedi1823/prodapi/blob/main/app/monitoring.py): `app/monitoring.py`

### Document loading

- [Local documents](https://github.com/dwivedi1823/prodapi/tree/main/data): `data`
- [Document loader](https://github.com/dwivedi1823/prodapi/blob/main/document_loaders.py): `document_loaders.py`

### Other components

- **Chat user**
- **Primary model**
- **Fallback model**
- **Web documents**

## Connections

- Chat user → Chat interface: uses
- Chat interface → FastAPI app: posts chat
- FastAPI app → Chat page: serves page
- FastAPI app → Request models: validates payload
- FastAPI app → Security pipeline: checks input
- FastAPI app → Response cache: looks up
- FastAPI app → LangGraph agent: invokes on miss
- LangGraph agent → Primary model: invokes
- LangGraph agent → Fallback model: falls back to
- FastAPI app → Security pipeline: validates output
- FastAPI app → Response cache: stores response
- FastAPI app → Metrics collector: records requests
- FastAPI app → Settings: loads settings
- LangGraph agent → Settings: loads settings
- Document loader → Local documents: reads
- Document loader → Web documents: loads pages
