How riadhlaroui/diploma_archive works
Purpose and Runtime
This is a Next.js diploma archive administration system. It manages students, academic taxonomy (faculties through specialties), staff, document types, diploma-document workflows, and printing. The application is containerized with Docker and deployed behind Nginx; PocketBase is the embedded backend/database service.
Paths: Dockerfile, docker-compose.yml, nginx/nginx.conf, pocketbase/Dockerfile
Application Entry and Route Partitioning
The App Router starts at app/layout.tsx and app/page.tsx. Routes are partitioned into authentication and protected/main application shells, each with a distinct layout. Main navigation leads to dashboard, student records, organization hierarchy, team, inbox, profile, and settings.
Paths: app/(auth)/layout.tsx, app/(main)/layout.tsx, app/(main)/dashboard/page.tsx
Authentication and Session Boundary
Client authentication is backed by PocketBase. Login and token refresh are exposed as Next API routes, while client services/hooks manage sign-in forms, session protection, and permission checks. Core entities and an authentication use case provide a lightweight domain boundary around the backend client.
Paths: app/api/auth/login/route.ts, app/api/auth/refresh/route.ts, app/src/infrastructure/auth/pocketbaseClient.ts, app/src/core/use-cases/ensureUserIsAuthenticated.ts, middleware.ts
Authorization Model
Permissions are centrally declared as permissions and groups, then consumed by client hooks to gate UI/actions. User identity is modeled separately from student identity, supporting staff/team administration alongside archive operations.
Paths: app/src/config/permissions.ts, app/src/config/permissionGroups.ts, app/src/hooks/usePermission.ts, app/src/core/domain/entities/User.ts
Archive and Academic Data Management
The main CRUD flow centers on student records, including individual creation/update, bulk entry/import, document upload/viewing, and diploma printing. Academic reference data is modeled as a navigable hierarchy: faculty → department → field → major → specialty. Service modules form the data-access boundary to PocketBase for each resource.
Paths: app/(main)/students/page.tsx, app/(main)/students/bulk-import/page.tsx, components/StudentForm.jsx, app/src/services/studentService.ts, app/src/services/facultieService.ts, app/src/services/specialtyService.ts
Document Extraction Pipeline
Uploaded diploma/archive documents can be handled through OCR UI components and two server-side API routes. One route is generic OCR and one explicitly integrates Gemini, keeping external AI/OCR invocation on the server boundary rather than in browser-facing components.
Paths: components/OCRUploader.tsx, components/DocumentUploadDialog.tsx, app/api/ocr/route.ts, app/api/ocr-gemini/route.ts, app/src/shared/utils/ocr.ts
Data, External Services, and Delivery
PocketBase provides authentication, collections, and persisted data; its bundled pb_data indicates local SQLite-backed state. Google Gemini is an external OCR/AI integration. Internationalization supports Arabic, English, and French. Nginx fronts the Next.js application in the composed deployment.
Paths: pocketbase/pocketbase_0.34.2_linux_amd64/pb_data/data.db, lib/pocketbase.js, lib/i18n/i18n.ts, lib/i18n/locales/ar/translation.json, nginx/nginx.conf
Components 22
Next.js UI
- App Router shell
app/layout.tsx - Authentication shell
app/(auth)/layout.tsx - Protected app shell · Hosts main navigation and protected sections.
app/(main)/layout.tsx - Dashboard
app/(main)/dashboard/page.tsx - Student records · Student CRUD, documents, and diploma printing.
app/(main)/students/page.tsx - Bulk student import
app/(main)/students/bulk-import/page.tsx - Student form
components/StudentForm.jsx - Document upload & OCR UI
components/OCRUploader.tsx - Arabic, English & French i18n
lib/i18n/i18n.ts
Application Services
- Login & token refresh · Server boundary for PocketBase session operations.
app/api/auth/login/route.ts - Session guard
app/src/core/use-cases/ensureUserIsAuthenticated.ts - Route middleware
middleware.ts - Permission checks · Uses centrally declared permissions and permission groups.
app/src/hooks/usePermission.ts - Student data service
app/src/services/studentService.ts - Academic taxonomy services · Faculty-to-specialty reference hierarchy.
app/src/services/facultieService.ts - OCR API
app/api/ocr/route.ts - Gemini OCR API · Keeps Gemini invocation server-side.
app/api/ocr-gemini/route.ts
Backend & Integrations
- PocketBase · Provides authentication and archive data collections.
app/src/infrastructure/auth/pocketbaseClient.ts - PocketBase SQLite data
pocketbase/pocketbase_0.34.2_linux_amd64/pb_data/data.db - Google Gemini
Deployment
- Nginx reverse proxy
nginx/nginx.conf - Docker Compose stack · Runs the Next.js, Nginx, and PocketBase services.
docker-compose.yml
Connections 24
- App Router shell → Authentication shell: partitions routes
- App Router shell → Protected app shell: partitions routes
- Protected app shell → Dashboard: hosts
- Protected app shell → Student records: hosts
- Student records → Bulk student import: supports
- Student records → Student form: uses
- Student records → Document upload & OCR UI: uploads documents
- Protected app shell → Permission checks: gates UI/actions
- Route middleware → Session guard: enforces session
- Session guard → PocketBase: validates session
- Login & token refresh → PocketBase: sign-in and refresh
- Student form → Student data service: creates and updates
- Student records → Student data service: reads archive records
- Student records → Academic taxonomy services: selects taxonomy
- Student data service → PocketBase: collection access
- Academic taxonomy services → PocketBase: collection access
- Document upload & OCR UI → OCR API: submits OCR
- Document upload & OCR UI → Gemini OCR API: submits AI OCR
- Gemini OCR API → Google Gemini: invokes
- PocketBase → PocketBase SQLite data: persists data
- Nginx reverse proxy → App Router shell: proxies requests
- Docker Compose stack → Nginx reverse proxy: runs
- Docker Compose stack → PocketBase: runs
- App Router shell → Arabic, English & French i18n: localizes UI