# siddharthvs8/field-tracking-software architecture

> Architecture diagram of the GitHub repository siddharthvs8/field-tracking-software, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/siddharthvs8/field-tracking-software
- Repository: https://github.com/siddharthvs8/field-tracking-software

## Overview

#### 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: [`apps/api/config/asgi.py`](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/config/asgi.py) (Django ASGI API), [`apps/api/tracking/services.py`](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/tracking/services.py) (Tracking ingestion), [`docker-compose.prod.yml`](https://github.com/siddharthvs8/field-tracking-software/blob/main/docker-compose.prod.yml) (Docker Compose runtime), [`apps/api/realtime/consumers.py`](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/realtime/consumers.py) (Channels consumers and broadcast)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Client apps"]
  node_web["Next.js operator portal<br/>Next.js app<br/>[layout.tsx]"]
  node_web_api["Browser API client<br/>[api.ts]"]
  node_web_socket["Dashboard socket client<br/>WebSocket client<br/>[socket.ts]"]
  node_maps["Live and playback maps<br/>map UI<br/>[LiveMap.tsx]"]
  node_mobile["Flutter staff app<br/>Flutter app<br/>[main.dart]"]
  node_mobile_api["Mobile API and auth<br/>API client<br/>[api_client.dart]"]
  node_tracking_service["GPS tracking service<br/>background service"]
  node_ping_queue["Offline ping queue<br/>local queue<br/>[ping_queue.dart]"]
end

subgraph group_api["Django API"]
  node_django["Django ASGI API<br/>Django 5 / ASGI<br/>[asgi.py]"]
  node_api_routing["URL and settings<br/>runtime configuration<br/>[urls.py]"]
  node_identity["Accounts and authorization<br/>identity domain<br/>[models.py]"]
  node_tasks["Task lifecycle<br/>operations domain<br/>[views.py]"]
  node_tracking["Tracking ingestion<br/>tracking domain<br/>[services.py]"]
  node_geocalc["Geographic calculations<br/>geo utility<br/>[geo.py]"]
end

subgraph group_realtime["Realtime"]
  node_channels["Channels consumers and broadcast<br/>WebSocket service<br/>[consumers.py]"]
end

subgraph group_data["Data services"]
  node_postgres[("PostgreSQL + TimescaleDB<br/>primary database")]
  node_redis[("Redis channel layer<br/>channel backend<br/>[docker-compose.yml]")]
end

subgraph group_deployment["Deployment"]
  node_compose["Docker Compose runtime<br/>container orchestration"]
  node_api_container["API startup<br/>container entrypoint<br/>[entrypoint.sh]"]
  node_aws["EC2 and Nginx<br/>production edge<br/>[nginx.conf]"]
end

node_web -->|"uses"| node_web_api
node_web -->|"opens live connection"| node_web_socket
node_web_socket -->|"WebSocket updates"| node_channels
node_maps -->|"renders live state"| node_web_socket
node_web_api -->|"REST"| node_django
node_mobile -->|"uses"| node_mobile_api
node_mobile -->|"runs"| node_tracking_service
node_tracking_service -->|"queues offline pings"| node_ping_queue
node_ping_queue -->|"retries batches"| node_mobile_api
node_mobile_api -->|"REST / JWT"| node_django
node_django -->|"configured by"| node_api_routing
node_django -->|"authenticates and authorizes"| node_identity
node_django -->|"serves task resources"| node_tasks
node_django -->|"serves tracking API"| node_tracking
node_tasks -->|"stores tasks and evidence"| node_postgres
node_tracking -->|"evaluates geofences"| node_geocalc
node_tracking -->|"writes location history"| node_postgres
node_tracking -->|"broadcasts updates"| node_channels
node_tasks -.->|"publishes task updates"| node_channels
node_channels -->|"channel layer"| node_redis
node_compose -->|"starts"| node_api_container
node_compose -->|"runs"| node_postgres
node_compose -->|"runs"| node_redis
node_aws -->|"deploys behind Nginx"| node_compose

