# fthabhishek-pandey/koshish-welfare-and-education-society architecture

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

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

## Overview

##### Project type and purpose
- Koshish is a multi-tenant full-stack school management application. It consists of:
- Two React-based frontends:
– Adminpannel: for administrators, coordinators, and co-circulers (club leaders)
– Koshish: the public/student/teacher-facing site
- A Node.js/Express backend providing RESTful endpoints
- MongoDB as the primary data store
- Third-party Cloudinary for image uploads
- JWT authentication layers per user role

##### File structure
- Top-level:
- Adminpannel/​ and Koshish/: separate React/Vite frontend codebases
- backend/: Express server, controllers, routes, models, middleware, config
- Frontends share a similar structure:
- src/components, src/pages, src/context, src/utilities (API calls)
- Vite config, public static assets, .env for API base URLs
- Backend:
- config/: MongoDB connection, Cloudinary setup
- middleware/: JWT auth per role, file-upload, error handling, logging
- controller/: business logic grouped by domain (app, cocirculer, coordinator, teacher, student)
- models/: Mongoose schemas grouped by domain
- routes/: maps URLs to controllers
- server.js: bootstraps Express, connects to DB, mounts routes
- uploads/: local file storage (fallback for images)

##### README for additional insights
- Four dashboards: Admin, Co-circuler, Teacher, Student (two in progress)
- Operations: user management, class & event management, announcements, submissions, metrics
- Tech stack callouts: React + Vite, Node/Express, MongoDB, JWT

##### Main components & their interactions
a. Components
- Frontend Tier
– Adminpannel App (React)
– Koshish Public App (React)
- API Tier
– Express.js server
– Route handlers (appRoutes, coCirculerRoutes, coordinatorRoutes, teacherRoutes, userRoutes)
- Persistence Tier
– MongoDB cluster
– Local uploads directory (for development)
– Cloudinary (for production uploads)
- Auth & Security
– JWT issuance and verification middleware per role
- External Systems
– Cloudinary CDN
– (Optional) Third-party analytics or logging

b. Relationships & Data Flow
1. User visits frontend (Adminpannel or Koshish)
2. Frontend fetches data via REST calls to Express server (e.g., GET /api/app/events)
3. Express middleware validates JWT, parses request, routes to controller
4. Controller calls repository or model to perform CRUD on MongoDB
5. For file uploads, middleware sends files to Cloudinary, returns URLs to controllers
6. Controller responds JSON to frontend
7. Frontend renders state, user interacts, cycle repeats
8. Logging middleware writes request logs; errorHandler catches exceptions

c. Architectural patterns & principles
- Layered architecture: Presentation (React), Application (Express controllers), Domain/Model (Mongoose), Infrastructure (MongoDB, Cloudinary)
- Separation of concerns: controllers vs. repositories vs. models
- Context providers (React Context) to manage global state (auth, user roles)
- Folder-by-domain grouping in backend for clarity
- JWT security per role to restrict endpoints

