# clarkwalker197-glitch/cpclms_v3-main architecture

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

- Interactive diagram: https://gitdiagram.com/clarkwalker197-glitch/cpclms_v3-main
- Repository: https://github.com/clarkwalker197-glitch/cpclms_v3-main

## Overview

CPCLMS is a library-management web application: patrons and librarians use the Next.js frontend to authenticate, browse the catalog, request or reserve books, and complete librarian-led QR or manual approvals; the Express API enforces roles and business rules and persists library records. Other documented capabilities include e-books, archives, notifications, reports, analytics, activity logs, policies, and offline synchronization. The excerpts show transaction and authentication routing, controller-to-service calls, and media-storage code; other subsystem links reflect README documentation and are marked accordingly. Database schema details and unsampled subsystem internals are not shown.

Main entry points: [`frontend/app`](https://github.com/clarkwalker197-glitch/cpclms_v3-main/tree/main/frontend/app) (Next.js pages), [`backend/src/routes/index.ts`](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/routes/index.ts) (API route registry), [`backend/src/controllers/auth.controller.ts`](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/controllers/auth.controller.ts) (Authentication controller), [`frontend/lib/api.ts`](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/frontend/lib/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_webapp["Next.js pages"]
  node_offline[("Offline cache and queue<br/>[offline-db.ts]")]
  node_clientapi["API client<br/>[api.ts]"]
  node_authui["Auth context<br/>[auth-context.tsx]"]
  node_sw["Service worker<br/>[sw.js]"]
end

subgraph group_api["API and access"]
  node_express["Express application<br/>[app.ts]"]
  node_routes["API route registry<br/>[index.ts]"]
  node_authroutes["Authentication routes<br/>[auth.routes.ts]"]
  node_txroutes["Transaction routes"]
  node_authctrl["Authentication controller<br/>[auth.controller.ts]"]
  node_txctrl["Transaction controller"]
end

subgraph group_library["Library services"]
  node_authsvc["Authentication service<br/>[auth.service.ts]"]
  node_txsvc["Borrowing and reservations"]
  node_catalog["Book catalog<br/>[book.service.ts]"]
  node_ebooks["E-book management<br/>[ebook.service.ts]"]
  node_archives["Archive retention"]
  node_insights["Reports and analytics<br/>[report.service.ts]"]
  node_notices["Notifications"]
  node_audit["Activity logging"]
end

subgraph group_media["Media storage"]
  node_upload["Upload middleware<br/>[upload.ts]"]
  node_covers["Cover image storage"]
  node_profile["Profile image storage"]
  node_ebookstore["E-book file storage"]
end

node_patron(("Patrons and librarians"))
node_db[("PostgreSQL")]
node_blob[("Vercel Blob")]

node_patron -->|"uses"| node_webapp
node_webapp -.->|"requests data"| node_clientapi
node_webapp -->|"uses auth"| node_authui
node_offline -.->|"queues mutations"| node_clientapi
node_sw -->|"caches shell"| node_webapp
node_clientapi -.->|"calls API"| node_express
node_express -->|"mounts routes"| node_routes
node_routes -->|"registers"| node_authroutes
node_routes -->|"registers"| node_txroutes
node_authroutes -->|"routes requests"| node_authctrl
node_txroutes -->|"routes requests"| node_txctrl
node_authctrl -->|"calls"| node_authsvc
node_txctrl -->|"calls"| node_txsvc
node_authsvc -.->|"persists records"| node_db
node_txsvc -.->|"persists transactions"| node_db
node_catalog -.->|"stores catalog"| node_db
node_ebooks -.->|"stores metadata"| node_db
node_archives -.->|"purges expired records"| node_db
node_insights -.->|"queries metrics"| node_db
node_notices -.->|"stores notifications"| node_db
node_audit -.->|"stores activity"| node_db
node_upload -->|"validates uploads"| node_covers
node_authctrl -->|"stores profile image"| node_profile
node_covers -->|"uploads images"| node_blob
node_profile -->|"uploads images"| node_blob
node_ebookstore -->|"uploads files"| node_blob

click node_webapp "https://github.com/clarkwalker197-glitch/cpclms_v3-main/tree/main/frontend/app"
click node_offline "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/frontend/lib/offline-db.ts"
click node_clientapi "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/frontend/lib/api.ts"
click node_authui "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/frontend/lib/auth-context.tsx"
click node_sw "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/frontend/public/sw.js"
click node_express "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/app.ts"
click node_routes "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/routes/index.ts"
click node_authroutes "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/routes/auth.routes.ts"
click node_txroutes "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/routes/transaction.routes.ts"
click node_authctrl "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/controllers/auth.controller.ts"
click node_txctrl "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/controllers/transaction.controller.ts"
click node_authsvc "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/auth.service.ts"
click node_txsvc "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/transaction.service.ts"
click node_catalog "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/book.service.ts"
click node_ebooks "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/ebook.service.ts"
click node_archives "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/archive-retention.service.ts"
click node_insights "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/report.service.ts"
click node_notices "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/notification.service.ts"
click node_audit "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/activity-log.service.ts"
click node_upload "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/middlewares/upload.ts"
click node_covers "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/cover-image-storage.service.ts"
click node_profile "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/profile-image-storage.service.ts"
click node_ebookstore "https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/ebook-file-storage.service.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_webapp,node_offline,node_clientapi,node_authui,node_sw toneBlue
class node_express,node_routes,node_authroutes,node_txroutes,node_authctrl,node_txctrl,node_db,node_blob toneAmber
class node_authsvc,node_txsvc,node_catalog,node_ebooks,node_archives,node_insights,node_notices,node_audit toneMint
class node_upload,node_covers,node_profile,node_ebookstore toneRose
class node_patron toneIndigo
```

## Components

### Web application

- [Next.js pages](https://github.com/clarkwalker197-glitch/cpclms_v3-main/tree/main/frontend/app): `frontend/app`
- [Offline cache and queue](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/frontend/lib/offline-db.ts): `frontend/lib/offline-db.ts`
- [API client](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/frontend/lib/api.ts): `frontend/lib/api.ts`
- [Auth context](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/frontend/lib/auth-context.tsx): `frontend/lib/auth-context.tsx`
- [Service worker](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/frontend/public/sw.js): `frontend/public/sw.js`

### API and access

- [Express application](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/app.ts): `backend/src/app.ts`
- [API route registry](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/routes/index.ts): `backend/src/routes/index.ts`
- [Authentication routes](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/routes/auth.routes.ts): `backend/src/routes/auth.routes.ts`
- [Transaction routes](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/routes/transaction.routes.ts): `backend/src/routes/transaction.routes.ts`
- [Authentication controller](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/controllers/auth.controller.ts): `backend/src/controllers/auth.controller.ts`
- [Transaction controller](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/controllers/transaction.controller.ts): `backend/src/controllers/transaction.controller.ts`

### Library services

- [Authentication service](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/auth.service.ts): `backend/src/services/auth.service.ts`
- [Borrowing and reservations](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/transaction.service.ts): `backend/src/services/transaction.service.ts`
- [Book catalog](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/book.service.ts): `backend/src/services/book.service.ts`
- [E-book management](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/ebook.service.ts): `backend/src/services/ebook.service.ts`
- [Archive retention](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/archive-retention.service.ts): `backend/src/services/archive-retention.service.ts`
- [Reports and analytics](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/report.service.ts): `backend/src/services/report.service.ts`
- [Notifications](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/notification.service.ts): `backend/src/services/notification.service.ts`
- [Activity logging](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/activity-log.service.ts): `backend/src/services/activity-log.service.ts`

### Media storage

- [Upload middleware](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/middlewares/upload.ts): `backend/src/middlewares/upload.ts`
- [Cover image storage](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/cover-image-storage.service.ts): `backend/src/services/cover-image-storage.service.ts`
- [Profile image storage](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/profile-image-storage.service.ts): `backend/src/services/profile-image-storage.service.ts`
- [E-book file storage](https://github.com/clarkwalker197-glitch/cpclms_v3-main/blob/main/backend/src/services/ebook-file-storage.service.ts): `backend/src/services/ebook-file-storage.service.ts`

### Other components

- **Patrons and librarians**
- **PostgreSQL**
- **Vercel Blob**

## Connections

- Patrons and librarians → Next.js pages: uses
- Next.js pages → API client: requests data
- Next.js pages → Auth context: uses auth (evidence: `frontend/lib/auth-context.tsx`)
- Offline cache and queue → API client: queues mutations
- Service worker → Next.js pages: caches shell
- API client → Express application: calls API
- Express application → API route registry: mounts routes (evidence: `backend/src/app.ts`)
- API route registry → Authentication routes: registers (evidence: `backend/src/routes/index.ts`)
- API route registry → Transaction routes: registers (evidence: `backend/src/routes/index.ts`)
- Authentication routes → Authentication controller: routes requests (evidence: `backend/src/routes/auth.routes.ts`)
- Transaction routes → Transaction controller: routes requests (evidence: `backend/src/routes/transaction.routes.ts`)
- Authentication controller → Authentication service: calls (evidence: `backend/src/controllers/auth.controller.ts`)
- Transaction controller → Borrowing and reservations: calls (evidence: `backend/src/controllers/transaction.controller.ts`)
- Authentication service → PostgreSQL: persists records
- Borrowing and reservations → PostgreSQL: persists transactions
- Book catalog → PostgreSQL: stores catalog
- E-book management → PostgreSQL: stores metadata
- Archive retention → PostgreSQL: purges expired records
- Reports and analytics → PostgreSQL: queries metrics
- Notifications → PostgreSQL: stores notifications
- Activity logging → PostgreSQL: stores activity
- Upload middleware → Cover image storage: validates uploads (evidence: `backend/src/middlewares/upload.ts`)
- Authentication controller → Profile image storage: stores profile image (evidence: `backend/src/controllers/auth.controller.ts`)
- Cover image storage → Vercel Blob: uploads images (evidence: `backend/src/services/cover-image-storage.service.ts`)
- Profile image storage → Vercel Blob: uploads images (evidence: `backend/src/services/profile-image-storage.service.ts`)
- E-book file storage → Vercel Blob: uploads files (evidence: `backend/src/services/ebook-file-storage.service.ts`)
