# fthabhishek-pandey/koshish-welfare architecture

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

- Interactive diagram: https://gitdiagram.com/fthabhishek-pandey/koshish-welfare
- Repository: https://github.com/fthabhishek-pandey/koshish-welfare

## Overview

##### Project Type & Purpose
- This is a full‐stack web application consisting of:
- Two React frontends:
– “Adminpannel/” for administrators, coordinators, mentors, etc.
– “koshish/” as the public site for students, guests, alumni.
- A Node.js/Express backend providing RESTful APIs.
- MongoDB for persistent data storage.
- Cloudinary (via multer) for file uploads.
- JWT and role‐based middleware for authentication & authorization.

##### File Structure
- Top‐level modules:
- Adminpannel/ (frontend #1)
- koshish/ (frontend #2)
- backend/ (API server & data layer)
- Each frontend follows a React + Vite layout: assets, components, context, pages, utils.
- The backend is organized in config, controllers, middleware, models, routes, repositories, server.js.
- Deployment configs: vercel.json for frontends, Render/Heroku for backend.

a. Frontends
– AdminPanel UI (Vite/React, Context API, Tailwind CSS)
– Public Koshish Site UI (Vite/React, Context API, Tailwind CSS)
b. API Layer
– Node.js + Express server
– Routes: /api/auth, /api/events, /api/announcements, /api/gallery, /api/users, etc.
c. Business Logic
– Controllers (app, cocirculer, coordinator, mentor, student domains)
– Repositories (data‐access layer)
d. Data Layer
– MongoDB cluster via Mongoose schemas
– Collections: users, events, announcements, gallery, mentors, attendance, classes, etc.
e. File Storage
– Cloudinary for images (via multer middleware)
– Fallback local uploads folder
f. Security & Middleware
– JWT authentication (verifyToken)
– Role‐based guards (checkRole: admin, coordinator, cocirculer, mentor, student)
– Error‐handler, logger
g. External Services & Deployment
– Vercel for both frontends (Adminpannel & koshish)
– Render/Heroku for backend
– MongoDB Atlas (or self-hosted)
– Cloudinary API

##### Relationships & Data Flows
- User (Web Browser) → Frontend (Adminpannel or koshish)
- Reads/writes UI state via React Context (AuthContext, UIContext, EventContext, etc.)
- Makes AJAX calls (Axios/fetch) to Express API at VITE_API_URL or backend URL.
- Frontend → REST API endpoints
- All calls carry JWT in Authorization header
- Role middleware gates protected routes
- Express API → Controllers → Repositories → MongoDB
- Express API → multer → Cloudinary → returns image URLs
- Backend logs actions via logger middleware → console or file
- Error flows bubble to centralized errorHandler → standardized HTTP responses

##### Architectural Patterns & Design Principles
- Three‐tier architecture: Presentation (React), Application (Express controllers), Data (MongoDB).
- MVC-like separation: controllers orchestrate, models define schemas, repositories handle persistence.
- Context API in React for global state (auth, UI toggles, domain data).
- RESTful APIs with clear URL structure and HTTP verbs.
- Middleware pipeline (authentication, authorization, file‐upload, error handling).

##### Final Checklist
- [ ] All major components represented (Frontends, API, DB, Cloudinary)
- [ ] Authentication & role middleware noted
- [ ] Deployment targets (Vercel, Render) shown as endpoints

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Frontend Layer"
        AP["AdminPanel UI"]:::frontend
        Koshish["Public Koshish Site UI"]:::frontend
        AP_Vercel["AdminPanel Vercel"]:::external
        Koshish_Vercel["Koshish Vercel"]:::external
    end

    subgraph "API Layer"
        API["Express API Server"]:::backend
        subgraph "Routes"
            Routes["API Routes"]:::backend
        end
        subgraph "Controllers"
            Ctrl["Controllers"]:::backend
        end
        subgraph "Repositories"
            Repo["Repositories"]:::backend
        end
        subgraph "Models"
            Models["Mongoose Models"]:::database
        end
        subgraph "Config"
            Conf1["MongoDB Config"]:::backend
            Conf2["Cloudinary Config"]:::backend
        end
        subgraph "Middleware"
            Auth["Auth & Role Middleware"]:::backend
            CloudImageM["Multer Middleware"]:::backend
            CloudImageC["Cloudinary Middleware"]:::backend
            ErrorH["ErrorHandler"]:::backend
            Logger["Logger"]:::backend
        end
    end

    subgraph "Data Layer"
        Mongo["MongoDB"]:::database
    end

    subgraph "External Services"
        Cloudinary["Cloudinary"]:::external
        LocalUploads["Local Uploads"]:::external
        Render["Backend Deployment"]:::external
        Atlas["MongoDB Atlas"]:::external
    end

    AP -->|HTTPS| API
    Koshish -->|HTTPS| API
    AP_Vercel --> AP
    Koshish_Vercel --> Koshish

    API -->|uses| Routes
    Routes -->|calls| Ctrl
    Ctrl -->|uses| Repo
    Repo -->|CRUD| Models
    Models -->|connect via Mongoose| Mongo

    API -->|init| Conf1
    API -->|init| Conf2

    API -->|middleware| Auth
    API -->|middleware| CloudImageM
    API -->|middleware| CloudImageC
    API -->|middleware| ErrorH
    API -->|middleware| Logger

    CloudImageC -->|uploads to| Cloudinary
    CloudImageC -->|fallback to| LocalUploads

    Mongo -->|hosted on| Atlas
    API -->|deployed on| Render

    click AP "https://github.com/fthabhishek-pandey/koshish-welfare/tree/develop/Adminpannel/src/"
    click Koshish "https://github.com/fthabhishek-pandey/koshish-welfare/tree/develop/koshish/src/"
    click API "https://github.com/fthabhishek-pandey/koshish-welfare/blob/develop/backend/server.js"
    click Routes "https://github.com/fthabhishek-pandey/koshish-welfare/tree/develop/backend/routes/"
    click Ctrl "https://github.com/fthabhishek-pandey/koshish-welfare/tree/develop/backend/controller/"
    click Repo "https://github.com/fthabhishek-pandey/koshish-welfare/tree/develop/backend/repositories/"
    click Models "https://github.com/fthabhishek-pandey/koshish-welfare/tree/develop/backend/models/"
    click Conf1 "https://github.com/fthabhishek-pandey/koshish-welfare/blob/develop/backend/config/connectMongodb.js"
    click Conf2 "https://github.com/fthabhishek-pandey/koshish-welfare/blob/develop/backend/config/cloudinary.js"
    click Auth "https://github.com/fthabhishek-pandey/koshish-welfare/tree/develop/backend/middleware/authentication/"
    click CloudImageM "https://github.com/fthabhishek-pandey/koshish-welfare/blob/develop/backend/middleware/cloudimage/multer.js"
    click CloudImageC "https://github.com/fthabhishek-pandey/koshish-welfare/blob/develop/backend/middleware/cloudimage/cloudinary.js"
    click ErrorH "https://github.com/fthabhishek-pandey/koshish-welfare/blob/develop/backend/middleware/errorHandler.js"
    click Logger "https://github.com/fthabhishek-pandey/koshish-welfare/blob/develop/backend/middleware/logger/logger.js"
    click LocalUploads "https://github.com/fthabhishek-pandey/koshish-welfare/tree/develop/backend/uploads/"
    click AP_Vercel "https://github.com/fthabhishek-pandey/koshish-welfare/blob/develop/Adminpannel/vercel.json"
    click Koshish_Vercel "https://github.com/fthabhishek-pandey/koshish-welfare/blob/develop/koshish/vercel.json"

    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef database fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
