# divyanshsingh575/chat_assistant architecture

> Architecture diagram of the GitHub repository divyanshsingh575/chat_assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/divyanshsingh575/chat_assistant
- Repository: https://github.com/divyanshsingh575/chat_assistant

## Overview

##### Project Type and Purpose
- This is a lightweight full-stack web application (server-rendered UI + HTTP API) whose primary function is to allow users to send natural-language queries about employees and departments, which the server parses and answers by querying an SQLite database.

##### File Structure Highlights
- Root
- README.md – project overview and instructions
- requirements.txt – Python dependencies
- setup_db.py – script to initialize the SQLite schema
- chat_assisment/
– app.py – Flask application entry point, routes, query parsing logic
– templates/index.html – minimal front-end UI served by Flask
– assets/ – static images (e.g., screenshot)
– chat_assistant.db – local SQLite database file (for development)
- chat_env/ – Python virtualenv (Flask, Flask-CORS, Jinja2, etc.)

##### Key Insights from README
- The app exposes a `/query` endpoint accepting JSON `{ "query": "..." }`.
- Query processing uses regular expressions to extract filters (department, date, manager, etc.).
- Data lives in two tables: Employees and Departments.
- Response is JSON (for API calls) or HTML (for the landing page).

##### Main Components
a. Client Browser/UI
b. Flask Web Server
c. Query-Parsing Module (regex-based NLP component inside Flask)
d. SQLite Database (Employees, Departments tables)
e. Static Assets (images, CSS if any)

##### Interactions and Data Flow
- Browser loads `index.html` → Flask serves template + static assets
- User submits natural-language query via HTTP POST to `/query`
- Flask route handler invokes the Query-Parsing Module
- Parsed parameters turn into SQL commands executed against SQLite
- SQLite returns result set → Flask marshals into JSON → HTTP response back to client
- (Optional) CORS layer allows cross-origin API usage

##### Architectural Patterns and Principles
- MVC-style separation:
- Model = SQLite DB
- View = Jinja2 template + JSON responses
- Controller = Flask route handlers + parsing logic
- Single-process, monolithic service (no microservices)
- Layered approach: HTTP layer → parsing layer → persistence layer

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Frontend Layer"
    Browser["Client Browser/UI"]:::ui
    StaticAssets["Static Resources"]:::ui
  end

  subgraph "Backend Layer"
    FlaskApp["Flask Web Server"]:::logic
    ParsingModule["Query-Parsing Module"]:::logic
  end

  subgraph "Data Layer"
    SQLiteDB["SQLite Database"]:::db
  end

  Browser -->|"HTTP GET index.html"| FlaskApp
  FlaskApp -->|"serves HTML"| Browser

  Browser -->|"GET static assets"| StaticAssets
  StaticAssets -->|"serves static files"| Browser

  Browser -->|"HTTP POST /query JSON"| FlaskApp
  FlaskApp -->|"invokes parsing"| ParsingModule
  ParsingModule -->|"SQL SELECT queries"| SQLiteDB
  SQLiteDB -->|"query result set"| ParsingModule
  ParsingModule -->|"JSON response"| FlaskApp
  FlaskApp -->|"HTTP 200 JSON"| Browser

  Requirements["requirements.txt"]:::config
  VirtualEnv["Python Virtualenv"]:::config
  InitScript["Database Init Script"]:::config

  Requirements -->|"specifies dependencies"| VirtualEnv
  VirtualEnv -->|"provides runtime"| FlaskApp
  InitScript -->|"initializes schema"| SQLiteDB

  click Browser "https://github.com/divyanshsingh575/chat_assistant/blob/master/chat_assisment/templates/index.html"
  click StaticAssets "https://github.com/divyanshsingh575/chat_assistant/tree/master/chat_assisment/assets/"
  click FlaskApp "https://github.com/divyanshsingh575/chat_assistant/blob/master/chat_assisment/app.py"
  click ParsingModule "https://github.com/divyanshsingh575/chat_assistant/blob/master/chat_assisment/app.py"
  click SQLiteDB "https://github.com/divyanshsingh575/chat_assistant/blob/master/chat_assisment/chat_assistant.db"
  click InitScript "https://github.com/divyanshsingh575/chat_assistant/blob/master/setup_db.py"
  click Requirements "https://github.com/divyanshsingh575/chat_assistant/blob/master/requirements.txt"
  click VirtualEnv "https://github.com/divyanshsingh575/chat_assistant/tree/master/chat_env/"

  classDef ui fill:#AED6F1,stroke:#1B4F72,color:#1B2631;
  classDef logic fill:#ABEBC6,stroke:#196F3D,color:#1B2631;
  classDef db fill:#F9E79F,stroke:#B9770E,color:#1B2631;
  classDef config fill:#D2B4DE,stroke:#6C3483,color:#1B2631;
```
