# kunalkharga/inventory-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/kunalkharga/inventory-management-system
- Repository: https://github.com/kunalkharga/inventory-management-system

## Overview

##### Project type and purpose
- This is a full-stack, monolithic PHP/MySQL web application—an Inventory Management System.
- It provides a browser-based UI for administrators to perform CRUD on products, track stock, manage sales and suppliers, and generate PDF invoices/reports.

##### High-level file-structure analysis
- Top-level PHP scripts (add_product.php, sales.php, admin.php, etc.) act as controllers/pages.
- includes/ holds shared modules: config.php (DB credentials), database.php (DB connection), sql.php (queries), session.php, upload.php, functions.php.
- layouts/ contains view templates (header, footer, menus).
- libs/css and libs/js serve static assets for styling/interaction.
- fpdf/ is an external library for PDF generation.
- uploads/ is the filesystem store for user- and product-uploaded images.
- DATABASE FILE/inventory_system.sql holds the MySQL schema.

##### README insights
- Confirms tech stack: Frontend – HTML/CSS/Bootstrap/JS; Backend – PHP; Database – MySQL; Local Server – XAMPP.
- Mentions core features like CRUD, stock tracking, sales processing, user auth, responsive design, PDF reports.

##### Main components and relationships
A. Browser (Client)
- Sends HTTP(S) requests, renders HTML/CSS/JS.
B. Web Server + PHP Runtime
- Receives requests, routes them to the appropriate .php page (index.php, auth.php, sales.php).
- Each page includes common modules (includes/*.php).
C. Business-Logic Layer (includes/functions.php + page scripts)
- Validates input, enforces rules (e.g., stock limits).
D. Data-Access Layer (includes/database.php + includes/sql.php)
- Executes SQL against MySQL.
E. MySQL Database
- Stores tables for users, products, categories, groups, sales, suppliers, sessions.
F. File Storage (uploads/)
- Persists uploaded product/user images.
G. PDF Generator (fpdf/)
- Generates invoice/sales PDF on demand.
H. Static Assets (libs/)
- CSS for styling, JS for client-side behaviors.

Data Flow:
1. Client → HTTP request → PHP page
2. PHP page → includes → business logic → data access → MySQL
3. MySQL → result → PHP builds HTML
4. PHP → HTML + CSS/JS → Client
5. On PDF/report: PHP → fpdf library → PDF → Client download
6. File upload: Client → PHP upload module → writes to uploads/ → DB updated with file path

##### Architectural patterns & design principles
- Layered architecture (Presentation / Business Logic / Data Access).
- Modularization via includes/ for reuse (e.g., session handling, DB connection).
- Logical separation of view templates (layouts/) from controllers (PHP pages) and models (SQL scripts).
- Use of external library (fpdf) for a cross-cutting concern (PDF generation).

##### Technologies and frameworks
- PHP 7+ on Apache (XAMPP)
- MySQL 5.7+
- fpdf for PDFs
- Bootstrap (via libs/css) for responsive UI
- Vanilla JS for client interactivity

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side
    subgraph "Client Side" 
        direction TB
        Browser["Browser (Client)"]:::client
        StaticCSS["CSS Assets (libs/css)"]:::client
        StaticJS["JS Assets (libs/js)"]:::client
    end

    %% Server Side
    subgraph "Server Side"
        direction TB
        WebServer["Web Server + PHP Runtime"]:::server

        subgraph "Controllers (Page Scripts)"
            direction TB
            Controllers["add_product.php, sales.php, admin.php, auth.php, index.php, etc."]:::server
        end

        subgraph "Business Logic Layer"
            direction TB
            Funcs["Business Logic Module<br/>(includes/functions.php)"]:::server
            Session["Session Management<br/>(includes/session.php)"]:::server
            Load["Common Loader<br/>(includes/load.php)"]:::server
        end

        subgraph "Data Access Layer"
            direction TB
            Config["Configuration Module<br/>(includes/config.php)"]:::server
            DBConn["DB Connection Module<br/>(includes/database.php)"]:::server
            SQL["SQL Queries Module<br/>(includes/sql.php)"]:::server
            UploadMod["File Upload Module<br/>(includes/upload.php)"]:::server
        end

        subgraph "View Templates (layouts/)"
            direction TB
            Header["header.php"]:::server
            Footer["footer.php"]:::server
            AdminMenu["admin_menu.php"]:::server
            UserMenu["user_menu.php"]:::server
            SpecialMenu["special_menu.php"]:::server
        end

        subgraph "PDF Generation"
            direction TB
            FPDF["fpdf/"]:::ext
            Generate["generate.php"]:::server
        end

        subgraph "Persistent Stores"
            direction TB
            MySQLDB["MySQL Inventory DB"]:::db
            UploadsProducts["uploads/products/"]:::db
            UploadsUsers["uploads/users/"]:::db
            Schema["inventory_system.sql"]:::db
        end
    end

    %% Connections
    Browser -->|"HTTP Request"| WebServer
    StaticCSS -->|Served Static| Browser
    StaticJS -->|Served Static| Browser

    WebServer -->|Routes Request| Controllers
    Controllers -->|Includes| Load
    Controllers -->|Invoke| Funcs
    Controllers -->|Manage Session| Session
    Controllers -->|Call| UploadMod
    Controllers -->|Generate PDF| Generate
    Generate -->|Uses| FPDF

    Controllers -->|Render Views| Header
    Controllers --> Header
    Controllers --> Footer
    Controllers --> AdminMenu
    Controllers --> UserMenu
    Controllers --> SpecialMenu

    Funcs -->|Use Config| Config
    Funcs -->|Use DB Connection| DBConn
    Funcs -->|Use Queries| SQL

    DBConn -->|Connects To| MySQLDB
    SQL -->|Queries| MySQLDB

    UploadMod -->|Writes Files| UploadsProducts
    UploadMod --> UploadsUsers
    UploadMod -->|Updates DB| MySQLDB

    Controllers -->|CRUD / Sales / Auth| MySQLDB

    %% Click Events
    click Controllers "https://github.com/kunalkharga/inventory-management-system/tree/master//"
    click Config "https://github.com/kunalkharga/inventory-management-system/blob/master/includes/config.php"
    click DBConn "https://github.com/kunalkharga/inventory-management-system/blob/master/includes/database.php"
    click SQL "https://github.com/kunalkharga/inventory-management-system/blob/master/includes/sql.php"
    click Funcs "https://github.com/kunalkharga/inventory-management-system/blob/master/includes/functions.php"
    click Session "https://github.com/kunalkharga/inventory-management-system/blob/master/includes/session.php"
    click UploadMod "https://github.com/kunalkharga/inventory-management-system/blob/master/includes/upload.php"
    click Load "https://github.com/kunalkharga/inventory-management-system/blob/master/includes/load.php"
    click Header "https://github.com/kunalkharga/inventory-management-system/blob/master/layouts/header.php"
    click Footer "https://github.com/kunalkharga/inventory-management-system/blob/master/layouts/footer.php"
    click AdminMenu "https://github.com/kunalkharga/inventory-management-system/blob/master/layouts/admin_menu.php"
    click UserMenu "https://github.com/kunalkharga/inventory-management-system/blob/master/layouts/user_menu.php"
    click SpecialMenu "https://github.com/kunalkharga/inventory-management-system/blob/master/layouts/special_menu.php"
    click StaticCSS "https://github.com/kunalkharga/inventory-management-system/blob/master/libs/css/main.css"
    click StaticJS "https://github.com/kunalkharga/inventory-management-system/blob/master/libs/js/functions.js"
    click FPDF "https://github.com/kunalkharga/inventory-management-system/tree/master/fpdf/"
    click Generate "https://github.com/kunalkharga/inventory-management-system/blob/master/generate.php"
    click UploadsProducts "https://github.com/kunalkharga/inventory-management-system/tree/master/uploads/products/"
    click UploadsUsers "https://github.com/kunalkharga/inventory-management-system/tree/master/uploads/users/"
    click Schema "https://github.com/kunalkharga/inventory-management-system/blob/master/DATABASE FILE/inventory_system.sql"

    %% Styles
    classDef client fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef server fill:#DFFFE0,stroke:#333,stroke-width:1px
    classDef db fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef ext fill:#E0E0E0,stroke:#333,stroke-width:1px
```
