# sharif-minhaz/mediaid architecture

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

- Interactive diagram: https://gitdiagram.com/sharif-minhaz/mediaid
- Repository: https://github.com/sharif-minhaz/mediaid

## Overview

##### Project type and purpose
- This is a full-stack web application (“MediAid”) whose goal is to let individuals and organizations donate unused or unexpired medicines and let receivers apply to receive them.
- The client is a React/Vite single-page application, the server is a Node.js/Express REST API, data is stored in MongoDB, and images are managed via Cloudinary.

##### File structure
- Top-level directories:
– client: React front-end (features folder with Redux slices, components, pages, routers, utils).
– server: Express back-end (controllers, routes, models, middlewares, utils, DB connection).
– template: static HTML/CSS templates (used for initial design or email templates).
- Config files:
– client/default.env & server/default.env for environment variables.
– vite.config.js, package.json in each to manage builds.
- Architectural patterns:
– Front-end: feature-based folder grouping + Redux Toolkit + React Router.
– Back-end: MVC pattern (models/controllers/routes) + middleware chain (auth, error handler, file upload).

##### README for additional insights
- Confirms usage of JWT for authentication (admin credentials given).
- Mentions donation workflow, file uploads (images/documents), admin approval process.

a. Main components
1. Browser / React SPA
2. Vite Dev Server (development)
3. Express API Server
4. MongoDB database
5. Cloudinary (image storage)
6. Optional: Static template host (serves template folder or email templates)
b. Relationships & interactions
– Browser sends HTTP/HTTPS requests (API calls) to the Express server.
– Server authenticates using JWT middleware, then routes requests to appropriate controllers.
– Controllers use Mongoose models to read/write data in MongoDB.
– For image/document uploads, server’s upload utility sends files to Cloudinary, stores URLs in MongoDB.
– Static template files are served either by Express or from a CDN.
c. Architectural patterns and design principles
– MVC on the server side.
– Feature slices + Redux Toolkit on the client side.
– RESTful API endpoints grouped by resource (auth, medicines, gallery, etc.).
– Separation of concerns: routing, business logic (controllers), data layer (models), middleware.
d. Key technologies
– Front-end: React, Vite, Redux Toolkit, React Router, Axios/fetch.
– Back-end: Node.js, Express, Mongoose, JWT, Cloudinary SDK, Multer.
– Database: MongoDB (Atlas or local).
– DevOps: dotenv files, .env, environment variables, CORS, error handling.

## Diagram (Mermaid)

