# ankitsaha00/bhasha architecture

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

- Interactive diagram: https://gitdiagram.com/ankitsaha00/bhasha
- Repository: https://github.com/ankitsaha00/bhasha

## Overview

##### Main Components
- Frontend Layer:
- The app directory is split into multiple segments:
- (marketing): For public-facing pages such as the header, footer, and basic marketing layout.
- (main): The main application for logged-in users that includes courses, learning, quests, leaderboard, and shop.
- (admin): A dedicated admin section that contains pages to create, edit, and list challenges, courses, lessons, and units.
- Additional routes: “lesson” folders for detailed lesson views.
- API Layer:
- Under app/api, there are separate endpoints for challenges, challengeOptions, courses, lessons, and units. These endpoints encapsulate the back-end business logic for handling CRUD operations and other interactions.
- Actions & State Management:
- The “actions” folder contains functions (e.g., challenge-progress.ts and user-progress.ts) that likely trigger state updates or API calls.
- The “store” directory manages UI states for modal components (exit, hearts, and practice modals).
- Database & Data Layer:
- The “db” folder alongside files like drizzle.config.ts and schema/queries show that the project uses drizzle ORM for managing database state.
- Utility & Library Modules:
- The “lib” folder includes helper files for admin operations, Stripe integration, and other utilities.
- Components & UI:
- A large “components” folder contains reusable UI components (such as custom-loading, feeds, sidebars, modal dialogs, and UI primitives) that are likely tied to shadcn/ui and Tailwind CSS.

##### Relationships and Data Flow
- Users interact with the Frontend via different routes:
- Marketing pages for brand introduction.
- Main app pages for learning, course management, quests, and shop functions.
- Lesson pages that provide a dedicated view for interactive lessons.
- Admin pages that allow content editors/administrators to manage challenges and courses.
- Frontend-to-API Communication:
- Frontend components (buttons, lists, cards, etc.) make requests to the corresponding API endpoints (located in app/api/*) to fetch or update data (courses, challenges, lessons, units).
- API-to-Database Interaction:
- The API routes interact with the database using drizzle (as seen in the “db” directory) for data persistence.
- External Integrations:
- Authentication is managed via Clerk.
- Payment or subscription features might be managed via Stripe (lib/stripe.ts).
- Modular Actions & State:
- “Actions” scripts are used to update challenge and user progress.
- “Store” files hold state information for various modal dialogs and UI feedback components.

##### Architectural Patterns & Design Principles
- Next.js Routing and App Folder Structure:
- The project leverages Next.js’s file-based routing with segmented folders (for marketing, main, admin, lesson, etc.) which helps in separating concerns among different user flows.
- Separation of Concerns:
- UI components, business logic (API endpoints and actions), and data access (database schema and queries) are neatly separated.
- Micro-Organized Modules:
- Different features (e.g., courses, lessons, challenges) have their own subdirectories under both the app and admin sections, indicating a modular organization.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        A["Marketing UI"]:::frontend
        B["Main App"]:::frontend
        C["Admin Dashboard"]:::frontend
        D["Lesson Pages"]:::frontend
        E["Reusable UI Components"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        subgraph "API Endpoints"
            F["API: Challenges"]:::api
            G["API: Courses"]:::api
            H["API: Lessons"]:::api
            I["API: Units"]:::api
            J["API: ChallengeOptions"]:::api
        end
        K["Actions (Progress Functions)"]:::actions
        L["UI State (Modals)"]:::store
        M["Utility & Library Modules"]:::lib
        N["Authentication (Clerk)"]:::external
        O["Payments (Stripe)"]:::external
    end

    %% Database Layer
    subgraph "Database Layer"
        P["Database (Drizzle ORM)"]:::database
    end

    %% Frontend to API Endpoints connections
    A -->|"HTTP"| F
    B -->|"HTTP"| H
    C -->|"HTTP"| J
    D -->|"HTTP"| H
    E -->|"HTTP"| G

    %% API Endpoints interactions with Database
    F -->|"CRUD"| P
    G -->|"CRUD"| P
    H -->|"CRUD"| P
    I -->|"CRUD"| P
    J -->|"CRUD"| P

    %% API Endpoints using Utility Modules
    F -->|"uses"| M
    G -->|"uses"| M
    H -->|"uses"| M
    I -->|"uses"| M
    J -->|"uses"| M

    %% Main App triggering Actions and UI State updates
    B -->|"triggers"| K
    B -->|"triggers"| L
    K -->|"update"| P

    %% External Integrations from Main App
    B -->|"auth"| N
    B -->|"payment"| O

    %% Styling Classes
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef api fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef actions fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef store fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef lib fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef database fill:#F4A460,stroke:#000,stroke-width:2px;

    %% Click Events for Component Mapping
    click A "https://github.com/ankitsaha00/bhasha/tree/master/app/(marketing)/"
    click B "https://github.com/ankitsaha00/bhasha/tree/master/app/(main)/"
    click C "https://github.com/ankitsaha00/bhasha/tree/master/app/admin/"
    click D "https://github.com/ankitsaha00/bhasha/tree/master/app/lesson/"
    click E "https://github.com/ankitsaha00/bhasha/tree/master/components/"
    click F "https://github.com/ankitsaha00/bhasha/tree/master/app/api/challenges/"
    click G "https://github.com/ankitsaha00/bhasha/tree/master/app/api/courses/"
    click H "https://github.com/ankitsaha00/bhasha/tree/master/app/api/lessons/"
    click I "https://github.com/ankitsaha00/bhasha/tree/master/app/api/units/"
    click J "https://github.com/ankitsaha00/bhasha/tree/master/app/api/challengeOptions/"
    click K "https://github.com/ankitsaha00/bhasha/tree/master/actions/"
    click L "https://github.com/ankitsaha00/bhasha/tree/master/store/"
    click M "https://github.com/ankitsaha00/bhasha/tree/master/lib/"
    click P "https://github.com/ankitsaha00/bhasha/tree/master/db/"
```
