# romeirofernandes/clarityai architecture

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

- Interactive diagram: https://gitdiagram.com/romeirofernandes/clarityai
- Repository: https://github.com/romeirofernandes/clarityai

## Overview

##### Project type and purpose
- ClarityAI is a full-stack web application that transforms static PDFs into dynamic learning materials (summaries, flashcards, quizzes) and supports active recall via speech-to-text and AI feedback.

##### File structure
- Top-level “frontend” and “backend” folders indicate a two-tier architecture.
- The backend follows an MVC-style layout:
- config/ (db.js) for database connections
- models/ (User, Deck, Streak)
- controllers/ (userController)
- routes/ (deckRoutes, revision, transcribe, upload, etc.)
- server.js to wire everything up
- The frontend is a React/Vite app with:
- src/pages/ for individual screens
- src/components/ for reusable UI modules
- src/Api/Auth.js and axios util for HTTP calls
- firebase.config.js for Firebase Authentication
- Key config files:
- backend/.nixpacks.toml, package.json, .env references
- frontend/vite.config.js, vercel.json, .env for VITE_API_URL and Firebase variables

##### README for additional insights
- Tech stack summary confirms: React + Tailwind CSS + Framer Motion + Axios on the front; Node/Express + Mongoose/MongoDB on the back; PDF-parse for parsing; Google Gemini AI for generative tasks; Web Speech API for transcription; Firebase for auth.
- Features map 1:1 to backend routes (upload, transcribe, revision, streaks, decks, users).

