# karan27q/erp architecture

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

- Interactive diagram: https://gitdiagram.com/karan27q/erp
- Repository: https://github.com/karan27q/erp

## Overview

##### Project type and purpose
- This is a full-stack Employee Management System that streamlines HR workflows: employee records, attendance, leave, payroll, tasks, reporting, and notifications.
- Frontend: React.js single-page app; Backend: Flask REST API; Database: relational (PostgreSQL/MySQL/SQLite); External services: Email service, PDF generator, CSV export.

##### File structure
- Top-level:
- frontend/ – React app
- backend/ (implied by README) – Flask API
- frontend contains public/ (static HTML), src/ (App.js, index.js, pages/, components/, services/, context/).
- backend (per README) includes app.py, routes/, controllers/, models/, utils/, config.py, migrations/, instance/, requirements.txt.
- Config/deployment manifests: .env files in both frontend and backend.

##### README for additional insights
- Tech Stack section lists libraries (Axios, React Router, Flask-RESTful, JWT).
- Folder Structure section clarifies MVC-style layering in backend and feature-based organization in frontend.
- Mentions API endpoints, authentication/authorization, environment variables, and external services (email, PDF, CSV).

a. Main components
- User’s Browser (React SPA)
- React Frontend (UI components, pages, React Router)
- Axios HTTP Client (in services/)
- Flask REST API Server (routes → controllers → models)
- Database (PostgreSQL/MySQL/SQLite)
- Authentication Layer (JWT issued by Flask, stored in client)
- External Services
- Email Service (SMTP or third-party like SendGrid)
- PDF Generation Engine (e.g. ReportLab)
- CSV Export Module
- Dev/Ops Components (environment variables, migration scripts)

b. Relationships and interactions
- Browser loads static assets from public/ via HTTP(S) → React App bootstraps.
- React App dispatches API calls (Axios) → Flask API endpoints.
- Flask API uses controllers to enforce business logic, communicates with models (ORM) → Database.
- Upon certain triggers, controllers call utils → Email Service or PDF generator.
- JWT issuance: login endpoint returns token to client → client stores token (local storage/context) → sent in Authorization header on subsequent API calls.
- Migration scripts run against Database for schema changes.
- Environment variables configure API base URLs, DB credentials, JWT secrets.

c. Architectural patterns and design principles
- Frontend: Component hierarchy + feature folders; Single-Page Application (SPA) pattern; Context API for global state.
- Backend: Layered MVC (routes → controllers → models); RESTful API design; Separation of concerns (config, utils, migrations).
- Security: JWT for stateless authentication; CORS and environment-based configs.
- Scalability: Decoupling via HTTP interface; externalizing heavy tasks (PDF, email) to separate services or queues.

d. Key technologies/frameworks
- React.js, React Router, Axios
- Python Flask, Flask-RESTful, SQLAlchemy (or ORM of choice)
- JWT library (PyJWT)
- Database (PostgreSQL/MySQL/SQLite)
- External libs: Email (SMTP or cloud API), PDF (ReportLab), CSV (Python csv)
- Dev tools: dotenv, Alembic (migrations)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["User Browser"]:::frontend
        HTMLTemplate["index.html"]:::frontend
        ReactEntry["React Entry Point"]:::frontend
        ReactApp["React App"]:::frontend
        LoginPage["Login Page"]:::frontend
        AxiosService["Axios HTTP Client"]:::frontend
        GlobalStyles1["index.css"]:::frontend
        GlobalStyles2["App.css"]:::frontend
        AppTests["App Tests"]:::frontend
        SetupTests["Testing Setup"]:::frontend
        WebVitals["Web Vitals"]:::frontend
        FrontPkg["package.json"]:::frontend
        Browser -->|"loads"| HTMLTemplate
        HTMLTemplate -->|"bootstraps"| ReactEntry
        ReactEntry -->|"renders"| ReactApp
        ReactApp -->|"navigates to"| LoginPage
        ReactApp -->|"uses"| AxiosService
        ReactApp -->|"imports"| GlobalStyles1
        ReactApp -->|"imports"| GlobalStyles2
        ReactApp -->|"tested by"| AppTests
        ReactApp -->|"setup by"| SetupTests
        ReactEntry -->|"reports metrics to"| WebVitals
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        FlaskAPI["Flask API Server"]:::backend
        Routes["Routes"]:::backend
        Controllers["Controllers"]:::backend
        Models["Models (ORM)"]:::backend
        DB[(Database)]:::database
        EnvVars["Environment Variables"]:::utils
        Migrations["Migration Scripts"]:::utils
        FlaskAPI -->|"handles requests"| Routes
        Routes -->|"calls"| Controllers
        Controllers -->|"queries"| Models
        Models -->|"reads/writes"| DB
        Controllers -->|"uses"| EnvVars
        Controllers -->|"runs"| Migrations
    end

    %% External Services
    subgraph "External Services"
        direction TB
        EmailService["Email Service"]:::external
        PDFService["PDF Generation"]:::external
        CSVService["CSV Export"]:::external
        Controllers -->|"- - -> sends email via SMTP"| EmailService
        Controllers -->|"- - -> generates PDF"| PDFService
        Controllers -->|"- - -> exports CSV"| CSVService
    end

    %% Authentication Flow
    subgraph "Authentication"
        direction TB
        LoginEndpoint["Login Endpoint"]:::backend
        JWTAuth["JWT Auth"]:::backend
        ReactApp -->|"POST /login"| LoginEndpoint
        LoginEndpoint -->|"issues token"| JWTAuth
        ReactApp -->|"Authorization header"| FlaskAPI
    end

    %% Click Events
    click ReactApp "https://github.com/karan27q/erp/blob/main/frontend/src/App.js"
    click ReactEntry "https://github.com/karan27q/erp/blob/main/frontend/src/index.js"
    click HTMLTemplate "https://github.com/karan27q/erp/blob/main/frontend/public/index.html"
    click LoginPage "https://github.com/karan27q/erp/blob/main/frontend/src/pages/login.jsx"
    click GlobalStyles1 "https://github.com/karan27q/erp/blob/main/frontend/src/index.css"
    click GlobalStyles2 "https://github.com/karan27q/erp/blob/main/frontend/src/App.css"
    click AppTests "https://github.com/karan27q/erp/blob/main/frontend/src/App.test.js"
    click SetupTests "https://github.com/karan27q/erp/blob/main/frontend/src/setupTests.js"
    click WebVitals "https://github.com/karan27q/erp/blob/main/frontend/src/reportWebVitals.js"
    click FrontPkg "https://github.com/karan27q/erp/blob/main/frontend/package.json"
    click RootReadme "https://github.com/karan27q/erp/blob/main/README.md"
    click FrontReadme "https://github.com/karan27q/erp/blob/main/frontend/README.md"
    click Gitignore "https://github.com/karan27q/erp/blob/main/frontend/.gitignore"

    %% Styles
    classDef frontend fill:#e3f2fd,stroke:#1e88e5,color:#0d47a1;
    classDef backend fill:#e8f5e9,stroke:#43a047,color:#1b5e20;
    classDef database fill:#fff3e0,stroke:#fb8c00,color:#e65100;
    classDef external fill:#f3e5f5,stroke:#8e24aa,color:#4a148c;
    classDef utils fill:#eceff1,stroke:#607d8b,color:#263238;
```
