Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ DB_PASSWORD=change_me_strong_password
# JWT signing secret — generate with: openssl rand -hex 32
JWT_SECRET=change_me_jwt_secret

# Global admin account seeded on every API boot.
# Global admin account seeded/updated on every API boot, so changing
# ADMIN_PASSWORD here and restarting the API updates the existing login.
# ADMIN_EMAIL defaults to admin@trackstack.local when omitted.
ADMIN_EMAIL=admin@trackstack.local
ADMIN_PASSWORD=change_me_admin_password
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ jobs:
- run: go vet ./...
- run: go test ./...

docs:
name: Docs version check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- run: python3 scripts/check_docs.py

frontend:
name: Frontend
runs-on: ubuntu-latest
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ pgdata/
# OS
.DS_Store
Thumbs.db
*.log
*.hprof

# IDE
# IDE / local tooling
.idea/
.gradle/
frontend/.vite/
frontend/coverage/
android/.kotlin/

# Android / Gradle build artifacts
android/build/
Expand Down
309 changes: 309 additions & 0 deletions AUDIT_LOG.md

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Contributing to TrackStack

Thanks for helping improve TrackStack. This file describes the checks to run
and the documentation to update before opening a pull request.

## Before you start

- Do not commit `.env` or any real secret. Copy `.env.example` to `.env` for
local runs and keep it untracked.
- Use a feature branch and open a pull request against `main`.
- Keep API behaviour, database schema, and existing migrations stable unless
the change is intentional and documented.

## Build and test

Run the checks that match what you changed. CI runs the same commands.

### Backend (Go 1.22)

```bash
cd backend/api-service
go build ./... && go vet ./... && go test ./...

cd ../protocol-gateway
go build ./... && go vet ./... && go test ./...
```

### Dashboard (Node.js 22)

```bash
cd frontend
npm ci
npm run lint
npm run build
```

### Android (JDK 17, Android SDK 34)

```bash
cd android
./gradlew assembleDebug
```

### Docker

```bash
cp .env.example .env # fill in throwaway values for a local test
docker compose config
docker compose up --build
curl -fsS http://localhost:8080/healthz
docker compose down # never use -v on a volume with data you need
```

## Documentation checklist

Update the docs in the same pull request as the code:

- [ ] **README.md** — if a version, service, port, endpoint, environment
variable, repo layout entry, or roadmap item changed. Keep the version
badges and the stack table in sync with `go.mod`, `frontend/package.json`,
and `docker-compose.yml` (CI runs `scripts/check_docs.py`).
- [ ] **README.md API overview** — when adding, removing, or renaming a route
in `backend/api-service/internal/handlers/router.go`.
- [ ] **`.env.example`** — when the API, gateway, or Compose file reads a new
environment variable. Document safe defaults and never put real secrets in it.
- [ ] **`frontend/README.md`** — when dashboard scripts, dependencies, or the
map implementation change.
- [ ] **Migrations** — do not edit an applied migration; add the next numbered
file instead (`0005_...sql`) and note it in the README's migration section.
- [ ] **Roadmap** — tick an item only when the feature is implemented and
covered by CI or a documented manual check.

## Commit style

Use short, imperative commit messages with an optional scope, for example:

```
fix(api): authorize trips through device_orgs
docs(readme): describe the Java + XML Android client
```

## Reporting issues

Include the command you ran, the expected and actual result, and the relevant
logs. Redact tokens, passwords, `.env` contents, and device identifiers.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 TrackStack contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 29 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# TrackStack

**Self-hosted fleet & GPS tracking platform.** A Go API, a React + Leaflet dashboard, a Kotlin Android client, and PostGIS storage — packaged so you can run the whole stack on your own server.
**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.