##### Capturing essential architectural elements
- Don’t omit the MVC substructure in the backend.
- Speech-to-text route’s dual interaction: client’s Web Speech API → backend transcribe route → Gemini or local engine.
- If deployed on Vercel or another platform, optionally include a “Deployment” layer showing Vercel for frontend and your hosting provider (e.g., Heroku, AWS) for the backend/API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Tier
    subgraph "Client Tier"
        direction TB
        Browser["User's Web Browser"]:::external
        FrontendApp["React Frontend"]:::frontend
        Pages["UI Pages (Upload, Dashboard, Revision, Active Recall)"]:::frontend
        Components["Reusable UI Components"]:::frontend
        AuthUtil["Auth & API Utilities"]:::frontend
        FirebaseConfig["Firebase Auth Configuration"]:::frontend
        ViteConfig["Vite Build Configuration"]:::frontend
        VercelConfig["Vercel Deployment Configuration"]:::frontend
        SpeechAPI["Web Speech API"]:::external
    end

    %% Server Tier
    subgraph "Server Tier"
        direction TB
        Server["Express API Service"]:::backend
        DBConfig["Database Config (db.js)"]:::backend
        subgraph "Models"
            direction TB
            UserModel["User Model"]:::backend
            DeckModel["Deck Model"]:::backend
            StreakModel["Streak Model"]:::backend
        end
        UserController["User Controller"]:::backend
        subgraph "Routes"
            direction TB
            RoutesIndex["Route Index"]:::backend
            DeckRoutes["Deck Management Routes"]:::backend
            RevisionRoutes["Revision Workflow Routes"]:::backend
            UploadRoutes["Upload & PDF Parsing Routes"]:::backend
            TranscribeRoutes["Speech-to-Text Route"]:::backend
            UserRoutes["User Management Routes"]:::backend
            StreakRoutes["Streak Tracking Routes"]:::backend
        end
        PDFParser["PDF Parser (pdf-parse)"]:::backend
        AIProcessor["AI Processing (Google Gemini)"]:::backend
    end

    %% Database & External Services
    MongoDB["MongoDB"]:::database
    FirebaseAuth["Firebase Authentication"]:::external
    GeminiAI["Google Gemini AI"]:::external

    %% Connections
    Browser -->|"interacts with"| FrontendApp
    FrontendApp -->|"renders"| Pages
    FrontendApp -->|"uses"| Components
    FrontendApp -->|"uses"| AuthUtil
    FrontendApp -->|"calls API"| Server
    FrontendApp -->|"captures audio"| SpeechAPI
    FrontendApp -->|"auth via"| FirebaseAuth
    FrontendApp -->|"deployed on"| VercelConfig
    FrontendApp -->|"built by"| ViteConfig
    Server -->|"loads config"| DBConfig
    Server -->|"registers models"| UserModel
    Server -->|"registers models"| DeckModel
    Server -->|"registers models"| StreakModel
    Server -->|"uses controller"| UserController
    Server -->|"mounts routes"| RoutesIndex
    RoutesIndex --> DeckRoutes
    RoutesIndex --> RevisionRoutes
    RoutesIndex --> UploadRoutes
    RoutesIndex --> TranscribeRoutes
    RoutesIndex --> UserRoutes
    RoutesIndex --> StreakRoutes
    UploadRoutes -->|"parses PDFs with"| PDFParser
    UploadRoutes -->|"stores data"| Server
    TranscribeRoutes -->|"processes audio from"| SpeechAPI
    TranscribeRoutes -->|"sends to AI"| AIProcessor
    DeckRoutes -->|"fetches/saves decks in"| MongoDB
    RevisionRoutes -->|"fetches data from"| MongoDB
    UserRoutes -->|"manages users in"| MongoDB
    StreakRoutes -->|"updates streaks in"| MongoDB
    Server -->|"queries"| MongoDB
    AIProcessor -->|"calls API"| GeminiAI
    FirebaseAuth -->|"validates tokens"| Server

    %% Click Events - Frontend
    click FrontendApp "https://github.com/romeirofernandes/clarityai/tree/main/frontend/"
    click Pages "https://github.com/romeirofernandes/clarityai/tree/main/frontend/src/pages/"
    click Components "https://github.com/romeirofernandes/clarityai/tree/main/frontend/src/components/"
    click AuthUtil "https://github.com/romeirofernandes/clarityai/blob/main/frontend/src/Api/Auth.js"
    click AxiosUtil "https://github.com/romeirofernandes/clarityai/blob/main/frontend/src/utils/axios.js"
    click FirebaseConfig "https://github.com/romeirofernandes/clarityai/blob/main/frontend/src/firebase.config.js"
    click ViteConfig "https://github.com/romeirofernandes/clarityai/blob/main/frontend/vite.config.js"
    click VercelConfig "https://github.com/romeirofernandes/clarityai/blob/main/frontend/vercel.json"

    %% Click Events - Backend
    click Server "https://github.com/romeirofernandes/clarityai/blob/main/backend/server.js"
    click DBConfig "https://github.com/romeirofernandes/clarityai/blob/main/backend/config/db.js"
    click UserModel "https://github.com/romeirofernandes/clarityai/blob/main/backend/models/user.js"
    click DeckModel "https://github.com/romeirofernandes/clarityai/blob/main/backend/models/deck.js"
    click StreakModel "https://github.com/romeirofernandes/clarityai/blob/main/backend/models/streak.js"
    click UserController "https://github.com/romeirofernandes/clarityai/blob/main/backend/controllers/userController.js"
    click RoutesIndex "https://github.com/romeirofernandes/clarityai/blob/main/backend/routes/index.js"
    click DeckRoutes "https://github.com/romeirofernandes/clarityai/blob/main/backend/routes/deckRoutes.js"
    click RevisionRoutes "https://github.com/romeirofernandes/clarityai/blob/main/backend/routes/revision.js"
    click UploadRoutes "https://github.com/romeirofernandes/clarityai/blob/main/backend/routes/upload.js"
    click TranscribeRoutes "https://github.com/romeirofernandes/clarityai/blob/main/backend/routes/transcribe.js"
    click UserRoutes "https://github.com/romeirofernandes/clarityai/blob/main/backend/routes/userRoutes.js"
    click StreakRoutes "https://github.com/romeirofernandes/clarityai/blob/main/backend/routes/streakRoutes.js"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#1976D2,stroke-width:1px
    classDef backend fill:#C8E6C9,stroke:#388E3C,stroke-width:1px
    classDef database fill:#FFE0B2,stroke:#F57C00,stroke-width:1px
    classDef external fill:#E1BEE7,stroke:#7B1FA2,stroke-width:1px
```
