# ashrafino/web-application-for-hr-management-with-rag-chatbot-integration architecture

> Architecture diagram of the GitHub repository ashrafino/web-application-for-hr-management-with-rag-chatbot-integration, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ashrafino/web-application-for-hr-management-with-rag-chatbot-integration
- Repository: https://github.com/ashrafino/web-application-for-hr-management-with-rag-chatbot-integration

## Overview

##### Project type and purpose
- This is a full-stack web application (HRMS) built with Flask (Python) on the backend, SQLAlchemy/SQLite for persistence, and a Bootstrap/HTML/CSS/JavaScript frontend.
- It includes core HR features (leave, event, user management), Excel import/export, and an intelligent RAG-based chatbot via Ollama.

##### File structure
- Top-level files:
- app.py – Flask application entry point
- config.py – environment and DB configuration
- routes.py – HTTP endpoints / controller logic
- data.db – SQLite database file
- requirements.txt – Python dependencies
- log/ – application logs
- test_import.xlsx – sample data for import
- Directories:
- static/ – client assets (CSS, JS, images, calendar widget)
- templates/ – Jinja2 HTML views, one per major page (add/edit/list for users/events, chatbot, import, login, home)
- Key patterns: MVC-style separation (templates = Views, routes = Controllers, SQLAlchemy models = Models), plus an external service integration (Ollama).

##### README for stack details
- Backend: Flask, SQLAlchemy, Pandas for Excel, Ollama API for RAG
- Frontend: Bootstrap, custom JS (calendar drag/drop, chatbot UI)
- Data store: SQLite (data.db) via ORM
- No microservices—monolithic codebase with third-party service call.

##### Main components and interactions
a. Frontend (Browser/UI)
- Serves HTML templates, CSS, JS.
- Pages: login, dashboard (leave, event, user management), chatbot interface.
- JS calls backend endpoints (e.g., /api/events, /api/chatbot).
b. Backend (Flask Server)
- app.py initializes Flask, loads config.py settings.
- routes.py defines endpoints:
- CRUD for users, events, leaves
- Excel import/export (Pandas)
- Chatbot endpoint that queries DB and forwards context to Ollama
- Business logic + SQLAlchemy ORM models handle data operations.
c. Database (SQLite)
- data.db: persistent store for user profiles, leave records, events.
- SQLAlchemy sessions abstract queries.
d. External Service (Ollama)
- RAG pipeline: backend queries SQLite for relevant HR data → packages “retrieved” context → sends to Ollama API → returns generated answer → backend returns JSON to client.
e. Logging & Configuration
- log/ folder captures application and error logs.
- config.py holds DB path, Flask secret keys, Ollama endpoint credentials.

##### Architectural patterns & design principles
- MVC-inspired layering
- Single responsibility: routes.py / app.py separate from templates and static assets
- Modular: each feature (leave, event, user, chatbot) grouped by route + template
- RAG pattern for chatbot (Data Retrieval + Language Generation)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Frontend Layer"
        direction TB
        Browser["Browser UI"]:::frontend
        StaticAssets["Static Assets<br/>(CSS, JS, calendar widget)"]:::frontend
        Templates["Jinja2 Templates"]:::frontend
    end

    subgraph "Backend Layer (Flask App)"
        direction TB
        AppEntry["app.py"]:::backend
        Config["config.py"]:::backend
        Controllers["routes.py<br/>(Controllers)"]:::backend
        ORM["SQLAlchemy Models"]:::backend
        Pandas["Pandas Import/Export"]:::backend
        ChatbotCtrl["Chatbot Controller<br/>(RAG Orchestration)"]:::backend
    end

    subgraph "Data Layer"
        direction TB
        DB["SQLite Database<br/>(data.db)"]:::database
    end

    subgraph "External Services"
        direction TB
        Ollama["Ollama RAG API"]:::external
    end

    subgraph "Logging"
        direction TB
        Logs["Log Storage<br/>(log/)"]:::logs
    end

    Browser -->|HTTP/HTML| Templates
    Browser -->|HTTP/Assets| StaticAssets
    Browser -->|HTTP/JSON| Controllers

    Controllers -->|ORM Calls| ORM
    ORM -->|SQL Queries| DB

    Controllers -->|Uses| Pandas
    Pandas -->|Reads/Writes| DB

    Controllers -->|REST API/JSON| ChatbotCtrl
    ChatbotCtrl -->|Context| DB
    ChatbotCtrl -->|REST API/JSON| Ollama
    Ollama -->|Response JSON| ChatbotCtrl
    ChatbotCtrl -->|HTTP/JSON| Browser

    Controllers -->|Writes Logs| Logs

    click StaticAssets "https://github.com/ashrafino/web-application-for-hr-management-with-rag-chatbot-integration/tree/main/static/"
    click Templates "https://github.com/ashrafino/web-application-for-hr-management-with-rag-chatbot-integration/tree/main/templates/"
    click AppEntry "https://github.com/ashrafino/web-application-for-hr-management-with-rag-chatbot-integration/blob/main/app.py"
    click Config "https://github.com/ashrafino/web-application-for-hr-management-with-rag-chatbot-integration/blob/main/config.py"
    click Controllers "https://github.com/ashrafino/web-application-for-hr-management-with-rag-chatbot-integration/blob/main/routes.py"
    click DB "https://github.com/ashrafino/web-application-for-hr-management-with-rag-chatbot-integration/blob/main/data.db"
    click Logs "https://github.com/ashrafino/web-application-for-hr-management-with-rag-chatbot-integration/tree/main/log/"
    click Pandas "https://github.com/ashrafino/web-application-for-hr-management-with-rag-chatbot-integration/blob/main/test_import.xlsx"

    classDef frontend fill:#D0E8FF,stroke:#3399FF,color:#000
    classDef backend fill:#DFF0D8,stroke:#3C763D,color:#000
    classDef database fill:#FCF8E3,stroke:#8A6D3B,color:#000,shape:cylinder
    classDef external fill:#E3D7FC,stroke:#7A42F4,color:#000
    classDef logs fill:#F5F5F5,stroke:#999,color:#000
```