```mermaid
graph TB
  subgraph "Frontend (React SPA)"
    direction TB
    Browser["Browser / React SPA"]:::frontend
    click Browser "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/app/App.jsx"
    click Browser "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/main.jsx"
    Vite["Vite Dev Server"]:::frontend
    click Vite "https://github.com/sharif-minhaz/mediaid/blob/master/client/vite.config.js"
    Routers["React Router"]:::frontend
    click Routers "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/Routers/Routers.jsx"
    Store["Redux Store"]:::frontend
    click Store "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/app/store.js"
    API["API Integration (apiSlice)"]:::frontend
    click API "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/features/api/apiSlice.js"
    subgraph "Features"
      Auth["Auth Feature"]:::frontend
      click Auth "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/features/auth/authSlice.js"
      click Auth "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/features/auth/Login.jsx"
      click Auth "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/features/auth/Register.jsx"
      MedicinesF["Medicines Feature"]:::frontend
      click MedicinesF "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/features/medicines/medicinesSlice.js"
      GalleryF["Gallery Feature"]:::frontend
      click GalleryF "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/features/gallery/gallerySlice.js"
      click GalleryF "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/features/gallery/Gallery.jsx"
      ProfileF["Profile Feature"]:::frontend
      click ProfileF "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/features/profile/profileSlice.js"
      PendingF["Pending Approvals Feature"]:::frontend
      click PendingF "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/features/pending/pendingSlice.js"
      ReviewF["Review Feature"]:::frontend
      click ReviewF "https://github.com/sharif-minhaz/mediaid/blob/master/client/src/features/medicines/reviewSlice.js"
    end
  end

  subgraph "Backend (Express API)"
    direction TB
    Server["Express API Server"]:::backend
    click Server "https://github.com/sharif-minhaz/mediaid/blob/master/server/server.js"
    subgraph "Middlewares"
      JWT["JWT Middleware"]:::backend
      click JWT "https://github.com/sharif-minhaz/mediaid/blob/master/server/middlewares/jwtMiddleware.js"
      ErrorH["Error Handler"]:::backend
      click ErrorH "https://github.com/sharif-minhaz/mediaid/blob/master/server/middlewares/errorHandler.js"
      Upload["File Upload Middleware"]:::backend
      click Upload "https://github.com/sharif-minhaz/mediaid/blob/master/server/middlewares/upload.js"
    end
    subgraph "Controllers & Routes"
      AuthC["Auth Controller"]:::backend
      click AuthC "https://github.com/sharif-minhaz/mediaid/blob/master/server/controllers/authController.js"
      AuthR["Auth Routes"]:::backend
      click AuthR "https://github.com/sharif-minhaz/mediaid/blob/master/server/routes/authRoute.js"
      MedC["Medicines Controller"]:::backend
      click MedC "https://github.com/sharif-minhaz/mediaid/blob/master/server/controllers/medicinesController.js"
      MedR["Medicine Routes"]:::backend
      click MedR "https://github.com/sharif-minhaz/mediaid/blob/master/server/routes/medicineRoute.js"
      GalleryC["Gallery Controller"]:::backend
      click GalleryC "https://github.com/sharif-minhaz/mediaid/blob/master/server/controllers/galleryController.js"
      GalleryR["Gallery Routes"]:::backend
      click GalleryR "https://github.com/sharif-minhaz/mediaid/blob/master/server/routes/galleryRoute.js"
      ReviewC["Review Controller"]:::backend
      click ReviewC "https://github.com/sharif-minhaz/mediaid/blob/master/server/controllers/reviewController.js"
      ReviewR["Review Routes"]:::backend
      click ReviewR "https://github.com/sharif-minhaz/mediaid/blob/master/server/routes/reviewRoute.js"
      ProfileC["Profile Controller"]:::backend
      click ProfileC "https://github.com/sharif-minhaz/mediaid/blob/master/server/controllers/profileController.js"
      ProfileR["Profile Routes"]:::backend
      click ProfileR "https://github.com/sharif-minhaz/mediaid/blob/master/server/routes/profileRoute.js"
      DonorC["Best Donor Controller"]:::backend
      click DonorC "https://github.com/sharif-minhaz/mediaid/blob/master/server/controllers/bestDonorController.js"
      DonorR["Best Donor Routes"]:::backend
      click DonorR "https://github.com/sharif-minhaz/mediaid/blob/master/server/routes/bestDonorRoute.js"
      DashboardC["Dashboard Controller"]:::backend
      click DashboardC "https://github.com/sharif-minhaz/mediaid/blob/master/server/controllers/dashboardController.js"
      DashboardR["Dashboard Routes"]:::backend
      click DashboardR "https://github.com/sharif-minhaz/mediaid/blob/master/server/routes/dashboardRoute.js"
      HistoryC["History Controller"]:::backend
      click HistoryC "https://github.com/sharif-minhaz/mediaid/blob/master/server/controllers/historyController.js"
      HistoryR["History Routes"]:::backend
      click HistoryR "https://github.com/sharif-minhaz/mediaid/blob/master/server/routes/historyRoute.js"
      TipC["Health Tip Controller"]:::backend
      click TipC "https://github.com/sharif-minhaz/mediaid/blob/master/server/controllers/healthTipController.js"
      TipR["Health Tip Routes"]:::backend
      click TipR "https://github.com/sharif-minhaz/mediaid/blob/master/server/routes/HealthTipRoute.js"
    end
    ConnectDB["DB Connection"]:::backend
    click ConnectDB "https://github.com/sharif-minhaz/mediaid/blob/master/server/db/connectDB.js"
    subgraph "Models"
      UserM["User Model"]:::backend
      click UserM "https://github.com/sharif-minhaz/mediaid/blob/master/server/models/UserModel.js"
      ReceiverM["Receiver Application Model"]:::backend
      click ReceiverM "https://github.com/sharif-minhaz/mediaid/blob/master/server/models/ReceiverApplicationModel.js"
      MedM["Medicine Model"]:::backend
      click MedM "https://github.com/sharif-minhaz/mediaid/blob/master/server/models/MedicineModel.js"
      GalleryM["Gallery Model"]:::backend
      click GalleryM "https://github.com/sharif-minhaz/mediaid/blob/master/server/models/GalleryModel.js"
    end
    subgraph "Utils"
      CloudUtil["Cloudinary Utility"]:::backend
      click CloudUtil "https://github.com/sharif-minhaz/mediaid/blob/master/server/utils/cloudinaryHandler.js"
      click CloudUtil "https://github.com/sharif-minhaz/mediaid/blob/master/server/utils/uploadImage.js"
    end
  end

  subgraph "External & Database"
    direction TB
    MongoDB["MongoDB"]:::database
    Cloudinary["Cloudinary"]:::external
    Template["Template Host"]:::external
    click Template "https://github.com/sharif-minhaz/mediaid/blob/master/template/components/index.html"
  end

  Browser -->|"HTTP Requests"| Server
  Vite -->|"Serves SPA"| Browser
  Routers -->|"Routing"| Browser
  Store -->|"State Management"| Browser
  API -->|"Dispatch API calls"| Store
  Auth -->|"Dispatch auth actions"| Store
  MedicinesF -->|"Dispatch medicines actions"| Store
  GalleryF -->|"Dispatch gallery actions"| Store
  ProfileF -->|"Dispatch profile actions"| Store
  PendingF -->|"Dispatch pending actions"| Store
  ReviewF -->|"Dispatch review actions"| Store

  Server -->|"uses"| JWT
  Server -->|"uses"| ErrorH
  Server -->|"uses"| Upload

  Server --> US[("API Routes")] 
  US --> AuthR
  US --> MedR
  US --> GalleryR
  US --> ReviewR
  US --> ProfileR
  US --> DonorR
  US --> DashboardR
  US --> HistoryR
  US --> TipR

  AuthR --> AuthC
  MedR --> MedC
  GalleryR --> GalleryC
  ReviewR --> ReviewC
  ProfileR --> ProfileC
  DonorR --> DonorC
  DashboardR --> DashboardC
  HistoryR --> HistoryC
  TipR --> TipC

  AuthC --> ConnectDB
  MedC --> ConnectDB
  GalleryC --> ConnectDB
  ReviewC --> ConnectDB
  ProfileC --> ConnectDB
  DonorC --> ConnectDB
  DashboardC --> ConnectDB
  HistoryC --> ConnectDB
  TipC --> ConnectDB

  ConnectDB --> MongoDB

  Upload --> CloudUtil
  CloudUtil --> Cloudinary

  classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
  classDef backend fill:#E6FFED,stroke:#28a745,color:#22863a
  classDef external fill:#FFF5EB,stroke:#d73a49,color:#cb2431
  classDef database fill:#F6F8FA,stroke:#586069,color:#444d56
```
