# rootme254/mitumba-shop architecture

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

- Interactive diagram: https://gitdiagram.com/rootme254/mitumba-shop
- Repository: https://github.com/rootme254/mitumba-shop

## Overview

1. This repository is a Next.js App Router application for retail/POS operations, not a generic website. The route structure and feature names suggest a store-management system covering sales, inventory, customers, staff, expenses, refunds, reporting, and layaway.

2. The app is organized primarily by route segment under `app/`, with each major business area exposed as its own page. Examples include `pos`, `products`, `customers`, `staff`, `expenses`, `refunds`, `reports`, `notifications`, `bales`, `layaway`, `dashboard`, and `diagnostic`.

3. The central transaction flow appears to live in the POS area. `app/pos/page.js`, `app/pos/sell/page.js`, `app/pos/shift-open/page.js`, and `app/pos/shift-close/page.js` indicate a cashier workflow with shift lifecycle management and an explicit sell path.

4. State and persistence are likely backed by Supabase. The presence of `lib/supabase.js` and `lib/supabase-server.js` implies both client-side and server-side access layers, while `lib/session.js` and `lib/auth.js` handle user/session concerns around that backend.

5. Authentication and route protection are enforced at the framework boundary. `middleware.js`, together with login-related code in `app/login/page.js`, suggests requests are gated before they reach protected application routes, rather than relying only on in-page checks.

6. There is a clear offline/PWA subsystem. `public/manifest.json`, `public/sw.js`, `components/SWRegistrar.jsx`, `components/PWAComponents.jsx`, and `app/offline/page.js` indicate the app is designed to install as a PWA and continue working in reduced-connectivity scenarios.

7. The offline support is not just cosmetic; `lib/offline.js` exists as a dedicated utility layer, so offline behavior is treated as a first-class architectural concern rather than a browser add-on. The offline page likely serves as a fallback or recovery surface when network access is unavailable.

8. Payment integration is present through `lib/mpesa.js`, which points to an external M-Pesa dependency. That means at least part of the sales flow likely coordinates with an external payment provider rather than using only local bookkeeping.

9. The application includes serverless/API functionality, but it is minimal compared with the page-based UI. The only explicit API route shown is `app/api/diagnostic/route.js`, which likely supports health checks, environment verification, or operational troubleshooting.

10. Shared layout and navigation are separated from business pages. `app/layout.js`, `components/NavWrapper.jsx`, and `components/BottomNav.jsx` suggest a reusable shell that wraps the different modules and probably supports a mobile-friendly navigation model.

11. Styling and static assets are standard Next.js concerns: `app/globals.css` provides global styles, while `public/` contains the web app manifest and service worker artifacts. `next.config.mjs`, `postcss.config.mjs`, and `eslint.config.mjs` indicate normal app build/tooling boundaries rather than custom infrastructure.

12. The top-level `dashboard`, `reports`, and `diagnostic` pages act as operational views rather than core transaction entry points. In an architecture diagram, these should sit as read/monitoring surfaces fed by the same backend data used by POS and inventory features.

13. Overall data flow is: authenticated user enters via login, middleware protects routes, feature pages read/write through Supabase-backed helpers, POS and payment actions may call M-Pesa, and the PWA layer plus service worker supports offline access and installable behavior.

