# varun987-a11/disasterlink architecture

> Architecture diagram of the GitHub repository varun987-a11/disasterlink, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/varun987-a11/disasterlink
- Repository: https://github.com/varun987-a11/disasterlink

## Overview

##### What this project is (type + purpose)
From the README + tree, **DisasterLink is a classic LAMP-style web application** (Apache/PHP + MySQL) with **two primary roles**:

- **Citizen/User**: submit emergency/disaster reports, view resources/locator, possibly fetch report locations.
- **Administrator**: authenticate, view/manage reports, update report status, export/report oversight.

It’s not microservices; it’s a **single web app** with multiple PHP endpoints/pages, shared “includes” for config/auth, and a MySQL database backing the workflows.

##### Public entry points (HTTP endpoints / pages)
These are the “controllers” in a simple PHP app (each is a route/page):

- **Root**
- `index.php`, `index.html` → landing / entry into the system
- **User area**
- `user/submit_report.php` → creates new report records
- `user/resources.php` → resource locator UI (likely reads resources / location data)
- `user/get_report_location.php` → location lookup endpoint (often used via AJAX)
- `user/export_csv.php` → exports report data to CSV (may be admin-only logically, but placed in user/)
- `user/user_home.php` → user dashboard/home
- **Admin area**
- `admin/admin_home.php` → admin landing
- `admin/dashboard.php` → admin dashboard (report listing/metrics)
- `admin/view_reports.php` → report list/details
- `admin/update_status.php` → status transition (Pending/In Progress/Resolved)
- `admin/delete_report.php` → deletion lifecycle

##### Shared backend modules (“library” / cross-cutting)
- `includes/config.php` → **DB connection** + likely constants (DB host/user/pass)
- `includes/user_login.php` / `includes/admin_login.php` → auth flows (session creation)
- `includes/logout.php` → session teardown
- `includes/create_admin.php` → admin bootstrap/seed tool

##### Static assets
- `assets/style.css` → UI styling (front-end layer)

##### Deployment assumptions
README explicitly references **XAMPP** → implies:
- **Apache** serving PHP
- **PHP runtime** executes the `.php` endpoints
- **MySQL** as the persistence layer

##### `submit_report.php` → `includes/config.php` (DB connection)
3. `submit_report.php` → **MySQL `reports`** (INSERT new report with default status = Pending)

##### Auth/session flow (should be explicit
- Admin Browser → `includes/admin_login.php` → DB (`admins`) for credential check → sets **PHP session**
- User Browser → `includes/user_login.php` (if used) → session
- Both roles → `includes/logout.php` to clear session

##### Resource locator / location lookup flow
- User Browser → `user/resources.php` (page)
- `resources.php` may call (or the browser may AJAX-call):
- `user/get_report_location.php` → DB (SELECT locations) → returns JSON/HTML fragment

##### CSV export flow
- Browser → `user/export_csv.php` → DB (SELECT reports) → outputs `text/csv` download

##### Notable architectural patterns/design principles present
- **Role separation by directory**: `/admin` vs `/user` (good to reflect as two logical subsystems)
- **Shared includes** for cross-cutting concerns (config/auth/logout)
- **Page-per-action** pattern typical of PHP apps (each endpoint handles request + DB + response)

- **DB connectivity** → `includes/config.php`
- **Admin auth** → `includes/admin_login.php`
- **User auth** → `includes/user_login.php`
- **Report submission** → `user/submit_report.php`
- **Report review** → `admin/view_reports.php`
- **Status update** → `admin/update_status.php`
- **CSV export** → `user/export_csv.php`

If anything is unclear (e.g., whether resources are stored in DB or hardcoded), reflect that honestly with:
- a note (“Resource data source: unknown—verify in resources.php”)

