# suryavamshikusam/photocopy-ledger architecture

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

- Interactive diagram: https://gitdiagram.com/suryavamshikusam/photocopy-ledger
- Repository: https://github.com/suryavamshikusam/photocopy-ledger

## Overview

Photocopy Ledger manages prepaid campus printing balances through an append-only transaction ledger. Admins search and filter student accounts, review history, and post single or batch deposits, deductions, and corrections; students see balances and statement history with live balance updates. Authentication and role-aware routing gate these experiences. The README documents parallel server-rendered data loading, RLS-protected direct history reads, and validated server-action writes. Some page and database implementation details were not sampled, so those links rely on README evidence.

Main entry points: [`src/app/admin/AdminClient.tsx`](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/admin/AdminClient.tsx) (Admin Command Center), [`src/app/actions/auth.ts`](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/actions/auth.ts) (Auth Actions), [`src/lib/supabase/server.ts`](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/lib/supabase/server.ts) (Server Supabase Client), [`supabase/schema.sql`](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/supabase/schema.sql) (Postgres Ledger)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and Accounts"]
  node_login["Sign-in Screen<br/>[page.tsx]"]
  node_auth["Auth Actions<br/>[auth.ts]"]
  node_middleware["Session and Role Guards<br/>[middleware.ts]"]
  node_password["Password Change"]
  node_signout["Sign-out Control<br/>[SignOutButton.tsx]"]
end

subgraph group_admin["Admin Operations"]
  node_adminpage["Admin Server Page<br/>[page.tsx]"]
  node_adminclient["Admin Command Center<br/>[AdminClient.tsx]"]
  node_transactions["Transaction Actions<br/>[transaction.ts]"]
  node_ui["Shared UI Components"]
end

subgraph group_student["Student Passbook"]
  node_studentpage["Student Server Page<br/>[page.tsx]"]
  node_passbook["Live Passbook"]
end

subgraph group_ledger["Ledger and Data"]
  node_browserclient["Browser Supabase Client<br/>[client.ts]"]
  node_serverclient["Server Supabase Client<br/>[server.ts]"]
  node_environment["Supabase Configuration<br/>[env.ts]"]
  node_database[("Postgres Ledger<br/>[schema.sql]")]
  node_realtime["Supabase Realtime"]
  node_authservice["Supabase Auth"]
  node_format["Ledger Formatting<br/>[format.ts]"]
end

node_user(("Campus User"))

node_user -->|"signs in"| node_login
node_login -->|"submits credentials"| node_auth
node_auth -->|"creates client"| node_serverclient
node_serverclient -->|"gets credentials"| node_environment
node_auth -->|"authenticates"| node_authservice
node_middleware -->|"refreshes session"| node_authservice
node_middleware -->|"guards routes"| node_adminpage
node_middleware -->|"guards routes"| node_studentpage
node_adminpage -->|"renders"| node_adminclient
node_adminclient -->|"posts transactions"| node_transactions
node_transactions -->|"creates client"| node_serverclient
node_transactions -->|"writes ledger entries"| node_database
node_adminclient -->|"queries history"| node_browserclient
node_browserclient -->|"reads RLS history"| node_database
node_adminclient -->|"prefetches history"| node_database
node_studentpage -->|"renders"| node_passbook
node_studentpage -->|"loads initial data"| node_serverclient
node_serverclient -->|"loads page data"| node_database
node_passbook -->|"creates client"| node_browserclient
node_passbook -->|"subscribes to updates"| node_realtime
node_database -->|"pushes changes"| node_realtime
node_password -.->|"changes credentials"| node_auth
node_signout -->|"calls logout"| node_auth
node_adminclient -->|"renders controls"| node_ui
node_passbook -->|"formats ledger dates"| node_format
node_browserclient -->|"gets credentials"| node_environment

