# snmcodes99/disaster-management architecture

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

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

## Overview

##### Project type and purpose
- This is a modular, C-based, terminal “Disaster Relief Resource Management System.”
- Purpose: manage cities as nodes in a weighted graph, accept disaster requests (with urgency and resource needs), compute nearest support city via Dijkstra, allocate resources (priority queue + hashmap), update statuses, and log allocations.

##### File structure
- Top-level C source/Header pairs:
- graph.c/h → graph representation (adjacency lists)
- dijkstra.c/h → shortest-path algorithm (min-heap)
- resources.c/h → request processing (max-heap + hashmap)
- utils.c/h → I/O, menu, logging support
- main.c → CLI/menu orchestrator
- Other files: Makefile (build), allocation_logs.txt (persistence), markfile/disaster_relief.exe (artifacts), .vscode (IDE settings).

##### README insights
- Describes each module’s responsibilities, data structures, complexity.
- Workflow: user + main menu → resources module (queues) → graph + dijkstra → update structures → log file.
- Emphasizes modular code, menu interface, file logging, cross-platform cleanup.

a. Main components
- CLI/Menu Layer (main.c + utils)
- Graph Module (graph.c/h)
- Dijkstra Module (dijkstra.c/h)
- Resources Module (resources.c/h)
- Persistence Layer (allocation_logs.txt)
- Data Structures: Priority Queues (min-heap/max-heap), Hashmap
b. Relationships & interactions
1. User invokes CLI → main.c (Menu system via utils)
2. “Add city/road” commands call Graph Module to update adjacency lists
3. “Raise Request” adds an entry to the max-heap in Resources Module + hashmap
4. “Allocate Resources” in Resources Module:
– Extracts highest-urgency request
– Calls Dijkstra Module, passing graph data structures
– Receives shortest path + distance
– Updates request status in hashmap
– Writes entry to allocation_logs.txt via Utils
5. “Display Status/Logs” commands read from in-memory hashmap or file
c. Architectural patterns/design principles
- Layered modular design (separation of concerns)
- Data abstraction (graph, queues, hashmap behind APIs)
- Single responsibility per module
- File-based persistence for logs (append-only)
d. Technologies & libraries
- Standard C (C99)
- Custom min/max heaps, hashmap chaining
- stdio, stdlib, string
- Makefile for build orchestration

##### Key elements to capture
- Module boundaries and APIs
- Data structures behind each module (adjacency list, heaps, hashmap)
- The request lifecycle: queuing → path calculation → allocation → logging
- Build artifact (Makefile) and persistence (allocation_logs.txt)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI/CLI Layer
    subgraph "UI/CLI Layer"
        Main["CLI/Menu Layer\n(main.c)"]:::cli
        Utils["Utils Module\n(utils.c, utils.h)"]:::cli
    end

    %% Algorithmic Modules
    subgraph "Algorithmic Modules"
        Graph["Graph Module\n(graph.c, graph.h)"]:::algo
        Dijkstra["Dijkstra Module\n(dijkstra.c, dijkstra.h)"]:::algo
        Resources["Resources Module\n(resources.c, resources.h)"]:::algo
    end

    %% Data Stores & Persistence
    subgraph "Data Stores & Persistence"
        Heap["Heaps\n(min-heap/max-heap)"]:::datastore
        Hashmap["Hashmap\n(chaining)"]:::datastore
        LogFile["Allocation Logs\n(allocation_logs.txt)"]:::datastore
    end

    %% Artifacts & Documentation
    subgraph "Build & Docs"
        Artifact["Build Artifact\n(disaster_relief.exe)"]:::artifact
        Readme["Documentation\n(readme)"]:::doc
    end

    %% User interactions
    User["User"]:::external
    User -->|"select menu option"| Main
    Main -->|"menu commands"| Utils

    %% Commands flow
    Main -->|"Add city/road"| Graph
    Main -->|"Raise request"| Resources
    Main -->|"Display status/logs"| LogFile

    %% Request lifecycle
    Resources -->|"enqueue request"| Heap
    Resources -->|"store metadata"| Hashmap
    Resources -->|"allocate resources"| Dijkstra
    Dijkstra -->|"compute shortest path"| Graph
    Dijkstra -->|"return path & distance"| Resources
    Resources -->|"update status"| Hashmap
    Resources -->|"log allocation"| Utils
    Utils -->|"append log"| LogFile

    %% Build & Docs
    Makefile["Makefile"]:::artifact
    Makefile -->|"build"| Artifact
    Main -.-> Readme
    Utils -.-> Readme
    Graph -.-> Readme
    Dijkstra -.-> Readme
    Resources -.-> Readme

    %% Click Events
    click Main "https://github.com/snmcodes99/disaster-management/blob/main/main.c"
    click Utils "https://github.com/snmcodes99/disaster-management/blob/main/utils.c"
    click Utils "https://github.com/snmcodes99/disaster-management/blob/main/utils.h"
    click Graph "https://github.com/snmcodes99/disaster-management/blob/main/graph.c"
    click Graph "https://github.com/snmcodes99/disaster-management/blob/main/graph.h"
    click Dijkstra "https://github.com/snmcodes99/disaster-management/blob/main/dijkstra.c"
    click Dijkstra "https://github.com/snmcodes99/disaster-management/blob/main/dijkstra.h"
    click Resources "https://github.com/snmcodes99/disaster-management/blob/main/resources.c"
    click Resources "https://github.com/snmcodes99/disaster-management/blob/main/resources.h"
    click LogFile "https://github.com/snmcodes99/disaster-management/blob/main/allocation_logs.txt"
    click Artifact "https://github.com/snmcodes99/disaster-management/blob/main/disaster_relief.exe"
    click Readme "https://github.com/snmcodes99/disaster-management/tree/main/readme"

    %% Styles
    classDef cli fill:#ffe4b5,stroke:#333,stroke-width:1px
    classDef algo fill:#add8e6,stroke:#333,stroke-width:1px
    classDef datastore fill:#98fb98,stroke:#333,stroke-width:1px
    classDef artifact fill:#ffdab9,stroke:#333,stroke-width:1px
    classDef doc fill:#fafad2,stroke:#333,stroke-width:1px
    classDef external fill:#ffffff,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
