# ajayprataps1/studynotion architecture

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

- Interactive diagram: https://gitdiagram.com/ajayprataps1/studynotion
- Repository: https://github.com/ajayprataps1/studynotion

## Overview

##### Project Type and Purpose
- This is a full-stack educational platform (“StudyNotion”) built on the MERN stack.
- Frontend: ReactJS + Redux Toolkit for dynamic UI and state management.
- Backend: NodeJS + ExpressJS implementing RESTful APIs.
- Database: MongoDB via Mongoose ODM.
- Additional services: Cloudinary (media storage), Razorpay (payment processing), SMTP/email templates.

##### File Structure Analysis
- Top level:
- “public” and “src” → React frontend code, assets, components, pages, Redux slices, services.
- “Server” → Express app: config, controllers, models, routes, utils, mail templates.
- Frontend follows a component-based architecture, organized by feature (Auth, Dashboard, Course, etc.).
- Backend follows MVC pattern:
- Models (Mongoose schemas in Server/models)
- Controllers (business logic in Server/controllers)
- Routes (API endpoints in Server/routes)
- Config folder holds integration code for Cloudinary, database, Razorpay.
- Utils and mail templates in Server for image upload, mailing, etc.

##### Key Components
- Client (React app)
- UI components, Redux store, API connector.
- API Layer (Express server)
- Route handlers mapping to controllers.
- Business Logic (Controllers)
- Auth, Course, Category, Payments, Profile, Rating & Review, Section, SubSection, ResetPassword, courseProgress.
- Data Layer (MongoDB)
- Collections: User, Course, Category, Section, SubSection, OTP, Profile, RatingAndReview, CourseProgress.
- External Services
- Cloudinary (media upload),
- Razorpay (payment gateway),
- Email service (SMTP/email provider using mailSender and templates).

##### Relationships and Data Flows
- User browsers → React UI
- UI dispatches Redux actions → apiconnector.js → Express endpoints.
- Express receives requests → auth middleware (JWT) → routes → controllers.
- Controllers perform CRUD via Mongoose models → MongoDB.
- For file uploads: controller → imageUploader → Cloudinary.
- For payments: controller → Razorpay config → external payment flow → webhook/confirmation email.
- For emails: controllers invoke mailSender → SMTP provider with email templates.
- Redux store updates UI based on API responses.

