# ahmadsallaq6/codebuddyfinal architecture

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

- Interactive diagram: https://gitdiagram.com/ahmadsallaq6/codebuddyfinal
- Repository: https://github.com/ahmadsallaq6/codebuddyfinal

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“CodeBuddy”) built with Next.js 14+ using the App Router.
- Purpose: An AI-powered learning platform connecting students and mentors, hosting interactive coding exercises, tracking progress, and providing AI-generated content & feedback.

##### File Structure
- Top-level:
- `app/` – Next.js App Router routes, subdivided into `auth`, `dashboard`, `admin`, `api`
- `components/` – Shared React UI components and shadcn/ui primitives under `components/ui/`
- `contexts/`, `hooks/`, `providers/` – State management and custom hooks
- `lib/`, `services/` – Business logic: interfaces to Firebase (auth, Firestore, storage), AI (Gemini), code evaluation
- `public/`, `styles/`, `scripts/` – Static assets, global styles, DB seed scripts
- Config files: `next.config.mjs`, `tailwind.config.ts`, `tsconfig.json`
- Patterns:
- Next.js App Route (nested layouts, server vs client components)
- Context Providers wrapping the tree (`auth-context`, `theme-provider`)
- Service layer abstraction (`lib/*-service.ts`, `services/*`)

##### README Insights
- Tech stack: Next.js, TypeScript, Firebase Auth/Firestore/Storage, Tailwind + shadcn/ui, Gemini API, Monaco Editor.
- Features: Auth (students, mentors), Dashboard, Exercises (code editor, test runner), AI feedback, Social (messaging, leaderboard), Admin tools.

##### Final Advice
- Be comprehensive: break the system into all logical components (UI, contexts, hooks, server, services, DB).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Client
    subgraph "Browser (Client)" 
        direction TB
        UI["Next.js App Router"]:::frontend
        AuthPages["Auth Pages & Layout"]:::frontend
        DashboardSection["Dashboard Section"]:::frontend
        Components["Shared UI Components"]:::frontend
        Contexts["Context Providers"]:::frontend
        Hooks["Custom Hooks"]:::frontend
        Monaco["Monaco Code Editor"]:::frontend
    end

    %% Next.js Server
    subgraph "Next.js Server (Node.js)" 
        direction TB
        ServerComp["Server Components & API Routes"]:::backend
        GeminiAPI["API Route: Gemini"]:::backend
        CodeEvalService["Code Evaluation Service"]:::backend
    end

    %% Firebase Services
    subgraph "Firebase Services" 
        direction TB
        AuthSvc["Authentication Service"]:::datastore
        FirestoreDB["Firestore Database"]:::datastore
        StorageSvc["Storage"]:::datastore
    end

    %% External AI
    GeminiExt["Gemini API"]:::external

    %% Code Evaluation Engine External
    CodeEvalExt["Code Evaluation Engine"]:::external

    %% Admin Tools & Scripts
    subgraph "Admin Tools & Scripts"
        direction TB
        AdminSeed["Seed Database Script"]:::backend
        AdminIndexes["Index Creation Script"]:::backend
        AdminChecker["Relationship Checker"]:::backend
    end

    %% Connections
    UI -->|"renders pages"| ServerComp
    AuthPages --> UI
    DashboardSection --> UI
    Components --> UI
    Contexts --> UI
    Hooks --> UI
    Monaco --> UI

    UI -->|"fetch/use-api"| ServerComp
    ServerComp -->|"auth calls"| AuthSvc
    ServerComp -->|"db reads/writes"| FirestoreDB
    ServerComp -->|"storage ops"| StorageSvc
    ServerComp -->|"calls AI"| GeminiExt
    ServerComp -->|"executes tests"| CodeEvalExt

    UI -->|"real-time listeners"| FirestoreDB
    UI -->|"code eval requests"| CodeEvalExt

    AdminSeed --> FirestoreDB
    AdminIndexes --> FirestoreDB
    AdminChecker --> FirestoreDB

    %% Click Events
    click UI "https://github.com/ahmadsallaq6/codebuddyfinal/tree/main/app/"
    click AuthPages "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/app/auth/layout.tsx"
    click AuthPages "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/app/auth/login/page.tsx"
    click AuthPages "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/app/auth/signup/page.tsx"
    click AuthPages "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/app/auth/reset-password/page.tsx"
    click DashboardSection "https://github.com/ahmadsallaq6/codebuddyfinal/tree/main/app/(dashboard)/"
    click Contexts "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/contexts/auth-context.tsx"
    click Contexts "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/contexts/achievements-context.tsx"
    click Contexts "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/providers/theme-provider.tsx"
    click Hooks "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/hooks/use-api.ts"
    click Hooks "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/hooks/use-auth-state.ts"
    click Hooks "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/hooks/use-code-evaluation.ts"
    click Monaco "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/components/code-editor.tsx"
    click Components "https://github.com/ahmadsallaq6/codebuddyfinal/tree/main/components/ui/"
    click ServerComp "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/app/api/gemini/actions.ts"
    click CodeEvalService "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/services/code-evaluation-service.ts"
    click AdminSeed "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/scripts/seed-database.tsx"
    click AdminIndexes "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/lib/create-indexes.ts"
    click AdminChecker "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/app/admin/tools/relationship-checker/page.tsx"
    click GeminiAPI "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/app/api/gemini/actions.ts"
    click AuthSvc "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/lib/firebase.ts"
    click FirestoreDB "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/lib/firestore.ts"
    click StorageSvc "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/lib/storage.ts"
    click Monaco "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/app/(dashboard)/exercises/[id]/code-evaluation.tsx"
    click AdminSeed "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/app/admin/seed/page.tsx"
    click AdminIndexes "https://github.com/ahmadsallaq6/codebuddyfinal/blob/main/app/admin/indexes/page.tsx"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#005B96,color:#000;
    classDef backend fill:#DFFDDA,stroke:#006400,color:#000;
    classDef external fill:#FFE4B5,stroke:#FF8C00,color:#000;
    classDef datastore fill:#E8E8E8,stroke:#A9A9A9,color:#000;
```
