How siddharthvs8/field-tracking-software works
Purpose and entry points
FieldTracking is a multi-tenant field-team operations platform: staff clock shifts, submit GPS pings, receive/complete tasks, and provide proof of work; tenant operators monitor live locations, routes, geofences, and performance. The deployable entry points are Django ASGI/API (apps/api/config/asgi.py, apps/api/manage.py), Next.js web portal (apps/web/app/page.tsx, apps/web/app/dashboard/page.tsx), and Flutter staff app (apps/mobile/lib/main.dart).
Backend API and tenancy
The Django 5 backend owns authentication, roles, tenant-scoped data, and REST endpoints. URL composition and runtime settings are centralized in apps/api/config/urls.py and apps/api/config/settings.py. Account identities, roles, profiles, and authentication endpoints reside in apps/api/accounts/models.py, apps/api/accounts/views.py, and apps/api/accounts/urls.py. JWT and authorization boundaries are implemented in apps/api/core/jwt.py and apps/api/core/permissions.py; every operational resource is expected to be constrained by the authenticated user’s tenant/role.
Field operations and task lifecycle
fieldtasks models dispatched work and its lifecycle, including task start/completion and evidence-oriented detail. The REST surface is implemented through apps/api/fieldtasks/models.py, apps/api/fieldtasks/views.py, and apps/api/fieldtasks/serializers.py. Dispatch/admin web views use this API to assign and inspect tasks, while the mobile task-detail UI consumes the same backend contract at apps/mobile/lib/src/screens/task_detail_screen.dart.
Location ingestion, history, and geofences
Staff devices batch location pings through the tracking API; service logic persists locations, evaluates geographic rules, and supports history/playback. This boundary is centered in apps/api/tracking/views.py, apps/api/tracking/services.py, and apps/api/tracking/models.py. Location history is stored in PostgreSQL with TimescaleDB hypertable migration support (apps/api/tracking/migrations/0002_locationlog_hypertable.py), making time-series tracking a core persistence concern. Shared geographic calculations are isolated in apps/api/core/geo.py.
Realtime propagation
After ingestion, backend broadcast logic publishes location/task-relevant updates over Django Channels, backed by Redis. The WebSocket routing and consumer boundary is in apps/api/realtime/routing.py, apps/api/realtime/consumers.py, and apps/api/realtime/broadcast.py. Web dashboard clients connect via apps/web/lib/socket.ts; map components render current positions and replay routes through apps/web/components/LiveMap.tsx and apps/web/components/PlaybackMap.tsx. REST remains the command/query interface; WebSockets deliver live state updates.
Web operator portal
The Next.js 14 application serves both owner-level administration and tenant dashboards. Route-level operational screens include apps/web/app/owner/page.tsx, apps/web/app/dashboard/staff/page.tsx, and apps/web/app/dashboard/tasks/[id]/page.tsx; dashboard layouts establish the tenant operator shell in apps/web/app/dashboard/layout.tsx. apps/web/lib/api.ts is the browser-to-Django API boundary. Mapping is a first-class UI dependency via react-leaflet components, including task/geofence selection in apps/web/components/TaskMap.tsx and apps/web/components/LocationPicker.tsx.
Mobile staff client and offline delivery
Flutter provides the field-staff workflow: authentication, shift state, assigned tasks, and background GPS collection. Its API/auth boundary is apps/mobile/lib/src/api/api_client.dart and apps/mobile/lib/src/api/auth_repository.dart. apps/mobile/lib/src/services/tracking_service.dart gathers and submits device locations; apps/mobile/lib/src/services/ping_queue.dart buffers pings locally for offline/retry sync, protecting the tracking pipeline from intermittent connectivity.
Infrastructure and deployment
Docker Compose runs TimescaleDB/PostgreSQL, Redis, Django/Daphne, and Next.js (docker-compose.yml, docker-compose.prod.yml). API container startup is controlled by apps/api/Dockerfile and apps/api/entrypoint.sh, including migration/seed workflow. Production deployment targets AWS/EC2 behind Nginx (deploy/ec2_setup.sh, deploy/nginx.conf); environment templates separate API and web runtime configuration (apps/api/.env.example, apps/web/.env.local.example).
Main entry points: asgi.py Django ASGI API · services.py Tracking ingestion · docker-compose.prod.yml Docker Compose runtime · consumers.py Channels consumers and broadcast
Components 20
Client apps
- Next.js operator portal · Owner administration and tenant dashboards.
apps/web/app/dashboard/layout.tsx - Browser API client
apps/web/lib/api.ts - Dashboard socket client
apps/web/lib/socket.ts - Live and playback maps · Renders current positions, routes, task, and geofence selections.
apps/web/components/LiveMap.tsx - Flutter staff app · Staff authentication, shifts, and assigned-task workflow.
apps/mobile/lib/main.dart - Mobile API and auth
apps/mobile/lib/src/api/api_client.dart - GPS tracking service
apps/mobile/lib/src/services/tracking_service.dart - Offline ping queue · Buffers location pings for retry during intermittent connectivity.
apps/mobile/lib/src/services/ping_queue.dart
Django API
- Django ASGI API · Tenant-scoped REST command and query boundary.
apps/api/config/asgi.py - URL and settings
apps/api/config/urls.py - Accounts and authorization · Owns identities, roles, profiles, JWT, and tenant/role access control.
apps/api/accounts/models.py - Task lifecycle · Dispatched work, completion, and proof-of-work resources.
apps/api/fieldtasks/views.py - Tracking ingestion · Persists batches, evaluates geographic rules, and serves history/playback.
apps/api/tracking/services.py - Geographic calculations
apps/api/core/geo.py
Realtime
- Channels consumers and broadcast · Publishes location and task-relevant live updates.
apps/api/realtime/consumers.py
Data services
- PostgreSQL + TimescaleDB · Stores tenant operations and time-series location history.
apps/api/tracking/migrations/0002_locationlog_hypertable.py - Redis channel layer
docker-compose.yml
Deployment
- Docker Compose runtime · Runs database, Redis, Django/Daphne, and Next.js.
docker-compose.prod.yml - API startup · Runs migration and seed workflow before API startup.
apps/api/entrypoint.sh - EC2 and Nginx
deploy/nginx.conf
Connections 24
- Next.js operator portal → Browser API client: uses
- Next.js operator portal → Dashboard socket client: opens live connection
- Dashboard socket client → Channels consumers and broadcast: WebSocket updates
- Live and playback maps → Dashboard socket client: renders live state
- Browser API client → Django ASGI API: REST
- Flutter staff app → Mobile API and auth: uses
- Flutter staff app → GPS tracking service: runs
- GPS tracking service → Offline ping queue: queues offline pings
- Offline ping queue → Mobile API and auth: retries batches
- Mobile API and auth → Django ASGI API: REST / JWT
- Django ASGI API → URL and settings: configured by
- Django ASGI API → Accounts and authorization: authenticates and authorizes
- Django ASGI API → Task lifecycle: serves task resources
- Django ASGI API → Tracking ingestion: serves tracking API
- Task lifecycle → PostgreSQL + TimescaleDB: stores tasks and evidence
- Tracking ingestion → Geographic calculations: evaluates geofences
- Tracking ingestion → PostgreSQL + TimescaleDB: writes location history
- Tracking ingestion → Channels consumers and broadcast: broadcasts updates
- Task lifecycle → Channels consumers and broadcast: publishes task updates
- Channels consumers and broadcast → Redis channel layer: channel layer
- Docker Compose runtime → API startup: starts
- Docker Compose runtime → PostgreSQL + TimescaleDB: runs
- Docker Compose runtime → Redis channel layer: runs
- EC2 and Nginx → Docker Compose runtime: deploys behind Nginx