# opula1234/persistent-memory-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/opula1234/persistent-memory-chatbot
- Repository: https://github.com/opula1234/persistent-memory-chatbot

## Overview

This repository is a single-file FastAPI chatbot. A client submits a session ID and prompt; the endpoint validates the prompt, loads that session’s saved messages, converts them to LangChain messages, calls Gemini, persists the new exchange, and returns the reply. SQLite table creation occurs during application startup. The main workflow and components are visible in main.py; broader deployment capabilities described in the README are not runtime components in this map.

Main entry points: [`main.py`](https://github.com/opula1234/persistent-memory-chatbot/blob/main/main.py) (Chat Endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Chat API"]
  node_endpoint["Chat Endpoint<br/>[main.py]"]
end

subgraph group_memory["Persistent Memory"]
  node_history["History Conversion<br/>[main.py]"]
  node_schema["Message Records<br/>[main.py]"]
  node_sqlite[("SQLite Store")]
  node_startup["Table Startup<br/>[main.py]"]
end

subgraph group_model["AI Response"]
  node_llm["LangChain Gemini Client<br/>[main.py]"]
  node_gemini["Gemini Model"]
end

node_client(("Chat Client"))

node_client -->|"sends request"| node_endpoint
node_endpoint -->|"reads history"| node_sqlite
node_endpoint -->|"converts records"| node_history
node_history -->|"maps records"| node_schema
node_endpoint -->|"invokes with history"| node_llm
node_llm -->|"requests response"| node_gemini
node_endpoint -->|"saves exchange"| node_sqlite
node_startup -->|"creates tables"| node_schema
node_startup -->|"initializes store"| node_sqlite
node_endpoint -->|"returns reply"| node_client

click node_endpoint "https://github.com/opula1234/persistent-memory-chatbot/blob/main/main.py"
click node_history "https://github.com/opula1234/persistent-memory-chatbot/blob/main/main.py"
click node_schema "https://github.com/opula1234/persistent-memory-chatbot/blob/main/main.py"
click node_startup "https://github.com/opula1234/persistent-memory-chatbot/blob/main/main.py"
click node_llm "https://github.com/opula1234/persistent-memory-chatbot/blob/main/main.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_endpoint,node_client toneBlue
class node_history,node_schema,node_sqlite,node_startup toneAmber
class node_llm,node_gemini toneMint
```

## Components

### Chat API

- [Chat Endpoint](https://github.com/opula1234/persistent-memory-chatbot/blob/main/main.py): `main.py`

### Persistent Memory

- [History Conversion](https://github.com/opula1234/persistent-memory-chatbot/blob/main/main.py): `main.py`
- [Message Records](https://github.com/opula1234/persistent-memory-chatbot/blob/main/main.py): `main.py`
- **SQLite Store**
- [Table Startup](https://github.com/opula1234/persistent-memory-chatbot/blob/main/main.py): `main.py`

### AI Response

- [LangChain Gemini Client](https://github.com/opula1234/persistent-memory-chatbot/blob/main/main.py): `main.py`
- **Gemini Model**

### Other components

- **Chat Client**

## Connections

- Chat Client → Chat Endpoint: sends request (evidence: `README.md`)
- Chat Endpoint → SQLite Store: reads history (evidence: `main.py`)
- Chat Endpoint → History Conversion: converts records (evidence: `main.py`)
- History Conversion → Message Records: maps records (evidence: `main.py`)
- Chat Endpoint → LangChain Gemini Client: invokes with history (evidence: `main.py`)
- LangChain Gemini Client → Gemini Model: requests response (evidence: `README.md`)
- Chat Endpoint → SQLite Store: saves exchange (evidence: `main.py`)
- Table Startup → Message Records: creates tables (evidence: `main.py`)
- Table Startup → SQLite Store: initializes store (evidence: `main.py`)
- Chat Endpoint → Chat Client: returns reply (evidence: `README.md`)
