# 150202-pratham/mongobuddy architecture

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

- Interactive diagram: https://gitdiagram.com/150202-pratham/mongobuddy
- Repository: https://github.com/150202-pratham/mongobuddy

## Overview

##### Project Type & Purpose
- Mongo Buddy is a full-stack, gamified learning platform for MongoDB (and/or Supabase).
- The frontend is a React SPA (Vite + Tailwind + React Context), deployed on Render.
- The “backend” is handled via Supabase (Auth + Postgres) and optionally a Node/Express layer (per README).

##### File Structure
- Top level: configuration files (vite.config.js, tailwind.config.js, postcss.config.js), package.json, public/ (static), src/ (React code).
- src/Components: UI modules (Auth, Index Page, Module lessons, Tasks, Debug panels, Bear mascots).
- src/config/supabase.js & src/services/supabaseProgressService.js: client-side access to Supabase.
- src/contexts/AuthContext.jsx: global auth state.
- No explicit “backend/” folder—data access is direct via supabase-js.

##### Extract Architectural Clues from the README
- Mentions Node.js/Express + MongoDB, but code uses Supabase. Treat Supabase (Auth + DB) as the primary API layer.
- Deployed on Render (URL given).
- Uses environment variables (VITE_SUPABASE_URL, VITE_SUPABASE_ANON_KEY).
- Gamified progression logic lives in React + Supabase stored procedures / SQL schema (supabase-schema.sql).

##### Main Components
a. Presentation Layer (Client Browser)
- React SPA (Vite-bundled, Tailwind-styled)
- UI components: AuthForm, QuizTasks, Module pages, Progress bar, Bear animations
b. API / BaaS Layer
- Supabase Auth (signup, login, JWT issuance)
- Supabase Database (Postgres tables for users, checkpoints, quizzes, tasks, progress)
- Optional Node/Express server (if actual REST endpoints wrap Supabase or MongoDB Atlas)
c. Data Layer
- Supabase-managed Postgres (or MongoDB Atlas if used)
- supabase-schema.sql defines tables & policies
d. Deployment & Hosting
- Render (serving static SPA)
- CI/CD (GitHub Actions or manual deploys)
e. External Services
- Firebase (if used for analytics or additional auth)
- Third-party libraries (Lottie for bear animations, supabase-js SDK, React Router)

##### Relationships & Data Flows
- Browser → Supabase Auth: login/signup requests → JWT
- Browser → Supabase DB: authenticated CRUD (progress, quiz answers)
- Browser → (Optional) Express API → MongoDB (if using separate backend)
- Supabase DB → triggers/policies → secure data access
- Git push → CI/CD → Render deploy → updated SPA

