# aashih/studynotionashish architecture

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

- Interactive diagram: https://gitdiagram.com/aashih/studynotionashish
- Repository: https://github.com/aashih/studynotionashish

## Overview

##### Project Type and Purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) Education Technology web application (“Study Notion”).
- The backend (in the `Server/` folder) is an Express.js REST API using MongoDB via Mongoose, JWT for authentication, Razorpay for payments, Cloudinary for image uploads, and Nodemailer for email.
- The frontend (in `src/`) is a React app with React Router for pages, Redux Toolkit for state management (slices), Tailwind CSS for styling, and client-side logic for authentication, course browsing, enrollment, and progress tracking.

##### File-Structure Analysis
- Top-level: `Server/`, `public/`, `src/`, configuration files (`package.json`, `tailwind.config.js`).
- Server layer follows MVC:
- `config/`: external service setup (database, Razorpay, Cloudinary)
- `models/`: Mongoose schemas (User, Course, Category, Section, etc.)
- `controllers/`: business logic per domain (Auth, Course, Payments, Profile, etc.)
- `routers/`: route definitions mapping endpoints to controllers
- `middlewares/`: JWT auth, error handling
- `utils/` & `mail/templates/`: common utilities (image upload, mail sender) and email templates
- Frontend layer:
- `src/pages/`: top-level routes/views (Home, Catalog, CourseDetails, Dashboard, Auth pages)
- `src/components/`: reusable UI pieces organized by feature (Common, Auth, Dashboard modules, Course view)
- `src/services/`: API connector, endpoint definitions, business-oriented operations
- `src/slices/`: Redux slices for auth, courses, cart, profile, etc.
- `src/hooks/`, `src/utils/`: helper hooks and functions
- `public/`: HTML entrypoint and static assets

##### Key Architecture Patterns
- Backend: Layered MVC pattern (Routes → Controllers → Models → Database).
- Frontend: Component-based UI, container/presentational separation, global state via Redux Toolkit, async actions in `services/operations`.
- Authentication: JWT tokens handled by Express middleware and stored in client (e.g., localStorage); protected routes via React Router wrappers (`PrivateRoute`, `OpenRoute`).
- Deployment consideration: single origin for API and static files in production or CORS configuration in dev.

##### Main Components
a. Client (React App)
- Pages/Components
- Redux Store (slices)
- API Connector (axios or fetch wrapper)
b. API Layer (Express Server)
- Routers → Controllers → Services → Models
- Middlewares (Auth, Error Handling)
c. Database
- MongoDB cluster (collections for Users, Courses, Categories, Progress, Reviews, OTPs)
d. External Services
- Razorpay Payment Gateway
- Cloudinary Image Storage
- Email Service (SMTP / Nodemailer)

##### Relationships & Data-Flow
- User Browser → HTTP(S) Requests → React Router → Components dispatch Redux actions → API Connector →
→ Express Routes → Controllers → Mongoose Models → MongoDB
- Payments flow: React → /payments endpoint → Razorpay SDK/webhook → Controller updates DB & triggers email.
- Media uploads: React form → API → imageUploader util → Cloudinary → URL returned → stored in DB.
- Email notifications: Controller triggers mailSender util → SMTP → user’s inbox.

