# saklinefarabee/erp-peer architecture

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

- Interactive diagram: https://gitdiagram.com/saklinefarabee/erp-peer
- Repository: https://github.com/saklinefarabee/erp-peer

## Overview

1. **High-level shape**
   ERP-PEER is a two-tier full-stack ERP app: a React/Vite frontend for the operator UI and a Node/Express backend for all business data, analytics, and AI calls. The frontend and backend run separately in development on `5173` and `5000`, respectively.

2. **Frontend: single-page application shell**
   The client is organized as a SPA with `client/src/App.jsx` as the main composition point. The UI is built from a small set of shared layout components, notably `Header.jsx` and `Sidebar.jsx`, which frame the application and provide navigation across business modules.

3. **Frontend: module-based pages**
   The main screens are separated into page-level views under `client/src/pages`: `Dashboard`, `Products`, `Orders`, `Customers`, and `AIHelper`. This indicates a domain-oriented UI, where each business function gets its own page and interacts with the backend through API requests.

4. **Frontend technology boundary**
   The client uses React 18 with Vite for fast local development and bundling, Tailwind CSS for styling, and Axios for HTTP calls. In architecture terms, the frontend is presentation and interaction only; it does not appear to own business state beyond transient UI state.

5. **Backend: Express API layer**
   The server entry point is `server/index.js`, which likely boots the Express app and mounts the route modules under `/api/*`. The backend is the only place where persistent business logic lives: CRUD, analytics aggregation, and AI request handling.

6. **Backend domain modules**
   Route files are separated by business concern: `dashboard.js`, `products.js`, `orders.js`, `customers.js`, and AI-related routes under `ai.js` / `aiRouter.js`. This separation maps cleanly to the app’s functional areas and is the clearest boundary for an architecture diagram.

7. **Data storage**
   Persistence is handled by SQLite, with database setup in `server/db/database.js`. The README notes that the database initializes automatically on first server start and ships with sample data, so the system is designed to be runnable immediately without external infrastructure.

8. **Core data flow**
   The standard flow is: user interacts with a page in the React client, the page issues an API request to the Express server, the server reads/writes SQLite, and JSON results are returned to update the UI. The dashboard is an aggregation endpoint rather than a separate storage model, pulling metrics from the same underlying business tables.

9. **AI helper flow**
   The AI Helper is a separate backend integration that requires `GEMINI_API_KEY`. The frontend sends prompts to the AI API, the server forwards them to Google Gemini, and the response is returned to the UI. This is an external-service boundary distinct from the ERP database flow.

10. **Operational/configuration boundaries**
   Runtime configuration is environment-driven, with `PORT`, `NODE_ENV`, and `GEMINI_API_KEY` in `server/.env`. The root project supports combined install/start workflows, while frontend and backend can also be developed independently. This makes the repo deployable as two units: a static frontend build and a Node backend API.

11. **What matters for an architecture diagram**
   The important nodes are: browser/client SPA, Express API server, SQLite database, and Gemini API. The important arrows are: UI requests to REST endpoints, API reads/writes to SQLite, dashboard aggregation from the same DB, and AI requests from the server to Gemini.

