# abelheddy/simplepos architecture

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

- Interactive diagram: https://gitdiagram.com/abelheddy/simplepos
- Repository: https://github.com/abelheddy/simplepos

## Overview

##### Project type and purpose
- This is a full-stack Point of Sale (SimplePos) application, consisting of:
- A React/Vite-based frontend
- Two alternative backend implementations (one in Go, one in Node.js)
- A database layer for storing users, roles, products, sales, etc.

##### File structure
- Top level:
- Backend/
– go/ (Go REST API: database init, handlers, middleware, models)
– node/ (Node.js Express API: controllers, models, routes, db.js)
- Frontend/ (React app under src/, uses Vite, Tailwind, React Router, Context API)
- Productos.sql (initial product data script)
- Backend/go follows a layered pattern (models → handlers → main), uses environment config, middleware for auth.
- Backend/node follows MVC (models ↔ controllers ↔ routes), with connection logic in src/db.js.
- Frontend uses component hierarchy and React contexts for authentication and role-based routing.

##### Pulling insights from the README
- The project is named SimplePos

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["User's Browser"]:::external
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        Frontend["React Frontend"]:::frontend
        Tailwind["tailwind.config.js"]:::frontend
        PostCSS["postcss.config.js"]:::frontend
        App["App.jsx"]:::frontend
        Main["main.jsx"]:::frontend
        AuthCtx["AuthContext.jsx"]:::frontend
        Protected["ProtectedRoute.jsx"]:::frontend
        APIService["api.js"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        subgraph "Go API Service"
            GoRoot["Backend/go/"]:::go
            GoEnv[".env"]:::go
            GoDBInit["database/init.go"]:::go
            GoMongo["database/mongo.go"]:::go
            GoMiddleware["middleware/auth.go"]:::go
            GoHandlers["handlers/*.go"]:::go
            GoModels["models/*.go"]:::go
            GoMain["main.go"]:::go
        end
        subgraph "Node.js API Service"
            NodeRoot["Backend/node/src/"]:::node
            NodeEnv[".env"]:::node
            CheckEnv["check-env.js"]:::node
            ConnTest["connection-test.js"]:::node
            CrudTest["crud-test.js"]:::node
            NodeDB["db.js"]:::node
            NodeRoutes["routes/*.js"]:::node
            NodeControllers["controllers/*.js"]:::node
            NodeModels["models/*.js"]:::node
            NodeServer["server.js"]:::node
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        DB["MongoDB"]:::db
        SQL["Productos.sql"]:::external
    end

    %% Connections
    Browser -->|"loads UI"| Frontend
    Frontend -->|"REST calls"| GoMain
    Frontend -->|"REST calls"| NodeServer
    GoMain -->|"connects via driver"| DB
    NodeServer -->|"connects via db.js"| DB
    SQL -->|"seed data"| DB

    %% Go internal flow
    GoMain --> GoMiddleware
    GoMiddleware --> GoHandlers
    GoHandlers --> GoModels
    GoModels --> GoDBInit
    GoDBInit --> GoMongo

    %% Node internal flow
    NodeServer --> NodeRoutes
    NodeRoutes --> NodeControllers
    NodeControllers --> NodeModels
    NodeModels --> NodeDB

    %% Click Events
    click Frontend "https://github.com/abelheddy/simplepos/tree/main/Frontend/"
    click App "https://github.com/abelheddy/simplepos/blob/main/Frontend/src/App.jsx"
    click Main "https://github.com/abelheddy/simplepos/blob/main/Frontend/src/main.jsx"
    click Tailwind "https://github.com/abelheddy/simplepos/blob/main/Frontend/tailwind.config.js"
    click PostCSS "https://github.com/abelheddy/simplepos/blob/main/Frontend/postcss.config.js"
    click AuthCtx "https://github.com/abelheddy/simplepos/blob/main/Frontend/src/context/AuthContext.jsx"
    click Protected "https://github.com/abelheddy/simplepos/blob/main/Frontend/src/components/ProtectedRoute.jsx"
    click APIService "https://github.com/abelheddy/simplepos/blob/main/Frontend/src/services/api.js"
    click GoRoot "https://github.com/abelheddy/simplepos/tree/main/Backend/go/"
    click GoEnv "https://github.com/abelheddy/simplepos/blob/main/Backend/go/.env"
    click GoDBInit "https://github.com/abelheddy/simplepos/blob/main/Backend/go/database/init.go"
    click GoMongo "https://github.com/abelheddy/simplepos/blob/main/Backend/go/database/mongo.go"
    click GoMiddleware "https://github.com/abelheddy/simplepos/blob/main/Backend/go/middleware/auth.go"
    click GoHandlers "https://github.com/abelheddy/simplepos/blob/main/Backend/go/handlers/*.go"
    click GoModels "https://github.com/abelheddy/simplepos/blob/main/Backend/go/models/*.go"
    click GoMain "https://github.com/abelheddy/simplepos/blob/main/Backend/go/main.go"
    click NodeRoot "https://github.com/abelheddy/simplepos/tree/main/Backend/node/src/"
    click NodeEnv "https://github.com/abelheddy/simplepos/blob/main/Backend/node/.env"
    click CheckEnv "https://github.com/abelheddy/simplepos/blob/main/Backend/node/check-env.js"
    click ConnTest "https://github.com/abelheddy/simplepos/blob/main/Backend/node/connection-test.js"
    click CrudTest "https://github.com/abelheddy/simplepos/blob/main/Backend/node/crud-test.js"
    click NodeDB "https://github.com/abelheddy/simplepos/blob/main/Backend/node/src/db.js"
    click NodeRoutes "https://github.com/abelheddy/simplepos/blob/main/Backend/node/src/routes/*.js"
    click NodeControllers "https://github.com/abelheddy/simplepos/blob/main/Backend/node/src/controllers/*.js"
    click NodeModels "https://github.com/abelheddy/simplepos/blob/main/Backend/node/src/models/*.js"
    click NodeServer "https://github.com/abelheddy/simplepos/blob/main/Backend/node/src/server.js"
    click SQL "https://github.com/abelheddy/simplepos/blob/main/Productos.sql"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef go fill:#D8F5D0,stroke:#333,stroke-width:1px
    classDef node fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef db fill:#CCCCCC,stroke:#333,stroke-width:1px
    classDef external fill:#F5F5F5,stroke-dasharray: 5 5,stroke:#333,stroke-width:1px
```
