# zoxe-scripts/zoxe-dispatch architecture

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

- Interactive diagram: https://gitdiagram.com/zoxe-scripts/zoxe-dispatch
- Repository: https://github.com/zoxe-scripts/zoxe-dispatch

## Overview

##### Project Type and Purpose
- Project Type: A Lua-based advanced dispatch system tailored for emergency services in a game server environment. It integrates with various roleplay frameworks like ESX, LGF, Qbox, and QB.
- Purpose: To manage multiple emergency calls, provide real-time location tracking, prioritize dispatches, customize notifications, and log call history. It interfaces with game server configurations and external dependencies (OX LIB, OX TARGET, OX INVENTORY).

##### File Structure
- Top-Level Directory (Zoxe-Dispatch) contains key components:
- /client: Client-side scripts that handle in-game events, commands, and events (modules, commands, and functions).
- The subdirectory “bridge” provides framework-specific implementations (esx.lua, qb.lua, qbox.lua) to bridge between the script’s logic and various game frameworks.
- /server: Server-side scripts mirror the client's architecture with bridges and modules, coordinating server-side events and communications.
- /shared: Contains common functions, shared logic, and utilities that are accessible by both client and server components.
- /nui: Holds assets for the web user interface (HTML, CSS, JavaScript, and sound files) which the client might use to display alerts and notifications.
- /locales: Contains localization files (e.g., en.json) for multi-language support.
- fxmanifest.lua: Defines resource metadata, ensuring proper integration within the game server’s resource framework.
- Additional files include the LICENSE, README.md, and a few configuration-related files (.editorconfig).

##### README for Additional Insights
- The README details the features (advanced call management, real-time tracking, customizable notifications) and provides configuration instructions.
- It lists dependencies (OX LIB, OX TARGET, OX INVENTORY) which help pinpoint integration points and external interactions.
- Specific sections regarding configuration, multiple core and notify systems, and how alerts are exported or triggered indicate a layered and modular design.

a. Main Components:
- Client Component:
- Contains Client Modules (commands, events, functions, main entry point).
- Client Bridge(s) that abstract away framework-specific details (ESX, QB, QBox).
- NUI Layer: A web-based interface (index.html, script.js, style.css, and event.js) for displaying alerts and interacting with the dispatch system.
- Server Component:
- Server Modules: Main server logic, functions, and bridging to different frameworks.
- Server Bridge(s) similar to the client for ESX, QB, QBox integration.
- Shared Component:
- Common functions, utilities, and shared logic residing in shared/ (shared.lua, function.lua, utils.lua).
- External Dependencies:
- Integration with OX LIB, OX TARGET, and OX INVENTORY.
- Localization Component:
- Locales folder for managing language translations.
- Configuration:
- Settings defined in script files (shared.lua in configuration context; information for server.cfg adjustments mentioned in the README).

b. Relationships and Interactions:
- The client interacts with the NUI layer to present the user interface for dispatch alerts.
- The client code uses bridges to communicate with different roleplay frameworks, then sends information to the server through defined exports or events (e.g., TriggerServerEvent("Zoxe_Dispatch:Post")).
- The server processes incoming events, forwards them as needed, and may use its own bridges to send back responses or trigger actions across the system.
- Both client and server share common logic from the shared module to maintain consistency.
- External dependencies ensure proper functionality (e.g., OX LIB for additional client or server utility functions).
- Localization is applied across the system’s user-facing components (client UI, console outputs, etc.).

c. Important Architectural Patterns or Design Principles:
- Modularity: Components are clearly separated into client, server, and shared parts.
- Layered Architecture: Presentation (NUI/UI), application logic (modules and bridges), and data/configuration layers (shared logic and configuration files) are distinct.
- Integration Abstraction: The use of bridge files for different frameworks (ESX, QB, QBox) emphasizes a pluggable design.
- Loose Coupling: Communication via exports and events, with clear separation of client and server responsibilities.

