# jeel-sarvadhi/sarvadhi_hrms architecture

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

- Interactive diagram: https://gitdiagram.com/jeel-sarvadhi/sarvadhi_hrms
- Repository: https://github.com/jeel-sarvadhi/sarvadhi_hrms

## Overview

##### Project type and purpose
- This is a Frappe/ERPNext “app” named Sarvadhi HRMS (a full-stack HR management module).
- It augments the Frappe framework with custom DocTypes (forms), client-side scripts, templates, data fixtures, hooks, and utility modules that integrate external services (email, APIs, QR code gen, weather, etc.).

##### Main components
a. Frappe Platform Layer
- Bench Manager (CLI) – runs server, scheduler, workers
- Web Server (gunicorn/WSGI) – serves HTTP(S)
- Redis – cache, real-time events
- MariaDB – persistent storage for all DocTypes and fixtures
b. Sarvadhi HRMS App Layer
- Hooks & Configuration (hooks.py, config/*) – extension points, scheduler hooks
- Doctype Definitions (sarvadhi_hrms/sarvadhi_hrms/doctype/*)
– JSON schemas + Python controllers + client JS
- Fixtures (sarvadhi_hrms/fixtures/*.json) – initial data load
- Public Assets (sarvadhi_hrms/public/js/*.js, images) – browser scripts & static files
- Templates (sarvadhi_hrms/templates/pages) – server-rendered pages
- Utility Modules (sarvadhi_hrms/utils/*.py) – external API wrappers, email, QR code, weather, bench commands
c. Client Layer
- Browser UI – Frappe desk interface + custom page templates + client JS
d. External Services
- Email SMTP Service
- External REST APIs (purchase_api, weather_details, etc.)
- QR Code generation (could be local lib or external)

##### Relationships & data flows
- Browser → HTTP(S) → Frappe Web Server
- Client JS calls server‐side RPC endpoints for CRUD on custom DocTypes
- Server renders templates for custom pages
- Frappe Server → MariaDB
- Reads/writes DocType tables (models defined by JSON + Python)
- Frappe Scheduler/Workers → Utility Modules
- Periodic tasks (e.g., sending reminder emails, fetching weather)
- Utility Modules ↔ External Services
- REST API calls, SMTP email submissions, QR code endpoints
- Hooks & Patches → Bench Manager
- on_install, on_update events, database migrations via patches.txt

##### Architectural patterns & design principles
- MVC as prescribed by Frappe:
- Models – DocType JSON + Python
- Views – templates (Jinja) + client JS
- Controllers – Python server methods + client scripts
- Plugin/Extension Architecture via hooks.py
- Fixtures‐driven data provisioning for reproducible installs
- Separation of concerns: UI assets vs. business logic vs. data layer
- Modular utilities for cross-cutting integrations

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    BrowserUI["Browser UI\n(Frappe Desk + Custom JS)"]:::client

    %% Frappe Core
    subgraph "Frappe Core"
        BenchManager["Bench Manager\n(CLI)"]:::core
        WebServer["Web Server\n(gunicorn/WSGI)"]:::core
    end

    %% Database & Cache
    subgraph "Database & Cache"
        Redis["Redis\n(cache, real-time events)"]:::cache
        MariaDB["MariaDB\n(persistent storage)"]:::db
    end

    %% Sarvadhi HRMS App
    subgraph "Sarvadhi HRMS App"
        HooksConfig["Hooks & Configuration"]:::app
        Metadata["App Metadata & Modules"]:::app
        Patches["DB Migrations & Patches"]:::app
        Fixtures["Fixtures\n(initial data load)"]:::app
        Doctypes["Doctypes\n(JSON + Python + Client JS)"]:::app
        PublicAssets["Public Assets\n(static/js, images)"]:::app
        Templates["Templates\n(Jinja pages)"]:::app
        Utils["Utility Modules\n(API, Email, QR, Weather, Bench Cmds)"]:::app
    end

    %% External Services
    subgraph "External Services"
        EmailService["Email SMTP Service"]:::external
        RestAPIs["External REST APIs"]:::external
        QRService["QR Code Generation"]:::external
    end

    %% Connections
    BrowserUI -->|HTTP/RPC| WebServer
    WebServer -->|SQL| MariaDB
    WebServer -->|serves| PublicAssets
    WebServer -->|renders| Templates
    WebServer -->|loads| Doctypes
    WebServer -->|invokes| HooksConfig

    BenchManager -->|Cron Trigger| Utils
    HooksConfig -->|on_install/update| BenchManager
    Patches -->|migrations| BenchManager

    Utils -->|SMTP| EmailService
    Utils -->|REST API| RestAPIs
    Utils -->|QR Code| QRService

    Fixtures -->|provision| MariaDB
    Doctypes -->|define models/controllers| MariaDB

    Metadata -->|defines modules| HooksConfig

    %% Click Events
    click HooksConfig "https://github.com/jeel-sarvadhi/sarvadhi_hrms/blob/main/sarvadhi_hrms/hooks.py"
    click Metadata "https://github.com/jeel-sarvadhi/sarvadhi_hrms/blob/main/sarvadhi_hrms/modules.txt"
    click Patches "https://github.com/jeel-sarvadhi/sarvadhi_hrms/blob/main/sarvadhi_hrms/patches.txt"
    click Fixtures "https://github.com/jeel-sarvadhi/sarvadhi_hrms/blob/main/sarvadhi_hrms/fixtures/custom_html_block.json"
    click Doctypes "https://github.com/jeel-sarvadhi/sarvadhi_hrms/blob/main/sarvadhi_hrms/sarvadhi_hrms/doctype/details_of_request/details_of_request.json"
    click PublicAssets "https://github.com/jeel-sarvadhi/sarvadhi_hrms/blob/main/sarvadhi_hrms/public/js/job_offer.js"
    click Templates "https://github.com/jeel-sarvadhi/sarvadhi_hrms/tree/main/sarvadhi_hrms/templates/pages"
    click Utils "https://github.com/jeel-sarvadhi/sarvadhi_hrms/blob/main/sarvadhi_hrms/utils/api/external_api.py"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef core fill:#90EE90,stroke:#333,stroke-width:1px
    classDef db fill:#F08080,stroke:#333,stroke-width:1px
    classDef cache fill:#F08080,stroke:#333,stroke-width:1px
    classDef app fill:#FFFFE0,stroke:#333,stroke-width:1px
    classDef external fill:#FFC0CB,stroke:#333,stroke-width:1px
```
