# akrathor18/note-sharing-app architecture

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

- Interactive diagram: https://gitdiagram.com/akrathor18/note-sharing-app
- Repository: https://github.com/akrathor18/note-sharing-app

## Overview

##### Project Type and Purpose
- StudyHub is a full-stack web application (MERN: MongoDB, Express, React, Node.js).
- Purpose: allow users to sign up/in, upload and browse study notes, and take MCQ quizzes.

##### File Structure
A. Top-level:
- backend/
- client/
B. Backend directories:
- config/ (db connection, Cloudinary setup)
- middleware/ (JWT auth, file upload)
- model/ (Mongoose schemas: User, Note, Quiz)
- routers/ (Express routes for users, notes, quizzes)
- index.js (Express app entrypoint)
C. Client directories:
- src/ (React components, auth utilities, axios config)
- Tailwind/Vite configuration files

##### README
- Confirms MERN stack, user-generated content (notes) + quizzes, interactive UX.

##### Main Components and Their Interactions
A. Frontend (React SPA)
- Browser runs React app (components: SignIn, SignUp, Dashboard, Notes, Quiz, etc.)
- Uses ProtectedRoute for client-side route guarding
- axios.js handles HTTP requests to backend API
B. Backend (Node.js + Express)
- index.js configures Express server, mounts routers
- Routers call Mongoose models for CRUD operations
- Middleware:
- authMiddleware + verifyJWT for protected endpoints
- upload (Cloudinary) for note image/files
C. Database (MongoDB)
- Stores Users, Notes, Quizzes
D. External Service (Cloudinary)
- Stores uploaded images/files for notes

Flow:
Browser → HTTP(S) → Express API → Middleware → Mongoose → MongoDB
↘ Cloudinary (for file uploads)

##### Architectural Patterns & Design Principles
- Layered architecture:
1. Presentation (React)
2. API layer (Express routers + middleware)
3. Data layer (Mongoose + MongoDB)
- Stateless JWT authentication
- Single-page application on client side
- Separation of concerns: each folder has a single responsibility (config, middleware, models, routers)

##### Putting It All Together
- Routers (Users, Notes, Quizzes)
- Middleware (auth, upload)
- Config (db.js, cloudinary.js)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser["React SPA"]:::frontend
        Axios["Axios HTTP Client"]:::frontend
        subgraph "UI Components"
            App["React Root Component"]:::frontend
            Pages["UI Components"]:::frontend
            Protected["ProtectedRoute"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Server["Express API Server"]:::backend
        subgraph "API Routers"
            UsersR["Users Router"]:::backend
            NotesR["Notes Router"]:::backend
            QuizzesR["Quizzes Router"]:::backend
        end
        subgraph "Middleware"
            AuthM["authMiddleware"]:::backend
            Verify["verifyJWT"]:::backend
            UploadM["upload (Cloudinary)"]:::backend
        end
        subgraph "Configuration"
            DBconfig["MongoDB Connection (db.js)"]:::backend
            CloudConfig["Cloudinary Setup (cloudinary.js)"]:::backend
        end
        subgraph "Data Layer"
            UserM["User Schema"]:::backend
            NoteM["Note Schema"]:::backend
            QuizM["Quiz Schema"]:::backend
        end
    end

    %% External & Database
    DB["MongoDB Atlas"]:::db
    Cloud["Cloudinary"]:::external

    %% Connections: Frontend to Backend
    Browser -->|"HTTP Requests"| Axios
    Axios -->|"GET/POST /users, /notes, /quizzes"| Server

    %% Backend internals
    Server --> UsersR
    Server --> NotesR
    Server --> QuizzesR
    UsersR --> AuthM
    NotesR --> AuthM
    NotesR --> UploadM
    QuizzesR --> Verify
    UsersR --> UserM
    NotesR --> NoteM
    QuizzesR --> QuizM
    Server --> DBconfig
    Server --> CloudConfig

    %% Backend to DB & External
    Server -->|"CRUD Operations"| DB
    NotesR -->|"upload to Cloudinary"| Cloud
    UploadM --> Cloud

    %% Click Events
    click Browser "https://github.com/akrathor18/note-sharing-app/blob/main/client/src/main.jsx"
    click App "https://github.com/akrathor18/note-sharing-app/blob/main/client/src/App.jsx"
    click Pages "https://github.com/akrathor18/note-sharing-app/tree/main/client/src/components/"
    click Protected "https://github.com/akrathor18/note-sharing-app/blob/main/client/src/auth/ProtectedRoute.jsx"
    click Axios "https://github.com/akrathor18/note-sharing-app/blob/main/client/src/config/axios.js"
    click Server "https://github.com/akrathor18/note-sharing-app/blob/main/backend/index.js"
    click UsersR "https://github.com/akrathor18/note-sharing-app/blob/main/backend/routers/users.js"
    click NotesR "https://github.com/akrathor18/note-sharing-app/blob/main/backend/routers/notes.js"
    click QuizzesR "https://github.com/akrathor18/note-sharing-app/blob/main/backend/routers/quizzes.js"
    click AuthM "https://github.com/akrathor18/note-sharing-app/blob/main/backend/middleware/authMiddleware.js"
    click Verify "https://github.com/akrathor18/note-sharing-app/blob/main/backend/middleware/verifyJWT.js"
    click UploadM "https://github.com/akrathor18/note-sharing-app/blob/main/backend/middleware/upload.js"
    click DBconfig "https://github.com/akrathor18/note-sharing-app/blob/main/backend/config/db.js"
    click CloudConfig "https://github.com/akrathor18/note-sharing-app/blob/main/backend/config/cloudinary.js"
    click UserM "https://github.com/akrathor18/note-sharing-app/blob/main/backend/model/UserSchema.js"
    click NoteM "https://github.com/akrathor18/note-sharing-app/blob/main/backend/model/noteSchema.js"
    click QuizM "https://github.com/akrathor18/note-sharing-app/blob/main/backend/model/quizSchema.js"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1;
    classDef backend fill:#E8F5E9,stroke:#66BB6A,color:#1B5E20;
    classDef db fill:#CFD8DC,stroke:#90A4AE,color:#263238,stroke-width:2px,shape:cylinder;
    classDef external fill:#FFF3E0,stroke:#FFA726,color:#E65100;
```
