# krusnap/epc-app architecture

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

- Interactive diagram: https://gitdiagram.com/krusnap/epc-app
- Repository: https://github.com/krusnap/epc-app

## Overview

Mahindra EPC is a field-travel and conveyance system: employees record trips and GPS locations, which feed distance-based claims; managers review claims and monitor employees. The Flutter app provides employee and manager workflows, while an Express API handles authentication, trips, locations, claims, and geofence management over PostgreSQL/PostGIS. The sampled backend shows route dispatch, database access, and claim fraud scoring. Mobile service-to-screen wiring and several README-listed capabilities are not shown in the excerpts, so those links are left unverified.

Main entry points: [`backend/config/database.js`](https://github.com/krusnap/epc-app/blob/main/backend/config/database.js) (Database access), [`backend/server.js`](https://github.com/krusnap/epc-app/blob/main/backend/server.js) (Express API), [`mobile_app/lib/main.dart`](https://github.com/krusnap/epc-app/blob/main/mobile_app/lib/main.dart) (Flutter app), [`backend/middleware/auth.js`](https://github.com/krusnap/epc-app/blob/main/backend/middleware/auth.js) (JWT and roles)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile workflows"]
  node_mobile_app["Flutter app<br/>[main.dart]"]
  node_login_ui["Login screen<br/>[login_screen.dart]"]
  node_employee_ui["Employee screens"]
  node_manager_ui["Manager screens"]
  node_mobile_services["Mobile services"]
end

subgraph group_api["API and access"]
  node_api_server["Express API<br/>[server.js]"]
  node_auth_routes["Authentication routes<br/>[auth.routes.js]"]
  node_auth_controller["Authentication<br/>[authController.js]"]
  node_auth_middleware["JWT and roles<br/>[auth.js]"]
end

subgraph group_travel["Travel and claims"]
  node_trip_routes["Trip routes<br/>[trip.routes.js]"]
  node_trip_controller["Trip lifecycle<br/>[tripController.js]"]
  node_location_routes["Location routes<br/>[location.routes.js]"]
  node_location_controller["GPS tracking"]
  node_claim_routes["Claim routes<br/>[claim.routes.js]"]
  node_claim_controller["Claim generation and review<br/>[claimController.js]"]
  node_fraud["Fraud scoring<br/>[fraudDetection.js]"]
  node_geofence["Geofence management<br/>[geofence.routes.js]"]
end

subgraph group_storage["Persistence and risk"]
  node_db_access["Database access<br/>[database.js]"]
  node_postgres[("PostgreSQL / PostGIS<br/>[schema.sql]")]
end

node_employee(("Employee"))
node_manager(("Manager"))

node_employee -->|"uses"| node_mobile_app
node_manager -->|"uses"| node_mobile_app
node_mobile_app -.->|"presents"| node_login_ui
node_mobile_app -.->|"presents"| node_employee_ui
node_mobile_app -.->|"presents"| node_manager_ui
node_login_ui -.->|"uses"| node_mobile_services
node_employee_ui -.->|"uses"| node_mobile_services
node_manager_ui -.->|"uses"| node_mobile_services
node_mobile_services -.->|"calls API"| node_api_server
node_api_server -->|"mounts"| node_auth_routes
node_api_server -->|"mounts"| node_trip_routes
node_api_server -->|"mounts"| node_location_routes
node_api_server -->|"mounts"| node_claim_routes
node_api_server -->|"mounts"| node_geofence
node_auth_routes -->|"dispatches"| node_auth_controller
node_auth_routes -->|"protects"| node_auth_middleware
node_trip_routes -->|"dispatches"| node_trip_controller
node_trip_routes -->|"protects"| node_auth_middleware
node_location_routes -->|"dispatches"| node_location_controller
node_location_routes -->|"protects"| node_auth_middleware
node_claim_routes -->|"dispatches"| node_claim_controller
node_claim_routes -->|"protects"| node_auth_middleware
node_geofence -->|"protects"| node_auth_middleware
node_auth_controller -->|"queries"| node_db_access
node_trip_controller -->|"queries"| node_db_access
node_location_controller -->|"queries"| node_db_access
node_claim_controller -->|"queries"| node_db_access
node_claim_controller -->|"calculates risk"| node_fraud
node_geofence -->|"queries"| node_db_access
node_db_access -->|"queries"| node_postgres
node_fraud -->|"queries"| node_db_access

click node_mobile_app "https://github.com/krusnap/epc-app/blob/main/mobile_app/lib/main.dart"
click node_login_ui "https://github.com/krusnap/epc-app/blob/main/mobile_app/lib/screens/shared/login_screen.dart"
click node_employee_ui "https://github.com/krusnap/epc-app/tree/main/mobile_app/lib/screens/employee"
click node_manager_ui "https://github.com/krusnap/epc-app/tree/main/mobile_app/lib/screens/manager"
click node_mobile_services "https://github.com/krusnap/epc-app/tree/main/mobile_app/lib/services"
click node_api_server "https://github.com/krusnap/epc-app/blob/main/backend/server.js"
click node_auth_routes "https://github.com/krusnap/epc-app/blob/main/backend/routes/auth.routes.js"
click node_auth_controller "https://github.com/krusnap/epc-app/blob/main/backend/controllers/authController.js"
click node_auth_middleware "https://github.com/krusnap/epc-app/blob/main/backend/middleware/auth.js"
click node_trip_routes "https://github.com/krusnap/epc-app/blob/main/backend/routes/trip.routes.js"
click node_trip_controller "https://github.com/krusnap/epc-app/blob/main/backend/controllers/tripController.js"
click node_location_routes "https://github.com/krusnap/epc-app/blob/main/backend/routes/location.routes.js"
click node_location_controller "https://github.com/krusnap/epc-app/blob/main/backend/controllers/locationController.js"
click node_claim_routes "https://github.com/krusnap/epc-app/blob/main/backend/routes/claim.routes.js"
click node_claim_controller "https://github.com/krusnap/epc-app/blob/main/backend/controllers/claimController.js"
click node_fraud "https://github.com/krusnap/epc-app/blob/main/backend/services/fraudDetection.js"
click node_geofence "https://github.com/krusnap/epc-app/blob/main/backend/routes/geofence.routes.js"
click node_db_access "https://github.com/krusnap/epc-app/blob/main/backend/config/database.js"
click node_postgres "https://github.com/krusnap/epc-app/blob/main/backend/database/schema.sql"

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_mobile_app,node_login_ui,node_employee_ui,node_manager_ui,node_mobile_services toneBlue
class node_api_server,node_auth_routes,node_auth_controller,node_auth_middleware toneAmber
class node_trip_routes,node_trip_controller,node_location_routes,node_location_controller,node_claim_routes,node_claim_controller,node_fraud,node_geofence toneMint
class node_db_access,node_postgres toneRose
class node_employee,node_manager toneIndigo
```

## Components

### Mobile workflows

- [Flutter app](https://github.com/krusnap/epc-app/blob/main/mobile_app/lib/main.dart): `mobile_app/lib/main.dart`
- [Login screen](https://github.com/krusnap/epc-app/blob/main/mobile_app/lib/screens/shared/login_screen.dart): `mobile_app/lib/screens/shared/login_screen.dart`
- [Employee screens](https://github.com/krusnap/epc-app/tree/main/mobile_app/lib/screens/employee): `mobile_app/lib/screens/employee`
- [Manager screens](https://github.com/krusnap/epc-app/tree/main/mobile_app/lib/screens/manager): `mobile_app/lib/screens/manager`
- [Mobile services](https://github.com/krusnap/epc-app/tree/main/mobile_app/lib/services): `mobile_app/lib/services`

### API and access

- [Express API](https://github.com/krusnap/epc-app/blob/main/backend/server.js): `backend/server.js`
- [Authentication routes](https://github.com/krusnap/epc-app/blob/main/backend/routes/auth.routes.js): `backend/routes/auth.routes.js`
- [Authentication](https://github.com/krusnap/epc-app/blob/main/backend/controllers/authController.js): `backend/controllers/authController.js`
- [JWT and roles](https://github.com/krusnap/epc-app/blob/main/backend/middleware/auth.js): `backend/middleware/auth.js`

### Travel and claims

- [Trip routes](https://github.com/krusnap/epc-app/blob/main/backend/routes/trip.routes.js): `backend/routes/trip.routes.js`
- [Trip lifecycle](https://github.com/krusnap/epc-app/blob/main/backend/controllers/tripController.js): `backend/controllers/tripController.js`
- [Location routes](https://github.com/krusnap/epc-app/blob/main/backend/routes/location.routes.js): `backend/routes/location.routes.js`
- [GPS tracking](https://github.com/krusnap/epc-app/blob/main/backend/controllers/locationController.js): `backend/controllers/locationController.js`
- [Claim routes](https://github.com/krusnap/epc-app/blob/main/backend/routes/claim.routes.js): `backend/routes/claim.routes.js`
- [Claim generation and review](https://github.com/krusnap/epc-app/blob/main/backend/controllers/claimController.js): `backend/controllers/claimController.js`
- [Fraud scoring](https://github.com/krusnap/epc-app/blob/main/backend/services/fraudDetection.js): `backend/services/fraudDetection.js`
- [Geofence management](https://github.com/krusnap/epc-app/blob/main/backend/routes/geofence.routes.js): `backend/routes/geofence.routes.js`

### Persistence and risk

- [Database access](https://github.com/krusnap/epc-app/blob/main/backend/config/database.js): `backend/config/database.js`
- [PostgreSQL / PostGIS](https://github.com/krusnap/epc-app/blob/main/backend/database/schema.sql): `backend/database/schema.sql`

### Other components

- **Employee**
- **Manager**

## Connections

- Employee → Flutter app: uses (evidence: `README.md`)
- Manager → Flutter app: uses (evidence: `README.md`)
- Flutter app → Login screen: presents
- Flutter app → Employee screens: presents
- Flutter app → Manager screens: presents
- Login screen → Mobile services: uses
- Employee screens → Mobile services: uses
- Manager screens → Mobile services: uses
- Mobile services → Express API: calls API
- Express API → Authentication routes: mounts (evidence: `backend/server.js`)
- Express API → Trip routes: mounts (evidence: `backend/server.js`)
- Express API → Location routes: mounts (evidence: `backend/server.js`)
- Express API → Claim routes: mounts (evidence: `backend/server.js`)
- Express API → Geofence management: mounts (evidence: `backend/server.js`)
- Authentication routes → Authentication: dispatches (evidence: `backend/routes/auth.routes.js`)
- Authentication routes → JWT and roles: protects (evidence: `backend/routes/auth.routes.js`)
- Trip routes → Trip lifecycle: dispatches (evidence: `backend/routes/trip.routes.js`)
- Trip routes → JWT and roles: protects (evidence: `backend/routes/trip.routes.js`)
- Location routes → GPS tracking: dispatches (evidence: `backend/routes/location.routes.js`)
- Location routes → JWT and roles: protects (evidence: `backend/routes/location.routes.js`)
- Claim routes → Claim generation and review: dispatches (evidence: `backend/routes/claim.routes.js`)
- Claim routes → JWT and roles: protects (evidence: `backend/routes/claim.routes.js`)
- Geofence management → JWT and roles: protects (evidence: `backend/routes/geofence.routes.js`)
- Authentication → Database access: queries (evidence: `backend/controllers/authController.js`)
- Trip lifecycle → Database access: queries (evidence: `backend/controllers/tripController.js`)
- GPS tracking → Database access: queries (evidence: `backend/controllers/locationController.js`)
- Claim generation and review → Database access: queries (evidence: `backend/controllers/claimController.js`)
- Claim generation and review → Fraud scoring: calculates risk (evidence: `backend/controllers/claimController.js`)
- Geofence management → Database access: queries (evidence: `backend/routes/geofence.routes.js`)
- Database access → PostgreSQL / PostGIS: queries (evidence: `backend/config/database.js`)
- Fraud scoring → Database access: queries (evidence: `backend/services/fraudDetection.js`)
