# aayushbharti/zenith-academy architecture

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

- Interactive diagram: https://gitdiagram.com/aayushbharti/zenith-academy
- Repository: https://github.com/aayushbharti/zenith-academy

## Overview

##### Main Components
- Frontend (Next.js Application):
- The app/ directory houses routing, page components, and layout files.
- The components/ folder contains UI and feature-specific components (such as Auth, Dashboard, Home, etc.) built using React and enhanced with Tailwind CSS.
- The store/ folder shows client-side state management, likely implemented with a state management library (such as Zustand or similar).
- The services/ and utils/ folders provide business logic and helper functions that interact with APIs and process data before presentation.

- Backend (Server-Side Application):
- The server/ folder comprises the complete backend, including:
▫ Configurations for cloud services, database, and payment systems (cloudinary.ts, database.ts, razorpay.ts).
▫ Controllers for handling different routes and business logic (Auth, Course, Category, Payments, etc.).
▫ Models that define the data schema (User, Course, Section, etc.).
▫ Middlewares for authentication and demo purposes.
▫ Routes that expose API endpoints to the frontend.
▫ Utility functions for tasks like image uploading and email sending.
▫ Mail templates for various email notifications such as email verification and payment success.

- External and Supporting Services:
- Integration with external services like Cloudinary (for media), Razorpay (for payment processing), and mailing systems (for sending notifications).
- A database as configured by the server (see server/config/database.ts) which underpins data persistence for models such as Course, Profile, etc.

##### Relationships and Interactions
- The Frontend communicates with the Backend through API calls. This is facilitated via the controllers and custom routes in the server/ folder.
- The Next.js routing in the app/ folder directs users to the proper pages (for authentication, course view, dashboard functions, etc.).
- Requests initiated from UI components might pass through the service layer (services/ folder), which then uses utility functions (utils/ and lib/) to interact with the backend.
- The backend controllers access the database using the models and execute business logic, ensuring a secure and modular interaction with external services.
- State management stores (in the store/ folder) are used on the frontend to manage user authentication, cart, course data, and profile details consistently across the app.

##### Architectural Patterns & Design Principles
- Separation of Concerns is clear with distinct directories for UI and business logic.
- Modular Design: Each feature (authentication, course management, dashboard) is encapsulated both in dedicated pages and via separate controllers and models.
- Layered Architecture: Frontend (UI and client-side logic) is separate from the backend (API, controllers, models, database) along with clearly defined service layers.
- Reusability is bolstered by organizing shared components in the components/ folder and common utilities in utils/, lib/ and data/.
- Route Grouping: The app/ directory uses grouped routes (e.g., (auth), (dashboard), (course-view)) that mirror the structural grouping of functionalities.

##### Elements
- Client Side (Next.js Frontend): Show subcomponents for pages, layouts, UI components, and state management stores.
- API Layer: Represent the generalized API endpoints provided by the server/ routes and controllers which the frontend communicates with.
- Backend: Include controllers, models, and routes, plus connections to a database and external services.
- External Services: Represent integration with third-party services (Cloudinary, Razorpay, Email services).

- Differentiate UI components (perhaps using rounded rectangles) from backend components (using standard rectangles).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        appPages["Next.js Pages & Routing"]:::frontend
        uiComponents["UI Components"]:::frontend
        clientState["Client State Management"]:::frontend
        serviceLayer["Frontend Service Layer"]:::frontend
        utilsFrontend["Frontend Utility Functions"]:::frontend
    end

    subgraph "Backend"
        backendRoutes["Backend Routes"]:::backend
        backendMiddlewares["Backend Middlewares"]:::backend
        backendControllers["Backend Controllers"]:::backend
        backendModels["Backend Models"]:::backend
        backendUtils["Backend Utility Functions"]:::backend
        backendConfig["Backend Config & External Integration"]:::backend
        backendMailTemplates["Backend Mail Templates"]:::backend
    end

    subgraph "External Services"
        cloudinary["Cloudinary"]:::external
        razorpay["Razorpay"]:::external
        emailService["Email Service"]:::external
    end

    %% Frontend interactions
    appPages -->|"renders"| uiComponents
    uiComponents -->|"calls"| serviceLayer
    uiComponents <-->|"state_updates"| clientState
    uiComponents -->|"uses"| utilsFrontend

    %% Communication from Frontend to Backend
    serviceLayer -->|"API_calls"| backendRoutes

    %% Backend processing flow
    backendRoutes -->|"middleware_check"| backendMiddlewares
    backendMiddlewares -->|"executes"| backendControllers
    backendControllers -->|"accesses"| backendModels
    backendControllers -->|"utilizes"| backendUtils
    backendControllers -->|"fetches_config"| backendConfig
    backendUtils -->|"uses_templates"| backendMailTemplates

    %% External integrations
    backendConfig -->|"media_uploads"| cloudinary
    backendConfig -->|"payment_processing"| razorpay
    backendConfig -->|"email_notifications"| emailService

    %% Click Events for Component Mapping
    click appPages "https://github.com/aayushbharti/zenith-academy/tree/master/app/"
    click uiComponents "https://github.com/aayushbharti/zenith-academy/tree/master/components/"
    click clientState "https://github.com/aayushbharti/zenith-academy/tree/master/store/"
    click serviceLayer "https://github.com/aayushbharti/zenith-academy/tree/master/services/"
    click utilsFrontend "https://github.com/aayushbharti/zenith-academy/tree/master/utils/"
    click backendControllers "https://github.com/aayushbharti/zenith-academy/tree/master/server/controllers/"
    click backendModels "https://github.com/aayushbharti/zenith-academy/tree/master/server/models/"
    click backendRoutes "https://github.com/aayushbharti/zenith-academy/tree/master/server/routes/"
    click backendConfig "https://github.com/aayushbharti/zenith-academy/tree/master/server/config/"
    click backendMiddlewares "https://github.com/aayushbharti/zenith-academy/tree/master/server/middlewares/"
    click backendUtils "https://github.com/aayushbharti/zenith-academy/tree/master/server/utils/"
    click backendMailTemplates "https://github.com/aayushbharti/zenith-academy/tree/master/server/mail/templates/"

    %% Styles
    classDef frontend fill:#f4f4f4,stroke:#333,stroke-width:2px;
    classDef backend fill:#cfe2f3,stroke:#0b5394,stroke-width:2px;
    classDef external fill:#ead1dc,stroke:#b45f06,stroke-width:2px;
```
