# harowwld/pupsj-rms-prototype architecture

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

- Interactive diagram: https://gitdiagram.com/harowwld/pupsj-rms-prototype
- Repository: https://github.com/harowwld/pupsj-rms-prototype

## Overview

PUP E-Manage is a local, office-scoped records-management system. Staff upload and manage student documents; the application stores records and supports scanning/OCR, review, and physical archive organization. Students and administrators have separate request, compliance, configuration, and oversight workflows. The README documents backups, PSA coordinate recognition, and local OCR integrations. Several feature routes were not sampled, so those capabilities are represented without asserting unverified internal calls.

Main entry points: [`next-app/src/lib/postgresCompat.js`](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/postgresCompat.js) (Postgres adapter), [`next-app/src/app/api/storage-layout/route.js`](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/app/api/storage-layout/route.js) (Archive layout API), [`next-app/src/app/api/documents/route.js`](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/app/api/documents/route.js) (Document API), [`next-app/src/lib/studentsRepo.js`](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/studentsRepo.js) (Student records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_records["Records workflows"]
  node_documents_api["Document API<br/>[route.js]"]
  node_documents_repo["Document records<br/>[documentsRepo.js]"]
  node_requests["Document requests<br/>[route.js]"]
  node_ingest["Scan and ingest"]
  node_ocr["OCR engines<br/>[ocrClient.js]"]
  node_recognition["PSA recognition"]
  node_students_repo["Student records<br/>[studentsRepo.js]"]
  node_storage_api["Archive layout API<br/>[route.js]"]
  node_storage_repo["Archive layout"]
  node_storage_admin["Layout editor"]
end

subgraph group_identity["Identity and access"]
  node_auth["Session authentication<br/>[authHelpers.js]"]
  node_staff_repo["Staff accounts<br/>[staffRepo.js]"]
  node_roles["Role policy<br/>[roleUtils.js]"]
end

subgraph group_operations["Administration"]
  node_admin_oversight["Audit and analytics"]
  node_backup["Backup and recovery"]
  node_system_admin["System configuration"]
end

subgraph group_platform["Data and integrations"]
  node_postgres_compat["Postgres adapter<br/>[postgresCompat.js]"]
  node_postgres[("PostgreSQL<br/>[postgres.js]")]
  node_sqlite[("Legacy SQLite<br/>[sqlite.js]")]
end

node_staff(("Records staff"))
node_student(("Students"))
node_admin(("Administrators"))

node_staff -->|"uploads documents"| node_documents_api
node_documents_api -->|"creates and lists"| node_documents_repo
node_documents_api -->|"resolves students"| node_students_repo
node_student -.->|"submits requests"| node_requests
node_staff -.->|"scans records"| node_ingest
node_ingest -.->|"extracts text"| node_ocr
node_admin -.->|"calibrates templates"| node_recognition
node_staff -.->|"manages archive"| node_storage_api
node_storage_admin -.->|"saves layout"| node_storage_api
node_storage_api -->|"reads and saves"| node_storage_repo
node_storage_api -->|"checks and reassigns"| node_students_repo
node_staff -.->|"authenticates"| node_auth
node_auth -->|"resolves staff"| node_staff_repo
node_admin -.->|"reviews activity"| node_admin_oversight
node_admin -->|"backs up data"| node_backup
node_admin -.->|"configures system"| node_system_admin
node_documents_repo -->|"queries database"| node_postgres_compat
node_students_repo -->|"queries database"| node_postgres_compat
node_staff_repo -->|"queries database"| node_postgres_compat
node_storage_repo -->|"reads and writes"| node_postgres_compat
node_postgres_compat -->|"executes queries"| node_postgres
node_admin -.->|"uses role policy"| node_roles
node_sqlite -.->|"legacy migration"| node_postgres

click node_documents_api "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/app/api/documents/route.js"
click node_documents_repo "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/documentsRepo.js"
click node_requests "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/app/api/document-requests/route.js"
click node_ingest "https://github.com/harowwld/pupsj-rms-prototype/tree/main/next-app/src/app/api/ingest"
click node_ocr "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/ocrClient.js"
click node_recognition "https://github.com/harowwld/pupsj-rms-prototype/tree/main/next-app/src/app/api/recognition"
click node_students_repo "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/studentsRepo.js"
click node_storage_api "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/app/api/storage-layout/route.js"
click node_storage_repo "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/storageLayoutRepo.js"
click node_storage_admin "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/components/admin/StorageLayoutEditorTab.js"
click node_auth "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/authHelpers.js"
click node_staff_repo "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/staffRepo.js"
click node_roles "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/roleUtils.js"
click node_admin_oversight "https://github.com/harowwld/pupsj-rms-prototype/tree/main/next-app/src/app/api/audit-logs"
click node_backup "https://github.com/harowwld/pupsj-rms-prototype/tree/main/next-app/src/app/api/system/backup"
click node_system_admin "https://github.com/harowwld/pupsj-rms-prototype/tree/main/next-app/src/app/api/system"
click node_postgres_compat "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/postgresCompat.js"
click node_postgres "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/postgres.js"
click node_sqlite "https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/sqlite.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_documents_api,node_documents_repo,node_requests,node_ingest,node_ocr,node_recognition,node_students_repo,node_storage_api,node_storage_repo,node_storage_admin toneBlue
class node_auth,node_staff_repo,node_roles toneAmber
class node_admin_oversight,node_backup,node_system_admin toneMint
class node_postgres_compat,node_postgres,node_sqlite toneRose
class node_staff,node_student,node_admin toneIndigo
```

## Components

### Records workflows

- [Document API](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/app/api/documents/route.js): `next-app/src/app/api/documents/route.js`
- [Document records](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/documentsRepo.js): `next-app/src/lib/documentsRepo.js`
- [Document requests](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/app/api/document-requests/route.js): `next-app/src/app/api/document-requests/route.js`
- [Scan and ingest](https://github.com/harowwld/pupsj-rms-prototype/tree/main/next-app/src/app/api/ingest): `next-app/src/app/api/ingest`
- [OCR engines](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/ocrClient.js): `next-app/src/lib/ocrClient.js`
- [PSA recognition](https://github.com/harowwld/pupsj-rms-prototype/tree/main/next-app/src/app/api/recognition): `next-app/src/app/api/recognition`
- [Student records](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/studentsRepo.js): `next-app/src/lib/studentsRepo.js`
- [Archive layout API](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/app/api/storage-layout/route.js): `next-app/src/app/api/storage-layout/route.js`
- [Archive layout](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/storageLayoutRepo.js): `next-app/src/lib/storageLayoutRepo.js`
- [Layout editor](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/components/admin/StorageLayoutEditorTab.js): `next-app/src/components/admin/StorageLayoutEditorTab.js`

### Identity and access

- [Session authentication](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/authHelpers.js): `next-app/src/lib/authHelpers.js`
- [Staff accounts](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/staffRepo.js): `next-app/src/lib/staffRepo.js`
- [Role policy](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/roleUtils.js): `next-app/src/lib/roleUtils.js`

### Administration

- [Audit and analytics](https://github.com/harowwld/pupsj-rms-prototype/tree/main/next-app/src/app/api/audit-logs): `next-app/src/app/api/audit-logs`
- [Backup and recovery](https://github.com/harowwld/pupsj-rms-prototype/tree/main/next-app/src/app/api/system/backup): `next-app/src/app/api/system/backup`
- [System configuration](https://github.com/harowwld/pupsj-rms-prototype/tree/main/next-app/src/app/api/system): `next-app/src/app/api/system`

### Data and integrations

- [Postgres adapter](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/postgresCompat.js): `next-app/src/lib/postgresCompat.js`
- [PostgreSQL](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/postgres.js): `next-app/src/lib/postgres.js`
- [Legacy SQLite](https://github.com/harowwld/pupsj-rms-prototype/blob/main/next-app/src/lib/sqlite.js): `next-app/src/lib/sqlite.js`

### Other components

- **Records staff**
- **Students**
- **Administrators**

## Connections

- Records staff → Document API: uploads documents
- Document API → Document records: creates and lists (evidence: `next-app/src/app/api/documents/route.js`)
- Document API → Student records: resolves students (evidence: `next-app/src/app/api/documents/route.js`)
- Students → Document requests: submits requests
- Records staff → Scan and ingest: scans records
- Scan and ingest → OCR engines: extracts text
- Administrators → PSA recognition: calibrates templates
- Records staff → Archive layout API: manages archive
- Layout editor → Archive layout API: saves layout (evidence: `next-app/src/components/admin/StorageLayoutEditorTab.js`)
- Archive layout API → Archive layout: reads and saves (evidence: `next-app/src/app/api/storage-layout/route.js`)
- Archive layout API → Student records: checks and reassigns (evidence: `next-app/src/app/api/storage-layout/route.js`)
- Records staff → Session authentication: authenticates
- Session authentication → Staff accounts: resolves staff (evidence: `next-app/src/lib/authHelpers.js`)
- Administrators → Audit and analytics: reviews activity
- Administrators → Backup and recovery: backs up data
- Administrators → System configuration: configures system
- Document records → Postgres adapter: queries database (evidence: `next-app/src/lib/documentsRepo.js`)
- Student records → Postgres adapter: queries database (evidence: `next-app/src/lib/studentsRepo.js`)
- Staff accounts → Postgres adapter: queries database (evidence: `next-app/src/lib/staffRepo.js`)
- Archive layout → Postgres adapter: reads and writes (evidence: `next-app/src/lib/storageLayoutRepo.js`)
- Postgres adapter → PostgreSQL: executes queries (evidence: `next-app/src/lib/postgresCompat.js`)
- Administrators → Role policy: uses role policy
- Legacy SQLite → PostgreSQL: legacy migration