Main entry points: [`lib/supabase.js`](https://github.com/rootme254/mitumba-shop/blob/main/lib/supabase.js) (Supabase Client), [`app/pos/page.js`](https://github.com/rootme254/mitumba-shop/blob/main/app/pos/page.js) (POS), [`components/PWAComponents.jsx`](https://github.com/rootme254/mitumba-shop/blob/main/components/PWAComponents.jsx) (PWA Layer), [`lib/supabase-server.js`](https://github.com/rootme254/mitumba-shop/blob/main/lib/supabase-server.js) (Supabase Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_app["App Router"]
  node_node_login["Login<br/>auth page<br/>[page.js]"]
  node_node_offline_page["Offline<br/>fallback page<br/>[page.js]"]
  node_node_pos(("POS<br/>sales workflow<br/>[page.js]"))
  node_node_shift(("Shift Ops<br/>cashier flow<br/>[page.js]"))
  node_node_sell(("Sell<br/>sale flow<br/>[page.js]"))
  node_node_products["Products<br/>inventory page<br/>[page.js]"]
  node_node_customers["Customers<br/>crm page<br/>[page.js]"]
  node_node_staff["Staff<br/>ops page<br/>[page.js]"]
  node_node_expenses["Expenses<br/>finance page<br/>[page.js]"]
  node_node_refunds["Refunds<br/>returns page<br/>[page.js]"]
  node_node_reports["Reports<br/>analytics page<br/>[page.js]"]
  node_node_dashboard["Dashboard<br/>overview page<br/>[page.js]"]
  node_node_diagnostic["Diagnostic<br/>ops page<br/>[page.js]"]
  node_node_api_diag["API Diagnostic<br/>api route<br/>[route.js]"]
end

subgraph group_group_core["Core Services"]
  node_node_middleware{{"Middleware<br/>route guard<br/>[middleware.js]"}}
  node_node_auth["Auth<br/>[auth.js]"]
  node_node_session["Session<br/>[session.js]"]
  node_node_supabase_client[("Supabase Client<br/>data access<br/>[supabase.js]")]
  node_node_supabase_server[("Supabase Server<br/>data access<br/>[supabase-server.js]")]
  node_node_mpesa["M-Pesa<br/>payment adapter<br/>[mpesa.js]"]
  node_node_offline_lib["Offline Utils<br/>offline logic<br/>[offline.js]"]
end

subgraph group_group_shell["Shell & PWA"]
  node_node_layout["App Shell<br/>layout<br/>[layout.js]"]
  node_node_nav["Navigation<br/>ui shell<br/>[NavWrapper.jsx]"]
  node_node_pwa["PWA Layer<br/>pwa ui<br/>[PWAComponents.jsx]"]
  node_node_sw["Service Worker<br/>pwa asset<br/>[sw.js]"]
  node_node_manifest["Manifest<br/>pwa asset<br/>[manifest.json]"]
end

node_node_middleware -->|"gates"| node_node_login
node_node_middleware -->|"protects"| node_node_pos
node_node_middleware -->|"protects"| node_node_dashboard
node_node_layout -->|"wraps"| node_node_nav
node_node_layout -->|"includes"| node_node_pwa
node_node_pwa -->|"registers"| node_node_sw
node_node_pwa -->|"uses"| node_node_manifest
node_node_pwa -->|"fallback"| node_node_offline_page
node_node_offline_lib -->|"supports"| node_node_offline_page
node_node_login -->|"uses"| node_node_auth
node_node_auth -->|"manages"| node_node_session
node_node_auth -->|"checks"| node_node_supabase_server
node_node_pos -->|"coordinates"| node_node_shift
node_node_pos -->|"routes to"| node_node_sell
node_node_sell -->|"charges"| node_node_mpesa
node_node_pos -->|"reads/writes"| node_node_supabase_client
node_node_products -->|"reads/writes"| node_node_supabase_client
node_node_customers -->|"reads/writes"| node_node_supabase_client
node_node_staff -->|"reads/writes"| node_node_supabase_client
node_node_expenses -->|"reads/writes"| node_node_supabase_client
node_node_refunds -->|"reads/writes"| node_node_supabase_client
node_node_reports -->|"aggregates"| node_node_supabase_server
node_node_dashboard -->|"summarizes"| node_node_supabase_server
node_node_diagnostic -->|"calls"| node_node_api_diag
node_node_api_diag -->|"verifies"| node_node_supabase_server

click node_node_login "https://github.com/rootme254/mitumba-shop/blob/main/app/login/page.js"
click node_node_middleware "https://github.com/rootme254/mitumba-shop/blob/main/middleware.js"
click node_node_layout "https://github.com/rootme254/mitumba-shop/blob/main/app/layout.js"
click node_node_nav "https://github.com/rootme254/mitumba-shop/blob/main/components/NavWrapper.jsx"
click node_node_pwa "https://github.com/rootme254/mitumba-shop/blob/main/components/PWAComponents.jsx"
click node_node_offline_page "https://github.com/rootme254/mitumba-shop/blob/main/app/offline/page.js"
click node_node_sw "https://github.com/rootme254/mitumba-shop/blob/main/public/sw.js"
click node_node_manifest "https://github.com/rootme254/mitumba-shop/blob/main/public/manifest.json"
click node_node_auth "https://github.com/rootme254/mitumba-shop/blob/main/lib/auth.js"
click node_node_session "https://github.com/rootme254/mitumba-shop/blob/main/lib/session.js"
click node_node_supabase_client "https://github.com/rootme254/mitumba-shop/blob/main/lib/supabase.js"
click node_node_supabase_server "https://github.com/rootme254/mitumba-shop/blob/main/lib/supabase-server.js"
click node_node_mpesa "https://github.com/rootme254/mitumba-shop/blob/main/lib/mpesa.js"
click node_node_pos "https://github.com/rootme254/mitumba-shop/blob/main/app/pos/page.js"
click node_node_shift "https://github.com/rootme254/mitumba-shop/blob/main/app/pos/shift-open/page.js"
click node_node_sell "https://github.com/rootme254/mitumba-shop/blob/main/app/pos/sell/page.js"
click node_node_products "https://github.com/rootme254/mitumba-shop/blob/main/app/products/page.js"
click node_node_customers "https://github.com/rootme254/mitumba-shop/blob/main/app/customers/page.js"
click node_node_staff "https://github.com/rootme254/mitumba-shop/blob/main/app/staff/page.js"
click node_node_expenses "https://github.com/rootme254/mitumba-shop/blob/main/app/expenses/page.js"
click node_node_refunds "https://github.com/rootme254/mitumba-shop/blob/main/app/refunds/page.js"
click node_node_reports "https://github.com/rootme254/mitumba-shop/blob/main/app/reports/page.js"
click node_node_dashboard "https://github.com/rootme254/mitumba-shop/blob/main/app/dashboard/page.js"
click node_node_diagnostic "https://github.com/rootme254/mitumba-shop/blob/main/app/diagnostic/page.js"
click node_node_api_diag "https://github.com/rootme254/mitumba-shop/blob/main/app/api/diagnostic/route.js"
click node_node_offline_lib "https://github.com/rootme254/mitumba-shop/blob/main/lib/offline.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_node_login,node_node_offline_page,node_node_pos,node_node_shift,node_node_sell,node_node_products,node_node_customers,node_node_staff,node_node_expenses,node_node_refunds,node_node_reports,node_node_dashboard,node_node_diagnostic,node_node_api_diag toneBlue
class node_node_middleware,node_node_auth,node_node_session,node_node_supabase_client,node_node_supabase_server,node_node_mpesa,node_node_offline_lib toneAmber
class node_node_layout,node_node_nav,node_node_pwa,node_node_sw,node_node_manifest toneMint
```

## Components

### App Router

Route-driven UI and server endpoints

- [Login](https://github.com/rootme254/mitumba-shop/blob/main/app/login/page.js): auth page · Entry page for user sign-in · `app/login/page.js`
- [Offline](https://github.com/rootme254/mitumba-shop/blob/main/app/offline/page.js): fallback page · Dedicated offline/recovery surface · `app/offline/page.js`
- [POS](https://github.com/rootme254/mitumba-shop/blob/main/app/pos/page.js): sales workflow · Cashier entry point and transaction flow · `app/pos/page.js`
- [Shift Ops](https://github.com/rootme254/mitumba-shop/blob/main/app/pos/shift-open/page.js): cashier flow · Open and close shift lifecycle · `app/pos/shift-open/page.js`
- [Sell](https://github.com/rootme254/mitumba-shop/blob/main/app/pos/sell/page.js): sale flow · Explicit sale checkout path · `app/pos/sell/page.js`
- [Products](https://github.com/rootme254/mitumba-shop/blob/main/app/products/page.js): inventory page · Product and catalogue management · `app/products/page.js`
- [Customers](https://github.com/rootme254/mitumba-shop/blob/main/app/customers/page.js): crm page · Customer records and interactions · `app/customers/page.js`
- [Staff](https://github.com/rootme254/mitumba-shop/blob/main/app/staff/page.js): ops page · Employee and staff management · `app/staff/page.js`
- [Expenses](https://github.com/rootme254/mitumba-shop/blob/main/app/expenses/page.js): finance page · Operational spending management · `app/expenses/page.js`
- [Refunds](https://github.com/rootme254/mitumba-shop/blob/main/app/refunds/page.js): returns page · Refund processing and reversals · `app/refunds/page.js`
- [Reports](https://github.com/rootme254/mitumba-shop/blob/main/app/reports/page.js): analytics page · Operational reporting and summaries · `app/reports/page.js`
- [Dashboard](https://github.com/rootme254/mitumba-shop/blob/main/app/dashboard/page.js): overview page · High-level operational summary · `app/dashboard/page.js`
- [Diagnostic](https://github.com/rootme254/mitumba-shop/blob/main/app/diagnostic/page.js): ops page · Troubleshooting and health surface · `app/diagnostic/page.js`
- [API Diagnostic](https://github.com/rootme254/mitumba-shop/blob/main/app/api/diagnostic/route.js): api route · Server endpoint for checks and diagnostics · `app/api/diagnostic/route.js`

### Core Services

Auth, session, persistence, payment, and offline helpers

- [Middleware](https://github.com/rootme254/mitumba-shop/blob/main/middleware.js): route guard · Protects app routes before they load · `middleware.js`
- [Auth](https://github.com/rootme254/mitumba-shop/blob/main/lib/auth.js): session auth · Authentication and session helpers · `lib/auth.js`
- [Session](https://github.com/rootme254/mitumba-shop/blob/main/lib/session.js): session state · Session handling utilities · `lib/session.js`
- [Supabase Client](https://github.com/rootme254/mitumba-shop/blob/main/lib/supabase.js): data access · Client-side Supabase access layer · `lib/supabase.js`
- [Supabase Server](https://github.com/rootme254/mitumba-shop/blob/main/lib/supabase-server.js): data access · Server-side Supabase access layer · `lib/supabase-server.js`
- [M-Pesa](https://github.com/rootme254/mitumba-shop/blob/main/lib/mpesa.js): payment adapter · External payment integration for sales · `lib/mpesa.js`
- [Offline Utils](https://github.com/rootme254/mitumba-shop/blob/main/lib/offline.js): offline logic · Offline behavior and sync helpers · `lib/offline.js`

### Shell & PWA

Shared layout, navigation, and install/offline support

- [App Shell](https://github.com/rootme254/mitumba-shop/blob/main/app/layout.js): layout · Root layout for the application · `app/layout.js`
- [Navigation](https://github.com/rootme254/mitumba-shop/blob/main/components/NavWrapper.jsx): ui shell · Shared navigation wrappers and bottom nav · `components/NavWrapper.jsx`
- [PWA Layer](https://github.com/rootme254/mitumba-shop/blob/main/components/PWAComponents.jsx): pwa ui · Service worker registration and offline-aware UI · `components/PWAComponents.jsx`
- [Service Worker](https://github.com/rootme254/mitumba-shop/blob/main/public/sw.js): pwa asset · Installable app and caching runtime · `public/sw.js`
- [Manifest](https://github.com/rootme254/mitumba-shop/blob/main/public/manifest.json): pwa asset · Web app install metadata · `public/manifest.json`

## Connections

- Middleware → Login: gates · Unauthenticated users are routed to login
- Middleware → POS: protects · Middleware shields protected app areas
- Middleware → Dashboard: protects · Middleware shields protected app areas
- App Shell → Navigation: wraps · Shared shell composes navigation
- App Shell → PWA Layer: includes · Root layout enables PWA behavior
- PWA Layer → Service Worker: registers · Client layer hooks up the service worker
- PWA Layer → Manifest: uses · PWA UI depends on install metadata
- PWA Layer → Offline: fallback · Offline UI points to recovery surface
- Offline Utils → Offline: supports · Offline helpers back the offline route
- Login → Auth: uses · Login relies on auth helpers
- Auth → Session: manages · Authentication builds on session state
- Auth → Supabase Server: checks · Server-side auth integrates with backend access
- POS → Shift Ops: coordinates · POS includes shift lifecycle actions
- POS → Sell: routes to · Sales flow branches into checkout
- Sell → M-Pesa: charges · Checkout may invoke external payment handling
- POS → Supabase Client: reads/writes · Client POS state persists through Supabase
- Products → Supabase Client: reads/writes · Inventory data is managed through Supabase
- Customers → Supabase Client: reads/writes · Customer records persist through Supabase
- Staff → Supabase Client: reads/writes · Staff data persists through Supabase
- Expenses → Supabase Client: reads/writes · Expense records persist through Supabase
- Refunds → Supabase Client: reads/writes · Refund records persist through Supabase
- Reports → Supabase Server: aggregates · Reports likely compute from server data access
- Dashboard → Supabase Server: summarizes · Dashboard is fed by backend data
- Diagnostic → API Diagnostic: calls · Diagnostic page can hit the API health endpoint
- API Diagnostic → Supabase Server: verifies · API diagnostic can validate server-side access
