Main Website - Documentation
π Background
Overviewβ
Bikun Tracker Frontend V2 is the client-side web interface for the Universitas Indonesia shuttle bus tracking system. It consumes data from Backend V2 via WebSocket connections for live location updates, and utilizes REST APIs for static data and authentication.
Stakeholdersβ
- Users: UI students and staff (monitoring real-time bus locations), Bikun Administrators (accessing reporting dashboards and schedules).
- Upstream Dependencies: Bikun Tracker Backend V2 (providing REST API endpoints and /ws WebSocket), UI SSO (for authentication).
- Downstream Consumers: End-user devices (Mobile and desktop web browsers).
Scope & Boundariesβ
In Scope
- Real-time interactive map rendering using Leaflet.
- Maintaining continuous WebSocket connections to receive live bus GPS coordinates.
- User interface for bus schedule management and reporting.
- Client-side authentication integration utilizing UI CAS SSO.
- Local state management for bus movement interpolation.
Out of Scope
- Heavy computational processing for lane detection or lap history (strictly backend responsibility).
- Relational data storage or direct interaction with PostgreSQL.
- Ingesting raw hardware GPS data from Damri.
βοΈ Architecture & Design
System Diagramβ
Architecture Decisions (ADRs)β
- Language/Framework: React 19 + TypeScript built with Vite
- Routing: TanStack React Router
- State Management: Zustand
- Styling & UI: Tailwind CSS v4
- Map Visualization: Leaflet
π»Technical Specifications
API Documentationβ
Data Model/Schemaβ
Project Structureβ
bikuntracker-frontend-v2
β£ public
β β£ assets
β β£ favicon
β β£ robots.txt
β β service-worker.js
β£ src
β β£ assets
β β β£ bus-stops/
β β β icons/
β β£ common
β β β£ components/ (Reusable UI: map, modal, drawer, navbar)
β β β£ constants/ (Absolute static data: busSchedule, routes, map config)
β β β£ data/ (Bus stops and routes definitions)
β β β£ hooks/ (React logic hooks: useAnimatedBus, useWebsocket)
β β β£ schema/ (Zod type validation: auth, ws)
β β β types/ (Global TypeScript interfaces)
β β£ lib
β β β£ store/ (Zustand global state logic: auth, global, ref)
β β β£ busStopUtils.ts
β β β utils.ts
β β£ routes
β β β£ __root.tsx
β β β£ bus-schedule.tsx
β β β£ create-report.tsx
β β β£ index.tsx
β β β£ report.tsx
β β β sso-login.tsx
β β£ services
β β β£ auth.ts
β β β util.ts
β β£ index.css
β β£ main.tsx
β β routeTree.gen.ts (Auto-generated by TanStack router)
β£ .env.example
β£ eslint.config.js
β£ package.json
β£ tsconfig.json
β vite.config.ts
Key Componentsβ
main.go β Application Bootstrap
- Reads config from .env via Viper
- Creates pgxpool connection to PostgreSQL
- Wires all handlers, services, repositories, and middlewares
- Registers HTTP routes via utils.HandleRoute
- Starts WebSocket broadcaster at /ws
- Exposes webhook endpoint at /wh for GPS ingestion
app/bus/container.go β Runtime State Manager
- Holds in-memory maps: busCoordinates, previousHalte, activeLaps, storedBuses, currentPlates
ApplyExternalCoordinates() β the main pipeline called by webhook: updates colours, detects lanes, tracks halte visits, detects lap start/end
- DQ_SIZE = 50: rolling deque per bus for lane detection sampling
InitRuntimeState() β hydrates runtime caches from DB on startup
app/bus/halte.go β Geofence Proximity
- 22 named haltes (bus stops) with fixed coordinates
- nearestHalte(lat, lng) returns the closest halte name + distance in metres
Threshold: 45 metres β bus must be within 45m to register a halte visit
app/bus/route.go β Route Definitions
- 4 route arrays: blueNormal, blueMorning, redNormal, redMorning
- Pre-built halte-pair sets for O(1) lookup
- detectRouteColorFromPair() returns blue / red / grey
app/auth/ β Authentication
- SSO Login: validates CAS ticket with sso.ui.ac.id, auto-creates user in DB on first login
- JWT pair (access + refresh) signed with HS256; expiry is configurable via env vars
- Admin protection: API_KEY header is checked against ADMIN_API_KEY env var
βοΈ Operational Playbook
Infrastructureβ
- Cloud Provider: AWS ECR + Pusilkom instance
- Container Registry: 638207107223.dkr.ecr.ap-southeast-1.amazonaws.com
- Image Name: bikun-tracker-v2-backend
- Production Tag: stable (deployed from main branch)
- Staging Tag: latest (deployed from staging branch)
- Region: ap-southeast-1 (Singapore)
Environment Variablesβ
| Key | Description | Default (Dev) | Sensitive? |
|---|---|---|---|
| DAMRI_API | Damri GPS API base URL | https://api-damri.istsolutions.co.id | No |
| DAMRI_LOGIN_USERNAME | Damri API username | β | Yes |
| DAMRI_LOGIN_PASSWORD | Damri API password | β | Yes |
| WS_URL | External GPS WebSocket URL | ws://localhost:8000/status | No |
| RM_API | RM lane-detection service URL | https://eta-bikun-tracker-production.up.railway.app | No |
| PRINT_CSV_LOGS | Enable CSV log POST to port 4040 | FALSE | No |
| PORT | Port the server listens on | 8080 | No |
| DB_HOST | PostgreSQL host address | localhost | No |
| DB_NAME | Database name | bikun_tracker | No |
| DB_USER | Database username | postgres | No |
| DB_PASSWORD | Database password | β | Yes |
| DB_PORT | Database port | 5043 | No |
| WS_UPGRADE_WHITELIST | Allowed WebSocket origins (comma-separated) | localhost:5173 | No |
| JWT_EXPIRY_IN_DAYS | Access token validity in days | 1 | No |
| JWT_REFRESH_EXPIRY_IN_DAYS | Refresh token validity in days | 30 | No |
| JWT_SECRET_KEY | HMAC secret for JWT signing | β | Yes |
| ADMIN_API_KEY | API key for admin-protected endpoints | β | Yes |
πQuestions
π List of frequently asked questions or question that need to be answered that is related to this initiative ..