# eusonlito/gps-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/eusonlito/gps-tracker
- Repository: https://github.com/eusonlito/gps-tracker

## Overview

##### Project type and purpose
- This is a monolithic, full-stack GPS tracking platform built on Laravel 12 (PHP 8.2) with MySQL 8 and Redis.
- It exposes an HTTP web UI for administrators, a REST/JSON API for clients and public sharing, and custom TCP/UDP servers for ingesting GPS device data (Sinotrack, Coban, Teltonika, etc.).

##### Top-level architectural containers
- Browser (Web UI)
- Laravel HTTP App (Laravel MVC & API)
- Device Data Ingestion Services
- Job Queue / Scheduler
- MySQL Database
- Redis (caching & queue backend)
- External Services (Telegram Bot API, Translation Providers – DeepL, Microsoft, OpenAI)

##### Main components & relationships
A. Browser
- Uses Blade‐rendered HTML, CSS and JavaScript (public/build) to present dashboards, device maps, trip reports, config screens.
- Invokes Laravel HTTP controllers via standard web routes or AJAX/JSON endpoints.

B. Laravel HTTP App
- Routes → Controllers (app/Domains/**/Controller) → Service/Action layers → Models → Database
- Domain modules (Alarm, Device, Trip, Maintenance, User, etc.) follow a consistent structure:
– Validate (input rules)
– Controller (HTTP request handling / routing)
– Service/Action (business logic)
– Model/Builder/Collection (Eloquent ORM + query builders)
– Fractal (transformers for JSON/API responses)
- Console Commands (app/Console) & Scheduled tasks (app/Domains/**/Schedule) orchestrate periodic jobs.
- Middleware (app/Http/Middleware & domain‐specific) manage auth, logging, rate‐limiting, IP locks.

C. Device Data Ingestion Services
- Socket & HTTP Servers (app/Services/Server) listen for incoming GPS device connections on TCP/UDP or HTTP.
- ProtocolFactory selects the correct Protocol Parser (GPS103, GT06, Teltonika, Aquila, OsmAnd, TK102).
- Parsed raw data is mapped to Domain Actions (e.g., PositionCreate, AlarmCheck) and persisted via Eloquent Models.
- Enqueues follow-up Jobs (app/Domains/**/Job) for notifications, analytics, geofence checks.

D. Job Queue & Scheduler
- Redis queue backend processes Jobs (alarms, notifications, data cleanup, statistics updates).
- Laravel Scheduler (cron) triggers recurring tasks (e.g., trip stats, city/country updates).

E. Data Storage
- MySQL 8 with GIS support for geographic queries (latitude/longitude, geofences).
- Schema is versioned with migrations (database/migrations).
- Seeders provide initial data (languages, timezones, configurations).

F. External Integrations
- Telegram Bot API for alarm notifications.
- Translation Providers (DeepL, Microsoft, OpenAI) for UI localization.

