# error1904/stockpulse architecture

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

- Interactive diagram: https://gitdiagram.com/error1904/stockpulse
- Repository: https://github.com/error1904/stockpulse

## Overview

StockPulse is a native PHP warehouse inventory and stock-movement tracker. Users view a dashboard of stock, valuation, low-stock alerts, and recent movements; staff can submit transfers and manage sessions through Ajax. The controller coordinates page rendering and actions, while the model owns database operations, including transactional transfers and audit logging. A separate REST endpoint exposes valuation metrics. The excerpts show the main request and data paths; schema and some dashboard/model details are documented but not fully sampled.

Main entry points: [`controllers/StockController.php`](https://github.com/error1904/stockpulse/blob/main/controllers/StockController.php) (Request controller), [`config/Database.php`](https://github.com/error1904/stockpulse/blob/main/config/Database.php) (PDO connection), [`public/js/stock.js`](https://github.com/error1904/stockpulse/blob/main/public/js/stock.js) (Ajax handlers), [`models/StockModel.php`](https://github.com/error1904/stockpulse/blob/main/models/StockModel.php) (Inventory queries)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_router["Front router<br/>[index.php]"]
  node_controller["Request controller"]
  node_ajax["Ajax handlers<br/>[stock.js]"]
  node_dashboard["Dashboard view<br/>[dashboard.php]"]
  node_header["Page header<br/>[header.php]"]
  node_footer["Page footer<br/>[footer.php]"]
end

subgraph group_domain["Stock operations"]
  node_stockreads["Inventory queries<br/>[StockModel.php]"]
  node_transfer["Transfer transaction<br/>[StockModel.php]"]
  node_authentication["Session authentication<br/>[StockModel.php]"]
end

subgraph group_data["Persistence"]
  node_database["PDO connection<br/>[Database.php]"]
  node_mysql[("StockPulse database<br/>[schema.sql]")]
end

subgraph group_api["Valuation API"]
  node_valuation["Valuation endpoint<br/>[valuation.php]"]
end

node_browser(("User browser"))
node_apiuser(("API consumer"))

node_browser -->|"requests pages"| node_router
node_router -->|"routes requests"| node_controller
node_controller -->|"renders dashboard"| node_dashboard
node_controller -->|"renders layout"| node_header
node_controller -->|"renders layout"| node_footer
node_footer -->|"loads handlers"| node_ajax
node_browser -->|"submits actions"| node_ajax
node_ajax -->|"posts Ajax actions"| node_controller
node_controller -->|"loads dashboard data"| node_stockreads
node_controller -->|"executes transfers"| node_transfer
node_controller -->|"checks user"| node_authentication
node_stockreads -->|"uses connection"| node_database
node_transfer -->|"uses connection"| node_database
node_authentication -->|"uses connection"| node_database
node_database -->|"connects via PDO"| node_mysql
node_browser -->|"requests metrics"| node_valuation
node_valuation -->|"queries metrics"| node_stockreads
node_apiuser -->|"requests JSON"| node_valuation

click node_router "https://github.com/error1904/stockpulse/blob/main/public/index.php"
click node_controller "https://github.com/error1904/stockpulse/blob/main/controllers/StockController.php"
click node_ajax "https://github.com/error1904/stockpulse/blob/main/public/js/stock.js"
click node_dashboard "https://github.com/error1904/stockpulse/blob/main/views/dashboard.php"
click node_header "https://github.com/error1904/stockpulse/blob/main/views/layout/header.php"
click node_footer "https://github.com/error1904/stockpulse/blob/main/views/layout/footer.php"
click node_stockreads "https://github.com/error1904/stockpulse/blob/main/models/StockModel.php"
click node_transfer "https://github.com/error1904/stockpulse/blob/main/models/StockModel.php"
click node_authentication "https://github.com/error1904/stockpulse/blob/main/models/StockModel.php"
click node_database "https://github.com/error1904/stockpulse/blob/main/config/Database.php"
click node_mysql "https://github.com/error1904/stockpulse/blob/main/schema.sql"
click node_valuation "https://github.com/error1904/stockpulse/blob/main/api/v1/valuation.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_router,node_controller,node_ajax,node_dashboard,node_header,node_footer,node_browser toneBlue
class node_stockreads,node_transfer,node_authentication toneAmber
class node_database,node_mysql,node_apiuser toneMint
class node_valuation toneRose
```

## Components

### Web experience

- [Front router](https://github.com/error1904/stockpulse/blob/main/public/index.php): `public/index.php`
- [Request controller](https://github.com/error1904/stockpulse/blob/main/controllers/StockController.php): `controllers/StockController.php`
- [Ajax handlers](https://github.com/error1904/stockpulse/blob/main/public/js/stock.js): `public/js/stock.js`
- [Dashboard view](https://github.com/error1904/stockpulse/blob/main/views/dashboard.php): `views/dashboard.php`
- [Page header](https://github.com/error1904/stockpulse/blob/main/views/layout/header.php): `views/layout/header.php`
- [Page footer](https://github.com/error1904/stockpulse/blob/main/views/layout/footer.php): `views/layout/footer.php`

### Stock operations

- [Inventory queries](https://github.com/error1904/stockpulse/blob/main/models/StockModel.php): `models/StockModel.php`
- [Transfer transaction](https://github.com/error1904/stockpulse/blob/main/models/StockModel.php): `models/StockModel.php`
- [Session authentication](https://github.com/error1904/stockpulse/blob/main/models/StockModel.php): `models/StockModel.php`

### Persistence

- [PDO connection](https://github.com/error1904/stockpulse/blob/main/config/Database.php): `config/Database.php`
- [StockPulse database](https://github.com/error1904/stockpulse/blob/main/schema.sql): `schema.sql`

### Valuation API

- [Valuation endpoint](https://github.com/error1904/stockpulse/blob/main/api/v1/valuation.php): `api/v1/valuation.php`

### Other components

- **User browser**
- **API consumer**

## Connections

- User browser → Front router: requests pages (evidence: `README.md`)
- Front router → Request controller: routes requests (evidence: `public/index.php`)
- Request controller → Dashboard view: renders dashboard (evidence: `controllers/StockController.php`)
- Request controller → Page header: renders layout (evidence: `controllers/StockController.php`)
- Request controller → Page footer: renders layout (evidence: `controllers/StockController.php`)
- Page footer → Ajax handlers: loads handlers (evidence: `views/layout/footer.php`)
- User browser → Ajax handlers: submits actions (evidence: `public/js/stock.js`)
- Ajax handlers → Request controller: posts Ajax actions (evidence: `public/js/stock.js`)
- Request controller → Inventory queries: loads dashboard data (evidence: `controllers/StockController.php`)
- Request controller → Transfer transaction: executes transfers (evidence: `controllers/StockController.php`)
- Request controller → Session authentication: checks user (evidence: `controllers/StockController.php`)
- Inventory queries → PDO connection: uses connection (evidence: `models/StockModel.php`)
- Transfer transaction → PDO connection: uses connection (evidence: `models/StockModel.php`)
- Session authentication → PDO connection: uses connection (evidence: `models/StockModel.php`)
- PDO connection → StockPulse database: connects via PDO (evidence: `config/Database.php`)
- User browser → Valuation endpoint: requests metrics (evidence: `README.md`)
- Valuation endpoint → Inventory queries: queries metrics (evidence: `api/v1/valuation.php`)
- API consumer → Valuation endpoint: requests JSON (evidence: `README.md`)
