# vaaditya320/track-lab architecture

> Architecture diagram of the GitHub repository vaaditya320/track-lab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vaaditya320/track-lab
- Repository: https://github.com/vaaditya320/track-lab

## Overview

##### Main Components
- Frontend (User Interface):
- Represented by the Next.js “app” directory. This contains public pages (e.g., app/page.js, app/projects, app/auth pages), components (e.g., DashboardSkeleton.jsx, ParticleBackground.js, ProjectStatsCard.jsx), theme files (trackLabTheme.js), and global layout files.
- It handles the UI rendering using Material UI, Framer Motion, and Tailwind CSS.

- Backend API Layer:
- Located in the “app/api” directory. Here, different endpoints are segmented by function:
▪ Authentication: app/api/auth/[...nextauth] routes using NextAuth for Google OAuth2 authentication.
▪ Projects: Routes handling project creation, updates, downloads, and completion (e.g., /api/projects/[id]/…).
▪ Admin: Separate endpoints for managing users, projects, and user roles.
▪ Students: Endpoints for student-related data.
- These endpoints provide CRUD operations and handle business logic.

- Database:
- PostgreSQL is the database used, with Prisma ORM managing the interactions.
- The “prisma” directory (schema.prisma & migrations) defines the database schema and migrations.

- External Services:
- Google OAuth2: Used for authentication.
- Email Notifications: Using Nodemailer for sending emails.
- PDF Generation: Through pdf-lib.
- AWS S3: Marked as planned for future storage integration.
- Google Analytics: Included via a component in the “utils” directory.

- Administration Panel:
- Found under app/admin, offering dedicated pages for managing projects, user roles, and users.
- It interacts with both the frontend UI and backend API routes.

##### Relationships and Interactions
- The browser (client) sends requests to the Next.js frontend, which renders pages based on the “app” structure.
- User interactions (like logging in, project submission, etc.) trigger API calls via endpoints in the “app/api” folder.
- The API layer communicates with the PostgreSQL database via Prisma.
- Authentication flows are managed by NextAuth connecting through the designated auth API endpoints with Google OAuth2.
- When projects are submitted or their status changes, associated modules trigger PDF generation and email notifications.
- The Admin Panel accesses both the API endpoints and UI components to provide an overview and management capabilities.
- Planned integrations (AWS S3) suggest that if file uploads or storage are needed, there will be additional interactions with S3.

##### Architectural Patterns and Technologies
- This project follows a Next.js App Router architecture separating frontend and backend API logic.
- It adheres to common full-stack design practices: a clear separation of concerns (UI vs. API vs. Database) and modular components.
- The use of Prisma ensures ORM-based, type-safe database interactions.
- Authentication is centralized via NextAuth, promoting secure access across both user-facing and admin routes.
- The integration of Material UI, Framer Motion, and Tailwind CSS enhances the frontend experience, while a standardized API layer simplifies backend services.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interface Layer
    subgraph "User Interface (Next.js Frontend)"
        UI_Pages["Pages (app/page.js, app/projects, app/auth, app/admin)"]:::frontend
        UI_Components["Components (DashboardSkeleton, ParticleBackground, ProjectStatsCard, ProjectStatusBadge)"]:::frontend
        UI_Theme["Custom Theme (trackLabTheme.js)"]:::frontend
    end

    %% Backend API Layer
    subgraph "Backend API Layer (Next.js API Routes)"
        API_Auth["Authentication API ([...nextauth]/route.js)"]:::api
        API_Projects["Projects API (various endpoints)"]:::api
        API_Admin["Administration API (app/api/admin)"]:::api
        API_Students["Students API (app/api/students/route.js)"]:::api
    end

    %% Database Layer
    subgraph "Database (PostgreSQL via Prisma)"
        DB["PostgreSQL (Prisma ORM)"]:::db
    end

    %% External Services
    subgraph "External Services Integration"
        ES_Google["Google OAuth2"]:::external
        ES_Email["Email Notifications (Nodemailer)"]:::external
        ES_PDF["PDF Generation (pdf-lib)"]:::external
        ES_AWS["AWS S3 (Planned)"]:::external
        ES_GA["Google Analytics"]:::external
    end

    %% Connections from UI to API
    UI_Pages -->|"api_call"| API_Auth
    UI_Pages -->|"api_call"| API_Projects
    UI_Pages -->|"api_call"| API_Admin
    UI_Pages -->|"api_call"| API_Students

    %% UI Components interacting with External Analytics
    UI_Components -->|"track"| ES_GA

    %% API Layer interactions with Database
    API_Auth -->|"CRUD"| DB
    API_Projects -->|"CRUD"| DB
    API_Admin -->|"CRUD"| DB
    API_Students -->|"CRUD"| DB

    %% API Layer interactions with External Services
    API_Auth -->|"auth_flow"| ES_Google
    API_Projects -->|"generate_pdf"| ES_PDF
    API_Projects -->|"send_email"| ES_Email
    API_Projects -->|"store_files"| ES_AWS

    %% Click Events
    click UI_Pages "https://github.com/vaaditya320/track-lab/tree/main/app/"
    click UI_Components "https://github.com/vaaditya320/track-lab/tree/main/app/components"
    click UI_Theme "https://github.com/vaaditya320/track-lab/blob/main/app/theme/trackLabTheme.js"
    click API_Auth "https://github.com/vaaditya320/track-lab/blob/main/app/api/auth/[...nextauth]/route.js"
    click API_Projects "https://github.com/vaaditya320/track-lab/tree/main/app/api/projects"
    click API_Admin "https://github.com/vaaditya320/track-lab/tree/main/app/api/admin"
    click API_Students "https://github.com/vaaditya320/track-lab/blob/main/app/api/students/route.js"
    click DB "https://github.com/vaaditya320/track-lab/tree/main/prisma/"
    click ES_GA "https://github.com/vaaditya320/track-lab/blob/main/utils/GoogleAnalytics.jsx"

    %% Class Definitions for Colors
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef api fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
    classDef db fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
    classDef external fill:#FFF9C4,stroke:#F57F17,stroke-width:2px;
```
