# huzaifajh/stock-manager architecture

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

- Interactive diagram: https://gitdiagram.com/huzaifajh/stock-manager
- Repository: https://github.com/huzaifajh/stock-manager

## Overview

##### Project type and purpose
- Stock Manager is a full-stack inventory and stock management solution that can run both as a web application (Next.js SSR/SSG) and as a desktop application (Electron).
- The frontend and backend are consolidated in a single Next.js codebase: React components under src/app and RESTful API routes under src/app/api. The persistence layer uses MySQL accessed via Sequelize (src/lib/sequelize.ts and src/lib/models).

##### File structure
- Top-level “main.js” and “preload.js” are your Electron entry points (main and renderer IPC bridge). “printService.js” likely encapsulates native printing logic.
- “next.config.ts”, “package.json” and “npm scripts” drive the Next.js build and development servers, as well as the Electron packaging.
- src/app/layout.tsx, globals.css and tailwind.config.ts define the global UI shell and theming. src/app contains two main areas:
- src/app/POS – point-of-sale pages.
- src/app/accounts – accounting reports pages.
- src/app/api – REST endpoints for CRUD operations (categories, products, sales, purchases, reports, etc.).
- src/lib/models + src/lib/sequelize.ts define your domain model and database schema mappings.

##### README for additional insights
- The README confirms MySQL as the database, Next.js for web, Electron for desktop builds, and highlights environment variables for DB credentials and API URL.

##### Detail
- Every major feature area (POS, Accounts, Settings) as sub-components of the React UI.
- Do not omit the build and packaging steps: illustrate how npm scripts transform the Next.js code into both a web service and an Electron installer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interfaces"
        subgraph Browser
            GlobalShell["Global UI Shell & Theming"]:::ui
            Home["Landing / Home Page"]:::ui
            NotFound["Not Found Page"]:::ui
            subgraph "Modules"
                POS["POS Module"]:::ui
                Accounts["Accounts Module"]:::ui
                Settings["Settings Module"]:::ui
            end
        end
        subgraph "Electron Desktop"
            ElectronMain["Electron Main Process"]:::electron
            Preload["Electron Preload / IPC Bridge"]:::electron
            PrintService["Native Printing Service"]:::electron
            RendererUI["React Frontend Renderer"]:::ui
        end
    end

    subgraph "Next.js Server"
        Config["Next.js Configuration & Build Scripts"]:::server
        SSR["SSR/SSG & Page Rendering"]:::server
        API["Next.js API Routes"]:::api
    end

    subgraph "Data Layer"
        ORM["Sequelize ORM"]:::data
        Models["Domain Models"]:::data
    end

    MySQL["MySQL Database"]:::db
    Build["Build & Packaging Pipeline"]:::build

    %% UI to Server/API flows
    Browser -->|loads pages| SSR
    Browser -->|HTTP/HTTPS| API
    RendererUI -->|HTTP/HTTPS| API
    Home --> SSR
    POS --> SSR
    Accounts --> SSR
    Settings --> SSR

    %% Electron flows
    ElectronMain -->|creates BrowserWindow| RendererUI
    RendererUI -->|IPC calls| Preload
    Preload -->|invokes native| ElectronMain
    ElectronMain -->|calls| PrintService

    %% Server to Data
    API -->|queries| ORM
    SSR --> ORM
    ORM --> Models
    ORM -->|reads/writes| MySQL

    %% Build pipeline
    Build -->|builds Next.js app| SSR
    Build -->|packages Electron| ElectronMain

    %% Configuration flows
    Config --> SSR
    Config --> Build

    %% Click Events
    click ElectronMain "https://github.com/huzaifajh/stock-manager/blob/main/main.js"
    click Preload "https://github.com/huzaifajh/stock-manager/blob/main/preload.js"
    click PrintService "https://github.com/huzaifajh/stock-manager/blob/main/printService.js"
    click Config "https://github.com/huzaifajh/stock-manager/blob/main/next.config.ts"
    click Config "https://github.com/huzaifajh/stock-manager/blob/main/package.json"
    click GlobalShell "https://github.com/huzaifajh/stock-manager/blob/main/src/app/layout.tsx"
    click GlobalShell "https://github.com/huzaifajh/stock-manager/blob/main/src/app/globals.css"
    click GlobalShell "https://github.com/huzaifajh/stock-manager/blob/main/tailwind.config.ts"
    click Home "https://github.com/huzaifajh/stock-manager/blob/main/src/app/page.tsx"
    click NotFound "https://github.com/huzaifajh/stock-manager/blob/main/src/app/not-found.tsx"
    click POS "https://github.com/huzaifajh/stock-manager/tree/main/src/app/POS"
    click Accounts "https://github.com/huzaifajh/stock-manager/tree/main/src/app/accounts"
    click Settings "https://github.com/huzaifajh/stock-manager/tree/main/src/app/settings"
    click API "https://github.com/huzaifajh/stock-manager/tree/main/src/app/api"
    click ORM "https://github.com/huzaifajh/stock-manager/blob/main/src/lib/sequelize.ts"
    click Models "https://github.com/huzaifajh/stock-manager/tree/main/src/lib/models"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef electron fill:#F0F0F0,stroke:#999999,color:#333333
    classDef server fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32
    classDef api fill:#FFF3E0,stroke:#EF6C00,color:#E65100
    classDef data fill:#E3F2FD,stroke:#1E88E5,color:#1565C0
    classDef db fill:#FFE0B2,stroke:#FB8C00,color:#E65100
    classDef build fill:#F3E5F5,stroke:#6A1B9A,color:#4A148C
```