##### What “best and most accurate” looks like for this repo
- **two role-based entry surfaces** (User vs Admin)
- **PHP endpoints** as first-class components (because they *are* the units of behavior here)
- **includes/config/auth** as shared dependencies
- **MySQL tables and the report-status lifecycle**
- **data flows** (submit → store → manage → update → export) end-to-end

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% =======================
    %% System Context
    %% =======================
    subgraph "System Context"
        Citizen["Citizen/User"]:::actor
        AdminUser["Administrator/Responder"]:::actor
        System["DisasterLink System"]:::system
        DB[("MySQL Database")]:::db
    end

    Citizen -->|"Submit_reports\nTrack_status\nView_resources"| System
    AdminUser -->|"Manage_reports\nUpdate_status\nExport_data"| System
    System -->|"SQL"| DB

    %% =======================
    %% Containers / Deployment
    %% =======================
    subgraph "Client Layer (Browsers)"
        UserBrowser["User Browser"]:::client
        AdminBrowser["Admin Browser"]:::client
    end

    subgraph "Server Layer (XAMPP)"
        subgraph "Apache Web Server"
            Apache["Apache (serves HTTP + static)"]:::server
        end

        subgraph "PHP Application (single deployable)"
            RootEntry["Root Entry (index.php / index.html)"]:::php

            subgraph "User Module (/user)"
                UHome["user/user_home.php"]:::php
                Submit["user/submit_report.php"]:::php
                Resources["user/resources.php"]:::php
                GetLoc["user/get_report_location.php"]:::php
                ExportCSV["user/export_csv.php"]:::php
            end

            subgraph "Admin Module (/admin)"
                AHome["admin/admin_home.php"]:::php
                Dashboard["admin/dashboard.php"]:::php
                ViewReports["admin/view_reports.php"]:::php
                UpdateStatus["admin/update_status.php"]:::php
                DeleteReport["admin/delete_report.php"]:::php
            end

            subgraph "Shared Includes (/includes)"
                Config["includes/config.php (DB connection)"]:::include
                AdminLogin["includes/admin_login.php"]:::include
                UserLogin["includes/user_login.php"]:::include
                Logout["includes/logout.php"]:::include
                CreateAdmin["includes/create_admin.php"]:::include
                Session["PHP Session (server-side)"]:::include
            end

            Assets["assets/style.css"]:::static
        end
    end

    %% =======================
    %% Database / Data Model
    %% =======================
    subgraph "Persistence"
        MySQL[("MySQL")]:::db
        Reports[("reports\nreport_id,type,location,description,urgency,status,created_at,updated_at")]:::db
        Admins[("admins\n(credentials)")]:::db
    end

    MySQL --- Reports
    MySQL --- Admins

    %% =======================
    %% HTTP Routing / Serving
    %% =======================
    UserBrowser -->|"HTTP GET/POST"| Apache
    AdminBrowser -->|"HTTP GET/POST"| Apache

    Apache -->|"Serve_landing"| RootEntry
    Apache -->|"Serve_pages/endpoints"| Submit
    Apache -->|"Serve_pages/endpoints"| Resources
    Apache -->|"Serve_AJAX_endpoint"| GetLoc
    Apache -->|"Serve_download"| ExportCSV
    Apache -->|"Serve_pages"| UHome

    Apache -->|"Serve_pages"| AHome
    Apache -->|"Serve_pages"| Dashboard
    Apache -->|"Serve_pages"| ViewReports
    Apache -->|"Serve_POST_action"| UpdateStatus
    Apache -->|"Serve_POST_action"| DeleteReport

    Apache -->|"Serve_static"| Assets

    %% =======================
    %% Includes / Dependencies
    %% =======================
    RootEntry -->|"require/include"| Config

    Submit -->|"require/include"| Config
    Resources -->|"require/include"| Config
    GetLoc -->|"require/include"| Config
    ExportCSV -->|"require/include"| Config
    UHome -->|"require/include"| Config

    Dashboard -->|"require/include"| Config
    ViewReports -->|"require/include"| Config
    UpdateStatus -->|"require/include"| Config
    DeleteReport -->|"require/include"| Config
    AHome -->|"require/include"| Config

    AdminLogin -->|"sets/uses"| Session
    UserLogin -->|"sets/uses"| Session
    Logout -->|"clears"| Session

    %% Auth usage (logical dependency)
    Dashboard -->|"auth_check"| AdminLogin
    ViewReports -->|"auth_check"| AdminLogin
    UpdateStatus -->|"auth_check"| AdminLogin
    DeleteReport -->|"auth_check"| AdminLogin
    AHome -->|"auth_check"| AdminLogin

    UHome -->|"auth_check(optional)"| UserLogin
    Submit -->|"auth_check(optional)"| UserLogin

    %% =======================
    %% DB Operations (Core flows)
    %% =======================
    Submit -->|"SQL INSERT (default status=Pending)"| Reports
    ViewReports -->|"SQL SELECT"| Reports
    Dashboard -->|"SQL SELECT (metrics/listings)"| Reports
    UpdateStatus -->|"SQL UPDATE reports.status\nPending->In_Progress->Resolved"| Reports
    DeleteReport -->|"SQL DELETE"| Reports

    ExportCSV -->|"SQL SELECT -> text/csv"| Reports

    Resources -->|"SQL SELECT (resource/source unknown)"| Reports
    UserBrowser -->|"AJAX/Fetch"| GetLoc
    GetLoc -->|"SQL SELECT (locations)"| Reports

    AdminLogin -->|"SQL SELECT (credential check)"| Admins
    CreateAdmin -->|"SQL INSERT/UPDATE (bootstrap)"| Admins

    Config -->|"SQL connection"| MySQL

    %% =======================
    %% Future Integrations (optional)
    %% =======================
    subgraph "Future Integrations (Roadmap)"
        MapProvider["Map Provider (Google Maps / Leaflet+OSM)"]:::external
        MsgGateway["SMS/Email Gateway"]:::external
        OfficialAPIs["Official Disaster APIs"]:::external
    end

    Resources -.->|"future_map_embed"| MapProvider
    GetLoc -.->|"future_geocoding"| MapProvider
    UpdateStatus -.->|"future_notifications"| MsgGateway
    Dashboard -.->|"future_data_ingest"| OfficialAPIs

    %% =======================
    %% Click Events (from mapping)
    %% =======================
    click RootEntry "https://github.com/varun987-a11/disasterlink/blob/main/index.php"
    click UHome "https://github.com/varun987-a11/disasterlink/blob/main/user/user_home.php"
    click Submit "https://github.com/varun987-a11/disasterlink/blob/main/user/submit_report.php"
    click Resources "https://github.com/varun987-a11/disasterlink/blob/main/user/resources.php"
    click GetLoc "https://github.com/varun987-a11/disasterlink/blob/main/user/get_report_location.php"
    click ExportCSV "https://github.com/varun987-a11/disasterlink/blob/main/user/export_csv.php"

    click AHome "https://github.com/varun987-a11/disasterlink/blob/main/admin/admin_home.php"
    click Dashboard "https://github.com/varun987-a11/disasterlink/blob/main/admin/dashboard.php"
    click ViewReports "https://github.com/varun987-a11/disasterlink/blob/main/admin/view_reports.php"
    click UpdateStatus "https://github.com/varun987-a11/disasterlink/blob/main/admin/update_status.php"
    click DeleteReport "https://github.com/varun987-a11/disasterlink/blob/main/admin/delete_report.php"

    click Config "https://github.com/varun987-a11/disasterlink/blob/main/includes/config.php"
    click AdminLogin "https://github.com/varun987-a11/disasterlink/blob/main/includes/admin_login.php"
    click UserLogin "https://github.com/varun987-a11/disasterlink/blob/main/includes/user_login.php"
    click Logout "https://github.com/varun987-a11/disasterlink/blob/main/includes/logout.php"
    click CreateAdmin "https://github.com/varun987-a11/disasterlink/blob/main/includes/create_admin.php"

    click Assets "https://github.com/varun987-a11/disasterlink/blob/main/assets/style.css"

    %% Directory-level clicks
    click Session "https://github.com/varun987-a11/disasterlink/tree/main/includes/"
    click MySQL "https://github.com/varun987-a11/disasterlink/tree/main/admin/"
    click Reports "https://github.com/varun987-a11/disasterlink/tree/main/user/"

    %% =======================
    %% Styles
    %% =======================
    classDef actor fill:#e5e7eb,stroke:#374151,stroke-width:1px,color:#111827;
    classDef system fill:#111827,stroke:#111827,color:#f9fafb,stroke-width:1px;
    classDef client fill:#dbeafe,stroke:#1d4ed8,stroke-width:1px,color:#0f172a;
    classDef server fill:#c7d2fe,stroke:#4338ca,stroke-width:1px,color:#0f172a;
    classDef php fill:#dcfce7,stroke:#166534,stroke-width:1px,color:#052e16;
    classDef include fill:#fef9c3,stroke:#a16207,stroke-width:1px,color:#422006;
    classDef db fill:#f3e8ff,stroke:#6b21a8,stroke-width:1px,color:#2e1065;
    classDef static fill:#bae6fd,stroke:#0369a1,stroke-width:1px,color:#082f49;
    classDef external fill:#ffffff,stroke:#6b7280,stroke-width:1px,color:#111827,stroke-dasharray: 5 5;
```