##### Architectural patterns & design principles
- MVC for HTTP side
- Domain-Driven module structure (each Domain has its own subfolders: Action, Controller, Service, Validate, Test, Fractal, Model, Job)
- Dependency Injection via Laravel service providers (app/Providers)
- Factory patterns for Actions, Commands, Protocols
- Queued Jobs for asynchronous processing
- Fractal transformer layer for clean JSON APIs
- Single‐responsibility classes (small controllers, isolated validation, dedicated service controllers)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser UI
    subgraph "Browser UI"
        Browser["Browser UI\n(HTML/Blade, CSS, JS)"]:::frontend
    end
    click Browser "https://github.com/eusonlito/gps-tracker/tree/master/public/build"

    %% Laravel HTTP App
    subgraph "Laravel HTTP App"
        Entry["public/index.php"]:::app
        Kernel["app/Http/Kernel.php"]:::app
        Middleware["app/Http/Middleware"]:::app
        Routes["app/Providers/Route.php"]:::app
        DI["app/Providers/*.php"]:::app
        Actions["Domain Controllers\napp/Domains/**/Controller"]:::app
        APIControllers["API Controllers\napp/Domains/**/ControllerApi"]:::app
        Services["Domain Services\napp/Domains/**/Service/Controller"]:::app
        Validate["Validation\napp/Domains/**/Validate & ValidateFactory.php"]:::app
        Models["Models & Builders\napp/Domains/**/Model"]:::app
        Fractal["Fractal Transformers\napp/Domains/**/Fractal/FractalFactory.php"]:::app
        Events["Jobs & Events\napp/Domains/**/Job"]:::app
        Utilities["Utilities & Helpers\napp/Services"]:::app
        Exception["Exceptions\napp/Exceptions/Handler.php"]:::app
    end
    click Entry "https://github.com/eusonlito/gps-tracker/blob/master/public/index.php"
    click Kernel "https://github.com/eusonlito/gps-tracker/blob/master/app/Http/Kernel.php"
    click Middleware "https://github.com/eusonlito/gps-tracker/tree/master/app/Http/Middleware"
    click Routes "https://github.com/eusonlito/gps-tracker/blob/master/app/Providers/Route.php"
    click DI "https://github.com/eusonlito/gps-tracker/blob/master/app/Providers/*.php"
    click Actions "https://github.com/eusonlito/gps-tracker/tree/master/app/Domains/**/Controller"
    click APIControllers "https://github.com/eusonlito/gps-tracker/tree/master/app/Domains/**/ControllerApi"
    click Services "https://github.com/eusonlito/gps-tracker/tree/master/app/Domains/**/Service/Controller"
    click Validate "https://github.com/eusonlito/gps-tracker/tree/master/app/Domains/**/Validate"
    click Models "https://github.com/eusonlito/gps-tracker/tree/master/app/Domains/**/Model"
    click Fractal "https://github.com/eusonlito/gps-tracker/blob/master/app/Domains/**/Fractal/FractalFactory.php"
    click Events "https://github.com/eusonlito/gps-tracker/tree/master/app/Domains/**/Job"
    click Utilities "https://github.com/eusonlito/gps-tracker/tree/master/app/Services"
    click Exception "https://github.com/eusonlito/gps-tracker/blob/master/app/Exceptions/Handler.php"

    %% Device Ingestion Services
    subgraph "Device Ingestion Services"
        Server["Server\napp/Services/Server"]:::app
        Factory["ProtocolFactory\napp/Services/Protocol/ProtocolFactory.php"]:::app
        Parsers["Parsers\napp/Services/Protocol/**/Parser"]:::app
        ServerAction["Server Actions & Jobs\napp/Domains/Server/Action & Job"]:::app
    end
    click Server "https://github.com/eusonlito/gps-tracker/tree/master/app/Services/Server"
    click Factory "https://github.com/eusonlito/gps-tracker/blob/master/app/Services/Protocol/ProtocolFactory.php"
    click Parsers "https://github.com/eusonlito/gps-tracker/tree/master/app/Services/Protocol/**/Parser"
    click ServerAction "https://github.com/eusonlito/gps-tracker/tree/master/app/Domains/Server/Action"
    click ServerAction "https://github.com/eusonlito/gps-tracker/tree/master/app/Domains/Server/Job"

    %% Queue & Scheduler
    subgraph "Job Queue & Scheduler"
        QueueConfig["Queue Config\nconfig/queue.php"]:::data
        Console["app/Console/Kernel.php"]:::app
        Commands["Console Commands\napp/Domains/**/Command"]:::app
        Schedule["Scheduled Tasks\napp/Domains/**/Schedule/Manager.php"]:::app
    end
    click QueueConfig "https://github.com/eusonlito/gps-tracker/blob/master/config/queue.php"
    click Console "https://github.com/eusonlito/gps-tracker/blob/master/app/Console/Kernel.php"
    click Commands "https://github.com/eusonlito/gps-tracker/tree/master/app/Domains/**/Command"
    click Schedule "https://github.com/eusonlito/gps-tracker/blob/master/app/Domains/**/Schedule/Manager.php"

    %% Data Stores
    MySQL["MySQL 8 (GIS)\n(database/migrations, config/database.php)"]:::data
    click MySQL "https://github.com/eusonlito/gps-tracker/blob/master/config/database.php"
    Redis["Redis\n(config/cache.php & config/queue.php)"]:::data
    click Redis "https://github.com/eusonlito/gps-tracker/blob/master/config/cache.php"
    click Redis "https://github.com/eusonlito/gps-tracker/blob/master/config/queue.php"

    %% External Services
    subgraph "External Services"
        Telegram["Telegram Bot API\napp/Services/Telegram/Client.php"]:::external
        Translator["Translation Providers\napp/Services/Translator"]:::external
    end
    click Telegram "https://github.com/eusonlito/gps-tracker/blob/master/app/Services/Telegram/Client.php"
    click Translator "https://github.com/eusonlito/gps-tracker/blob/master/app/Services/Translator/TranslatorFactory.php"

    %% Data Flows
    Browser -->|"HTTP/API"| Entry
    Entry --> Kernel
    Kernel --> Middleware
    Middleware --> Actions
    Actions --> Models
    Models --> MySQL
    APIControllers --> Fractal
    Fractal --> Browser

    %% Ingestion Flow
    Server --> Factory
    Factory --> Parsers
    Parsers --> ServerAction
    ServerAction --> Models
    Models --> MySQL
    ServerAction -->|"Job"| QueueConfig
    QueueConfig --> Commands
    Commands --> Redis
    Redis --> Events
    Events --> Telegram
    Events --> Translator

    %% Scheduler Flow
    Schedule -->|"Cron"| Console
    Console -->|"Dispatch Jobs"| Redis
    Redis --> Events
    Events --> Models
    Models --> MySQL

    %% Click events for external translator config
    click Translator "https://github.com/eusonlito/gps-tracker/blob/master/app/Services/Translator/TranslatorFactory.php"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef app fill:#d3d3d3,stroke:#000,stroke-width:1px;
    classDef data fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef external fill:#ffa500,stroke:#000,stroke-width:1px;
```
