# prince-codes/invoice_v2 architecture

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

- Interactive diagram: https://gitdiagram.com/prince-codes/invoice_v2
- Repository: https://github.com/prince-codes/invoice_v2

## Overview

This is a shop-specific invoicing application. The user signs in, chooses one of three bill-entry workflows, saves or prints invoices, and can revisit local or cloud history. Cloud Invoice Management adds review, editing, deletion, consolidated printing and exports. The browser modules handle invoice-specific entry and presentation; shared client code supports authentication and cloud synchronization, while Pages Functions protect routes and provide invoice and numbering APIs backed by D1. Workflow and management capabilities are documented in the README; unsampled implementation details are not inferred.

Main entry points: [`Selection/selection.js`](https://github.com/prince-codes/invoice_v2/blob/main/Selection/selection.js) (Workflow selection), [`Management/management.js`](https://github.com/prince-codes/invoice_v2/blob/main/Management/management.js) (Cloud management), [`Mod 1/js/main.js`](https://github.com/prince-codes/invoice_v2/blob/main/Mod%201/js/main.js) (Mod 1 monthly), [`Mod 2/js/main.js`](https://github.com/prince-codes/invoice_v2/blob/main/Mod%202/js/main.js) (Mod 2 daily)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and navigation"]
  node_login["Sign in<br/>[login.js]"]
  node_selection["Workflow selection<br/>[selection.js]"]
end

subgraph group_billing["Invoice workflows"]
  node_mod1["Mod 1 monthly<br/>[main.js]"]
  node_mod2["Mod 2 daily<br/>[main.js]"]
  node_mod3["Mod 3 old method<br/>[main.js]"]
  node_management["Cloud management<br/>[management.js]"]
  node_excel_export["Excel export helper<br/>[excel-export.js]"]
end

subgraph group_cloud["Cloud records"]
  node_cloud_sync["Cloud sync client<br/>[cloud-sync.js]"]
  node_invoice_api["Invoice API<br/>[invoices.js]"]
  node_number_api["Number allocator<br/>[next-id.js]"]
  node_local_store[("Browser invoice history")]
  node_d1[("Shared D1 database")]
end

subgraph group_security["Authentication"]
  node_auth_client["Auth client<br/>[auth-client.js]"]
  node_middleware["Route protection<br/>[_middleware.js]"]
  node_auth_core["Session utilities<br/>[_auth.js]"]
  node_auth_login["Login endpoint<br/>[login.js]"]
  node_auth_session["Session endpoint<br/>[session.js]"]
  node_auth_logout["Logout endpoint<br/>[logout.js]"]
end

node_shop_user(("Shop user"))

node_shop_user -->|"signs in"| node_login
node_login -->|"submits credentials"| node_auth_login
node_shop_user -->|"chooses workflow"| node_selection
node_selection -->|"opens"| node_mod1
node_selection -->|"opens"| node_mod2
node_selection -->|"opens"| node_mod3
node_selection -->|"opens"| node_management
node_mod1 -->|"saves invoices"| node_local_store
node_mod2 -->|"saves invoices"| node_local_store
node_mod3 -->|"saves invoices"| node_local_store
node_mod1 -->|"syncs history"| node_cloud_sync
node_mod2 -->|"syncs history"| node_cloud_sync
node_mod3 -->|"syncs history"| node_cloud_sync
node_cloud_sync -->|"requests records"| node_invoice_api
node_invoice_api -->|"reads and writes"| node_d1
node_number_api -->|"allocates numbers"| node_d1
node_management -->|"manages records"| node_invoice_api
node_management -->|"opens print layout"| node_mod1
node_management -->|"opens print layout"| node_mod2
node_management -->|"exports records"| node_excel_export
node_mod1 -.->|"exports history"| node_excel_export
node_mod2 -.->|"exports history"| node_excel_export
node_mod3 -.->|"exports history"| node_excel_export
node_auth_client -->|"checks session"| node_auth_session
node_auth_client -->|"requests logout"| node_auth_logout
node_middleware -->|"validates session"| node_auth_core
node_auth_login -->|"creates session"| node_auth_core
node_auth_session -->|"checks user"| node_auth_core
node_auth_logout -->|"clears cookie"| node_auth_core

click node_login "https://github.com/prince-codes/invoice_v2/blob/main/login.js"
click node_selection "https://github.com/prince-codes/invoice_v2/blob/main/Selection/selection.js"
click node_mod1 "https://github.com/prince-codes/invoice_v2/blob/main/Mod%201/js/main.js"
click node_mod2 "https://github.com/prince-codes/invoice_v2/blob/main/Mod%202/js/main.js"
click node_mod3 "https://github.com/prince-codes/invoice_v2/blob/main/Mod%203/js/main.js"
click node_management "https://github.com/prince-codes/invoice_v2/blob/main/Management/management.js"
click node_auth_client "https://github.com/prince-codes/invoice_v2/blob/main/auth-client.js"
click node_middleware "https://github.com/prince-codes/invoice_v2/blob/main/functions/_middleware.js"
click node_auth_core "https://github.com/prince-codes/invoice_v2/blob/main/functions/_auth.js"
click node_auth_login "https://github.com/prince-codes/invoice_v2/blob/main/functions/api/auth/login.js"
click node_auth_session "https://github.com/prince-codes/invoice_v2/blob/main/functions/api/auth/session.js"
click node_auth_logout "https://github.com/prince-codes/invoice_v2/blob/main/functions/api/auth/logout.js"
click node_cloud_sync "https://github.com/prince-codes/invoice_v2/blob/main/cloud-sync.js"
click node_invoice_api "https://github.com/prince-codes/invoice_v2/blob/main/functions/api/invoices.js"
click node_number_api "https://github.com/prince-codes/invoice_v2/blob/main/functions/api/invoices/next-id.js"
click node_excel_export "https://github.com/prince-codes/invoice_v2/blob/main/Assets/excel-export.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_login,node_selection,node_shop_user toneBlue
class node_mod1,node_mod2,node_mod3,node_management,node_excel_export toneAmber
class node_cloud_sync,node_invoice_api,node_number_api,node_local_store,node_d1 toneMint
class node_auth_client,node_middleware,node_auth_core,node_auth_login,node_auth_session,node_auth_logout toneRose
```

## Components

### Access and navigation

- [Sign in](https://github.com/prince-codes/invoice_v2/blob/main/login.js): `login.js`
- [Workflow selection](https://github.com/prince-codes/invoice_v2/blob/main/Selection/selection.js): `Selection/selection.js`

### Invoice workflows

- [Mod 1 monthly](https://github.com/prince-codes/invoice_v2/blob/main/Mod%201/js/main.js): `Mod 1/js/main.js`
- [Mod 2 daily](https://github.com/prince-codes/invoice_v2/blob/main/Mod%202/js/main.js): `Mod 2/js/main.js`
- [Mod 3 old method](https://github.com/prince-codes/invoice_v2/blob/main/Mod%203/js/main.js): `Mod 3/js/main.js`
- [Cloud management](https://github.com/prince-codes/invoice_v2/blob/main/Management/management.js): `Management/management.js`
- [Excel export helper](https://github.com/prince-codes/invoice_v2/blob/main/Assets/excel-export.js): `Assets/excel-export.js`

### Cloud records

- [Cloud sync client](https://github.com/prince-codes/invoice_v2/blob/main/cloud-sync.js): `cloud-sync.js`
- [Invoice API](https://github.com/prince-codes/invoice_v2/blob/main/functions/api/invoices.js): `functions/api/invoices.js`
- [Number allocator](https://github.com/prince-codes/invoice_v2/blob/main/functions/api/invoices/next-id.js): `functions/api/invoices/next-id.js`
- **Browser invoice history**
- **Shared D1 database**

### Authentication

- [Auth client](https://github.com/prince-codes/invoice_v2/blob/main/auth-client.js): `auth-client.js`
- [Route protection](https://github.com/prince-codes/invoice_v2/blob/main/functions/_middleware.js): `functions/_middleware.js`
- [Session utilities](https://github.com/prince-codes/invoice_v2/blob/main/functions/_auth.js): `functions/_auth.js`
- [Login endpoint](https://github.com/prince-codes/invoice_v2/blob/main/functions/api/auth/login.js): `functions/api/auth/login.js`
- [Session endpoint](https://github.com/prince-codes/invoice_v2/blob/main/functions/api/auth/session.js): `functions/api/auth/session.js`
- [Logout endpoint](https://github.com/prince-codes/invoice_v2/blob/main/functions/api/auth/logout.js): `functions/api/auth/logout.js`

### Other components

- **Shop user**

## Connections

- Shop user → Sign in: signs in (evidence: `README.md`)
- Sign in → Login endpoint: submits credentials (evidence: `README.md`)
- Shop user → Workflow selection: chooses workflow (evidence: `README.md`)
- Workflow selection → Mod 1 monthly: opens (evidence: `README.md`)
- Workflow selection → Mod 2 daily: opens (evidence: `README.md`)
- Workflow selection → Mod 3 old method: opens (evidence: `README.md`)
- Workflow selection → Cloud management: opens (evidence: `README.md`)
- Mod 1 monthly → Browser invoice history: saves invoices (evidence: `README.md`)
- Mod 2 daily → Browser invoice history: saves invoices (evidence: `README.md`)
- Mod 3 old method → Browser invoice history: saves invoices (evidence: `README.md`)
- Mod 1 monthly → Cloud sync client: syncs history (evidence: `README.md`)
- Mod 2 daily → Cloud sync client: syncs history (evidence: `README.md`)
- Mod 3 old method → Cloud sync client: syncs history (evidence: `README.md`)
- Cloud sync client → Invoice API: requests records (evidence: `cloud-sync.js`)
- Invoice API → Shared D1 database: reads and writes (evidence: `functions/api/invoices.js`)
- Number allocator → Shared D1 database: allocates numbers (evidence: `README.md`)
- Cloud management → Invoice API: manages records (evidence: `Management/management.js`)
- Cloud management → Mod 1 monthly: opens print layout (evidence: `README.md`)
- Cloud management → Mod 2 daily: opens print layout (evidence: `README.md`)
- Cloud management → Excel export helper: exports records (evidence: `README.md`)
- Mod 1 monthly → Excel export helper: exports history
- Mod 2 daily → Excel export helper: exports history
- Mod 3 old method → Excel export helper: exports history
- Auth client → Session endpoint: checks session (evidence: `auth-client.js`)
- Auth client → Logout endpoint: requests logout (evidence: `auth-client.js`)
- Route protection → Session utilities: validates session (evidence: `functions/_middleware.js`)
- Login endpoint → Session utilities: creates session (evidence: `functions/api/auth/login.js`)
- Session endpoint → Session utilities: checks user (evidence: `functions/api/auth/session.js`)
- Logout endpoint → Session utilities: clears cookie (evidence: `functions/api/auth/logout.js`)
