# jafarfarzi-stack/afagh architecture

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

- Interactive diagram: https://gitdiagram.com/jafarfarzi-stack/afagh
- Repository: https://github.com/jafarfarzi-stack/afagh

## Overview

Afagh ERP is a university information system delivered in a modern Next.js generation and a smaller Node/SQLite phase-zero generation. The main user journey is authenticated student and staff work across enrollment, teaching and grades, then policy-driven graduation, clearance, and alumni services; administrators manage the associated academic, finance, workflow, and reporting functions. The modern generation also documents robust enrollment queuing, electronic archiving, and public credential verification. The tree and excerpts establish the phase-zero API’s engine calls; several modern subsystems are represented from README descriptions and paths, not inspected implementations.

Main entry points: [`afagh-next/src/app/admin`](https://github.com/jafarfarzi-stack/afagh/tree/main/afagh-next/src/app/admin) (Admin portal), [`afagh-erp/src/server.js`](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/server.js) (Phase-zero API), [`afagh-erp/src/db/index.js`](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/db/index.js) (SQLite database), [`afagh-next/src/app/student`](https://github.com/jafarfarzi-stack/afagh/tree/main/afagh-next/src/app/student) (Student portal)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_modern["Modern university system"]
  node_student_portal["Student portal"]
  node_professor_portal["Professor portal"]
  node_alumni_portal["Alumni portal"]
end

subgraph group_academic["Academic operations"]
  node_enrollment["Enrollment and waitlist<br/>[enroll-engine.ts]"]
  node_curriculum["Curriculum management<br/>[actions.ts]"]
  node_exam["Exam management<br/>[exam-engine.ts]"]
  node_grades["Grades and transcript<br/>[grades-core.ts]"]
  node_graduation["Graduation and clearance"]
  node_credentials["Certificates and verification"]
end

subgraph group_admin["Administration"]
  node_admin_portal["Admin portal"]
  node_workflow["Workflow engine<br/>[workflow-engine.ts]"]
  node_finance["Finance and tuition<br/>[finance-engine.ts]"]
  node_payroll["Payroll<br/>[payroll-engine.ts]"]
  node_bi["Business intelligence<br/>[bi-engine.ts]"]
  node_archive["Electronic archive<br/>[objectStore.ts]"]
end

subgraph group_phasezero["Phase-zero system"]
  node_legacy_api["Phase-zero API<br/>[server.js]"]
  node_legacy_enrollment["Enrollment validation<br/>[enrollment.js]"]
  node_legacy_grades["Grades and GPA<br/>[grades.js]"]
  node_legacy_rules["Academic regulations<br/>[regulations.js]"]
  node_legacy_workflow["Workflow<br/>[workflow.js]"]
  node_legacy_payroll["Payroll and pay rules<br/>[payroll.js]"]
  node_legacy_rbac["RBAC and audit<br/>[rbac.js]"]
  node_legacy_db[("SQLite database<br/>[index.js]")]
  node_legacy_payrules["Pay rules<br/>[payRules.js]"]
end

subgraph group_platform["Shared platform"]
  node_auth["Authentication and roles<br/>[auth.ts]"]
  node_modern_db[("PostgreSQL data<br/>[index.ts]")]
  node_redis["Redis queue"]
  node_minio[("MinIO object storage")]
end

node_student(("Student"))
node_staff(("Staff"))
node_public(("Public verifier"))

node_student -->|"uses"| node_student_portal
node_staff -->|"uses"| node_professor_portal
node_staff -->|"uses"| node_admin_portal
node_student_portal -.->|"authenticates"| node_auth
node_professor_portal -.->|"authenticates"| node_auth
node_admin_portal -.->|"authenticates"| node_auth
node_student_portal -->|"requests enrollment"| node_enrollment
node_enrollment -->|"queues capacity"| node_redis
node_admin_portal -->|"manages curriculum"| node_curriculum
node_admin_portal -->|"plans exams"| node_exam
node_professor_portal -->|"submits grades"| node_grades
node_grades -->|"triggers completion"| node_graduation
node_graduation -->|"routes clearance"| node_workflow
node_graduation -->|"transfers account"| node_alumni_portal
node_alumni_portal -->|"requests credentials"| node_credentials
node_public -->|"verifies degree"| node_credentials
node_admin_portal -->|"manages finance"| node_finance
node_admin_portal -->|"manages payroll"| node_payroll
node_admin_portal -->|"views reports"| node_bi
node_admin_portal -->|"manages archive"| node_archive
node_archive -->|"stores files"| node_minio
node_student -.->|"uses API"| node_legacy_api
node_staff -.->|"uses API"| node_legacy_api
node_legacy_api -->|"dispatches"| node_legacy_enrollment
node_legacy_api -->|"dispatches"| node_legacy_grades
node_legacy_api -->|"dispatches"| node_legacy_workflow
node_legacy_api -->|"dispatches"| node_legacy_payroll
node_legacy_api -->|"checks access"| node_legacy_rbac
node_legacy_enrollment -->|"reads limits"| node_legacy_rules
node_legacy_grades -->|"uses policies"| node_legacy_rules
node_legacy_payroll -.->|"uses pay rules"| node_legacy_payrules
node_legacy_api -->|"reads and writes"| node_legacy_db
node_legacy_enrollment -->|"reads and writes"| node_legacy_db
node_legacy_grades -->|"reads and writes"| node_legacy_db
node_legacy_workflow -->|"reads and writes"| node_legacy_db
node_legacy_rbac -->|"reads and writes"| node_legacy_db

click node_student_portal "https://github.com/jafarfarzi-stack/afagh/tree/main/afagh-next/src/app/student"
click node_professor_portal "https://github.com/jafarfarzi-stack/afagh/tree/main/afagh-next/src/app/professor"
click node_admin_portal "https://github.com/jafarfarzi-stack/afagh/tree/main/afagh-next/src/app/admin"
click node_alumni_portal "https://github.com/jafarfarzi-stack/afagh/tree/main/afagh-next/src/app/alumni"
click node_auth "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/auth.ts"
click node_enrollment "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/enroll-engine.ts"
click node_curriculum "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/app/admin/curriculum/actions.ts"
click node_exam "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/exam-engine.ts"
click node_grades "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/app/professor/grades/grades-core.ts"
click node_graduation "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/graduation-engine.ts"
click node_credentials "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/certificate-engine.ts"
click node_workflow "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/workflow-engine.ts"
click node_finance "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/finance-engine.ts"
click node_payroll "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/payroll-engine.ts"
click node_bi "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/bi-engine.ts"
click node_archive "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/objectStore.ts"
click node_legacy_api "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/server.js"
click node_legacy_enrollment "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/enrollment.js"
click node_legacy_grades "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/grades.js"
click node_legacy_rules "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/regulations.js"
click node_legacy_workflow "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/workflow.js"
click node_legacy_payroll "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/payroll.js"
click node_legacy_rbac "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/rbac.js"
click node_legacy_db "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/db/index.js"
click node_modern_db "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/db/index.ts"
click node_legacy_payrules "https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/payRules.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_student_portal,node_professor_portal,node_alumni_portal toneBlue
class node_enrollment,node_curriculum,node_exam,node_grades,node_graduation,node_credentials toneAmber
class node_admin_portal,node_workflow,node_finance,node_payroll,node_bi,node_archive toneMint
class node_legacy_api,node_legacy_enrollment,node_legacy_grades,node_legacy_rules,node_legacy_workflow,node_legacy_payroll,node_legacy_rbac,node_legacy_db,node_legacy_payrules toneRose
class node_auth,node_modern_db,node_redis,node_minio,node_student,node_staff,node_public toneIndigo
```

## Components

### Modern university system

- [Student portal](https://github.com/jafarfarzi-stack/afagh/tree/main/afagh-next/src/app/student): `afagh-next/src/app/student`
- [Professor portal](https://github.com/jafarfarzi-stack/afagh/tree/main/afagh-next/src/app/professor): `afagh-next/src/app/professor`
- [Alumni portal](https://github.com/jafarfarzi-stack/afagh/tree/main/afagh-next/src/app/alumni): `afagh-next/src/app/alumni`

### Academic operations

- [Enrollment and waitlist](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/enroll-engine.ts): `afagh-next/src/lib/enroll-engine.ts`
- [Curriculum management](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/app/admin/curriculum/actions.ts): `afagh-next/src/app/admin/curriculum/actions.ts`
- [Exam management](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/exam-engine.ts): `afagh-next/src/lib/exam-engine.ts`
- [Grades and transcript](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/app/professor/grades/grades-core.ts): `afagh-next/src/app/professor/grades/grades-core.ts`
- [Graduation and clearance](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/graduation-engine.ts): `afagh-next/src/lib/graduation-engine.ts`
- [Certificates and verification](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/certificate-engine.ts): `afagh-next/src/lib/certificate-engine.ts`

### Administration

- [Admin portal](https://github.com/jafarfarzi-stack/afagh/tree/main/afagh-next/src/app/admin): `afagh-next/src/app/admin`
- [Workflow engine](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/workflow-engine.ts): `afagh-next/src/lib/workflow-engine.ts`
- [Finance and tuition](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/finance-engine.ts): `afagh-next/src/lib/finance-engine.ts`
- [Payroll](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/payroll-engine.ts): `afagh-next/src/lib/payroll-engine.ts`
- [Business intelligence](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/bi-engine.ts): `afagh-next/src/lib/bi-engine.ts`
- [Electronic archive](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/objectStore.ts): `afagh-next/src/lib/objectStore.ts`

### Phase-zero system

- [Phase-zero API](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/server.js): `afagh-erp/src/server.js`
- [Enrollment validation](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/enrollment.js): `afagh-erp/src/engines/enrollment.js`
- [Grades and GPA](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/grades.js): `afagh-erp/src/engines/grades.js`
- [Academic regulations](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/regulations.js): `afagh-erp/src/engines/regulations.js`
- [Workflow](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/workflow.js): `afagh-erp/src/engines/workflow.js`
- [Payroll and pay rules](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/payroll.js): `afagh-erp/src/engines/payroll.js`
- [RBAC and audit](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/rbac.js): `afagh-erp/src/engines/rbac.js`
- [SQLite database](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/db/index.js): `afagh-erp/src/db/index.js`
- [Pay rules](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-erp/src/engines/payRules.js): `afagh-erp/src/engines/payRules.js`

### Shared platform

- [Authentication and roles](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/lib/auth.ts): `afagh-next/src/lib/auth.ts`
- [PostgreSQL data](https://github.com/jafarfarzi-stack/afagh/blob/main/afagh-next/src/db/index.ts): `afagh-next/src/db/index.ts`
- **Redis queue**
- **MinIO object storage**

### Other components

- **Student**
- **Staff**
- **Public verifier**

## Connections

- Student → Student portal: uses (evidence: `README.md`)
- Staff → Professor portal: uses (evidence: `README.md`)
- Staff → Admin portal: uses (evidence: `README.md`)
- Student portal → Authentication and roles: authenticates
- Professor portal → Authentication and roles: authenticates
- Admin portal → Authentication and roles: authenticates
- Student portal → Enrollment and waitlist: requests enrollment (evidence: `README.md`)
- Enrollment and waitlist → Redis queue: queues capacity (evidence: `README.md`)
- Admin portal → Curriculum management: manages curriculum (evidence: `afagh-next/src/app/admin/curriculum/CurriculumManagerClient.tsx`)
- Admin portal → Exam management: plans exams (evidence: `README.md`)
- Professor portal → Grades and transcript: submits grades (evidence: `README.md`)
- Grades and transcript → Graduation and clearance: triggers completion (evidence: `README.md`)
- Graduation and clearance → Workflow engine: routes clearance (evidence: `README.md`)
- Graduation and clearance → Alumni portal: transfers account (evidence: `README.md`)
- Alumni portal → Certificates and verification: requests credentials (evidence: `README.md`)
- Public verifier → Certificates and verification: verifies degree (evidence: `README.md`)
- Admin portal → Finance and tuition: manages finance (evidence: `README.md`)
- Admin portal → Payroll: manages payroll (evidence: `README.md`)
- Admin portal → Business intelligence: views reports (evidence: `README.md`)
- Admin portal → Electronic archive: manages archive (evidence: `README.md`)
- Electronic archive → MinIO object storage: stores files (evidence: `README.md`)
- Student → Phase-zero API: uses API
- Staff → Phase-zero API: uses API
- Phase-zero API → Enrollment validation: dispatches (evidence: `afagh-erp/src/server.js`)
- Phase-zero API → Grades and GPA: dispatches (evidence: `afagh-erp/src/server.js`)
- Phase-zero API → Workflow: dispatches (evidence: `afagh-erp/src/server.js`)
- Phase-zero API → Payroll and pay rules: dispatches (evidence: `afagh-erp/src/server.js`)
- Phase-zero API → RBAC and audit: checks access (evidence: `afagh-erp/src/server.js`)
- Enrollment validation → Academic regulations: reads limits (evidence: `afagh-erp/src/engines/enrollment.js`)
- Grades and GPA → Academic regulations: uses policies (evidence: `afagh-erp/src/engines/grades.js`)
- Payroll and pay rules → Pay rules: uses pay rules (evidence: `afagh-erp/src/engines/payroll.js`)
- Phase-zero API → SQLite database: reads and writes (evidence: `afagh-erp/src/server.js`)
- Enrollment validation → SQLite database: reads and writes (evidence: `afagh-erp/src/engines/enrollment.js`)
- Grades and GPA → SQLite database: reads and writes (evidence: `afagh-erp/src/engines/grades.js`)
- Workflow → SQLite database: reads and writes (evidence: `afagh-erp/src/engines/workflow.js`)
- RBAC and audit → SQLite database: reads and writes (evidence: `afagh-erp/src/engines/rbac.js`)
