# inkithai/pizza-billing-app architecture

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

- Interactive diagram: https://gitdiagram.com/inkithai/pizza-billing-app
- Repository: https://github.com/inkithai/pizza-billing-app

## Overview

##### Project Type and Purpose
- This is a full‐stack web application (“Pizza Billing Application”) for managing menu items and customer invoices for a pizza shop.
- Frontend: React-based SPA running on Node.js (port 3000).
- Backend: RESTful API server in Go (Gin or net/http) running on port 8080.
- Database: MySQL (database name: pizza_billing), accessed via Go’s database driver.

##### Key Architectural Components
a. Presentation Layer (Frontend)
- Browser / User
- React SPA (frontend/src):
- Components: Navbar, Welcome, ItemManagement, InvoiceManagement, InvoicePrint
- Third-party libs: react-to-print for invoice printing
- Static assets (frontend/public)
b. API Layer (Backend)
- HTTP Server (backend/main.go)
- Middleware (CORS handler in backend/middleware/cors.go)
- Routing (backend/routes/routes.go)
- Controllers (backend/controllers): invoice_controller.go, item_controller.go
- Models (backend/models): invoice.go, item.go
- Config (backend/config/db.go): MySQL connection setup
c. Data Layer
- MySQL database (“pizza_billing”)
- Tables: items, invoices (implied by models)
d. External Systems
- MySQL server (XAMPP stack)
- Printer (via browser’s print dialog triggered by react-to-print)

##### Interactions and Data Flow
- User interacts with the React UI in the browser.
- React app issues HTTP(S) requests to the Go API endpoints:
- /items (GET, POST), /items/{id} (GET, PUT, DELETE)
- /invoices (GET, POST), /invoices/{id} (GET, DELETE)
- API middleware handles CORS, then routes requests to controllers.
- Controllers invoke model methods to perform SQL queries.
- Models communicate with the MySQL database and return data or status.
- API serializes responses (JSON) back to the React app.
- For printing, the InvoicePrint component uses react-to-print to open the browser’s print dialog.

##### Architectural Patterns and Principles
- Layered (n-tier) architecture: Presentation → API/Business → Data
- MVC-style separation in backend: routes → controllers → models
- Single-Page Application pattern in frontend
- RESTful API design for CRUD operations
- CORS middleware to allow cross‐origin calls (frontend ↔ backend)

a. Components / Containers
- Browser / User
- React SPA (Node.js container)
- Go API Server (Go runtime container)
- MySQL Database
- Printer (external)
b. Relationships / Data Flows
c. Technologies & Frameworks
- Frontend: React, Node.js, react-to-print
- Backend: Go (go.mod), net/http or Gin, MySQL driver
- Database: MySQL (XAMPP)
d. Detailed Backend Sub‐components
- Middleware layer (CORS)
- Routing layer → controller functions
- Data access layer (models, config/db.go)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Browser / User"]:::external
        ReactSPA["React SPA (Node.js, port 3000)"]:::frontend
        subgraph "React Components"
            direction TB
            Navbar["Navbar"]:::frontend
            Welcome["Welcome"]:::frontend
            ItemManagement["ItemManagement"]:::frontend
            InvoiceManagement["InvoiceManagement"]:::frontend
            InvoicePrint["InvoicePrint"]:::frontend
        end
        StaticAssets["Static Assets"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        APIServer["Go API Server (port 8080)\nEndpoints: /items, /items/{id}, /invoices, /invoices/{id}"]:::backend
        CORS["CORS Middleware"]:::backend
        Routing["Routing"]:::backend
        subgraph "Controllers"
            direction TB
            invoice_ctrl["InvoiceController"]:::backend
            item_ctrl["ItemController"]:::backend
        end
        subgraph "Models & Config"
            direction TB
            invoice_model["InvoiceModel"]:::data
            item_model["ItemModel"]:::data
            DBConfig["DB Config"]:::backend
        end
    end

    %% Data Layer
    DB["MySQL Database\n(pizza_billing)"]:::data

    %% External Systems
    Printer["Printer (Browser Print Dialog)"]:::external

    %% Connections
    Browser -->|"UI Interaction"| ReactSPA
    ReactSPA -->|"HTTP/JSON"| APIServer
    APIServer --> CORS
    CORS --> Routing
    Routing --> invoice_ctrl
    Routing --> item_ctrl
    invoice_ctrl --> invoice_model
    item_ctrl --> item_model
    invoice_model -->|"SQL"| DB
    item_model -->|"SQL"| DB
    ReactSPA -->|"Print Command"| InvoicePrint
    InvoicePrint -->|"react-to-print"| Printer

    %% Click Events
    click ReactSPA "https://github.com/inkithai/pizza-billing-app/tree/main/frontend/src"
    click Navbar "https://github.com/inkithai/pizza-billing-app/blob/main/frontend/src/components/Navbar.js"
    click Welcome "https://github.com/inkithai/pizza-billing-app/blob/main/frontend/src/components/Welcome.js"
    click ItemManagement "https://github.com/inkithai/pizza-billing-app/blob/main/frontend/src/components/ItemManagement.js"
    click InvoiceManagement "https://github.com/inkithai/pizza-billing-app/blob/main/frontend/src/components/InvoiceManagement.js"
    click InvoicePrint "https://github.com/inkithai/pizza-billing-app/blob/main/frontend/src/components/InvoicePrint.js"
    click StaticAssets "https://github.com/inkithai/pizza-billing-app/tree/main/frontend/public"
    click APIServer "https://github.com/inkithai/pizza-billing-app/blob/main/backend/main.go"
    click CORS "https://github.com/inkithai/pizza-billing-app/blob/main/backend/middleware/cors.go"
    click Routing "https://github.com/inkithai/pizza-billing-app/blob/main/backend/routes/routes.go"
    click invoice_ctrl "https://github.com/inkithai/pizza-billing-app/blob/main/backend/controllers/invoice_controller.go"
    click item_ctrl "https://github.com/inkithai/pizza-billing-app/blob/main/backend/controllers/item_controller.go"
    click invoice_model "https://github.com/inkithai/pizza-billing-app/blob/main/backend/models/invoice.go"
    click item_model "https://github.com/inkithai/pizza-billing-app/blob/main/backend/models/item.go"
    click DBConfig "https://github.com/inkithai/pizza-billing-app/blob/main/backend/config/db.go"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef backend  fill:#E0F8D8,stroke:#28a745,color:#28a745
    classDef data     fill:#FFE8A0,stroke:#d97706,color:#d97706
    classDef external fill:#F0F0F0,stroke:#6a737d,color:#6a737d
```