<p>
<img alt="Go" src="https://img.shields.io/badge/Go-1.22-00ADD8?style=flat-square&logo=go&logoColor=white">
<img alt="React" src="https://img.shields.io/badge/React-19-20232A?style=flat-square&logo=react&logoColor=61DAFB">
<img alt="Kotlin" src="https://img.shields.io/badge/Kotlin-Compose-7F52FF?style=flat-square&logo=kotlin&logoColor=white">
<img alt="Android" src="https://img.shields.io/badge/Android-Java%20%2B%20XML-3DDC84?style=flat-square&logo=android&logoColor=white">
<img alt="Node" src="https://img.shields.io/badge/Node-22-339933?style=flat-square&logo=node.js&logoColor=white">
<img alt="PostgreSQL" src="https://img.shields.io/badge/PostgreSQL-16%20%2B%20PostGIS-4169E1?style=flat-square&logo=postgresql&logoColor=white">
<img alt="Docker" src="https://img.shields.io/badge/Docker%20Compose-2496ED?style=flat-square&logo=docker&logoColor=white">
<img alt="CI" src="https://img.shields.io/github/actions/workflow/status/AYMANOULHOUF/trackstack/ci.yml?branch=main&style=flat-square&label=CI">
Expand All @@ -17,15 +18,15 @@

## What it does

- **Live map** — positions stream over WebSocket and render on an OpenStreetMap/Leaflet map.
- **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 tracking and device activity.
- **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.

---
Expand All @@ -34,10 +35,10 @@

```mermaid
flowchart LR
Phone["Android client<br/>Kotlin + Compose"] -->|"device token<br/>POST /v1/positions"| API
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 :8080"] --> API["Go API<br/>Chi + JWT"]
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")]
Expand All @@ -50,15 +51,15 @@ flowchart LR
| **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 |
| **Android** | Kotlin, Jetpack Compose, foreground location service, osmdroid, OkHttp |
| **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 |

---

## Quick start (Docker)

**Requirements:** Docker with Compose v2.
**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.

```bash
git clone https://github.com/AYMANOULHOUF/trackstack.git
Expand Down Expand Up @@ -124,14 +125,16 @@ Apply `backend/migrations/*.sql` to a PostGIS-enabled database before starting t

```bash
cd frontend
npm install
npm ci
VITE_API_URL=http://localhost:8080/v1 npm run dev
```

The Vite dev server runs on `http://localhost:5173`; set `VITE_API_URL` so API calls reach the Go service.

### Android

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:

```bash
Expand Down Expand Up @@ -163,9 +166,15 @@ backend/
protocol-gateway/ Go service for hardware protocol adapters
migrations/ PostgreSQL/PostGIS schema
frontend/ React 19 + Vite dashboard
android/ Kotlin + Jetpack Compose tracking client
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
```

---
Expand Down Expand Up @@ -219,12 +228,18 @@ delays tracking.
## Applying migrations to an existing database

Docker's init directory only runs on a fresh volume. If you already have a
`pgdata` volume from an earlier version, apply new migrations manually:
`pgdata` volume from an earlier version, apply the migrations your volume has
not seen yet, in filename order. For example, the latest one:

```bash
docker compose exec -T db psql -U trackproj -d trackproj < backend/migrations/0004_trips_notifications_gateway.sql
```

The 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.

---

## Roadmap
Expand All @@ -239,8 +254,8 @@ docker compose exec -T db psql -U trackproj -d trackproj < backend/migrations/00

## Design notes

The decisions behind the architecture — auth model, background-tracking constraints, datastore choice, transport, and deployment — are documented in [`read_me.md`](read_me.md). The Android bootstrap is covered in [`session_log_android_bootstrap.md`](session_log_android_bootstrap.md).
The decisions behind the architecture — auth model, background-tracking constraints, datastore choice, transport, and deployment — are documented in the historical [`docs/read_me.md`](docs/read_me.md). The Android bootstrap session is in [`docs/session_log_android_bootstrap.md`](docs/session_log_android_bootstrap.md), and the Kotlin → Java/XML rewrite is described in [`docs/Android-Java-Migration.docx`](docs/Android-Java-Migration.docx). Both markdown logs predate later changes, so treat this README and the code as current.

## Status

TrackStack is under active development. The API, dashboard, and Android client are functional; the roadmap above tracks what is still in progress. CI 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 every push.
TrackStack is under active development. The API, dashboard, and Android client are functional; the roadmap above tracks what is still in progress. CI 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.
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="TrackProj"
android:label="@string/app_name"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.TrackProj">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void reportTrackingState(boolean active) {

