# misbahkhan0009/flood-guard-server architecture

> Architecture diagram of the GitHub repository misbahkhan0009/flood-guard-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/misbahkhan0009/flood-guard-server
- Repository: https://github.com/misbahkhan0009/flood-guard-server

## Overview

##### Project Type and Purpose
- Flood Guard is a full-stack application centered on flood prediction, early warnings, and support for flood victims and rescuers. The main website forecasts floods, shows nearby shelters, and provides navigation details.
- The README explicitly describes how the system will help mitigate flood damages by forecasting floods, monitoring water levels, and coordinating rescue efforts through a web-based interface.
- In addition to Express-based backend services, there is a dedicated ML Model directory that contains several Python scripts and notebooks, indicating an integration of machine learning for flood prediction.

##### File Structure and Major Components
- Backend (Express.js Server):
- Top-level files like index.js, package.json and package-lock.json indicate the Node.js backend.
- The “routes” directory contains API route definitions for different resources (e.g., victims, shelters, floods, emergency alerts). This shows a RESTful design.
- The “controllers” directory holds the business logic for handling API requests—one for each domain (e.g., water levels, hospitals, hydro level maps).
- The “config” folder (containing db.js and firebase.js) manages database connectivity and authentication setup.
- ML Model Component:
- The “ML Model” directory includes Jupyter notebooks, Python scripts (app1.py, app2.py, predict_api.py), CSV input data, and multiple serialized model files (e.g., .pkl and .sav). This indicates that the ML part is used for flood prediction.
- There could be a microservice or an integrated module which the main backend may call, either synchronously via an API or through batch processing.
- Database:
- The presence of a FloodGuard.sql file indicates that the database schema (described in the README) is set up in MySQL.
- The README also outlines a detailed relational schema with tables for Emergency Alerts, Mobile Towers, Donations, Water Levels, and several other critical components.
- External Services:
- Firebase (in config/firebase.js) is used for authentication.
- Cloudinary is noted in the README for file management.
- Other aspects:
- The ML model may communicate its predictions back to the Express.js API, contributing to decisions like navigation and resource allocation.

##### Key Architectural Patterns and Relationships
- The system follows an MVC-like separation (routes, controllers, configuration) for the RESTful backend API.
- The ML component appears to be a separate unit which handles flood predictions. There is a clear interaction point where the Node.js server will likely trigger predictions from the Python module.
- The server acts as a mediator, receiving client requests, interacting with the database (via MySQL), processing inputs (using ML predictions), and interfacing with external services (Firebase for auth and Cloudinary for file storage).
- The architecture promotes modularity by splitting responsibilities: one module for forecast/prediction and another for API management & database operations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend/Client"
        A["Client (Flood Victim & Rescuer)"]:::client
    end

    subgraph "Express.js API Server"
        S["Main Server (index.js)"]:::api
        R["Routes Directory"]:::api
        C["Controllers Directory"]:::api
        D["Database Configuration (db.js)"]:::config
        F["Firebase Configuration (firebase.js)"]:::config
        P["Package Files (package.json, package-lock.json)"]:::config
    end

    subgraph "ML Prediction Service"
        ML["ML Code (Python Scripts & Notebooks)"]:::ml
    end

    subgraph "Data Persistence"
        DB["MySQL Database (FloodGuard.sql)"]:::database
    end

    subgraph "External Services"
        FA["Firebase Auth"]:::external
        CL["Cloudinary File Storage"]:::external
    end

    A -->|"sendsRequest"| S
    S -->|"definesRoutes"| R
    S -->|"executesLogic"| C
    S -->|"loadsConfig"| D
    S -->|"loadsConfig"| F
    S -->|"packageInfo"| P
    S -->|"queries"| DB
    S -->|"triggersPrediction"| ML
    ML -->|"returnsPrediction"| S
    S -->|"authVia"| FA
    S -->|"storesFiles"| CL

    click S "https://github.com/misbahkhan0009/flood-guard-server/blob/main/index.js"
    click R "https://github.com/misbahkhan0009/flood-guard-server/tree/main/routes/"
    click C "https://github.com/misbahkhan0009/flood-guard-server/tree/main/controllers/"
    click D "https://github.com/misbahkhan0009/flood-guard-server/blob/main/config/db.js"
    click F "https://github.com/misbahkhan0009/flood-guard-server/blob/main/config/firebase.js"
    click P "https://github.com/misbahkhan0009/flood-guard-server/blob/main/package.json"
    click ML "https://github.com/misbahkhan0009/flood-guard-server/tree/main/ML Model/Code"
    click DB "https://github.com/misbahkhan0009/flood-guard-server/blob/main/FloodGuard.sql"

    classDef client fill:#ffdead,stroke:#333,stroke-width:2px;
    classDef api fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef config fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef ml fill:#d3ffd3,stroke:#333,stroke-width:2px;
    classDef database fill:#ffe4e1,stroke:#333,stroke-width:2px;
    classDef external fill:#e0ffff,stroke:#333,stroke-width:2px;
```
