Self-hosted fleet & GPS tracking platform. A Go API, a React + Leaflet dashboard, a Java Android client (XML layouts), and PostGIS storage — packaged so you can run the whole stack on your own server.
Consent first. TrackStack is built for devices you own or are explicitly authorized to track — your own phone, your own fleet, or hardware you administer. It is not a tool for covert tracking.
- Live map — positions stream over WebSocket and render on a Leaflet map with keyless Esri basemaps.
- Multi-tenant organizations — a global admin creates organizations and assigns devices; org users only see their own fleet.
- Device enrollment — a freshly installed Android client self-enrolls and waits in a pending state until an admin assigns it.
- Two auth models — short-lived JWTs with refresh for dashboard users, long-lived revocable tokens for devices.
- Geofences — draw polygon geofences on the map and inspect enter/exit events.
- Speed events & trips — speed violations are recorded, and trips are segmented automatically from position history.
- Notifications — alerts reach the dashboard over WebSocket and can also be delivered by email or browser push.
- Hardware trackers — GT06/Concox TCP and HTTP/JSON trackers feed the same ingest pipeline through the protocol gateway.
- Activity log — an audit trail of dashboard actions (currently geofence and notification changes).
- Android tracking — a foreground location service keeps reporting while the app is backgrounded, with an osmdroid map and tracking on/off control.
flowchart LR
Phone["Android client<br/>Java + XML"] -->|"device token<br/>POST /v1/positions"| Caddy
Browser["React dashboard<br/>Vite + Leaflet"] -->|"JWT + WebSocket"| Caddy
Tracker["GT06 / HTTP tracker"] -->|"TCP :5023 or /proto/*"| GW
Caddy["Caddy :80<br/>(host :8080)"] --> API["Go API<br/>Chi + JWT"]
Caddy -->|"/proto/*"| GW["Protocol gateway"]
GW -->|"X-Gateway-Secret"| API
API --> DB[("PostgreSQL 16<br/>+ PostGIS 3.4")]
API -.->|"trip worker"| DB
API -.->|"email / Web Push"| Alerts["SMTP + push services"]
| Layer | Implementation |
|---|---|
| API | Go 1.22, Chi router, golang-jwt, Gorilla WebSocket, lib/pq |
| Gateway | Separate Go service: GT06/Concox TCP adapter, HTTP/JSON adapter, shared secret to the API |
| Database | PostgreSQL 16 + PostGIS 3.4, SQL migrations mounted at container init |
| Web | React 19, Vite 8, React Router, TanStack Query, Axios, Leaflet + react-leaflet (keyless Esri basemaps) |
| Android | Java 17 + XML layouts (Material 3), foreground location service, osmdroid, OkHttp; minSdk 26, compile/target SDK 34 |
| Deployment | Docker Compose, Caddy serving the built frontend and reverse-proxying the API |
Requirements: Docker with Compose v2. For local (non-Docker) development you also need Go 1.22+, Node.js 22+, and JDK 17 with Android SDK 34.
git clone https://github.com/AYMANOULHOUF/trackstack.git
cd trackstack
cp .env.example .env
# edit .env and set DB_PASSWORD, JWT_SECRET, and ADMIN_PASSWORD
docker compose up --buildOpen http://localhost:8080 and sign in with ADMIN_EMAIL / ADMIN_PASSWORD.
The API is available at http://localhost:8080/v1, health check at /healthz.
Postgres is exposed on host port 5433 by default (override with DB_PORT).
| Variable | Required | Purpose |
|---|---|---|
DB_PASSWORD |
yes | Password for the Postgres user and the API's DATABASE_URL |
JWT_SECRET |
yes | Signs dashboard access/refresh tokens |
ADMIN_PASSWORD |
yes | Password for the seeded global admin; re-applied on every boot |
ADMIN_EMAIL |
no | Admin login (default admin@trackstack.local) |
DB_PORT |
no | Host port for Postgres (default 5433) |
GATEWAY_SECRET |
no | Shared secret for hardware ingest; empty disables it |
GT06_PORT |
no | Host port for GT06/Concox trackers (default 5023) |
TRIP_WORKER_INTERVAL |
no | Trip segmentation pass interval (default 30s) |
SMTP_ADDR, SMTP_FROM |
no | Enable email alerts (host:port and sender address) |
SMTP_USER, SMTP_PASSWORD |
no | SMTP credentials when the server requires auth |
VAPID_PUBLIC_KEY, VAPID_PRIVATE_KEY |
no | Enable Web Push alerts |
VAPID_SUBJECT |
no | VAPID contact, e.g. mailto:you@example.com |
Generate a strong JWT secret with openssl rand -hex 32. Never commit .env.
Generate a VAPID key pair from the API module:
cd backend/api-service
go run ./cmd/vapidEmail and Web Push are independent. When a channel is enabled in the dashboard but its credentials are missing, the API logs why it skipped delivery and the rest of tracking keeps working.
cd backend/api-service
export DATABASE_URL='postgres://trackproj:trackproj@localhost:5432/trackproj?sslmode=disable'
export JWT_SECRET='dev-secret'
export ADMIN_EMAIL='admin@trackstack.local'
export ADMIN_PASSWORD='dev-password'
go run ./cmd/apiApply backend/migrations/*.sql to a PostGIS-enabled database before starting the API.
cd frontend
npm ci
VITE_API_URL=http://localhost:8080/v1 npm run devThe Vite dev server runs on http://localhost:5173; set VITE_API_URL so API calls reach the Go service.
The client is plain Java + XML layouts (no Kotlin source). Build it with JDK 17 and Android SDK platform 34 / build-tools 34.0.0 via the Gradle 8.7 wrapper.
Open android/ in Android Studio and build. The app defaults to http://10.0.2.2:8080, which reaches the host machine from the Android emulator. For a physical device, point it at your machine's LAN address:
cd android
./gradlew assembleDebug -PbaseUrl=http://192.168.1.50:8080Grant location and notification permissions, then enroll the device.
| Area | Endpoints |
|---|---|
| Public | POST /v1/auth/login, POST /v1/auth/refresh, POST /v1/enroll, GET /healthz |
| Device token | POST /v1/positions, POST /v1/tracking-state |
| Gateway | POST /v1/gateway/positions (requires X-Gateway-Secret) |
| Dashboard (JWT) | GET /v1/me (caller role/org), GET /v1/live (WebSocket), /v1/devices, /v1/positions, /v1/geofences, /v1/trips, /v1/activity, /v1/notifications |
| Admin only | /v1/orgs, PUT /v1/devices/{id}/orgs, POST /v1/devices/{id}/revoke-token |
backend/
api-service/ Go API (cmd/api, internal/auth, handlers, ws, db, models)
protocol-gateway/ Go service for hardware protocol adapters
migrations/ PostgreSQL/PostGIS schema
frontend/ React 19 + Vite dashboard
android/ Java + XML tracking client (Gradle 8.7, AGP 8.5)
docs/ Historical design/session notes and the Java migration note
scripts/ Repository checks (docs/version consistency)
docker-compose.yml db, api-service, protocol-gateway, caddy
Dockerfile.caddy multi-stage build for the static dashboard image
Caddyfile static frontend + API/gateway reverse proxy
CONTRIBUTING.md Build/test commands and documentation checklist
AUDIT_LOG.md Latest full repository audit and unresolved findings
LICENSE MIT license
The protocol gateway accepts two kinds of hardware:
- GT06/Concox over raw TCP on
GT06_PORT(default5023). The tracker logs in with its IMEI; the gateway acknowledges frames and forwards each fix. - HTTP/JSON at
POST /proto/http/positions, either with a normal device bearer token or withexternal_idplusX-Gateway-Secret.
Link a tracker to a device by setting its Hardware ID (IMEI or serial) in
the admin device editor. That value is stored as external_id and must be
unique. Until it is linked, forwarded positions are rejected with 404.
A background worker runs every TRIP_WORKER_INTERVAL. For each device it reads
fixes newer than a stored cursor and applies the device's stop thresholds:
a trip opens on the first fix above trip_stop_speed_kmh, accumulates
great-circle distance, and closes once the device has been stationary for
trip_stop_duration_seconds. The cursor lives in devices.trip_cursor_position_id,
so restarts never re-segment the same fixes.
The dashboard Trips page lists trips per device and draws the recorded track for the selected trip.
Dashboard alerts (speed violations, geofence enter/exit) always stream over the WebSocket firehose. The Notifications page adds two optional delivery channels per organization:
- Email — requires
SMTP_ADDRandSMTP_FROM;SMTP_USER/SMTP_PASSWORDare used when the server authenticates. Port465uses implicit TLS, other ports use STARTTLS when offered. - Web Push — requires a VAPID key pair and an HTTPS origin (or localhost).
The page registers
public/sw.jsand stores the browser subscription.
Delivery happens on a queue behind position ingest, so a slow SMTP server never delays tracking.
Docker's init directory only runs on a fresh volume. If you already have a
pgdata volume from an earlier version, apply the migrations your volume has
not seen yet, in filename order. For example, the latest one:
docker compose exec -T db psql -U trackproj -d trackproj < backend/migrations/0004_trips_notifications_gateway.sqlThe files are 0001_init.sql, 0002_admin_multiorg.sql,
0003_tracking_state.sql, and 0004_trips_notifications_gateway.sql. Do not
replay migrations that are already applied: 0001 and 0002 are not
idempotent.
- Automated trip segmentation worker
- Geofence drawing UI
- Email and Web Push notification delivery
- Hardware protocol adapters (GT06 TCP + HTTP/JSON)
- iOS client (the codebase targets Android; no iOS target yet)
The decisions behind the architecture — auth model, background-tracking constraints, datastore choice, transport, and deployment — are documented in the historical docs/read_me.md. The Android bootstrap session is in docs/session_log_android_bootstrap.md, and the Kotlin → Java/XML rewrite is described in docs/Android-Java-Migration.docx. Both markdown logs predate later changes, so treat this README and the code as current.
TrackStack is under active development. The API, dashboard, and Android client are functional; the roadmap above tracks what is still in progress. CI checks README version consistency, builds and tests both Go services, lints and builds the dashboard, assembles the Android debug APK, builds the Docker images, and smoke-tests the full Compose stack on pushes to main and on pull requests.