# devnexessam/uni-portal architecture

> Architecture diagram of the GitHub repository devnexessam/uni-portal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/devnexessam/uni-portal
- Repository: https://github.com/devnexessam/uni-portal

## Overview

##### Project type and purpose
- This is a full-stack university student portal built with Next.js (frontend + backend combined).
- Purpose: Allow students and admins to register/login, upload and manage academic files, track schedules and assignments, and use an AI assistant to query PDF materials.

##### File structure
- Top-level “app” directory: Next.js 13+ App Router containing all page routes (both public and authenticated).
- Under “app/(pages)/admin” and “app/(pages)/student”: separate dashboards for each role, with nested layouts and pages for assignments, courses, files, schedules, settings, etc.
- “app/api”: Next.js API routes for admin operations (CRUD on assignments, courses, files, schedules, students), student operations (profile, courses, assignments, files, schedule, AI questions), and authentication via next-auth.
- “components”: UI components organized by domain (admin, student, forms, layout, generic UI widgets).
- “lib”: configuration for database (mongodb.ts), authentication options (adminAuthOptions.ts, studentAuthOptions.ts), and external services (cloudinary.ts).
- “models”: Mongoose schemas for each domain entity (Admin, Student, Course, Assignment, File, Schedule).
- Config files: next.config.ts, tsconfig.json, nginx/.envs implicit, tailwind/postcss configs.

##### README for additional insights
- Confirms tech stack: Next.js + Tailwind CSS, MongoDB via Mongoose.
- Features: secure auth, file upload, dashboard, role-based access, AI assistant (probably via OpenAI).

##### Detailed capture of essential elements
- Don’t over-segment: group related API routes under one “API Layer” block, but call out Next-auth within it.
- Nested dashboards (admin vs. student) as sub-blocks within the Frontend layer.
- Data flows for critical use cases: e.g., “Upload Assignment → Cloudinary → store metadata in MongoDB → update dashboard.”
- AI flow: “Student clicks Q&A → sends PDF content + question to Next.js AI endpoint → calls OpenAI → returns answer.”

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Next.js App Router)" 
        direction TB
        AppLayout["App Layout"]:::frontend
        AppPage["Home Page"]:::frontend
        subgraph "Admin Dashboard"
            direction TB
            AdminLayout["Admin Layout"]:::frontend
            AdminPage["Admin Dashboard Page"]:::frontend
        end
        subgraph "Student Dashboard"
            direction TB
            StudentLayout["Student Layout"]:::frontend
            StudentPage["Student Dashboard Page"]:::frontend
            AIAssistantComp["AI Assistant Component"]:::frontend
            AIAssistantPage["AI Assistant Page"]:::frontend
        end
    end

    %% API Layer
    subgraph "API Layer (app/api)" 
        direction TB
        AuthAPI["Next-Auth API"]:::backend
        subgraph "Admin APIs"
            direction TB
            AdminAssignAPI["Assignments API"]:::backend
            AdminCourseAPI["Courses API"]:::backend
            AdminFilesAPI["Files API"]:::backend
            AdminSchedAPI["Schedules API"]:::backend
            AdminStudentsAPI["Students API"]:::backend
        end
        subgraph "Student APIs"
            direction TB
            StuProfileAPI["Profile API"]:::backend
            StuAssignAPI["Assignments API"]:::backend
            StuCourseAPI["Courses API"]:::backend
            StuFilesAPI["Files API"]:::backend
            StuSchedAPI["Schedule API"]:::backend
            StuAIAPI["AI Question API"]:::backend
        end
    end

    %% Data Access Layer
    subgraph "Data & Integrations"
        direction TB
        MongoDB[(MongoDB Atlas)]:::external
        Cloudinary[(Cloudinary)]:::external
        OpenAI[(OpenAI AI Service)]:::external
    end

    %% Flows
    Browser["Web Browser"]:::frontend -->|"requests pages"| AppLayout
    AppPage -->|renders Landing UI| Browser

    AppLayout -->|navigates to Admin| AdminLayout
    AppLayout -->|navigates to Student| StudentLayout

    AdminPage -->|calls API| AdminAssignAPI
    StudentPage -->|calls API| StuProfileAPI
    AIAssistantPage -->|calls API| StuAIAPI

    %% API to Services
    AuthAPI -->|validate sessions| MongoDB
    AdminAssignAPI -->|CRUD operations| MongoDB
    AdminCourseAPI -->|CRUD operations| MongoDB
    AdminFilesAPI -->|upload/download| Cloudinary
    AdminFilesAPI -->|metadata| MongoDB
    AdminSchedAPI -->|CRUD operations| MongoDB
    AdminStudentsAPI -->|CRUD operations| MongoDB

    StuProfileAPI -->|read/write| MongoDB
    StuAssignAPI -->|read| MongoDB
    StuCourseAPI -->|read| MongoDB
    StuFilesAPI -->|download/upload| Cloudinary
    StuSchedAPI -->|read| MongoDB
    StuAIAPI -->|query| OpenAI

    %% Click Events
    click AppLayout "https://github.com/devnexessam/uni-portal/blob/master/app/layout.tsx"
    click AppPage "https://github.com/devnexessam/uni-portal/blob/master/app/page.tsx"
    click AdminLayout "https://github.com/devnexessam/uni-portal/blob/master/app/(pages)/admin/dashboard/layout.tsx"
    click AdminPage "https://github.com/devnexessam/uni-portal/blob/master/app/(pages)/admin/dashboard/page.tsx"
    click StudentLayout "https://github.com/devnexessam/uni-portal/blob/master/app/(pages)/student/dashboard/layout.tsx"
    click StudentPage "https://github.com/devnexessam/uni-portal/blob/master/app/(pages)/student/dashboard/page.tsx"
    click AIAssistantComp "https://github.com/devnexessam/uni-portal/blob/master/components/student/AIAssistant.tsx"
    click AIAssistantPage "https://github.com/devnexessam/uni-portal/blob/master/app/(pages)/student/dashboard/(pages)/Ai-assistant/page.tsx"
    click AuthAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/auth/[...nextauth]/route.ts"
    click AdminAssignAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/admin/assignments/route.ts"
    click AdminCourseAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/admin/courses/route.ts"
    click AdminFilesAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/admin/files/route.ts"
    click AdminSchedAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/admin/schedules/route.ts"
    click AdminStudentsAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/admin/students/route.ts"
    click StuProfileAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/student/profile/route.ts"
    click StuAssignAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/student/assignments/route.ts"
    click StuCourseAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/student/courses/route.ts"
    click StuFilesAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/student/files/route.ts"
    click StuSchedAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/student/schedule/route.ts"
    click StuAIAPI "https://github.com/devnexessam/uni-portal/blob/master/app/api/student/ai-question/route.ts"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#0d47a1,color:#0d47a1
    classDef backend fill:#c8e6c9,stroke:#1b5e20,color:#1b5e20
    classDef external fill:#ffe0b2,stroke:#e65100,color:#e65100
```
