# tngoman/store-pos architecture

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

- Interactive diagram: https://gitdiagram.com/tngoman/store-pos
- Repository: https://github.com/tngoman/store-pos

## Overview

##### Project type and purpose
- This is a desktop Point-of-Sale (POS) application built on Electron.
- It bundles a Node.js/Express “backend” (in server.js + api/) with a browser-based “frontend” (in index.html + assets/) inside an Electron shell.
- It connects to a central database on the network, offers receipt printing and file uploads, and manages products, users, transactions, etc.

##### File structure
- Top-level Electron entrypoints:
- start.js (or build.js) to bootstrap Electron
- server.js: spins up an Express server and mounts api/*.js endpoints
- renderer.js: handles renderer-process scripts or IPC
- “api” folder: REST routes for categories, customers, inventory, settings, transactions, users.
- “assets” + “public”: static UI (CSS, JS, fonts, plugins, images, public/uploads) served to the renderer.
- “installers”: Windows packaging hooks
- package.json: dependency list and build scripts

##### Extract architecture insights from the README
- Multi-PC support via a single central database
- Receipt printing (access to OS print APIs)
- Electron packaging as an MSI installer
- UI communicates with local Express API, which in turn communicates with the DB

a. Electron Shell
- Main Process (start.js)
- Renderer Process (index.html loaded into BrowserWindow)
b. Local Express Server
- server.js + api/*.js (REST API)
c. Database
- Central DB (MySQL, Postgres, or SQLite on network)
d. File System / Uploads
- public/uploads for product images
e. OS Services
- Print Service for receipts
f. Plugins & Static Assets
- assets/js, assets/css, assets/plugins

##### Relationships & data flows
- Renderer → (HTTP / IPC) → Local Express Server → Central Database
- Express → File System (uploads)
- Express → OS Print Service → Printer hardware
- Renderer ↔ Main Process via Electron IPC (for privileged operations)
- Packaging: build.js / package.json → creates installers

##### Architectural patterns & design principles
- Desktop MVC:
- View – assets + index.html
- Controller – api/*.js
- Model – Database access layer within api modules
- Layered architecture:
- Presentation (Renderer)
- API (Express)
- Persistence (DB + FS)
- Separation of concerns: UI vs. business logic vs. data storage

##### Technologies & frameworks
- Electron (start.js, build.js)
- Node.js + Express (server.js, api/)
- Static web tech: HTML5, CSS3, Vanilla JS + jQuery + plugins (DataTables, datepicker, Chosen, etc.)
- Central DB (configure in settings.js)
- MSI installer (installers/)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Electron Layer
    subgraph "Electron Layer"
        MP["Main Process"]:::electron
        RP["Renderer Process"]:::electron
    end

    %% API Layer
    subgraph "API Layer"
        ES["Express Server"]:::server
        CAT["Categories API"]:::server
        CUS["Customers API"]:::server
        INV["Inventory API"]:::server
        SET["Settings API"]:::server
        TRX["Transactions API"]:::server
        USR["Users API"]:::server
    end

    %% Static Assets
    subgraph "Static Assets"
        CSS["CSS Files"]:::assets
        POSJS["pos.js"]:::assets
        PFJS["product-filter.js"]:::assets
        PLG["Plugins"]:::assets
    end

    %% Public UI Shell
    subgraph "Public UI Shell"
        UIIDX["index.html"]:::assets
        MAN["manifest.json"]:::assets
        ROB["robots.txt"]:::assets
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        DB["Central Database"]:::db
        UP["Uploads Folder"]:::os
    end

    %% OS Integration
    subgraph "OS Integration"
        PS["Print Service"]:::os
    end

    %% Packaging
    subgraph "Packaging"
        SETUP["setupEvents.js"]:::os
        PKG["package.json"]:::os
    end

    %% Connections
    RP -->|HTTP calls| ES
    RP -->|"IPC"| MP
    ES -->|mounts endpoints| CAT & CUS & INV & SET & TRX & USR
    ES -->|queries| DB
    ES -->|reads/writes| UP
    ES -->|sends print jobs| PS
    RP -->|loads static assets| CSS & POSJS & PFJS & PLG
    RP -->|loads public UI| UIIDX & MAN & ROB

    %% Click Events
    click MP "https://github.com/tngoman/store-pos/blob/master/start.js"
    click MP "https://github.com/tngoman/store-pos/blob/master/build.js"
    click RP "https://github.com/tngoman/store-pos/blob/master/public/index.html"
    click RP "https://github.com/tngoman/store-pos/blob/master/renderer.js"
    click ES "https://github.com/tngoman/store-pos/blob/master/server.js"
    click CAT "https://github.com/tngoman/store-pos/blob/master/api/categories.js"
    click CUS "https://github.com/tngoman/store-pos/blob/master/api/customers.js"
    click INV "https://github.com/tngoman/store-pos/blob/master/api/inventory.js"
    click SET "https://github.com/tngoman/store-pos/blob/master/api/settings.js"
    click TRX "https://github.com/tngoman/store-pos/blob/master/api/transactions.js"
    click USR "https://github.com/tngoman/store-pos/blob/master/api/users.js"
    click CSS "https://github.com/tngoman/store-pos/tree/master/assets/css/"
    click POSJS "https://github.com/tngoman/store-pos/blob/master/assets/js/pos.js"
    click PFJS "https://github.com/tngoman/store-pos/blob/master/assets/js/product-filter.js"
    click PLG "https://github.com/tngoman/store-pos/tree/master/assets/plugins/"
    click UIIDX "https://github.com/tngoman/store-pos/blob/master/public/index.html"
    click MAN "https://github.com/tngoman/store-pos/blob/master/public/manifest.json"
    click ROB "https://github.com/tngoman/store-pos/blob/master/public/robots.txt"
    click UP "https://github.com/tngoman/store-pos/tree/master/public/uploads/"
    click SETUP "https://github.com/tngoman/store-pos/blob/master/installers/setupEvents.js"
    click PKG "https://github.com/tngoman/store-pos/blob/master/package.json"

    %% Styles
    classDef electron fill:#D6EAF8,stroke:#1B4F72,stroke-width:1px
    classDef server fill:#D5F5E3,stroke:#145A32,stroke-width:1px
    classDef db fill:#FAD7A0,stroke:#7D6608,stroke-width:1px
    classDef os fill:#E5E7E9,stroke:#566573,stroke-width:1px
    classDef assets fill:#FADBD8,stroke:#943126,stroke-width:1px
```