click node_login "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/login/page.tsx"
click node_auth "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/actions/auth.ts"
click node_middleware "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/middleware.ts"
click node_password "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/components/ChangePasswordDialog.tsx"
click node_adminpage "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/admin/page.tsx"
click node_adminclient "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/admin/AdminClient.tsx"
click node_transactions "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/actions/transaction.ts"
click node_studentpage "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/dashboard/page.tsx"
click node_passbook "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/dashboard/DashboardLiveClient.tsx"
click node_signout "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/components/SignOutButton.tsx"
click node_browserclient "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/lib/supabase/client.ts"
click node_serverclient "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/lib/supabase/server.ts"
click node_environment "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/lib/env.ts"
click node_database "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/supabase/schema.sql"
click node_ui "https://github.com/suryavamshikusam/photocopy-ledger/tree/main/src/components/ui"
click node_format "https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/lib/format.ts"

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_auth,node_middleware,node_password,node_signout,node_user toneBlue
class node_adminpage,node_adminclient,node_transactions,node_ui toneAmber
class node_studentpage,node_passbook toneMint
class node_browserclient,node_serverclient,node_environment,node_database,node_realtime,node_authservice,node_format toneRose
```

## Components

### Access and Accounts

- [Sign-in Screen](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/login/page.tsx): `src/app/login/page.tsx`
- [Auth Actions](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/actions/auth.ts): `src/app/actions/auth.ts`
- [Session and Role Guards](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/middleware.ts): `src/middleware.ts`
- [Password Change](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/components/ChangePasswordDialog.tsx): `src/components/ChangePasswordDialog.tsx`
- [Sign-out Control](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/components/SignOutButton.tsx): `src/components/SignOutButton.tsx`

### Admin Operations

- [Admin Server Page](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/admin/page.tsx): `src/app/admin/page.tsx`
- [Admin Command Center](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/admin/AdminClient.tsx): `src/app/admin/AdminClient.tsx`
- [Transaction Actions](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/actions/transaction.ts): `src/app/actions/transaction.ts`
- [Shared UI Components](https://github.com/suryavamshikusam/photocopy-ledger/tree/main/src/components/ui): `src/components/ui`

### Student Passbook

- [Student Server Page](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/dashboard/page.tsx): `src/app/dashboard/page.tsx`
- [Live Passbook](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/app/dashboard/DashboardLiveClient.tsx): `src/app/dashboard/DashboardLiveClient.tsx`

### Ledger and Data

- [Browser Supabase Client](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/lib/supabase/client.ts): `src/lib/supabase/client.ts`
- [Server Supabase Client](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/lib/supabase/server.ts): `src/lib/supabase/server.ts`
- [Supabase Configuration](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/lib/env.ts): `src/lib/env.ts`
- [Postgres Ledger](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/supabase/schema.sql): `supabase/schema.sql`
- **Supabase Realtime**
- **Supabase Auth**
- [Ledger Formatting](https://github.com/suryavamshikusam/photocopy-ledger/blob/main/src/lib/format.ts): `src/lib/format.ts`

### Other components

- **Campus User**

## Connections

- Campus User → Sign-in Screen: signs in (evidence: `README.md`)
- Sign-in Screen → Auth Actions: submits credentials (evidence: `src/app/login/page.tsx`)
- Auth Actions → Server Supabase Client: creates client (evidence: `src/app/actions/auth.ts`)
- Server Supabase Client → Supabase Configuration: gets credentials (evidence: `src/lib/supabase/server.ts`)
- Auth Actions → Supabase Auth: authenticates (evidence: `src/app/actions/auth.ts`)
- Session and Role Guards → Supabase Auth: refreshes session (evidence: `README.md`)
- Session and Role Guards → Admin Server Page: guards routes (evidence: `README.md`)
- Session and Role Guards → Student Server Page: guards routes (evidence: `README.md`)
- Admin Server Page → Admin Command Center: renders (evidence: `src/app/admin/page.tsx`)
- Admin Command Center → Transaction Actions: posts transactions (evidence: `src/app/admin/AdminClient.tsx`)
- Transaction Actions → Server Supabase Client: creates client (evidence: `src/app/actions/transaction.ts`)
- Transaction Actions → Postgres Ledger: writes ledger entries (evidence: `README.md`)
- Admin Command Center → Browser Supabase Client: queries history (evidence: `src/app/admin/AdminClient.tsx`)
- Browser Supabase Client → Postgres Ledger: reads RLS history
- Admin Command Center → Postgres Ledger: prefetches history (evidence: `README.md`)
- Student Server Page → Live Passbook: renders (evidence: `src/app/dashboard/page.tsx`)
- Student Server Page → Server Supabase Client: loads initial data (evidence: `src/app/dashboard/page.tsx`)
- Server Supabase Client → Postgres Ledger: loads page data (evidence: `README.md`)
- Live Passbook → Browser Supabase Client: creates client (evidence: `src/app/dashboard/DashboardLiveClient.tsx`)
- Live Passbook → Supabase Realtime: subscribes to updates (evidence: `src/app/dashboard/DashboardLiveClient.tsx`)
- Postgres Ledger → Supabase Realtime: pushes changes (evidence: `README.md`)
- Password Change → Auth Actions: changes credentials
- Sign-out Control → Auth Actions: calls logout (evidence: `src/components/SignOutButton.tsx`)
- Admin Command Center → Shared UI Components: renders controls (evidence: `src/app/admin/AdminClient.tsx`)
- Live Passbook → Ledger Formatting: formats ledger dates (evidence: `src/app/dashboard/DashboardLiveClient.tsx`)
- Browser Supabase Client → Supabase Configuration: gets credentials (evidence: `src/lib/supabase/client.ts`)