private void startForegroundWithNotification() {
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("TrackProj is tracking")
.setContentTitle("TrackStack is tracking")
.setContentText("Sharing your location with the dashboard")
.setSmallIcon(R.drawable.ic_stat_track)
.setOngoing(true)
Expand Down
6 changes: 3 additions & 3 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TrackProj</string>
<string name="app_name">TrackStack</string>

<string name="toggle_map_theme">Toggle map theme</string>
<string name="zoom_in">Zoom in</string>
Expand All @@ -20,8 +20,8 @@
<string name="retry">Retry</string>

<string name="location_needed">Location access needed</string>
<string name="permission_body">TrackProj needs location access to track this device. Please allow it to continue.</string>
<string name="permission_off_body">Location permission is turned off. Open settings and allow location to use TrackProj.</string>
<string name="permission_body">TrackStack needs location access to track this device. Please allow it to continue.</string>
<string name="permission_off_body">Location permission is turned off. Open settings and allow location to use TrackStack.</string>
<string name="grant_permission">Grant permission</string>
<string name="open_settings">Open settings</string>
</resources>
7 changes: 7 additions & 0 deletions read_me.md → docs/read_me.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Project: Phone/GPS Tracking Platform — Decision Log

> **Historical design log.** This records decisions from the initial build and
> is not a description of the current code. Several details have changed since:
> the Android client is now **Java + XML layouts** (not Kotlin/Compose), the
> dashboard uses keyless **Esri** basemaps (not raw OSM tiles), and some pages
> listed below were later renamed or split. Treat the code and the root
> `README.md` as the source of truth; see `AUDIT_LOG.md` for the audit notes.

General-purpose, self-hostable location tracking platform. Usable by companies (fleet)
and self-hosting individuals (own devices). Android app is visible (icon, normal
permission prompts, persistent notification while tracking). Designed to later extend
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Session Log — Backend Fixes, Deployment Debugging, and Android App Bootstrap

> **Historical session log.** This was written while the Android client was a
> Kotlin/Compose scaffold. It has since been rewritten in **Java + XML layouts**
> (see `docs/Android-Java-Migration.docx` and the current `android/` sources), so
> the Kotlin class/file names below no longer exist. Kept for project history.

Continuation of `read_me.md`. This session covered fixing the backend deployment,
verifying the tracking pipeline end-to-end, and starting the Android app from
scratch (scaffold → build toolchain → auth flow).
Expand Down
8 changes: 4 additions & 4 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TrackStack Dashboard

React 19 + Vite dashboard for [TrackStack](../README.md). It talks to the Go API over REST and a WebSocket, and renders device positions on a Leaflet/OpenStreetMap map.
React 19 + Vite dashboard for [TrackStack](../README.md). It talks to the Go API over REST and a WebSocket, and renders device positions on a Leaflet map with keyless Esri basemaps (no tile API key required).

## Stack

Expand All @@ -13,11 +13,11 @@ React 19 + Vite dashboard for [TrackStack](../README.md). It talks to the Go API
## Run locally

```bash
npm install
npm ci
VITE_API_URL=http://localhost:8080/v1 npm run dev
```

The app starts on `http://localhost:5173`. `VITE_API_URL` must point at the API service; without it the app falls back to the relative `/v1` path.
The app starts on `http://localhost:5173`. `VITE_API_URL` must point at the API service; without it the app falls back to the relative `/v1` path. The live WebSocket and the token-refresh call both derive their URL from `VITE_API_URL`, so they follow the same target in development.

## Scripts

Expand All @@ -36,7 +36,7 @@ src/
AuthContext.jsx Login state and token handling
useDevices.js Device queries
useSocket.js Live WebSocket connection
mapTiles.js Shared basemap definitions
mapTiles.js Shared keyless Esri basemap definitions
pages/ Login, admin, and organization views
components/ Shared UI and the Leaflet map component
```
Expand Down
Loading
Loading