Skip to main content

Bikun Tracker Backend V2

Real-time backend for the Bikun shuttle system. It receives live GPS webhooks, keeps the bus state in sync, detects halte transitions and lap history, and serves both the public dashboard and internal admin workflows.

At a Glance

AreaDetails
RoleIngestion, state management, real-time broadcast, and admin APIs
RuntimeGo 1.23 with net/http
DatabasePostgreSQL 16 via pgxpool
AuthUI CAS JWT + API key for admin writes
Real-time channelPOST /wh and WS /ws
DeploymentAWS ECR + Pusilkom
Main consumersFrontend dashboard, admin tools, ETA service

What It Does

  • Accepts Damri GPS updates through a webhook.
  • Normalizes bus coordinates and updates runtime state.
  • Detects halte visits, route color, and lap history.
  • Broadcasts live state to connected clients over WebSocket.
  • Exposes protected CRUD and history endpoints for admins.

Request Flow

  1. The GPS provider posts a location event to POST /wh.
  2. The backend resolves the bus, updates coordinates, and applies halte logic.
  3. Runtime caches are refreshed so the next WebSocket tick has current state.
  4. Connected dashboards receive the latest snapshot from WS /ws.
  5. Admin tools use REST endpoints for bus management and history review.

API Surface

MethodEndpointAuthPurpose
POST/auth/sso/loginPublicLogin with UI CAS ticket
POST/auth/refreshPublicRefresh access token
GET/auth/meBearer JWTGet current user profile
GET/busPublicList buses
POST/busAPI keyCreate a bus
PUT/bus/:idAPI keyUpdate a bus
DELETE/bus/:idAPI keyDelete a bus
GET/bus/lap-historyAPI keyFilter lap history
GET/bus/:imei/lap-historyPublicLap history by bus
GET/bus/:imei/active-lapPublicCurrent active lap
WS/wsPublicLive coordinate broadcast
POST/whPublicReceive GPS updates
POST/bus/test-lap-dataPublicSeed debug lap data
GET/bus/check-tablePublicDebug table existence check

Core Modules

  • main.go: bootstrap, config loading, database pool, route wiring, and server startup.
  • app/auth: CAS login, token issuance, refresh flow, and auth helpers.
  • app/bus: bus state, halte detection, route logic, lap tracking, and WebSocket handling.
  • app/damri: provider integration and payload normalization.
  • app/rm: lane detection model integration.
  • db/migrations: schema evolution and historical data changes.
  • utils/middleware: CORS, JWT, logging, route parsing, and access control.

Data Model

EntityPurpose
busRegistered fleet data
bus_stopHalte definitions and fixed coordinates
bus_lap_historyLap transitions and visit history
userAuthenticated users and admin roles

Operational Notes

Infrastructure

ItemValue
Container registry638207107223.dkr.ecr.ap-southeast-1.amazonaws.com
Image namebikun-tracker-v2-backend
Production tagstable
Staging taglatest
Regionap-southeast-1

Environment Variables

KeyPurposeNotes
DAMRI_APIDamri GPS API base URLExternal provider endpoint
DAMRI_LOGIN_USERNAMEDamri usernameSecret value, not committed
DAMRI_LOGIN_PASSWORDDamri passwordSecret value, not committed
WS_URLExternal GPS WebSocket URLUsed by the live feed
RM_APILane detection service URLML service dependency
PRINT_CSV_LOGSEnable CSV log forwardingOptional debug mode
PORTHTTP portDefault server port
DB_HOSTPostgreSQL hostDatabase connection
DB_NAMEPostgreSQL database nameDatabase connection
DB_USERPostgreSQL usernameDatabase connection
DB_PASSWORDPostgreSQL passwordSecret value, not committed
DB_PORTPostgreSQL portDatabase connection
WS_UPGRADE_WHITELISTAllowed WebSocket originsComma-separated list
JWT_EXPIRY_IN_DAYSAccess token lifetimeToken policy
JWT_REFRESH_EXPIRY_IN_DAYSRefresh token lifetimeToken policy
JWT_SECRET_KEYJWT signing secretSecret value, not committed
ADMIN_API_KEYAdmin endpoint keySecret value, not committed

Next Sections