# remyfrancis/hurrinet architecture

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

- Interactive diagram: https://gitdiagram.com/remyfrancis/hurrinet
- Repository: https://github.com/remyfrancis/hurrinet

## Overview

**Project Overview:**

##### Project Type and Purpose
- **Type:** Full-Stack Web Application
- **Purpose:** To manage and streamline emergency response operations, including incident management, resource allocation, weather monitoring, and communication among various stakeholders (admins, citizens, emergency personnel, medical staff).

##### File Structure
- **Top-Level Directories:**
- **backend:** Contains the Django backend with multiple apps (`accounts`, `alerts`, `chats`, `incidents`, `resource_management`, `social`, `weather`, etc.). Each app includes models, views, serializers, and migrations, indicating a modular approach.
- **src:** Houses the Next.js frontend with multiple dashboards (`admin-dashboard`, `citizen-dashboard`, `emergency-dashboard`, etc.) and a comprehensive set of React components.
- **components:** Reusable React components categorized by functionality (e.g., `Alerts`, `Dashboard`, `Incidents`, `Map`, `MedicalDashboard`, etc.).
- **public, styles, configuration files:** Standard directories and files for Next.js applications.

- **Architectural Patterns:**
- **Modular Architecture:** Both frontend and backend are divided into multiple modules/apps for scalability and maintainability.
- **Separation of Concerns:** Clear delineation between frontend (user interface) and backend (business logic, data management).
- **RESTful API:** Presence of serializers and views in Django suggests the use of REST APIs for communication between frontend and backend.

##### README for Additional Insights
The README primarily details the setup and deployment of the Next.js frontend, with no direct information about the backend. However, combined with the file structure, it's evident that the backend plays a crucial role in handling data operations, user authentication, and business logic.

**a. Identify the Main Components:**
- **Frontend:**
- **Next.js Application:** Responsible for rendering the user interface and handling client-side interactions.
- **Dashboards:** Multiple dashboards catering to different user roles (admin, citizen, emergency personnel, medical staff, resource managers).
- **Components:** Reusable UI elements like Alerts, Maps, Weather Widgets, etc.

- **Backend:**
- **Django Server (`hurrinet`):** Manages business logic, data processing, and serves APIs.
- **Django Apps:**
- **Accounts:** Handles user authentication and authorization.
- **Alerts:** Manages emergency alerts and notifications.
- **Chats:** Facilitates real-time communication.
- **Incidents:** Manages incident reporting and tracking.
- **Resource Management:** Oversees resource allocation and inventory.
- **Social:** Manages social interactions and integrations.
- **Weather:** Integrates weather forecasting and alerts.

- **Database:**
- **SQLite (`db.sqlite3`):** Serves as the primary database for storing application data.

- **External Services:**
- **Vercel:** For deploying the Next.js frontend.
- **Redis (`redis.ts`):** Possibly used for caching or managing real-time data.
- **WebSockets (`websocket`):** Handles real-time communication for incidents and alerts.

**b. Determine Relationships and Interactions:**
- **Frontend ↔ Backend:**
- Communication via RESTful APIs for data retrieval and manipulation.
- Real-time updates facilitated through WebSockets for features like alerts and chats.

- **Backend ↔ Database:**
- Django ORM manages interactions with the SQLite database for CRUD operations.

- **Backend ↔ External Services:**
- Redis for caching and managing real-time data streams.
- Integration with weather APIs for forecasting data.

**c. Highlight Architectural Patterns and Design Principles:**
- **MVC (Model-View-Controller):** Evident in the Django backend structure.
- **Component-Based Architecture:** In the Next.js frontend, promoting reusability and scalability.
- **API-First Design:** Backend exposes APIs consumed by the frontend, ensuring decoupled development.
- **Real-Time Communication:** Utilization of WebSockets for instant data updates.