d. Key technologies & frameworks
- React + Vite + styled-components (frontends)
- React Context for state
- Axios or fetch wrappers in src/utilities/src/utils for API calls
- Express.js + Node.js
- Mongoose (MongoDB ODM)
- JWT (jsonwebtoken)
- Cloudinary SDK + multer for file uploads
- Winston or custom logger middleware
- Vercel or similar for frontend deployment, Heroku/​Docker for backend

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Tier
    subgraph "Frontends"
        direction TB
        AdminApp["Adminpannel React App"]:::frontend
        AdminUtils["Adminpannel Utilities & Context"]:::frontend
        AdminApp -->|"uses"| AdminUtils
        KoshishApp["Koshish React App"]:::frontend
        KoshishUtils["Koshish Utilities & Context"]:::frontend
        KoshishApp -->|"uses"| KoshishUtils
    end

    %% API Tier
    subgraph "API Tier"
        direction TB
        ExpressServer["Express.js Server"]:::api

        subgraph "Middleware"
            direction TB
            Auth["JWT Authentication"]:::api
            Upload["File Upload / Cloudinary"]:::api
            ErrorLog["Error Handling & Logging"]:::api
        end

        subgraph "Routes"
            direction TB
            AppRoutes["appRoutes.js"]:::api
            CoCirculerRoutes["coCirculerRoutes.js"]:::api
            CoordinatorRoutes["coordinaterRoutes.js"]:::api
            TeacherRoutes["teacherRoutes.js"]:::api
            UserRoutes["userRoutes.js"]:::api
        end

        subgraph "Controllers"
            direction TB
            PublicCtrl["Public/App Controllers"]:::api
            CocirculerCtrl["Co-circuler Controllers"]:::api
            CoordinatorCtrl["Coordinator Controllers"]:::api
            MentorCtrl["Mentor Controllers"]:::api
            StudentCtrl["Student Controllers"]:::api
        end

        subgraph "Models"
            direction TB
            Models["Mongoose Models"]:::api
        end

        ExpressServer --> Auth
        ExpressServer --> Upload
        ExpressServer --> ErrorLog
        Auth --> AppRoutes
        Auth --> CoCirculerRoutes
        Auth --> CoordinatorRoutes
        Auth --> TeacherRoutes
        Auth --> UserRoutes
        AppRoutes --> PublicCtrl
        CoCirculerRoutes --> CocirculerCtrl
        CoordinatorRoutes --> CoordinatorCtrl
        TeacherRoutes --> MentorCtrl
        UserRoutes --> StudentCtrl
        PublicCtrl --> Models
        CocirculerCtrl --> Models
        CoordinatorCtrl --> Models
        MentorCtrl --> Models
        StudentCtrl --> Models
    end

    %% Persistence Tier
    subgraph "Persistence Tier"
        direction TB
        MongoDB["MongoDB Cluster"]:::database
        LocalUploads["Local Uploads Directory"]:::database
        ExpressServer --> MongoDB
        Upload --> LocalUploads
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Cloudinary["Cloudinary CDN"]:::external
    end

    Upload --> Cloudinary
    AdminApp -->|"REST API calls"| ExpressServer
    KoshishApp -->|"REST API calls"| ExpressServer

    %% Config Files
    subgraph "Config"
        direction TB
        DBConfig["connectMongodb.js"]:::api
        CloudConfig["cloudinary.js"]:::api
    end
    DBConfig --> MongoDB
    CloudConfig --> Cloudinary
    ExpressServer --> DBConfig
    ExpressServer --> CloudConfig

    %% Static Assets
    AdminApp --> AdminPublic["Adminpannel Public Assets"]:::frontend
    KoshishApp --> KoshishPublic["Koshish Public Assets"]:::frontend

    %% Click Events
    click AdminApp "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/tree/develop/Adminpannel/src"
    click AdminUtils "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/tree/develop/Adminpannel/src/utilities"
    click KoshishApp "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/tree/develop/koshish/src"
    click KoshishUtils "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/tree/develop/koshish/src/utils"
    click ExpressServer "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/server.js"
    click DBConfig "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/config/connectMongodb.js"
    click CloudConfig "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/config/cloudinary.js"
    click Auth "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/middleware/authentication/cocirculerAuth.js"
    click Auth "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/middleware/authentication/coordinaterAuth.js"
    click Auth "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/middleware/authentication/coordinatorLogin.js"
    click Auth "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/middleware/authentication/logincocerculer.js"
    click Upload "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/middleware/cloudimage/multer.js"
    click Upload "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/middleware/cloudimage/cloudinary.js"
    click ErrorLog "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/middleware/errorHandler.js"
    click ErrorLog "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/middleware/logger/logger.js"
    click AppRoutes "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/routes/appRoutes.js"
    click CoCirculerRoutes "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/routes/coCirculerRoutes.js"
    click CoordinatorRoutes "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/routes/coordinaterRoutes.js"
    click TeacherRoutes "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/routes/teacherRoutes.js"
    click UserRoutes "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/blob/develop/backend/routes/userRoutes.js"
    click AdminPublic "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/tree/develop/Adminpannel/public"
    click KoshishPublic "https://github.com/fthabhishek-pandey/koshish-welfare-and-education-society/tree/develop/koshish/public"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#42A5F5,color:#0D47A1
    classDef api fill:#E8F5E9,stroke:#66BB6A,color:#1B5E20
    classDef database fill:#FFF3E0,stroke:#FFA726,color:#E65100
    classDef external fill:#F3E5F5,stroke:#AB47BC,color:#4A148C
```