d. Relevant Technologies, Frameworks, and Libraries:
- Technologies: Lua as the primary programming language; HTML/CSS/JavaScript for the NUI layer.
- Frameworks/Libraries: OX LIB, OX TARGET, OX INVENTORY; Built-in bridging for popular game server frameworks (ESX, LGF, QB, QBox).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        CM["Client Modules"]:::client
        CBE["Client Bridge ESX"]:::bridge
        CBB["Client Bridge QB"]:::bridge
        CBQ["Client Bridge QBox"]:::bridge
        NUI["NUI Interface"]:::nui
    end

    %% Server Layer
    subgraph "Server Layer"
        SM["Server Modules"]:::server
        SBE["Server Bridge ESX"]:::bridge
        SBB["Server Bridge QB"]:::bridge
        SBQ["Server Bridge QBox"]:::bridge
    end

    %% Shared Layer
    subgraph "Shared Layer"
        SU["Shared Utilities"]:::shared
    end

    %% Other Components
    subgraph "Other Components"
        LOC["Localization"]:::localization
        FX["Resource Configuration"]:::config
    end

    %% External Dependencies
    subgraph "External Dependencies"
        OXL["OX LIB"]:::external
        OXT["OX TARGET"]:::external
        OXI["OX INVENTORY"]:::external
    end

    %% Connections within Client
    CM -->|"uses"| CBE
    CM -->|"uses"| CBB
    CM -->|"uses"| CBQ
    CM -->|"alerts to"| NUI

    %% Connections between Client and Server
    CM -->|"TriggerServerEvent"| SM
    SM -->|"ServerCallback"| CM

    %% Shared Utilities used by both Client and Server
    CM -->|"common functions"| SU
    SM -->|"common functions"| SU

    %% Bridges within Server Layer
    SM -->|"integrates"| SBE
    SM -->|"integrates"| SBB
    SM -->|"integrates"| SBQ

    %% External dependencies used by both Client and Server
    CM -->|"external"| OXL
    CM -->|"external"| OXT
    CM -->|"external"| OXI
    SM -->|"external"| OXL
    SM -->|"external"| OXT
    SM -->|"external"| OXI

    %% Other Components affecting the system
    NUI -->|"localized content"| LOC
    SU -->|"configuration"| FX

    %% Click Events for Component Mapping
    click CM "https://github.com/zoxe-scripts/zoxe-dispatch/tree/main/Zoxe-Dispatch/client/modules"
    click CBE "https://github.com/zoxe-scripts/zoxe-dispatch/blob/main/Zoxe-Dispatch/client/bridge/esx.lua"
    click CBB "https://github.com/zoxe-scripts/zoxe-dispatch/blob/main/Zoxe-Dispatch/client/bridge/qb.lua"
    click CBQ "https://github.com/zoxe-scripts/zoxe-dispatch/blob/main/Zoxe-Dispatch/client/bridge/qbox.lua"
    click NUI "https://github.com/zoxe-scripts/zoxe-dispatch/tree/main/Zoxe-Dispatch/nui"
    click SM "https://github.com/zoxe-scripts/zoxe-dispatch/tree/main/Zoxe-Dispatch/server/modules"
    click SBE "https://github.com/zoxe-scripts/zoxe-dispatch/blob/main/Zoxe-Dispatch/server/bridge/esx.lua"
    click SBB "https://github.com/zoxe-scripts/zoxe-dispatch/blob/main/Zoxe-Dispatch/server/bridge/qb.lua"
    click SBQ "https://github.com/zoxe-scripts/zoxe-dispatch/blob/main/Zoxe-Dispatch/server/bridge/qbox.lua"
    click SU "https://github.com/zoxe-scripts/zoxe-dispatch/tree/main/Zoxe-Dispatch/shared"
    click LOC "https://github.com/zoxe-scripts/zoxe-dispatch/tree/main/Zoxe-Dispatch/locales"
    click FX "https://github.com/zoxe-scripts/zoxe-dispatch/blob/main/Zoxe-Dispatch/fxmanifest.lua"

    %% Styles
    classDef client fill:#CDEBFF,stroke:#036,stroke-width:2px;
    classDef server fill:#FFE5B4,stroke:#C65,stroke-width:2px;
    classDef shared fill:#E8E8E8,stroke:#999,stroke-width:2px;
    classDef nui fill:#F9E2F2,stroke:#D34,stroke-width:2px;
    classDef bridge fill:#D6F5D6,stroke:#2D6,stroke-width:2px;
    classDef localization fill:#FFF2CC,stroke:#B58900,stroke-width:2px;
    classDef config fill:#FCE4D6,stroke:#D66,stroke-width:2px;
    classDef external fill:#DDF3DD,stroke:#090,stroke-width:2px;
```