##### Architectural Patterns and Design Principles
- Frontend:
- Component-driven, “container-presentational” split.
- Redux Toolkit slices for state segmentation (authSlice, courseSlice, etc.).
- Hooks for cross-cutting concerns (useOnClickOutside).
- Backend:
- MVC separation: routes, controllers, models.
- Middlewares for authentication and error handling.
- Config-driven integration of third-party services.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Client["Browser / React App"]:::frontend
        Components["UI Components"]:::frontend
        Pages["Pages (Routing)"]:::frontend
        Slices["Redux Store Slices"]:::frontend
        APIConn["API Connector"]:::frontend
        APIDefs["Frontend API Definitions"]:::frontend
        Hooks["Common Hooks"]:::frontend
        UtilsFE["Helper Services & Utils"]:::frontend
        Public["Static Public Assets"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        ServerEntry["Express Server Entry Point"]:::backend
        subgraph "Routes"
            direction TB
            UserRoutes["User/Auth Routes"]:::backend
            CourseRoutes["Course Routes"]:::backend
            PaymentRoutes["Payments Routes"]:::backend
            ProfileRoutes["Profile Routes"]:::backend
        end
        subgraph "Controllers"
            direction TB
            AuthCtrl["Auth Controller"]:::backend
            CatCtrl["Category Controller"]:::backend
            CourseCtrl["Course Controller"]:::backend
            PayCtrl["Payments Controller"]:::backend
            ProfileCtrl["Profile Controller"]:::backend
            ReviewCtrl["Rating & Review Controller"]:::backend
            ResetCtrl["Reset Password Controller"]:::backend
            SectionCtrl["Section Controller"]:::backend
            SubSectionCtrl["SubSection Controller"]:::backend
            ProgressCtrl["Course Progress Controller"]:::backend
        end
        subgraph "Middlewares & Config"
            direction TB
            AuthMW["Authentication Middleware"]:::backend
            DBConfig["DB Configuration"]:::backend
            CloudConfig["Cloudinary Integration"]:::backend
            RazorConfig["Razorpay Integration"]:::backend
        end
        subgraph "Utilities"
            direction TB
            ImageUtil["Image Upload Utility"]:::backend
            MailUtil["Mail Sender Utility"]:::backend
            subgraph "Email Templates"
                direction TB
                EmailVerify["Email Verification Template"]:::backend
                EnrollEmail["Course Enrollment Email"]:::backend
                PaymentEmail["Payment Success Email"]:::backend
                PasswordEmail["Password Update Email"]:::backend
            end
        end
        subgraph "Models"
            direction TB
            UserModel["User Model"]:::backend
            CategoryModel["Category Model"]:::backend
            CourseModel["Course Model"]:::backend
            SectionModel["Section Model"]:::backend
            SubSectionModel["SubSection Model"]:::backend
            OTPModel["OTP Model"]:::backend
            ProfileModel["Profile Model"]:::backend
            ReviewModel["RatingAndReview Model"]:::backend
            ProgressModel["CourseProgress Model"]:::backend
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MongoDB["MongoDB"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Cloudinary["Cloudinary API"]:::external
        Razorpay["Razorpay SDK"]:::external
        EmailService["SMTP / Email Provider"]:::external
    end

    %% Connections - Presentation to Application
    Client -->|"dispatch actions"| Slices
    Slices -->|"calls apiconnector"| APIConn
    APIConn -->|"HTTP requests"| APIDefs
    APIDefs -->|"REST calls"| ServerEntry

    %% Server entry to routes and middleware
    ServerEntry --> AuthMW
    ServerEntry --> DBConfig
    ServerEntry --> CloudConfig
    ServerEntry --> RazorConfig
    ServerEntry --> UserRoutes
    ServerEntry --> CourseRoutes
    ServerEntry --> PaymentRoutes
    ServerEntry --> ProfileRoutes

    %% Routes to controllers
    UserRoutes --> AuthCtrl
    UserRoutes --> ResetCtrl
    CourseRoutes --> CourseCtrl
    CourseRoutes --> CatCtrl
    CourseRoutes --> SectionCtrl
    CourseRoutes --> SubSectionCtrl
    CourseRoutes --> ProgressCtrl
    PaymentRoutes --> PayCtrl
    ProfileRoutes --> ProfileCtrl

    %% Controllers to models
    AuthCtrl --> UserModel
    ResetCtrl --> OTPModel
    CatCtrl --> CategoryModel
    CourseCtrl --> CourseModel
    SectionCtrl --> SectionModel
    SubSectionCtrl --> SubSectionModel
    ProgressCtrl --> ProgressModel
    ReviewCtrl --> ReviewModel
    ProfileCtrl --> ProfileModel
    PayCtrl --> UserModel
    PayCtrl --> CourseModel

    %% Controllers to utilities/external
    CourseCtrl --> ImageUtil
    ImageUtil --> Cloudinary
    PayCtrl --> Razorpay
    PayCtrl --> MailUtil
    MailUtil --> EmailVerify
    MailUtil --> EnrollEmail
    MailUtil --> PaymentEmail
    MailUtil --> PasswordEmail
    MailUtil --> EmailService

    %% Controllers to DB
    AuthCtrl --> MongoDB
    CourseCtrl --> MongoDB
    PayCtrl --> MongoDB
    ProfileCtrl --> MongoDB

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#42A5F5;
    classDef backend fill:#E8F5E9,stroke:#66BB6A;
    classDef datastore fill:#FFF3E0,stroke:#FFB74D;
    classDef external fill:#ECEFF1,stroke:#B0BEC5;

    %% Click Events
    click Client "https://github.com/ajayprataps1/studynotion/tree/main/src/"
    click Components "https://github.com/ajayprataps1/studynotion/tree/main/src/components/"
    click Pages "https://github.com/ajayprataps1/studynotion/tree/main/src/pages/"
    click Slices "https://github.com/ajayprataps1/studynotion/tree/main/src/slices/"
    click APIConn "https://github.com/ajayprataps1/studynotion/blob/main/src/services/apiconnector.js"
    click APIDefs "https://github.com/ajayprataps1/studynotion/blob/main/src/services/apis.js"
    click Hooks "https://github.com/ajayprataps1/studynotion/blob/main/src/hooks/useOnClickOutside.js"
    click UtilsFE "https://github.com/ajayprataps1/studynotion/tree/main/src/utils/"
    click Public "https://github.com/ajayprataps1/studynotion/tree/main/public/"
    click ServerEntry "https://github.com/ajayprataps1/studynotion/blob/main/Server/index.js"
    click UserRoutes "https://github.com/ajayprataps1/studynotion/blob/main/Server/routes/User.js"
    click CourseRoutes "https://github.com/ajayprataps1/studynotion/blob/main/Server/routes/Course.js"
    click PaymentRoutes "https://github.com/ajayprataps1/studynotion/blob/main/Server/routes/Payments.js"
    click ProfileRoutes "https://github.com/ajayprataps1/studynotion/blob/main/Server/routes/Profile.js"
    click AuthCtrl "https://github.com/ajayprataps1/studynotion/blob/main/Server/controllers/Auth.js"
    click CatCtrl "https://github.com/ajayprataps1/studynotion/blob/main/Server/controllers/Category.js"
    click CourseCtrl "https://github.com/ajayprataps1/studynotion/blob/main/Server/controllers/Course.js"
    click PayCtrl "https://github.com/ajayprataps1/studynotion/blob/main/Server/controllers/Payments.js"
    click ProfileCtrl "https://github.com/ajayprataps1/studynotion/blob/main/Server/controllers/Profile.js"
    click ReviewCtrl "https://github.com/ajayprataps1/studynotion/blob/main/Server/controllers/RatingAndReview.js"
    click ResetCtrl "https://github.com/ajayprataps1/studynotion/blob/main/Server/controllers/ResetPassword.js"
    click SectionCtrl "https://github.com/ajayprataps1/studynotion/blob/main/Server/controllers/Section.js"
    click SubSectionCtrl "https://github.com/ajayprataps1/studynotion/blob/main/Server/controllers/SubSection.js"
    click ProgressCtrl "https://github.com/ajayprataps1/studynotion/blob/main/Server/controllers/courseProgress.js"
    click UserModel "https://github.com/ajayprataps1/studynotion/blob/main/Server/models/User.js"
    click CategoryModel "https://github.com/ajayprataps1/studynotion/blob/main/Server/models/Category.js"
    click CourseModel "https://github.com/ajayprataps1/studynotion/blob/main/Server/models/Course.js"
    click SectionModel "https://github.com/ajayprataps1/studynotion/blob/main/Server/models/Section.js"
    click SubSectionModel "https://github.com/ajayprataps1/studynotion/blob/main/Server/models/SubSection.js"
    click OTPModel "https://github.com/ajayprataps1/studynotion/blob/main/Server/models/OTP.js"
    click ProfileModel "https://github.com/ajayprataps1/studynotion/blob/main/Server/models/Profile.js"
    click ReviewModel "https://github.com/ajayprataps1/studynotion/blob/main/Server/models/RatingAndReview.js"
    click ProgressModel "https://github.com/ajayprataps1/studynotion/blob/main/Server/models/CourseProgress.js"
    click DBConfig "https://github.com/ajayprataps1/studynotion/blob/main/Server/config/database.js"
    click CloudConfig "https://github.com/ajayprataps1/studynotion/blob/main/Server/config/cloudinary.js"
    click RazorConfig "https://github.com/ajayprataps1/studynotion/blob/main/Server/config/razorpay.js"
    click AuthMW "https://github.com/ajayprataps1/studynotion/blob/main/Server/middlewares/auth.js"
    click ImageUtil "https://github.com/ajayprataps1/studynotion/blob/main/Server/utils/imageUploader.js"
    click MailUtil "https://github.com/ajayprataps1/studynotion/blob/main/Server/utils/mailSender.js"
    click EmailVerify "https://github.com/ajayprataps1/studynotion/blob/main/Server/mail/templates/emailVerificationTemplate.js"
    click EnrollEmail "https://github.com/ajayprataps1/studynotion/blob/main/Server/mail/templates/courseEnrollmentEmail.js"
    click PaymentEmail "https://github.com/ajayprataps1/studynotion/blob/main/Server/mail/templates/paymentSuccessEmail.js"
    click PasswordEmail "https://github.com/ajayprataps1/studynotion/blob/main/Server/mail/templates/passwordUpdate.js"
```