##### Technologies & Frameworks to Annotate
- Frontend: React, Redux Toolkit, React Router, Axios (apiConnector), Tailwind CSS
- Backend: Node.js, Express.js, Mongoose, JWT, Razorpay SDK, Cloudinary SDK, Nodemailer
- Database: MongoDB Atlas (or local)
- Dev Tools: nodemon, concurrently (`npm run dev`), PostCSS CLI

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Presentation Layer (Browser UI)"
        direction TB
        FE_Index["React Entry<br/>src/index.js"]:::frontend
        FE_App["App Component<br/>src/App.jsx"]:::frontend
        Pages["React Pages<br/>src/pages/"]:::frontend
        Components["UI Components<br/>src/components/"]:::frontend
        RouterGuards["PrivateRoute/OpenRoute<br/>src/components/core/Auth/"]:::frontend
        StoreConfig["Redux Store<br/>src/reducer/index.js"]:::frontend
        Slices["Redux Slices<br/>src/slices/"]:::frontend
        APIConnector["API Connector<br/>src/services/apiConnector.js"]:::frontend
        APIEndpoints["API Endpoints<br/>src/services/apis.js"]:::frontend
        Operations["Async Operations<br/>src/services/operations/"]:::frontend
        UtilsHooks["Utils & Hooks<br/>src/utils/, src/hooks/"]:::frontend
        TailwindConfig["Tailwind Config<br/>tailwind.config.js"]:::frontend
    end

    %% Backend Layer
    subgraph "Application Layer (API Server)"
        direction TB
        ServerEntry["Server Entry<br/>Server/index.js"]:::backend
        ConfigDB["DB Config<br/>Server/config/database.js"]:::backend
        ConfigRazor["Razorpay Config<br/>Server/config/razorPay.js"]:::backend
        ConfigCloud["Cloudinary Config<br/>Server/config/cloudinary.js"]:::backend
        Routers["Express Routers<br/>Server/routers/"]:::backend
        Controllers["Controllers<br/>Server/controllers/"]:::backend
        Models["Mongoose Models<br/>Server/models/"]:::backend
        AuthMW["Auth Middleware<br/>Server/middlewares/auth.js"]:::backend
        ErrorMW["Error Middleware<br/>Server/middlewares/"]:::backend
        UtilsImage["Image Uploader<br/>Server/utils/imageUploader.js"]:::backend
        UtilsMail["Mail Sender<br/>Server/utils/mailSender.js"]:::backend
        UtilsSec["Duration Util<br/>Server/utils/secToDuration.js"]:::backend
        EmailTemplates["Email Templates<br/>Server/mail/templates/"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MongoDB["MongoDB Cluster\n(Collections)"]:::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Razorpay["Razorpay Gateway"]:::external
        Cloudinary["Cloudinary Storage"]:::external
        SMTP["SMTP Email Service"]:::external
    end

    %% Connections - Frontend to Backend
    FE_App -->|renders| Pages
    FE_App -->|uses| Components
    FE_App -->|wraps routes| RouterGuards
    Pages -->|dispatch actions| StoreConfig
    StoreConfig -->|registers| Slices
    Pages -->|calls| APIConnector
    Components -->|calls| APIConnector
    APIConnector -->|uses| APIEndpoints
    APIEndpoints -->|triggers| Operations
    Operations -->|HTTP request| ServerEntry

    %% Backend flow
    ServerEntry -->|applies config| ConfigDB
    ServerEntry -->|applies config| ConfigRazor
    ServerEntry -->|applies config| ConfigCloud
    ServerEntry -->|uses routers| Routers
    Routers -->|invoke| AuthMW
    Routers -->|map to| Controllers
    Controllers -->|manipulate| Models
    Models -->|CRUD operations| MongoDB
    Controllers -->|use util| UtilsImage
    Controllers -->|use util| UtilsMail
    Controllers -->|use util| UtilsSec
    Controllers -->|send template| EmailTemplates

    %% Payment and Email flows
    Operations -->|POST /payments| Routers
    Routers -->|calls| Controllers
    Controllers -->|invoke SDK| Razorpay
    Razorpay -.->|webhook| Controllers
    Controllers -->|update DB| MongoDB
    Controllers -->|send email| SMTP

    %% Media upload flow
    Operations -->|POST /upload| Routers
    Controllers -->|upload image| Cloudinary
    Cloudinary -->|return URL| Controllers
    Controllers -->|store URL| MongoDB

    %% Email verification flow
    Controllers -->|trigger| UtilsMail
    UtilsMail -->|SMTP| SMTP

    %% Auth flow
    RouterGuards -->|protect routes| FE_App
    APIConnector -->|attach JWT| Operations
    AuthMW -->|verify JWT| Controllers

    %% Click Events - Frontend
    click FE_Index "https://github.com/aashih/studynotionashish/blob/main/src/index.js"
    click FE_App "https://github.com/aashih/studynotionashish/blob/main/src/App.jsx"
    click Pages "https://github.com/aashih/studynotionashish/tree/main/src/pages/"
    click Components "https://github.com/aashih/studynotionashish/tree/main/src/components/"
    click RouterGuards "https://github.com/aashih/studynotionashish/blob/main/src/components/core/Auth/PrivateRoute.jsx"
    click RouterGuards "https://github.com/aashih/studynotionashish/blob/main/src/components/core/Auth/OpenRoute.jsx"
    click StoreConfig "https://github.com/aashih/studynotionashish/blob/main/src/reducer/index.js"
    click Slices "https://github.com/aashih/studynotionashish/tree/main/src/slices/"
    click APIConnector "https://github.com/aashih/studynotionashish/blob/main/src/services/apiConnector.js"
    click APIEndpoints "https://github.com/aashih/studynotionashish/blob/main/src/services/apis.js"
    click Operations "https://github.com/aashih/studynotionashish/tree/main/src/services/operations/"
    click UtilsHooks "https://github.com/aashih/studynotionashish/tree/main/src/utils/"
    click UtilsHooks "https://github.com/aashih/studynotionashish/blob/main/src/hooks/useOnClickOutside.jsx"
    click TailwindConfig "https://github.com/aashih/studynotionashish/blob/main/tailwind.config.js"

    %% Click Events - Backend
    click ServerEntry "https://github.com/aashih/studynotionashish/blob/main/Server/index.js"
    click ConfigDB "https://github.com/aashih/studynotionashish/blob/main/Server/config/database.js"
    click ConfigRazor "https://github.com/aashih/studynotionashish/blob/main/Server/config/razorPay.js"
    click ConfigCloud "https://github.com/aashih/studynotionashish/blob/main/Server/config/cloudinary.js"
    click Routers "https://github.com/aashih/studynotionashish/tree/main/Server/routers/"
    click Controllers "https://github.com/aashih/studynotionashish/tree/main/Server/controllers/"
    click Models "https://github.com/aashih/studynotionashish/tree/main/Server/models/"
    click AuthMW "https://github.com/aashih/studynotionashish/blob/main/Server/middlewares/auth.js"
    click ErrorMW "https://github.com/aashih/studynotionashish/tree/main/Server/middlewares/"
    click UtilsImage "https://github.com/aashih/studynotionashish/blob/main/Server/utils/imageUploader.js"
    click UtilsMail "https://github.com/aashih/studynotionashish/blob/main/Server/utils/mailSender.js"
    click UtilsSec "https://github.com/aashih/studynotionashish/blob/main/Server/utils/secToDuration.js"
    click EmailTemplates "https://github.com/aashih/studynotionashish/tree/main/Server/mail/templates/"

    %% Styles
    classDef frontend fill:#E8F0FE,stroke:#2B5CB0,stroke-width:1px
    classDef backend fill:#E6FFFA,stroke:#2C7A7B,stroke-width:1px
    classDef database fill:#FFF5F7,stroke:#C53030,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#F0FFF4,stroke:#2F855A,stroke-width:1px,stroke-dasharray: 5 5
```