**d. Include Relevant Technologies, Frameworks, and Libraries:**
- **Frontend:**
- **Next.js:** Framework for server-rendered React applications.
- **React:** JavaScript library for building user interfaces.
- **Tailwind CSS:** Utility-first CSS framework for styling.

- **Backend:**
- **Django:** High-level Python web framework.
- **Django REST Framework (DRF):** For building RESTful APIs.
- **Redis:** In-memory data structure store, used as a database, cache, and message broker.

- **Other Tools:**
- **ESLint:** For linting JavaScript/TypeScript code.
- **PostCSS:** For transforming CSS with JavaScript plugins.

##### Elements
- **Clear Labels for Each Component:**
- Frontend, Backend, Database, External Services, and each major module/app.

- Data flow between components, such as API calls from the frontend to the backend, and responses or real-time data streams back.

- Differentiate between types of components:

- **Technologies and Frameworks:**
- Components with the technologies they use (e.g., Next.js, Django, Redis).

##### Detailed and Comprehensive Representation

**Final Recommendations:**

- **Iterative Refinement:** Start with a high-level overview and progressively add more details to capture the complexity of the system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global entities
    Frontend["Frontend (Next.js Application)"]:::frontend
    Backend["Backend (Django Server)"]:::backend
    Database["Database (SQLite)"]:::database
    ExternalServices["External Services"]:::external

    %% Subgraphs and modules
    subgraph "Frontend"
        AdminDashboard["Admin Dashboard"]:::frontend
        CitizenDashboard["Citizen Dashboard"]:::frontend
        EmergencyDashboard["Emergency Dashboard"]:::frontend
        EmergencyPersonnelDashboard["Emergency Personnel Dashboard"]:::frontend
        MedicalDashboard["Medical Dashboard"]:::frontend
        ResourceManagerDashboard["Resource Manager Dashboard"]:::frontend
        ReusableComponents["Reusable Components"]:::frontend
        NextConfig["Next.js Configuration"]:::frontend
        TailwindConfig["Tailwind CSS Configuration"]:::frontend
        ESLintConfig["ESLint Configuration"]:::frontend
        APIUtilities["API Utilities"]:::frontend
        AuthClient["Client-Side Authentication"]:::frontend
        AuthServer["Server-Side Authentication"]:::frontend
        IncidentSocket["WebSocket Utilities"]:::frontend
        ReusableUIComponents["Reusable UI Components"]:::frontend
        AlertContext["Alert Context"]:::frontend
        SupplierUpdatesContext["Supplier Updates Context"]:::frontend
        ToastHook["Toast Hook"]:::frontend
        AlertsHook["Alerts Hook"]:::frontend
    end

    subgraph "Backend"
        Accounts["Accounts"]:::backend
        Alerts["Alerts"]:::backend
        Chats["Chats"]:::backend
        Incidents["Incidents"]:::backend
        ResourceManagement["Resource Management"]:::backend
        Social["Social"]:::backend
        Weather["Weather"]:::backend
    end

    subgraph "External Services"
        Redis["Redis Service"]:::external
        WebSockets["WebSockets"]:::external
    end

    %% Connections
    Frontend -->|"REST API calls"| Backend
    Backend -->|"CRUD Operations"| Database
    Backend -->|"Caching / Real-Time Data"| Redis
    Backend -->|"Real-Time Communication"| WebSockets
    Frontend -->|"WebSockets"| WebSockets

    %% Click Events
    click Frontend "https://github.com/remyfrancis/hurrinet/tree/main/src/"
    click AdminDashboard "https://github.com/remyfrancis/hurrinet/tree/main/src/app/admin-dashboard/"
    click CitizenDashboard "https://github.com/remyfrancis/hurrinet/tree/main/src/app/citizen-dashboard/"
    click EmergencyDashboard "https://github.com/remyfrancis/hurrinet/tree/main/src/app/emergency-dashboard/"
    click EmergencyPersonnelDashboard "https://github.com/remyfrancis/hurrinet/tree/main/src/app/emergency-personnel-dashboard/"
    click MedicalDashboard "https://github.com/remyfrancis/hurrinet/tree/main/src/app/medical-dashboard/"
    click ResourceManagerDashboard "https://github.com/remyfrancis/hurrinet/tree/main/src/app/resource-manager-dashboard/"
    click ReusableComponents "https://github.com/remyfrancis/hurrinet/tree/main/src/components/"
    click NextConfig "https://github.com/remyfrancis/hurrinet/blob/main/next.config.ts"
    click TailwindConfig "https://github.com/remyfrancis/hurrinet/blob/main/tailwind.config.ts"
    click ESLintConfig "https://github.com/remyfrancis/hurrinet/blob/main/.eslintrc.json"
    click APIUtilities "https://github.com/remyfrancis/hurrinet/blob/main/src/lib/api.ts"
    click AuthClient "https://github.com/remyfrancis/hurrinet/blob/main/src/lib/auth-client.ts"
    click AuthServer "https://github.com/remyfrancis/hurrinet/blob/main/src/lib/auth-server.ts"
    click IncidentSocket "https://github.com/remyfrancis/hurrinet/blob/main/src/lib/websocket/incidentSocket.ts"
    click ReusableUIComponents "https://github.com/remyfrancis/hurrinet/tree/main/src/components/ui/"
    click AlertContext "https://github.com/remyfrancis/hurrinet/blob/main/src/contexts/AlertContext.tsx"
    click SupplierUpdatesContext "https://github.com/remyfrancis/hurrinet/blob/main/src/contexts/SupplierUpdatesContext.tsx"
    click ToastHook "https://github.com/remyfrancis/hurrinet/blob/main/src/hooks/use-toast.ts"
    click AlertsHook "https://github.com/remyfrancis/hurrinet/blob/main/src/hooks/useAlerts.ts"
    click Accounts "https://github.com/remyfrancis/hurrinet/tree/main/backend/hurrinet/accounts/"
    click Alerts "https://github.com/remyfrancis/hurrinet/tree/main/backend/hurrinet/alerts/"
    click Chats "https://github.com/remyfrancis/hurrinet/tree/main/backend/hurrinet/chats/"
    click Incidents "https://github.com/remyfrancis/hurrinet/tree/main/backend/hurrinet/incidents/"
    click ResourceManagement "https://github.com/remyfrancis/hurrinet/tree/main/backend/hurrinet/resource_management/"
    click Social "https://github.com/remyfrancis/hurrinet/tree/main/backend/hurrinet/social/"
    click Weather "https://github.com/remyfrancis/hurrinet/tree/main/backend/hurrinet/weather/"
    click Database "https://github.com/remyfrancis/hurrinet/blob/main/backend/hurrinet/db.sqlite3"
    click Redis "https://github.com/remyfrancis/hurrinet/blob/main/src/lib/redis.ts"
    click WebSockets "https://github.com/remyfrancis/hurrinet/tree/main/src/lib/websocket/"

    %% Styles
    classDef frontend fill:#1f78b4, stroke:#333, stroke-width:2px;
    classDef backend fill:#33a02c, stroke:#333, stroke-width:2px;
    classDef database fill:#ff7f00, stroke:#333, stroke-width:2px;
    classDef external fill:#6a3d9a, stroke:#333, stroke-width:2px;
    class Frontend,AdminDashboard,CitizenDashboard,EmergencyDashboard,EmergencyPersonnelDashboard,MedicalDashboard,ResourceManagerDashboard,ReusableComponents,NextConfig,TailwindConfig,ESLintConfig,APIUtilities,AuthClient,AuthServer,IncidentSocket,ReusableUIComponents,AlertContext,SupplierUpdatesContext,ToastHook,AlertsHook frontend;
    class Backend,Accounts,Alerts,Chats,Incidents,ResourceManagement,Social,Weather backend;
    class Database database;
    class ExternalServices,Redis,WebSockets external;
```
