# asifalthaf/crowdfunding architecture

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

- Interactive diagram: https://gitdiagram.com/asifalthaf/crowdfunding
- Repository: https://github.com/asifalthaf/crowdfunding

## Overview

##### Project Type and Purpose
- This is a full-stack crowdfunding platform (“CrowdFundingX”) where creators launch campaigns and investors fund them.
- Frontend: React + Vite + Tailwind CSS.
- Backend: Express.js REST API with MVC-style controllers, MongoDB for persistence, Cloudinary for media storage, and a payment gateway integration.
- Features include user/admin authentication (JWT), project CRUD, document uploads, real-time updates (WebSocket), and payment processing.

##### File Structure Analysis
- Top-level “backend” and “frontend” directories denote a clear separation of concerns.
- Backend:
- config/ (db.js, cloudinary.js)
- controllers/ (admin, auth, project, payment, document)
- models/ (User, Project, Investment, Document)
- routes/ (REST endpoints)
- middleware/ (auth, admin, rate limiter, error handler, file upload)
- utils/ (error formatting, standardized responses)
- server.js (app entry)
- Frontend:
- src/components & src/pages (UI components & route pages)
- src/services/api.js (HTTP client)
- src/store/*.js (state management)
- src/utils/socket.js (real-time communications)
- Vite/Tailwind configs.

##### Key Architecture Insights from README
- Full-stack, JWT-based auth, admin dashboard, MongoDB data store, Cloudinary for media, payment gateway for transactions.

a. Main Components
- Client Browser (React Single-Page App)
- API Gateway / Express Backend
- MongoDB Database
- Cloudinary (Media Storage)
- Payment Service (e.g., Stripe)
- WebSocket Server (real-time updates)

b. Relationships & Data Flow
1. Client ↔ Backend REST API (HTTPS)
2. Backend ↔ MongoDB (via Mongoose)
3. Backend ↔ Cloudinary (via cloudinary.js config) for file uploads/downloads
4. Backend ↔ Payment Gateway (payment.controller)
5. Client ↔ Backend WebSocket (socket.js) for live feeds (e.g., funding updates)
6. Admin Client ↔ Admin endpoints (protected by admin.middleware)

c. Architectural Patterns & Principles
- Backend follows MVC (models, controllers, routes) and layered middleware (auth, validation, error handling).
- Frontend is component-based, with a service layer for API calls and a store layer for state management.
- JWT tokens carry stateless auth; rateLimiter middleware prevents abuse.
- Separation of concerns: upload middleware abstracts file handling, utils centralize error/response formatting.

d. Key Technologies
- Frontend: React, Vite, Tailwind CSS, Zustand or similar state store, WebSocket (socket.io or native).
- Backend: Node.js, Express.js, Mongoose/MongoDB, Cloudinary SDK, JWT, Stripe (or similar), ESLint.
- DevOps: .env or config JSON for environment settings, scripts for admin user creation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React App)"
        direction TB
        ReactApp["Client Browser<br/>(React SPA)"]:::frontend
        Services["API Service Layer<br/>(api.js)"]:::frontend
        Store["State Management<br/>(authStore, adminStore,<br/>campaignStore, investmentStore)"]:::frontend
        SocketUtil["WebSocket Utility<br/>(socket.js)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express API)"
        direction TB
        APIGateway["API Gateway<br/>(server.js)"]:::backend

        subgraph "API Layer (Routes)"
            direction TB
            AuthRoutes["auth.routes.js"]:::backend
            AdminRoutes["admin.routes.js"]:::backend
            ProjectRoutes["project.routes.js"]:::backend
            PaymentRoutes["payment.routes.js"]:::backend
            DocumentRoutes["document.routes.js"]:::backend
            UserRoutes["user.routes.js"]:::backend
        end

        subgraph "Business Logic (Controllers)"
            direction TB
            AuthController["auth.controller.js"]:::backend
            AdminController["admin.controller.js"]:::backend
            ProjectController["project.controller.js"]:::backend
            PaymentController["payment.controller.js"]:::backend
            DocumentController["documentController.js"]:::backend
        end

        subgraph "Data Layer (Models)"
            direction TB
            UserModel["User.js"]:::backend
            ProjectModel["project.js"]:::backend
            InvestmentModel["Investment.js"]:::backend
            DocumentModel["Document.js"]:::backend
        end

        subgraph "Middleware"
            direction TB
            UploadMW["upload.middleware.js"]:::backend
            AuthMW["auth.middleware.js"]:::backend
            AdminMW["admin.middleware.js"]:::backend
            RateLimiter["rateLimiter.js"]:::backend
            ErrorHandler["error.middleware.js"]:::backend
        end

        subgraph "Utils"
            direction TB
            ErrorsUtil["errors.js"]:::backend
            ResponseUtil["response.js"]:::backend
        end
    end

    %% External Services
    MongoDB["MongoDB Database"]:::db
    Cloudinary["Cloudinary"]:::external
    PaymentService["Payment Gateway (Stripe)"]:::external

    %% Connections
    ReactApp -->|"HTTPS REST"| APIGateway
    ReactApp -.->|"WebSocket"| SocketUtil
    SocketUtil -.->|"WS Connection"| APIGateway
    APIGateway -->|"loads routes"| AuthRoutes
    APIGateway --> AdminRoutes
    APIGateway --> ProjectRoutes
    APIGateway --> PaymentRoutes
    APIGateway --> DocumentRoutes
    APIGateway --> UserRoutes

    AuthRoutes -->|calls| AuthController
    AdminRoutes -->|calls| AdminController
    ProjectRoutes -->|calls| ProjectController
    PaymentRoutes -->|calls| PaymentController
    DocumentRoutes -->|calls| DocumentController
    UserRoutes -->|calls| AuthController

    AuthController -->|uses| AuthMW
    AdminController -->|uses| AdminMW
    ProjectController -->|uses| UploadMW
    PaymentController -->|uses| RateLimiter
    DocumentController -->|uses| UploadMW

    AuthController -->|queries| UserModel
    ProjectController -->|queries| ProjectModel
    ProjectController -->|creates| InvestmentModel
    DocumentController -->|creates| DocumentModel

    APIGateway -->|connects| MongoDB
    APIGateway -->|uploads/downloads| Cloudinary
    APIGateway -->|processes payments| PaymentService

    %% Click Events Frontend
    click ReactApp "https://github.com/asifalthaf/crowdfunding/tree/main/project/project/frontend/src"
    click Services "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/frontend/src/services/api.js"
    click Store "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/frontend/src/store/authStore.js"
    click SocketUtil "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/frontend/src/utils/socket.js"

    %% Click Events Backend
    click APIGateway "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/server.js"
    click AuthRoutes "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/routes/auth.routes.js"
    click AdminRoutes "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/routes/admin.routes.js"
    click ProjectRoutes "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/routes/project.routes.js"
    click PaymentRoutes "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/routes/payment.routes.js"
    click DocumentRoutes "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/routes/document.routes.js"
    click UserRoutes "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/routes/user.routes.js"

    click AuthController "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/controllers/auth.controller.js"
    click AdminController "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/controllers/admin.controller.js"
    click ProjectController "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/controllers/project.controller.js"
    click PaymentController "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/controllers/payment.controller.js"
    click DocumentController "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/controllers/documentController.js"

    click UserModel "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/models/User.js"
    click ProjectModel "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/models/project.js"
    click InvestmentModel "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/models/Investment.js"
    click DocumentModel "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/models/Document.js"

    click UploadMW "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/middleware/upload.middleware.js"
    click AuthMW "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/middleware/auth.middleware.js"
    click AdminMW "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/middleware/admin.middleware.js"
    click RateLimiter "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/middleware/rateLimiter.js"
    click ErrorHandler "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/middleware/error.middleware.js"

    click ErrorsUtil "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/utils/errors.js"
    click ResponseUtil "https://github.com/asifalthaf/crowdfunding/blob/main/project/project/backend/utils/response.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef backend fill:#d4edda,stroke:#333,stroke-width:1px
    classDef external fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef db fill:#e2e3e5,stroke:#333,stroke-width:1px
```
