# traccar/traccar-client-ios architecture

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

- Interactive diagram: https://gitdiagram.com/traccar/traccar-client-ios
- Repository: https://github.com/traccar/traccar-client-ios

## Overview

##### Project type and purpose
- This is a native iOS client application (“Traccar Client for iOS”) that implements GPS‐based tracking and reports position updates to a remote Traccar server.
- It is not a full‐stack app; rather it is a mobile client that interacts via REST/HTTP with an external server.

##### File structure
- Top‐level Xcode project (“TraccarClient.xcodeproj”) and Swift source folder (“TraccarClient/…”).
- MVC style:
– Views & Storyboards: MainStoryboard.storyboard, LaunchScreen.xib, Assets Catalogs.
– View Controllers: MainViewController.swift, StatusViewController.swift.
– Models: Position.swift, BatteryStatus.swift, Core Data model under TraccarClient.xcdatamodeld.
– Services/Managers:
- PositionProvider.swift (wraps CoreLocation)
- NetworkManager.swift (low‐level networking)
- RequestManager.swift (builds and fires requests)
- ProtocolFormatter.swift (serializes data to Traccar protocol)
- DatabaseHelper.swift (wraps Core Data for persistence)
- DistanceCalculator.swift (computes distances from position history)
– SiriKit Intents: Intents.intentdefinition plus StartTrackingIntent.swift / StopTrackingIntent.swift.
- Tests folder mirrors core modules for unit testing.
- Configuration files: Info.plist, entitlements, InAppSettings.bundle.

##### Key insights from README
- CocoaPods manages third‐party dependencies.
- The app’s sole external integration is the Traccar server API over HTTP.
- Intent support for hands‐free (“Start/Stop Tracking”) via Siri.

##### Main components
a. UI Layer
– Storyboard & ViewControllers (MainViewController, StatusViewController)
– In‐App Settings bundle
b. Business Logic / Application Layer
– TrackingController (coordinating start/stop)
– DistanceCalculator
c. Location & Intent Layer
– PositionProvider (CoreLocation)
– Siri Intents handlers (StartTrackingIntent, StopTrackingIntent)
d. Networking Layer
– ProtocolFormatter → formats JSON/protocol payload
– RequestManager → constructs HTTP requests
– NetworkManager → executes URLSession calls
e. Persistence Layer
– DatabaseHelper (Core Data stack)
– Entities: Position, BatteryStatus
f. External System
– Traccar Server API (REST endpoints)

##### Relationships & data flows
– UI triggers TrackingController (e.g., “Start” button or Siri Intent).
– TrackingController invokes PositionProvider to begin location updates.
– Each new Position passes to:
- DistanceCalculator (in‐memory metrics)
- DatabaseHelper (persist)
- ProtocolFormatter → RequestManager → NetworkManager → Traccar Server.
– Feedback (success/failure) flows back up to StatusViewController.

##### Architectural patterns & design principles
- Layered architecture (UI → Application → Data/Network → Persistence → External).
- MVC pattern for ViewControllers + Models.
- Single Responsibility: each manager handles one concern.
- Delegation/Observer: PositionProvider delegates location updates.
- Dependency Injection (pass managers into controllers).

##### Technologies & frameworks
- Swift, Xcode, Cocoa Touch (UIKit)
- CoreLocation, Core Data, SiriKit (Intents)
- URLSession (networking)
- CocoaPods (third-party dependencies)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        MSB["MainStoryboard"]:::frontend
        LS["Launch Screen"]:::frontend
        MVC["MainViewController"]:::frontend
        SVC["StatusViewController"]:::frontend
        IAS["In-App Settings Bundle"]:::frontend
    end

    %% Business Logic / Application Layer
    subgraph "Application Layer"
        TC["TrackingController"]:::business
        DC["DistanceCalculator"]:::business
    end

    %% Location & Intent Layer
    subgraph "Location & Intent Layer"
        PP["PositionProvider"]:::service
        IntentDef["Intents.intentdefinition"]:::service
        STI["StartTrackingIntent"]:::service
        SII["StopTrackingIntent"]:::service
    end

    %% Networking Layer
    subgraph "Networking Layer"
        PF["ProtocolFormatter"]:::service
        RM["RequestManager"]:::service
        NM["NetworkManager"]:::service
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        CDM["Core Data Model"]:::persistence
        DBH["DatabaseHelper"]:::persistence
        PE["Position Entity"]:::persistence
        BE["BatteryStatus Entity"]:::persistence
    end

    %% External System
    subgraph "External System"
        TS["Traccar Server API"]:::external
    end

    %% Connections
    MVC -->|"user taps Start"| TC
    SVC -->|"updates status"| TC
    STI -->|"voice command"| TC
    SII -->|"voice command"| TC

    TC -->|"start/stop updates"| PP
    PP -->|"CLLocation"| DC
    PP -->|"CLLocation"| DBH
    PP -->|"CLLocation"| PF

    PF -->|"formatted payload"| RM
    RM -->|"HTTP Request"| NM
    NM -->|"POST /positions"| TS
    TS -->|"200 OK / Error"| NM
    NM -->|"response status"| SVC

    %% Click Events
    click MSB "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/Base.lproj/MainStoryboard.storyboard"
    click LS "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/LaunchScreen.xib"
    click MVC "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/MainViewController.swift"
    click SVC "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/StatusViewController.swift"
    click IAS "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/InAppSettings.bundle"
    click TC "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/TrackingController.swift"
    click DC "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/DistanceCalculator.swift"
    click PP "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/PositionProvider.swift"
    click IntentDef "https://github.com/traccar/traccar-client-ios/blob/master/Intents.intentdefinition"
    click STI "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/StartTrackingIntent.swift"
    click SII "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/StopTrackingIntent.swift"
    click PF "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/ProtocolFormatter.swift"
    click RM "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/RequestManager.swift"
    click NM "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/NetworkManager.swift"
    click CDM "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/TraccarClient.xcdatamodeld"
    click DBH "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/DatabaseHelper.swift"
    click PE "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/Position.swift"
    click BE "https://github.com/traccar/traccar-client-ios/blob/master/TraccarClient/BatteryStatus.swift"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef business fill:#d4edda,stroke:#155724,color:#155724
    classDef service fill:#fff3cd,stroke:#856404,color:#856404
    classDef persistence fill:#f5e1da,stroke:#7b4a3e,color:#7b4a3e
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
