# arafatrahman216/disaster-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/arafatrahman216/disaster-management-system
- Repository: https://github.com/arafatrahman216/disaster-management-system

## Overview

##### Main Components
- Client Application (Frontend): This is organized under the “client” directory. The React application comprises pages (e.g., Home, Auth, Community, MedicalHome, Register, Login), components (e.g., Header, Footer, ImgSlider, community-specific components, map, statistics), and dedicated assets (CSS and images). It uses Tailwind CSS and possibly other styling resources.
- Backend API Layer: Notice that there are two directories, “Backend” and “server”, both structured to handle API logic. They contain controllers (for Authentication, Community, Home, Incident), routes, models, database connection scripts, middleware (such as authentication for protected endpoints in the “server” folder), and even service layers (like UserService). This indicates an MVC-like or microservices-inspired separation within the server-side code.
- Database: The project follows the MERN stack and therefore uses MongoDB as the database, as is suggested by the project description and the structure of “db/connect.js” files in both server directories.

##### Relationships and Interactions
- The Client (React) communicates with the Backend API over HTTP/HTTPS via RESTful endpoints.
- The Backend API controllers and routes process incoming requests (whether for incident reporting, community actions, or resource queries) and utilize models to interact with MongoDB.
- Within the backend, controllers are grouped by functionality (e.g., Community-related tasks are handled by both “CommunityRouter” and related controllers), while modular service layers (e.g., in “server/services/User”) encapsulate business logic.
- Middleware (e.g., authentication checks in “server/middleware/auth.js”) ensures proper request validation and security.
- The database acts as the centralized store for all disaster management data, including users, community posts, incidents, announcements, and more.

##### Architectural Patterns and Design Principles
- Modularization and Separation of Concerns: The clear separation into “client” and “server” (or “Backend”) emphasizes the decoupling of presentation and business logic.
- RESTful API Communication: The client’s API calls route to endpoints defined in Express (as seen in the various “Router” files), enforcing the separation between user interface and data management.

##### Relevant Technologies and Frameworks
- Frontend: React, Tailwind CSS, and associated asset management.
- Backend: Node.js with Express.js (as evident from controllers, routes, middleware) and additional libraries that support database connectivity.
- Database: MongoDB, suggested by the MERN stack reference.
- Additional Tools: The structure includes configuration files (.env, package.json, .gitignore) and build configurations (e.g., netlify.toml for client deployment).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Application Subgraph
    subgraph "Client Application (React)"
        client["Client Application"]:::client
        pages["Frontend Pages"]:::client
        components["Frontend Components"]:::client
    end

    %% Backend API Layer (Legacy) Subgraph
    subgraph "Backend API Layer (Legacy)"
        legacyGateway["Legacy API Gateway"]:::backend
        legacyAuth["Authentication Controller (Legacy)"]:::backend
        legacyCommunity["Community Controller (Legacy)"]:::backend
        legacyHome["Home Controller (Legacy)"]:::backend
        legacyRoutes["API Routes (Legacy)"]:::backend
        legacyDB["DB Connection (Legacy)"]:::backend
    end

    %% API Server (Modern/Microservices) Subgraph
    subgraph "API Server (Modern/Microservices)"
        modernGateway["API Gateway (Modern)"]:::server
        modernAuth["Authentication Controller (Modern)"]:::server
        modernCommunity["Community Controller (Modern)"]:::server
        modernHome["Home Controller (Modern)"]:::server
        modernIncident["Incident Controller (Modern)"]:::server
        modernRoutes["API Routes (Modern)"]:::server
        modernMiddleware["Auth Middleware"]:::server
        modernUserService["User Service"]:::server
        modernDB["DB Connection (Server)"]:::server
    end

    %% MongoDB Database
    database["MongoDB Database"]:::database

    %% Connections from Client to both Backend layers
    client -->|"HTTP Request"| legacyGateway
    client -->|"HTTP Request"| modernGateway

    %% Internal connections for Legacy API Layer
    legacyGateway -->|"routes request"| legacyAuth
    legacyGateway -->|"routes request"| legacyCommunity
    legacyGateway -->|"routes request"| legacyHome
    legacyGateway -->|"routes request"| legacyRoutes
    legacyRoutes -->|"DB operation"| legacyDB
    legacyAuth -->|"DB call"| legacyDB
    legacyCommunity -->|"DB call"| legacyDB
    legacyHome -->|"DB call"| legacyDB
    legacyDB -->|"persist/read data"| database

    %% Internal connections for Modern API Server
    modernGateway -->|"routes request"| modernAuth
    modernGateway -->|"routes request"| modernCommunity
    modernGateway -->|"routes request"| modernHome
    modernGateway -->|"routes request"| modernIncident
    modernGateway -->|"routes request"| modernRoutes
    modernGateway -->|"passes through"| modernMiddleware
    modernAuth -->|"DB call"| modernDB
    modernCommunity -->|"DB call"| modernDB
    modernHome -->|"DB call"| modernDB
    modernIncident -->|"DB call"| modernDB
    modernUserService -->|"business logic"| modernAuth
    modernRoutes -->|"DB operation"| modernDB
    modernMiddleware -->|"authentication"| modernGateway
    modernDB -->|"persist/read data"| database

    %% Click Events for Client Application
    click client "https://github.com/arafatrahman216/disaster-management-system/tree/master/client/"
    click pages "https://github.com/arafatrahman216/disaster-management-system/tree/master/client/src/pages/"
    click components "https://github.com/arafatrahman216/disaster-management-system/tree/master/client/src/components/"

    %% Click Events for Backend API Layer (Legacy)
    click legacyGateway "https://github.com/arafatrahman216/disaster-management-system/tree/master/Backend/"
    click legacyAuth "https://github.com/arafatrahman216/disaster-management-system/tree/master/Backend/controllers/Authentication/"
    click legacyCommunity "https://github.com/arafatrahman216/disaster-management-system/tree/master/Backend/controllers/Community/"
    click legacyHome "https://github.com/arafatrahman216/disaster-management-system/blob/master/Backend/controllers/Home/HomeController.js"
    click legacyRoutes "https://github.com/arafatrahman216/disaster-management-system/tree/master/Backend/routes/"
    click legacyDB "https://github.com/arafatrahman216/disaster-management-system/blob/master/Backend/db/connect.js"

    %% Click Events for API Server (Modern/Microservices)
    click modernGateway "https://github.com/arafatrahman216/disaster-management-system/tree/master/server/"
    click modernAuth "https://github.com/arafatrahman216/disaster-management-system/tree/master/server/controllers/Authentication/"
    click modernCommunity "https://github.com/arafatrahman216/disaster-management-system/tree/master/server/controllers/Community/"
    click modernHome "https://github.com/arafatrahman216/disaster-management-system/blob/master/server/controllers/Home.js"
    click modernIncident "https://github.com/arafatrahman216/disaster-management-system/blob/master/server/controllers/Incident.js"
    click modernRoutes "https://github.com/arafatrahman216/disaster-management-system/tree/master/server/routes/"
    click modernMiddleware "https://github.com/arafatrahman216/disaster-management-system/blob/master/server/middleware/auth.js"
    click modernUserService "https://github.com/arafatrahman216/disaster-management-system/blob/master/server/services/User/UserService.js"
    click modernDB "https://github.com/arafatrahman216/disaster-management-system/blob/master/server/db/connect.js"

    %% Styling Classes
    classDef client fill:#FCEBB6,stroke:#333,stroke-width:2px;
    classDef backend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef server fill:#B8F2E6,stroke:#333,stroke-width:2px;
    classDef database fill:#E2F0CB,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
```