##### Architectural Patterns & Principles
- SPA with component-based UI (separation of concerns)
- BaaS pattern (delegating auth + data storage to Supabase)
- React Context for global state (AuthContext)
- Service layer (supabaseProgressService) abstracts data operations
- Environment-driven configuration (.env variables for endpoints/keys)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (Browser)"
        direction TB
        subgraph "Entry Points"
            direction TB
            IndexHTML["index.html"]:::frontend
            MainJS["src/main.jsx"]:::frontend
            AppJS["src/App.jsx"]:::frontend
        end
        subgraph "UI Components"
            direction TB
            AuthForm["AuthForm.jsx"]:::frontend
            LoginPage["Login.jsx"]:::frontend
            SignupPage["Signup.jsx"]:::frontend
            ModuleLessons["Module Lessons"]:::frontend
            TaskRunners["Task Runners"]:::frontend
            LandingPage["Home.jsx"]:::frontend
            BearMascots["Bear Mascots & Animations"]:::frontend
            DebugPanels["Debug Panels"]:::frontend
        end
        subgraph "Global State"
            direction TB
            AuthContext["AuthContext.jsx"]:::frontend
        end
    end

    %% BaaS / API Layer
    subgraph "API / BaaS Layer"
        direction TB
        SupabaseAuth["Supabase Auth"]:::api
        SupabaseClientConfig["supabase.js"]:::api
        ProgressService["supabaseProgressService.js"]:::api
        OptionalExpress["Node/Express API"]:::api
    end

    %% Data Store
    subgraph "Data Store"
        direction TB
        PostgresDB["Supabase Postgres DB"]:::db
        DBSchema["supabase-schema.sql"]:::db
        MongoDB["MongoDB Atlas"]:::db
    end

    %% Deployment & Hosting
    subgraph "Deployment & CI/CD"
        direction TB
        GitHubActions["GitHub Actions"]:::infra
        Render["Render (Static SPA)"]:::infra
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Firebase["Firebase (Analytics/Auth)"]:::external
        Lottie["Lottie CDN"]:::external
    end

    %% Connections
    IndexHTML -->|loads| MainJS
    MainJS -->|renders| AppJS
    AppJS -->|uses| AuthContext
    AppJS -->|routes| AuthForm
    AppJS -->|routes| LoginPage
    AppJS -->|routes| SignupPage
    AppJS -->|routes| ModuleLessons
    AppJS -->|routes| TaskRunners
    AppJS -->|routes| LandingPage
    AppJS -->|renders| BearMascots
    AppJS -->|renders| DebugPanels

    AuthForm -->|HTTPS REST| SupabaseAuth
    LoginPage -->|HTTPS REST| SupabaseAuth
    SignupPage -->|HTTPS REST| SupabaseAuth

    AppJS -->|calls| SupabaseClientConfig
    SupabaseClientConfig -->|provides| ProgressService
    ProgressService -->|CRUD over HTTPS| PostgresDB

    OptionalExpress -->|/api/* endpoints| MongoDB

    SupabaseAuth -->|JWT| AppJS
    SupabaseAuth -->|manages| PostgresDB

    GitHubActions -->|on push| Render
    Render -->|serves| IndexHTML

    AppJS -->|optional analytics| Firebase
    BearMascots -->|animations via| Lottie

    %% Click Events
    click IndexHTML "https://github.com/150202-pratham/mongobuddy/blob/master/index.html"
    click MainJS "https://github.com/150202-pratham/mongobuddy/blob/master/src/main.jsx"
    click AppJS "https://github.com/150202-pratham/mongobuddy/blob/master/src/App.jsx"
    click AuthForm "https://github.com/150202-pratham/mongobuddy/blob/master/src/Components/Auth/AuthForm.jsx"
    click LoginPage "https://github.com/150202-pratham/mongobuddy/blob/master/src/Components/Login.jsx"
    click SignupPage "https://github.com/150202-pratham/mongobuddy/blob/master/src/Components/Signup.jsx"
    click ModuleLessons "https://github.com/150202-pratham/mongobuddy/tree/master/src/Components/Module"
    click TaskRunners "https://github.com/150202-pratham/mongobuddy/tree/master/src/Components/Task"
    click LandingPage "https://github.com/150202-pratham/mongobuddy/blob/master/src/Components/Index page/Home.jsx"
    click BearMascots "https://github.com/150202-pratham/mongobuddy/blob/master/src/Components/BearMascot.jsx"
    click DebugPanels "https://github.com/150202-pratham/mongobuddy/blob/master/src/Components/DebugPanel.jsx"
    click AuthContext "https://github.com/150202-pratham/mongobuddy/blob/master/src/contexts/AuthContext.jsx"
    click SupabaseClientConfig "https://github.com/150202-pratham/mongobuddy/blob/master/src/config/supabase.js"
    click ProgressService "https://github.com/150202-pratham/mongobuddy/blob/master/src/services/supabaseProgressService.js"
    click DBSchema "https://github.com/150202-pratham/mongobuddy/blob/master/supabase-schema.sql"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef api fill:#FFE8B0,stroke:#D97706,color:#B45309;
    classDef db fill:#D3F9D8,stroke:#15803D,color:#166534;
    classDef infra fill:#E5E7EB,stroke:#6B7280,color:#374151;
    classDef external fill:#F3E8FF,stroke:#7C3AED,color:#5B21B6;
```
