# iamaniket10/learning_hub architecture

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

- Interactive diagram: https://gitdiagram.com/iamaniket10/learning_hub
- Repository: https://github.com/iamaniket10/learning_hub

## Overview

##### Main Components
- Frontend Application:
- Built using Next.js, TypeScript, and Tailwind CSS.
- Contains pages for different user roles (admin and regular users), as well as components and services.
- Includes dedicated API routes (e.g., /api/hello) and a context for authentication.
- Backend Application:
- Built on Node.js using Express.js with dedicated directories for controllers (courseController.js, userController.js), routes (courseRoutes.js, userRoutes.js), models (Course.js, User.js), and middleware (authMiddleware, errorMiddleware).
- Uses JWT for authentication.
- Configurations for the database and environment variables are organized in the config directory and .env files.
- Database:
- MongoDB is used as the data store. The connection is managed via a configuration file (backend/config/database.js).
- External Services/Deployment:
- Environment variables mention deployment aspects for production (e.g., FRONTEND_URL), and the README highlights Vercel for frontend and Render for the backend, with MongoDB Atlas as the database host.

##### Relationships and Interactions
- The Frontend communicates with the Backend via HTTP calls (Axios) using RESTful APIs.
- The Backend exposes API endpoints for user authentication and course management, which include CRUD operations.
- The Backend is connected to a MongoDB database to persist user and course data.
- JWT tokens are used for secure communication between the Frontend and Backend, enforced by authentication middleware.
- Admin and user workflows are separated via different API routes and frontend pages.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Clear separation between frontend and backend logic.
- The backend is organized into controllers, routes, models, and middleware following common MVC-like patterns.
- Security:
- JWT-based authentication and dedicated auth middleware protect sensitive endpoints.
- Modular Design:
- Components, services, and API integration on the frontend are encapsulated in their own directories.
- Scalability:
- Project structure indicates readiness for expansion (e.g., dedicated admin-specific pages, modular backend controllers).

##### Relevant Technologies
- Frontend libraries and frameworks: Next.js, TypeScript, Tailwind CSS, Lucide React, Axios.
- Backend Framework: Node.js with Express.js.
- Database: MongoDB (hosted on MongoDB Atlas).
- Deployment platforms: Vercel (Frontend) and Render (Backend).

##### Elements
- Clear and precise labels: Each component should be named (e.g., “UserController”, “CourseRoutes”, “Authentication Middleware”).
- From Frontend to Backend (representing Axios API calls).
- From Backend to MongoDB (database operations).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FCE["Frontend (Next.js)"]:::frontend
        FP["Pages (User & Admin)"]:::frontend
        FC["Components & Context"]:::frontend
        FS["Service Layer (Axios API)"]:::frontend
        FAR["API Routes"]:::frontend
        FCE --> FP
        FCE --> FC
        FCE --> FS
        FCE --> FAR
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE["Backend (Express API)"]:::backend
        BServer["Main Express Server"]:::backend
        BControllers["Controllers (Course, User)"]:::backend
        BRoutes["Routes (CourseRoutes, UserRoutes)"]:::backend
        BMiddleware["Middleware (Auth, Error)"]:::backend
        BModels["Models (Course, User)"]:::backend
        BConfig["Configuration & Env Setup"]:::backend
        BE --> BServer
        BE --> BControllers
        BE --> BRoutes
        BE --> BMiddleware
        BE --> BModels
        BE --> BConfig
    end

    %% Database
    subgraph "Database"
        DB["MongoDB Atlas"]:::db
    end

    %% Deployment
    subgraph "Deployment"
        FDeploy["Frontend Deployment (Vercel)"]:::deploy
        BDeploy["Backend Deployment (Render)"]:::deploy
    end

    %% Interactions
    FCE -->|"HTTP_API_Calls"| BServer
    BServer -->|"CRUD_Operations"| DB
    FCE -->|"Deployed_on"| FDeploy
    BE -->|"Deployed_on"| BDeploy

    %% Click Events for Frontend
    click FCE "https://github.com/iamaniket10/learning_hub/tree/main/frontend/"
    click FP "https://github.com/iamaniket10/learning_hub/tree/main/frontend/src/pages/"
    click FC "https://github.com/iamaniket10/learning_hub/tree/main/frontend/src/components/"
    click FC "https://github.com/iamaniket10/learning_hub/blob/main/frontend/src/context/AuthContext.tsx"
    click FS "https://github.com/iamaniket10/learning_hub/blob/main/frontend/src/services/courseService.ts"
    click FAR "https://github.com/iamaniket10/learning_hub/tree/main/frontend/src/pages/api/"

    %% Click Events for Backend
    click BServer "https://github.com/iamaniket10/learning_hub/blob/main/backend/server.js"
    click BControllers "https://github.com/iamaniket10/learning_hub/tree/main/backend/controllers/"
    click BRoutes "https://github.com/iamaniket10/learning_hub/tree/main/backend/routes/"
    click BMiddleware "https://github.com/iamaniket10/learning_hub/tree/main/backend/middleware/"
    click BModels "https://github.com/iamaniket10/learning_hub/tree/main/backend/models/"
    click BConfig "https://github.com/iamaniket10/learning_hub/blob/main/backend/config/database.js"

    %% Click Event for Deployment
    click FDeploy "https://github.com/iamaniket10/learning_hub/blob/main/frontend/README.md"

    %% Styles
    classDef frontend fill:#AED9E0,stroke:#333,stroke-width:2px;
    classDef backend fill:#F6C8EA,stroke:#333,stroke-width:2px;
    classDef db fill:#F5E1A4,stroke:#333,stroke-width:2px;
    classDef deploy fill:#C1E1C1,stroke:#333,stroke-width:2px;
```