click node_web "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/web/app/dashboard/layout.tsx"
click node_web_api "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/web/lib/api.ts"
click node_web_socket "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/web/lib/socket.ts"
click node_maps "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/web/components/LiveMap.tsx"
click node_mobile "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/mobile/lib/main.dart"
click node_mobile_api "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/mobile/lib/src/api/api_client.dart"
click node_tracking_service "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/mobile/lib/src/services/tracking_service.dart"
click node_ping_queue "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/mobile/lib/src/services/ping_queue.dart"
click node_django "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/config/asgi.py"
click node_api_routing "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/config/urls.py"
click node_identity "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/accounts/models.py"
click node_tasks "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/fieldtasks/views.py"
click node_tracking "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/tracking/services.py"
click node_geocalc "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/core/geo.py"
click node_channels "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/realtime/consumers.py"
click node_postgres "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/tracking/migrations/0002_locationlog_hypertable.py"
click node_redis "https://github.com/siddharthvs8/field-tracking-software/blob/main/docker-compose.yml"
click node_compose "https://github.com/siddharthvs8/field-tracking-software/blob/main/docker-compose.prod.yml"
click node_api_container "https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/entrypoint.sh"
click node_aws "https://github.com/siddharthvs8/field-tracking-software/blob/main/deploy/nginx.conf"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_web_api,node_web_socket,node_maps,node_mobile,node_mobile_api,node_tracking_service,node_ping_queue toneBlue
class node_django,node_api_routing,node_identity,node_tasks,node_tracking,node_geocalc toneAmber
class node_channels toneMint
class node_postgres,node_redis toneRose
class node_compose,node_api_container,node_aws toneIndigo
```

## Components

### Client apps

- [Next.js operator portal](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/web/app/dashboard/layout.tsx): Next.js app · Owner administration and tenant dashboards. · `apps/web/app/dashboard/layout.tsx`
- [Browser API client](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/web/lib/api.ts): API client · `apps/web/lib/api.ts`
- [Dashboard socket client](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/web/lib/socket.ts): WebSocket client · `apps/web/lib/socket.ts`
- [Live and playback maps](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/web/components/LiveMap.tsx): map UI · Renders current positions, routes, task, and geofence selections. · `apps/web/components/LiveMap.tsx`
- [Flutter staff app](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/mobile/lib/main.dart): Flutter app · Staff authentication, shifts, and assigned-task workflow. · `apps/mobile/lib/main.dart`
- [Mobile API and auth](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/mobile/lib/src/api/api_client.dart): API client · `apps/mobile/lib/src/api/api_client.dart`
- [GPS tracking service](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/mobile/lib/src/services/tracking_service.dart): background service · `apps/mobile/lib/src/services/tracking_service.dart`
- [Offline ping queue](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/mobile/lib/src/services/ping_queue.dart): local queue · Buffers location pings for retry during intermittent connectivity. · `apps/mobile/lib/src/services/ping_queue.dart`

### Django API

- [Django ASGI API](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/config/asgi.py): Django 5 / ASGI · Tenant-scoped REST command and query boundary. · `apps/api/config/asgi.py`
- [URL and settings](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/config/urls.py): runtime configuration · `apps/api/config/urls.py`
- [Accounts and authorization](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/accounts/models.py): identity domain · Owns identities, roles, profiles, JWT, and tenant/role access control. · `apps/api/accounts/models.py`
- [Task lifecycle](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/fieldtasks/views.py): operations domain · Dispatched work, completion, and proof-of-work resources. · `apps/api/fieldtasks/views.py`
- [Tracking ingestion](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/tracking/services.py): tracking domain · Persists batches, evaluates geographic rules, and serves history/playback. · `apps/api/tracking/services.py`
- [Geographic calculations](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/core/geo.py): geo utility · `apps/api/core/geo.py`

### Realtime

- [Channels consumers and broadcast](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/realtime/consumers.py): WebSocket service · Publishes location and task-relevant live updates. · `apps/api/realtime/consumers.py`

### Data services

- [PostgreSQL + TimescaleDB](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/tracking/migrations/0002_locationlog_hypertable.py): primary database · Stores tenant operations and time-series location history. · `apps/api/tracking/migrations/0002_locationlog_hypertable.py`
- [Redis channel layer](https://github.com/siddharthvs8/field-tracking-software/blob/main/docker-compose.yml): channel backend · `docker-compose.yml`

### Deployment

- [Docker Compose runtime](https://github.com/siddharthvs8/field-tracking-software/blob/main/docker-compose.prod.yml): container orchestration · Runs database, Redis, Django/Daphne, and Next.js. · `docker-compose.prod.yml`
- [API startup](https://github.com/siddharthvs8/field-tracking-software/blob/main/apps/api/entrypoint.sh): container entrypoint · Runs migration and seed workflow before API startup. · `apps/api/entrypoint.sh`
- [EC2 and Nginx](https://github.com/siddharthvs8/field-tracking-software/blob/main/deploy/nginx.conf): production edge · `deploy/nginx.conf`

## Connections

- 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
