# ritesh2006m/google architecture

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

- Interactive diagram: https://gitdiagram.com/ritesh2006m/google
- Repository: https://github.com/ritesh2006m/google

## Overview

##### Project type and purpose
- Score Lab is a full-stack, serverless web application built with Next.js (TypeScript) that automates grading of student answer-script PDFs using Google’s Document AI and the Gemini API. The system provides separate dashboards for admins, teachers, and students, stores data in Cloud SQL, and assets in a Google Cloud Storage bucket.

##### File structure
- Top-level “app” directory:
- app/api/* → Next.js API Routes (serverless endpoints for auth, student workflows, teacher workflows, general OCR)
- app/dashboard/* → React pages/components for Admin, Teacher, Student UIs
- app/user/* → Login and Signup flows
- app/layout.tsx & app/page.tsx → Root layout and landing page
- “components” folder → Reusable UI components (charts, form inputs, sidebar)
- “lib” folder → Utility modules for DB (Cloud SQL via Prisma/pg), Google Storage, and helpers
- Configuration and scripts: next.config.mjs, tailwind.config.ts, tsconfig.json

##### README for additional insights
- Describes core flows:
1) Teacher uploads question PDF
2) Student uploads answer PDF
3) Document AI OCR
4) Gemini API scoring & feedback
5) Persist results in Cloud SQL & Cloud Storage
6) Dashboards retrieve and display metrics
- Tech Stack confirms Next.js serverless model, Cloud Run hosting, Cloud Functions for AI orchestration, Cloud SQL, GCS bucket

a. Main components
- Frontend (Next.js pages & components)
- API Layer (Next.js API Routes)
- Cloud Storage Bucket
- Document AI Service
- Gemini API
- Cloud Functions (optional orchestration)
- Cloud SQL Database
- External Auth (e.g., JWT or session store)
b. Relationships and interactions
1. User (Teacher/Student) → Frontend UI
2. Frontend → Next.js API Routes (REST endpoints)
3. “Upload” endpoints → lib/googleStorage.ts → Cloud Storage
4. app/api/general/ocr.ts → Document AI OCR
5. OCR output → Gemini API evaluation
6. Gemini result → Cloud Functions (if heavy compute) or direct API Route
7. Persist feedback & scores → Cloud SQL
8. Dashboards → API Routes → Cloud SQL (queries) → Frontend
c. Architectural patterns and design principles
- Serverless micro-services using Next.js API Routes
- Separation of concerns: UI vs. data-access (lib/db.ts) vs. storage service vs. AI service
- Stateless frontends, stateful database
- Reusable UI component library for consistent design
d. Key technologies/frameworks
- Next.js (React + serverless API routes)
- Tailwind CSS for styling
- Cloud SQL (PostgreSQL)
- Google Cloud Storage bucket
- Google Document AI (OCR)
- Gemini API (scoring & feedback)
- Cloud Functions (for heavy AI orchestrations)
- Recharts for data visualization

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Users
    User["Browser (Teacher/Student/Admin)"]:::user

    %% Frontend Layer
    subgraph "UI Layer" 
        direction TB
        Layout["Root Layout"]:::frontend
        Landing["Landing Page"]:::frontend
        Login["Login Page"]:::frontend
        StudentSignup["Student Signup"]:::frontend
        TeacherSignup["Teacher Signup"]:::frontend
        EmailVerify["Email Verification"]:::frontend

        subgraph "Dashboard UIs"
            direction TB
            AdminDashboard["Admin Dashboard"]:::frontend
            AdminSidebar["Admin Sidebar"]:::frontend
            AdminStudents["Admin Students"]:::frontend
            AdminTeachers["Admin Teachers"]:::frontend

            TeacherDashboard["Teacher Dashboard"]:::frontend
            TeacherSidebar["Teacher Sidebar"]:::frontend
            AssignTasks["Assign Tasks"]:::frontend
            UploadAssignments["Upload Assignments"]:::frontend

            StudentDashboard["Student Dashboard"]:::frontend
            StudentTasksList["Assignments List"]:::frontend
            StudentResult["Result View"]:::frontend
            StudentPerfChart["Performance Chart"]:::frontend
            StudentTasksChart["Tasks Chart"]:::frontend
            StudentSidebar["Student Sidebar"]:::frontend
        end
    end

    %% API Layer
    subgraph "API Layer" 
        direction TB
        AuthLogin["Auth: Login"]:::api
        AuthSubjects["Auth: Subjects"]:::api
        AuthVerify["Auth: Verify"]:::api

        AdminAddStudents["Admin: Add Students"]:::api

        TeacherUploadMeta["Teacher: Upload Assignment Metadata"]:::api
        TeacherTasks["Teacher: Tasks"]:::api

        StudentUploadAnswer["Student: Upload Answer PDF"]:::api
        StudentGetAssignments["Student: Get Assignments"]:::api
        StudentGetPDF["Student: Download PDF"]:::api
        StudentSubmitResult["Student: Submit Result"]:::api
        StudentMetricsTasks["Student: Metrics/GetTasks"]:::api
        StudentMetrics["Student: Metrics"]:::api

        GeneralOCR["General: OCR"]:::api
    end

    %% Utility Modules
    libGS["lib/googleStorage.ts"]:::util
    libDB["lib/db.ts"]:::util
    libUtils["lib/utils.ts"]:::util

    %% Services
    CloudStorage["Cloud Storage Bucket"]:::storage
    DocumentAI["Document AI Service"]:::ai
    Gemini["Gemini API"]:::ai
    CloudFunctions["Cloud Functions"]:::compute

    %% Database
    CloudSQL["Cloud SQL Database"]:::db

    %% Connections
    User -->|"interacts with"| Layout
    User --> Landing
    User --> Login
    User --> StudentSignup
    User --> TeacherSignup
    User --> EmailVerify
    User --> AdminDashboard
    User --> TeacherDashboard
    User --> StudentDashboard

    %% UI to API
    Layout --> API["API Layer"]:::api
    Landing --> API
    Login --> AuthLogin
    StudentSignup --> AuthSubjects
    TeacherSignup --> AuthSubjects
    EmailVerify --> AuthVerify

    AdminDashboard --> AdminAddStudents
    AdminStudents --> AdminAddStudents
    AdminTeachers --> AdminAddStudents

    TeacherDashboard --> TeacherUploadMeta
    AssignTasks --> TeacherTasks
    UploadAssignments --> TeacherUploadMeta

    StudentDashboard --> StudentGetAssignments
    StudentTasksList --> StudentGetAssignments
    StudentGetPDF --> StudentGetPDF
    StudentResult --> StudentSubmitResult
    StudentPerfChart --> StudentMetrics
    StudentTasksChart --> StudentMetricsTasks

    %% API to Storage and Services
    TeacherUploadMeta -->|POST upload| libGS
    StudentUploadAnswer -->|POST upload| libGS
    libGS -->|stores PDF| CloudStorage

    GeneralOCR -->|OCR request| DocumentAI
    DocumentAI -->|OCR response| GeneralOCR

    GeneralOCR -->|send text| Gemini
    Gemini -->|scoring feedback| GeneralOCR

    GeneralOCR --> libDB
    TeacherTasks --> libDB
    StudentGetAssignments --> libDB
    StudentSubmitResult --> libDB
    StudentMetrics --> libDB
    StudentMetricsTasks --> libDB
    AdminAddStudents --> libDB

    libDB -->|reads/writes| CloudSQL

    %% Optional orchestration
    GeneralOCR --> CloudFunctions
    CloudFunctions --> Gemini
    CloudFunctions --> libDB

    %% Responses back to UI
    AuthLogin --> Login
    AuthVerify --> EmailVerify
    AuthSubjects --> StudentSignup
    AuthSubjects --> TeacherSignup
    AdminAddStudents --> AdminDashboard
    TeacherUploadMeta --> UploadAssignments
    TeacherTasks --> AssignTasks
    StudentGetAssignments --> StudentDashboard
    StudentGetPDF --> StudentTasksList
    StudentSubmitResult --> StudentResult
    StudentMetrics --> StudentPerfChart
    StudentMetricsTasks --> StudentTasksChart

    %% Click Events
    click Layout "https://github.com/ritesh2006m/google/blob/main/app/layout.tsx"
    click Landing "https://github.com/ritesh2006m/google/blob/main/app/page.tsx"
    click Login "https://github.com/ritesh2006m/google/blob/main/app/user/login/page.tsx"
    click StudentSignup "https://github.com/ritesh2006m/google/blob/main/app/user/signup/student/page.tsx"
    click TeacherSignup "https://github.com/ritesh2006m/google/blob/main/app/user/signup/teacher/page.tsx"
    click EmailVerify "https://github.com/ritesh2006m/google/blob/main/app/user/signup/verify/page.tsx"
    click AdminDashboard "https://github.com/ritesh2006m/google/blob/main/app/dashboard/admin/page.tsx"
    click AdminSidebar "https://github.com/ritesh2006m/google/blob/main/app/dashboard/admin/Sidebar.tsx"
    click AdminStudents "https://github.com/ritesh2006m/google/blob/main/app/dashboard/admin/students/page.tsx"
    click AdminTeachers "https://github.com/ritesh2006m/google/blob/main/app/dashboard/admin/teachers/page.tsx"
    click TeacherDashboard "https://github.com/ritesh2006m/google/blob/main/app/dashboard/teacher/page.tsx"
    click TeacherSidebar "https://github.com/ritesh2006m/google/blob/main/app/dashboard/teacher/sidebar.tsx"
    click AssignTasks "https://github.com/ritesh2006m/google/blob/main/app/dashboard/teacher/assign/page.tsx"
    click UploadAssignments "https://github.com/ritesh2006m/google/blob/main/app/dashboard/teacher/upload/page.tsx"
    click StudentDashboard "https://github.com/ritesh2006m/google/blob/main/app/dashboard/student/page.tsx"
    click StudentTasksList "https://github.com/ritesh2006m/google/blob/main/app/dashboard/student/assignments/page.tsx"
    click StudentResult "https://github.com/ritesh2006m/google/blob/main/app/dashboard/student/result/page.tsx"
    click StudentPerfChart "https://github.com/ritesh2006m/google/blob/main/app/dashboard/student/components/StudentPerformanceChart.tsx"
    click StudentTasksChart "https://github.com/ritesh2006m/google/blob/main/app/dashboard/student/components/StudentTasksChart.tsx"
    click StudentSidebar "https://github.com/ritesh2006m/google/blob/main/app/dashboard/student/sidebar.tsx"
    click libGS "https://github.com/ritesh2006m/google/blob/main/lib/googleStorage.ts"
    click libDB "https://github.com/ritesh2006m/google/blob/main/lib/db.ts"
    click libUtils "https://github.com/ritesh2006m/google/blob/main/lib/utils.ts"
    click AuthLogin "https://github.com/ritesh2006m/google/blob/main/app/api/auth/login/route.ts"
    click AuthSubjects "https://github.com/ritesh2006m/google/blob/main/app/api/auth/subjects/route.ts"
    click AuthVerify "https://github.com/ritesh2006m/google/blob/main/app/api/auth/verify/route.ts"
    click AdminAddStudents "https://github.com/ritesh2006m/google/blob/main/app/api/admin/addStudents/route.ts"
    click TeacherUploadMeta "https://github.com/ritesh2006m/google/blob/main/app/api/teacher/upload-assignment/route.ts"
    click TeacherTasks "https://github.com/ritesh2006m/google/blob/main/app/api/teacher/tasks/route.ts"
    click StudentUploadAnswer "https://github.com/ritesh2006m/google/blob/main/app/api/student/uploadAssignment/route.ts"
    click StudentGetAssignments "https://github.com/ritesh2006m/google/blob/main/app/api/student/getAssignments/route.ts"
    click StudentGetPDF "https://github.com/ritesh2006m/google/blob/main/app/api/student/getpdf/route.ts"
    click StudentSubmitResult "https://github.com/ritesh2006m/google/blob/main/app/api/student/result/route.ts"
    click StudentMetricsTasks "https://github.com/ritesh2006m/google/blob/main/app/api/student/metrics/getTasks/route.ts"
    click StudentMetrics "https://github.com/ritesh2006m/google/blob/main/app/api/student/metrics/route.ts"
    click GeneralOCR "https://github.com/ritesh2006m/google/blob/main/app/api/general/ocr.ts"

    %% Styles
    classDef user fill:#E0F7FA,stroke:#006064,color:#006064
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1
    classDef api fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20
    classDef util fill:#FFE0B2,stroke:#E65100,color:#E65100
    classDef storage fill:#FFCCBC,stroke:#BF360C,color:#BF360C
    classDef ai fill:#E1BEE7,stroke:#4A148C,color:#4A148C
    classDef compute fill:#D1C4E9,stroke:#311B92,color:#311B92
    classDef db fill:#B2DFDB,stroke:#004D40,color:#004D40
```