Main entry points: [`server/index.js`](https://github.com/saklinefarabee/erp-peer/blob/main/server/index.js) (API server), [`client/src/App.jsx`](https://github.com/saklinefarabee/erp-peer/blob/main/client/src/App.jsx) (App shell), [`server/db/database.js`](https://github.com/saklinefarabee/erp-peer/blob/main/server/db/database.js) (SQLite), [`client/src/pages/Dashboard.jsx`](https://github.com/saklinefarabee/erp-peer/blob/main/client/src/pages/Dashboard.jsx) (Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_browser(("Browser<br/>ui client"))
  node_app_shell["App shell<br/>React SPA<br/>[App.jsx]"]
  node_header["Header<br/>layout<br/>[Header.jsx]"]
  node_sidebar["Sidebar<br/>layout<br/>[Sidebar.jsx]"]
  node_dashboard_page["Dashboard<br/>page<br/>[Dashboard.jsx]"]
  node_products_page["Products<br/>page<br/>[Products.jsx]"]
  node_orders_page["Orders<br/>page<br/>[Orders.jsx]"]
  node_customers_page["Customers<br/>page<br/>[Customers.jsx]"]
  node_ai_page["AI Helper<br/>page<br/>[AIHelper.jsx]"]
end

subgraph group_server["Server"]
  node_api_server["API server<br/>Express app<br/>[index.js]"]
  node_dashboard_routes["Dashboard API<br/>route module<br/>[dashboard.js]"]
  node_products_routes["Products API<br/>route module<br/>[products.js]"]
  node_orders_routes["Orders API<br/>route module<br/>[orders.js]"]
  node_customers_routes["Customers API<br/>route module<br/>[customers.js]"]
  node_ai_routes["AI API<br/>route module<br/>[ai.js]"]
  node_database[("SQLite<br/>persistent store<br/>[database.js]")]
end

subgraph group_external["External"]
  node_gemini(("Gemini API<br/>external AI service"))
end

node_browser -->|"loads"| node_app_shell
node_app_shell -->|"composes"| node_header
node_app_shell -->|"composes"| node_sidebar
node_app_shell -->|"shows"| node_dashboard_page
node_app_shell -->|"shows"| node_products_page
node_app_shell -->|"shows"| node_orders_page
node_app_shell -->|"shows"| node_customers_page
node_app_shell -->|"shows"| node_ai_page
node_dashboard_page -->|"requests"| node_api_server
node_products_page -->|"requests"| node_api_server
node_orders_page -->|"requests"| node_api_server
node_customers_page -->|"requests"| node_api_server
node_ai_page -->|"prompts"| node_api_server
node_api_server -->|"mounts"| node_dashboard_routes
node_api_server -->|"mounts"| node_products_routes
node_api_server -->|"mounts"| node_orders_routes
node_api_server -->|"mounts"| node_customers_routes
node_api_server -->|"mounts"| node_ai_routes
node_dashboard_routes -->|"reads"| node_database
node_products_routes -->|"reads/writes"| node_database
node_orders_routes -->|"reads/writes"| node_database
node_customers_routes -->|"reads/writes"| node_database
node_ai_routes -->|"calls"| node_gemini
node_api_server -->|"uses"| node_database

click node_app_shell "https://github.com/saklinefarabee/erp-peer/blob/main/client/src/App.jsx"
click node_header "https://github.com/saklinefarabee/erp-peer/blob/main/client/src/components/Header.jsx"
click node_sidebar "https://github.com/saklinefarabee/erp-peer/blob/main/client/src/components/Sidebar.jsx"
click node_dashboard_page "https://github.com/saklinefarabee/erp-peer/blob/main/client/src/pages/Dashboard.jsx"
click node_products_page "https://github.com/saklinefarabee/erp-peer/blob/main/client/src/pages/Products.jsx"
click node_orders_page "https://github.com/saklinefarabee/erp-peer/blob/main/client/src/pages/Orders.jsx"
click node_customers_page "https://github.com/saklinefarabee/erp-peer/blob/main/client/src/pages/Customers.jsx"
click node_ai_page "https://github.com/saklinefarabee/erp-peer/blob/main/client/src/pages/AIHelper.jsx"
click node_api_server "https://github.com/saklinefarabee/erp-peer/blob/main/server/index.js"
click node_dashboard_routes "https://github.com/saklinefarabee/erp-peer/blob/main/server/routes/dashboard.js"
click node_products_routes "https://github.com/saklinefarabee/erp-peer/blob/main/server/routes/products.js"
click node_orders_routes "https://github.com/saklinefarabee/erp-peer/blob/main/server/routes/orders.js"
click node_customers_routes "https://github.com/saklinefarabee/erp-peer/blob/main/server/routes/customers.js"
click node_ai_routes "https://github.com/saklinefarabee/erp-peer/blob/main/server/routes/ai.js"
click node_database "https://github.com/saklinefarabee/erp-peer/blob/main/server/db/database.js"

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_browser,node_app_shell,node_header,node_sidebar,node_dashboard_page,node_products_page,node_orders_page,node_customers_page,node_ai_page toneBlue
class node_api_server,node_dashboard_routes,node_products_routes,node_orders_routes,node_customers_routes,node_ai_routes,node_database toneAmber
class node_gemini toneMint
```

## Components

### Client

React/Vite SPA for operator workflows.

- **Browser**: ui client · Operator-facing single-page application runtime.
- [App shell](https://github.com/saklinefarabee/erp-peer/blob/main/client/src/App.jsx): React SPA · Main client composition point for navigation and page routing. · `client/src/App.jsx`
- [Header](https://github.com/saklinefarabee/erp-peer/blob/main/client/src/components/Header.jsx): layout · Top-level application framing and status area. · `client/src/components/Header.jsx`
- [Sidebar](https://github.com/saklinefarabee/erp-peer/blob/main/client/src/components/Sidebar.jsx): layout · Primary navigation across ERP modules. · `client/src/components/Sidebar.jsx`
- [Dashboard](https://github.com/saklinefarabee/erp-peer/blob/main/client/src/pages/Dashboard.jsx): page · Aggregated operational overview screen. · `client/src/pages/Dashboard.jsx`
- [Products](https://github.com/saklinefarabee/erp-peer/blob/main/client/src/pages/Products.jsx): page · Product catalog management screen. · `client/src/pages/Products.jsx`
- [Orders](https://github.com/saklinefarabee/erp-peer/blob/main/client/src/pages/Orders.jsx): page · Order management screen. · `client/src/pages/Orders.jsx`
- [Customers](https://github.com/saklinefarabee/erp-peer/blob/main/client/src/pages/Customers.jsx): page · Customer management screen. · `client/src/pages/Customers.jsx`
- [AI Helper](https://github.com/saklinefarabee/erp-peer/blob/main/client/src/pages/AIHelper.jsx): page · Prompt-based assistant interface. · `client/src/pages/AIHelper.jsx`

### Server

Express API, business logic, and persistence.

- [API server](https://github.com/saklinefarabee/erp-peer/blob/main/server/index.js): Express app · Backend entry point for ERP data and AI requests. · `server/index.js`
- [Dashboard API](https://github.com/saklinefarabee/erp-peer/blob/main/server/routes/dashboard.js): route module · Metrics and summary endpoints. · `server/routes/dashboard.js`
- [Products API](https://github.com/saklinefarabee/erp-peer/blob/main/server/routes/products.js): route module · Product CRUD endpoints. · `server/routes/products.js`
- [Orders API](https://github.com/saklinefarabee/erp-peer/blob/main/server/routes/orders.js): route module · Order workflow endpoints. · `server/routes/orders.js`
- [Customers API](https://github.com/saklinefarabee/erp-peer/blob/main/server/routes/customers.js): route module · Customer CRUD endpoints. · `server/routes/customers.js`
- [AI API](https://github.com/saklinefarabee/erp-peer/blob/main/server/routes/ai.js): route module · Backend AI prompt handling and Gemini forwarding. · `server/routes/ai.js`
- [SQLite](https://github.com/saklinefarabee/erp-peer/blob/main/server/db/database.js): persistent store · Local ERP data store initialized on server start. · `server/db/database.js`

### External

Outside services used by the backend.

- **Gemini API**: external AI service · Google Gemini integration for AI helper responses.

## Connections

- Browser → App shell: loads · The browser opens the React SPA.
- App shell → Header: composes · App shell renders the shared header.
- App shell → Sidebar: composes · App shell renders the shared navigation.
- App shell → Dashboard: shows · App shell routes to the dashboard view.
- App shell → Products: shows · App shell routes to the products view.
- App shell → Orders: shows · App shell routes to the orders view.
- App shell → Customers: shows · App shell routes to the customers view.
- App shell → AI Helper: shows · App shell routes to the AI helper view.
- Dashboard → API server: requests · Dashboard fetches aggregated metrics from the backend.
- Products → API server: requests · Product screen reads and writes via REST APIs.
- Orders → API server: requests · Order screen reads and writes via REST APIs.
- Customers → API server: requests · Customer screen reads and writes via REST APIs.
- AI Helper → API server: prompts · AI helper sends user prompts to the backend.
- API server → Dashboard API: mounts · Server exposes dashboard endpoints.
- API server → Products API: mounts · Server exposes product endpoints.
- API server → Orders API: mounts · Server exposes order endpoints.
- API server → Customers API: mounts · Server exposes customer endpoints.
- API server → AI API: mounts · Server exposes AI endpoints.
- Dashboard API → SQLite: reads · Dashboard aggregates data from SQLite.
- Products API → SQLite: reads/writes · Product APIs persist catalog data in SQLite.
- Orders API → SQLite: reads/writes · Order APIs persist workflow data in SQLite.
- Customers API → SQLite: reads/writes · Customer APIs persist CRM data in SQLite.
- AI API → Gemini API: calls · Backend forwards prompts to Gemini.
- API server → SQLite: uses · Server shares the local database connection.
