# arya920/lexis architecture

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

- Interactive diagram: https://gitdiagram.com/arya920/lexis
- Repository: https://github.com/arya920/lexis

## Overview

Lexis is a Flask-backed knowledge assistant with a browser chat interface. The main workflow is a user query routed by Flask into direct LLM chat, document retrieval-augmented generation, or web search; users can also upload PDFs for indexing and manage files. A separate dataset workflow supports analysis and chart generation. The README documents these modes and session/UI capabilities. Edges follow the shown Flask calls, source-index references, or README statements; unsampled routing and storage details are not inferred.

Main entry points: [`app.py`](https://github.com/arya920/lexis/blob/main/app.py) (Flask API), [`services/ingestion.py`](https://github.com/arya920/lexis/blob/main/services/ingestion.py) (PDF ingestion), [`services/retrieval.py`](https://github.com/arya920/lexis/blob/main/services/retrieval.py) (Hybrid retrieval), [`static/app.js`](https://github.com/arya920/lexis/blob/main/static/app.js) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_frontend["Chat interface<br/>[app.js]"]
  node_html["UI entry page<br/>[index4.html]"]
end

subgraph group_backend["Request handling"]
  node_flask["Flask API<br/>[app.py]"]
end

subgraph group_knowledge["Knowledge services"]
  node_ingestion["PDF ingestion<br/>[ingestion.py]"]
  node_retrieval["Hybrid retrieval<br/>[retrieval.py]"]
  node_embeddings["Embedding models<br/>[embeddings.py]"]
  node_vectorstore[("FAISS index<br/>[ingestion.py]")]
  node_chunkstore[("Chunk store<br/>[ingestion.py]")]
  node_generation["Answer generation<br/>[generation.py]"]
  node_prompts["Prompt templates<br/>[prompts.py]"]
  node_websearch["Web search<br/>[tavily_search.py]"]
end

subgraph group_analytics["Dataset agents"]
  node_datafiles[("Dataset files<br/>[settings.py]")]
  node_analysis["Data analysis"]
  node_visualization["Visualization agent"]
  node_vizagent["Advanced chart agent"]
end

subgraph group_support["Shared services"]
  node_logging[("Query logging<br/>[query_logging.py]")]
  node_mysql["MySQL connector<br/>[db_connector.py]"]
end

node_user(("Browser user"))
node_tavily["Tavily service"]

node_user -->|"uses"| node_frontend
node_frontend -->|"mounts in"| node_html
node_frontend -->|"calls API"| node_flask
node_flask -->|"ingests PDFs"| node_ingestion
node_flask -->|"retrieves context"| node_retrieval
node_flask -->|"generates answers"| node_generation
node_flask -->|"searches web"| node_websearch
node_websearch -->|"queries"| node_tavily
node_flask -->|"runs analysis"| node_analysis
node_flask -->|"runs charts"| node_vizagent
node_flask -->|"runs visualization"| node_visualization
node_ingestion -->|"embeds chunks"| node_embeddings
node_ingestion -->|"writes index"| node_vectorstore
node_ingestion -->|"writes chunks"| node_chunkstore
node_retrieval -->|"embeds query"| node_embeddings
node_retrieval -->|"reads index"| node_vectorstore
node_retrieval -->|"reads chunks"| node_chunkstore
node_generation -->|"uses prompts"| node_prompts
node_generation -->|"records calls"| node_logging
node_analysis -->|"loads datasets"| node_datafiles
node_visualization -->|"loads datasets"| node_datafiles
node_vizagent -->|"delegates to"| node_visualization
node_analysis -->|"records calls"| node_logging
node_vizagent -->|"records calls"| node_logging
node_mysql -.->|"analytics use"| node_datafiles

click node_frontend "https://github.com/arya920/lexis/blob/main/static/app.js"
click node_html "https://github.com/arya920/lexis/blob/main/templates/index4.html"
click node_flask "https://github.com/arya920/lexis/blob/main/app.py"
click node_ingestion "https://github.com/arya920/lexis/blob/main/services/ingestion.py"
click node_retrieval "https://github.com/arya920/lexis/blob/main/services/retrieval.py"
click node_embeddings "https://github.com/arya920/lexis/blob/main/services/embeddings.py"
click node_vectorstore "https://github.com/arya920/lexis/blob/main/services/ingestion.py"
click node_chunkstore "https://github.com/arya920/lexis/blob/main/services/ingestion.py"
click node_generation "https://github.com/arya920/lexis/blob/main/services/generation.py"
click node_prompts "https://github.com/arya920/lexis/blob/main/services/prompts.py"
click node_websearch "https://github.com/arya920/lexis/blob/main/services/tavily_search.py"
click node_datafiles "https://github.com/arya920/lexis/blob/main/config/settings.py"
click node_analysis "https://github.com/arya920/lexis/blob/main/agents/data_analysis_agent.py"
click node_visualization "https://github.com/arya920/lexis/blob/main/agents/visualization_agent.py"
click node_vizagent "https://github.com/arya920/lexis/blob/main/agents/data_visualization_agent.py"
click node_logging "https://github.com/arya920/lexis/blob/main/services/query_logging.py"
click node_mysql "https://github.com/arya920/lexis/blob/main/services/db_connector.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_html,node_user toneBlue
class node_flask toneAmber
class node_ingestion,node_retrieval,node_embeddings,node_vectorstore,node_chunkstore,node_generation,node_prompts,node_websearch toneMint
class node_datafiles,node_analysis,node_visualization,node_vizagent toneRose
class node_logging,node_mysql,node_tavily toneIndigo
```

## Components

### User interface

- [Chat interface](https://github.com/arya920/lexis/blob/main/static/app.js): `static/app.js`
- [UI entry page](https://github.com/arya920/lexis/blob/main/templates/index4.html): `templates/index4.html`

### Request handling

- [Flask API](https://github.com/arya920/lexis/blob/main/app.py): `app.py`

### Knowledge services

- [PDF ingestion](https://github.com/arya920/lexis/blob/main/services/ingestion.py): `services/ingestion.py`
- [Hybrid retrieval](https://github.com/arya920/lexis/blob/main/services/retrieval.py): `services/retrieval.py`
- [Embedding models](https://github.com/arya920/lexis/blob/main/services/embeddings.py): `services/embeddings.py`
- [FAISS index](https://github.com/arya920/lexis/blob/main/services/ingestion.py): `services/ingestion.py`
- [Chunk store](https://github.com/arya920/lexis/blob/main/services/ingestion.py): `services/ingestion.py`
- [Answer generation](https://github.com/arya920/lexis/blob/main/services/generation.py): `services/generation.py`
- [Prompt templates](https://github.com/arya920/lexis/blob/main/services/prompts.py): `services/prompts.py`
- [Web search](https://github.com/arya920/lexis/blob/main/services/tavily_search.py): `services/tavily_search.py`

### Dataset agents

- [Dataset files](https://github.com/arya920/lexis/blob/main/config/settings.py): `config/settings.py`
- [Data analysis](https://github.com/arya920/lexis/blob/main/agents/data_analysis_agent.py): `agents/data_analysis_agent.py`
- [Visualization agent](https://github.com/arya920/lexis/blob/main/agents/visualization_agent.py): `agents/visualization_agent.py`
- [Advanced chart agent](https://github.com/arya920/lexis/blob/main/agents/data_visualization_agent.py): `agents/data_visualization_agent.py`

### Shared services

- [Query logging](https://github.com/arya920/lexis/blob/main/services/query_logging.py): `services/query_logging.py`
- [MySQL connector](https://github.com/arya920/lexis/blob/main/services/db_connector.py): `services/db_connector.py`

### Other components

- **Browser user**
- **Tavily service**

## Connections

- Browser user → Chat interface: uses (evidence: `README.md`)
- Chat interface → UI entry page: mounts in (evidence: `README.md`)
- Chat interface → Flask API: calls API (evidence: `README.md`)
- Flask API → PDF ingestion: ingests PDFs (evidence: `app.py`)
- Flask API → Hybrid retrieval: retrieves context (evidence: `app.py`)
- Flask API → Answer generation: generates answers (evidence: `app.py`)
- Flask API → Web search: searches web (evidence: `README.md`)
- Web search → Tavily service: queries (evidence: `services/tavily_search.py`)
- Flask API → Data analysis: runs analysis (evidence: `app.py`)
- Flask API → Advanced chart agent: runs charts (evidence: `app.py`)
- Flask API → Visualization agent: runs visualization (evidence: `agents/visualization_agent.py`)
- PDF ingestion → Embedding models: embeds chunks (evidence: `services/ingestion.py`)
- PDF ingestion → FAISS index: writes index (evidence: `services/ingestion.py`)
- PDF ingestion → Chunk store: writes chunks (evidence: `services/ingestion.py`)
- Hybrid retrieval → Embedding models: embeds query (evidence: `services/retrieval.py`)
- Hybrid retrieval → FAISS index: reads index (evidence: `README.md`)
- Hybrid retrieval → Chunk store: reads chunks (evidence: `README.md`)
- Answer generation → Prompt templates: uses prompts (evidence: `services/generation.py`)
- Answer generation → Query logging: records calls (evidence: `services/generation.py`)
- Data analysis → Dataset files: loads datasets (evidence: `README.md`)
- Visualization agent → Dataset files: loads datasets (evidence: `agents/visualization_agent.py`)
- Advanced chart agent → Visualization agent: delegates to (evidence: `agents/data_visualization_agent.py`)
- Data analysis → Query logging: records calls (evidence: `agents/data_analysis_agent.py`)
- Advanced chart agent → Query logging: records calls (evidence: `agents/data_visualization_agent.py`)
- MySQL connector → Dataset files: analytics use (evidence: `README.md`)
