# vishnukoushikbatreddy/swaya-attendence architecture

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

- Interactive diagram: https://gitdiagram.com/vishnukoushikbatreddy/swaya-attendence
- Repository: https://github.com/vishnukoushikbatreddy/swaya-attendence

## Overview

Swaya is a workforce attendance product: employees check in and out at assigned sites, while administrators manage staff, schedules, shifts, sites, live tracking, reports, and notifications. The web API and attendance service enforce attendance rules and persist records; a native Android service collects location in the background and queues uploads, including geofence events when the app is killed. The tree and source index support these major capabilities, but unsampled UI and API implementations limit confidence about their specific call paths.

Main entry points: [`src/lib/attendance-service.ts`](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/attendance-service.ts) (Attendance service), [`src/models`](https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/models) (Attendance and workforce records), [`src/app/(dashboard)/admin`](https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/(dashboard)/admin) (Admin portal), [`src/lib/api-helpers.ts`](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/api-helpers.ts) (API access helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_employee["Employee portal"]
  node_adminui["Admin portal"]
  node_authui["Sign-in and signup"]
end

subgraph group_attendance["Attendance workflows"]
  node_attendanceapi["Attendance endpoints"]
  node_nativeapi["Native ping endpoint<br/>[route.ts]"]
  node_geofenceapi["Geofence event endpoint<br/>[route.ts]"]
  node_service["Attendance service"]
  node_logic["Attendance rules"]
end

subgraph group_tracking["Location tracking"]
  node_android["Android tracking service"]
  node_deviceplugin["Device setup plugin"]
  node_pingqueue["Ping queue<br/>[PingQueue.java]"]
  node_pinguploader["Ping uploader<br/>[PingUploader.java]"]
  node_geoplugin["Geofence plugin"]
  node_geoupload["Geofence uploader"]
end

subgraph group_admin["Workforce administration"]
  node_scheduleapi["Schedule endpoints"]
  node_adminapi["Admin endpoints"]
  node_sitesapi["Site endpoints"]
  node_notifications["Notification feed<br/>[route.ts]"]
  node_reports["Attendance reports"]
end

subgraph group_foundation["Application foundation"]
  node_auth["Authentication and roles<br/>[auth.ts]"]
  node_apihelpers["API access helpers<br/>[api-helpers.ts]"]
  node_validators["Request validation<br/>[validators.ts]"]
  node_nativeauth["Native token verification<br/>[native-token.ts]"]
  node_db["Database connection<br/>[db.ts]"]
  node_models[("Attendance and workforce records")]
  node_time["Work-date and timezone rules<br/>[workdate.ts]"]
  node_company["Company settings<br/>[company.ts]"]
  node_csv["CSV reporting<br/>[csv.ts]"]
  node_env["Runtime configuration<br/>[env.ts]"]
end

node_webactor(("Employee or admin"))

node_webactor -->|"signs in"| node_authui
node_webactor -->|"uses"| node_employee
node_webactor -->|"uses"| node_adminui
node_employee -.->|"requests attendance"| node_attendanceapi
node_adminui -.->|"manages schedules"| node_scheduleapi
node_adminui -.->|"manages employees"| node_adminapi
node_adminui -.->|"manages sites"| node_sitesapi
node_adminui -.->|"loads feed"| node_notifications
node_adminui -.->|"requests reports"| node_reports
node_attendanceapi -.->|"delegates attendance"| node_service
node_nativeapi -->|"processes pings"| node_service
node_nativeapi -->|"uses helpers"| node_apihelpers
node_nativeapi -->|"validates batches"| node_validators
node_nativeapi -->|"verifies token"| node_nativeauth
node_nativeapi -->|"reads and writes"| node_models
node_geofenceapi -->|"processes transition"| node_service
node_geofenceapi -->|"checks freshness"| node_logic
node_geofenceapi -->|"validates event"| node_validators
node_geofenceapi -->|"verifies token"| node_nativeauth
node_geofenceapi -->|"checks employee"| node_models
node_service -->|"delegates decisions"| node_logic
node_service -->|"connects database"| node_db
node_service -->|"reads and writes"| node_models
node_service -->|"resolves work dates"| node_time
node_service -->|"loads timezone"| node_company
node_scheduleapi -->|"reads and writes schedules"| node_models
node_scheduleapi -->|"validates entries"| node_validators
node_scheduleapi -->|"converts shift times"| node_time
node_scheduleapi -->|"resolves shift end"| node_logic
node_notifications -->|"reads and updates"| node_models
node_notifications -->|"uses helpers"| node_apihelpers
node_notifications -->|"loads timezone"| node_company
node_notifications -->|"converts day bounds"| node_time
node_reports -->|"queries records"| node_models
node_reports -->|"uses helpers"| node_apihelpers
node_reports -->|"formats export"| node_csv
node_android -->|"queues location pings"| node_pingqueue
node_android -->|"flushes ping batches"| node_pinguploader
node_deviceplugin -->|"controls tracking"| node_android
node_deviceplugin -->|"configures alerts"| node_android
node_pinguploader -->|"uploads queued pings"| node_pingqueue
node_geoplugin -.->|"uses geofence helper"| node_geoupload
node_geoupload -.->|"uploads events"| node_geoupload
node_auth -->|"connects database"| node_db
node_auth -->|"loads user records"| node_models
node_apihelpers -->|"loads auth options"| node_auth
node_apihelpers -->|"connects database"| node_db
node_apihelpers -->|"loads active user"| node_models

click node_employee "https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/(dashboard)/employee"
click node_adminui "https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/(dashboard)/admin"
click node_authui "https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/(auth)"
click node_attendanceapi "https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/api/attendance"
click node_nativeapi "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/app/api/native/pings/route.ts"
click node_geofenceapi "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/app/api/geofence-event/route.ts"
click node_service "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/attendance-service.ts"
click node_logic "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/attendance-logic.ts"
click node_scheduleapi "https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/api/schedules"
click node_adminapi "https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/api/admin"
click node_sitesapi "https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/api/sites"
click node_notifications "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/app/api/notifications/route.ts"
click node_reports "https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/api/reports/attendance"
click node_android "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/LocationTrackingService.java"
click node_deviceplugin "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/DeviceSetupPlugin.java"
click node_pingqueue "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/PingQueue.java"
click node_pinguploader "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/PingUploader.java"
click node_geoplugin "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/GeofencePlugin.java"
click node_geoupload "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/GeofenceUploader.java"
click node_auth "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/auth.ts"
click node_apihelpers "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/api-helpers.ts"
click node_validators "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/validators.ts"
click node_nativeauth "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/native-token.ts"
click node_db "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/db.ts"
click node_models "https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/models"
click node_time "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/workdate.ts"
click node_company "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/company.ts"
click node_csv "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/csv.ts"
click node_env "https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/env.ts"

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_employee,node_adminui,node_authui toneBlue
class node_attendanceapi,node_nativeapi,node_geofenceapi,node_service,node_logic toneAmber
class node_android,node_deviceplugin,node_pingqueue,node_pinguploader,node_geoplugin,node_geoupload toneMint
class node_scheduleapi,node_adminapi,node_sitesapi,node_notifications,node_reports toneRose
class node_auth,node_apihelpers,node_validators,node_nativeauth,node_db,node_models,node_time,node_company,node_csv,node_env,node_webactor toneIndigo
```

## Components

### Web experience

- [Employee portal](https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/(dashboard)/employee): `src/app/(dashboard)/employee`
- [Admin portal](https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/(dashboard)/admin): `src/app/(dashboard)/admin`
- [Sign-in and signup](https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/(auth)): `src/app/(auth)`

### Attendance workflows

- [Attendance endpoints](https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/api/attendance): `src/app/api/attendance`
- [Native ping endpoint](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/app/api/native/pings/route.ts): `src/app/api/native/pings/route.ts`
- [Geofence event endpoint](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/app/api/geofence-event/route.ts): `src/app/api/geofence-event/route.ts`
- [Attendance service](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/attendance-service.ts): `src/lib/attendance-service.ts`
- [Attendance rules](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/attendance-logic.ts): `src/lib/attendance-logic.ts`

### Location tracking

- [Android tracking service](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/LocationTrackingService.java): `android/app/src/main/java/com/swaya/attendance/LocationTrackingService.java`
- [Device setup plugin](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/DeviceSetupPlugin.java): `android/app/src/main/java/com/swaya/attendance/DeviceSetupPlugin.java`
- [Ping queue](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/PingQueue.java): `android/app/src/main/java/com/swaya/attendance/PingQueue.java`
- [Ping uploader](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/PingUploader.java): `android/app/src/main/java/com/swaya/attendance/PingUploader.java`
- [Geofence plugin](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/GeofencePlugin.java): `android/app/src/main/java/com/swaya/attendance/GeofencePlugin.java`
- [Geofence uploader](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/android/app/src/main/java/com/swaya/attendance/GeofenceUploader.java): `android/app/src/main/java/com/swaya/attendance/GeofenceUploader.java`

### Workforce administration

- [Schedule endpoints](https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/api/schedules): `src/app/api/schedules`
- [Admin endpoints](https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/api/admin): `src/app/api/admin`
- [Site endpoints](https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/api/sites): `src/app/api/sites`
- [Notification feed](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/app/api/notifications/route.ts): `src/app/api/notifications/route.ts`
- [Attendance reports](https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/app/api/reports/attendance): `src/app/api/reports/attendance`

### Application foundation

- [Authentication and roles](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [API access helpers](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/api-helpers.ts): `src/lib/api-helpers.ts`
- [Request validation](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/validators.ts): `src/lib/validators.ts`
- [Native token verification](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/native-token.ts): `src/lib/native-token.ts`
- [Database connection](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/db.ts): `src/lib/db.ts`
- [Attendance and workforce records](https://github.com/vishnukoushikbatreddy/swaya-attendence/tree/main/src/models): `src/models`
- [Work-date and timezone rules](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/workdate.ts): `src/lib/workdate.ts`
- [Company settings](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/company.ts): `src/lib/company.ts`
- [CSV reporting](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/csv.ts): `src/lib/csv.ts`
- [Runtime configuration](https://github.com/vishnukoushikbatreddy/swaya-attendence/blob/main/src/lib/env.ts): `src/lib/env.ts`

### Other components

- **Employee or admin**

## Connections

- Employee or admin → Sign-in and signup: signs in
- Employee or admin → Employee portal: uses
- Employee or admin → Admin portal: uses
- Employee portal → Attendance endpoints: requests attendance
- Admin portal → Schedule endpoints: manages schedules
- Admin portal → Admin endpoints: manages employees
- Admin portal → Site endpoints: manages sites
- Admin portal → Notification feed: loads feed
- Admin portal → Attendance reports: requests reports
- Attendance endpoints → Attendance service: delegates attendance (evidence: `src/app/api/attendance/today/route.ts`)
- Native ping endpoint → Attendance service: processes pings (evidence: `src/app/api/native/pings/route.ts`)
- Native ping endpoint → API access helpers: uses helpers (evidence: `src/app/api/native/pings/route.ts`)
- Native ping endpoint → Request validation: validates batches (evidence: `src/app/api/native/pings/route.ts`)
- Native ping endpoint → Native token verification: verifies token (evidence: `src/app/api/native/pings/route.ts`)
- Native ping endpoint → Attendance and workforce records: reads and writes (evidence: `src/app/api/native/pings/route.ts`)
- Geofence event endpoint → Attendance service: processes transition (evidence: `src/app/api/geofence-event/route.ts`)
- Geofence event endpoint → Attendance rules: checks freshness (evidence: `src/app/api/geofence-event/route.ts`)
- Geofence event endpoint → Request validation: validates event (evidence: `src/app/api/geofence-event/route.ts`)
- Geofence event endpoint → Native token verification: verifies token (evidence: `src/app/api/geofence-event/route.ts`)
- Geofence event endpoint → Attendance and workforce records: checks employee (evidence: `src/app/api/geofence-event/route.ts`)
- Attendance service → Attendance rules: delegates decisions (evidence: `src/lib/attendance-service.ts`)
- Attendance service → Database connection: connects database (evidence: `src/lib/attendance-service.ts`)
- Attendance service → Attendance and workforce records: reads and writes (evidence: `src/lib/attendance-service.ts`)
- Attendance service → Work-date and timezone rules: resolves work dates (evidence: `src/lib/attendance-service.ts`)
- Attendance service → Company settings: loads timezone (evidence: `src/lib/attendance-service.ts`)
- Schedule endpoints → Attendance and workforce records: reads and writes schedules (evidence: `src/app/api/schedules/route.ts`)
- Schedule endpoints → Request validation: validates entries (evidence: `src/app/api/schedules/route.ts`)
- Schedule endpoints → Work-date and timezone rules: converts shift times (evidence: `src/app/api/schedules/route.ts`)
- Schedule endpoints → Attendance rules: resolves shift end (evidence: `src/app/api/schedules/route.ts`)
- Notification feed → Attendance and workforce records: reads and updates (evidence: `src/app/api/notifications/route.ts`)
- Notification feed → API access helpers: uses helpers (evidence: `src/app/api/notifications/route.ts`)
- Notification feed → Company settings: loads timezone (evidence: `src/app/api/notifications/route.ts`)
- Notification feed → Work-date and timezone rules: converts day bounds (evidence: `src/app/api/notifications/route.ts`)
- Attendance reports → Attendance and workforce records: queries records (evidence: `src/app/api/reports/attendance/route.ts`)
- Attendance reports → API access helpers: uses helpers (evidence: `src/app/api/reports/attendance/route.ts`)
- Attendance reports → CSV reporting: formats export (evidence: `src/app/api/reports/attendance/route.ts`)
- Android tracking service → Ping queue: queues location pings (evidence: `android/app/src/main/java/com/swaya/attendance/LocationTrackingService.java`)
- Android tracking service → Ping uploader: flushes ping batches (evidence: `android/app/src/main/java/com/swaya/attendance/LocationTrackingService.java`)
- Device setup plugin → Android tracking service: controls tracking (evidence: `android/app/src/main/java/com/swaya/attendance/DeviceSetupPlugin.java`)
- Device setup plugin → Android tracking service: configures alerts (evidence: `android/app/src/main/java/com/swaya/attendance/DeviceSetupPlugin.java`)
- Ping uploader → Ping queue: uploads queued pings (evidence: `android/app/src/main/java/com/swaya/attendance/PingUploader.java`)
- Geofence plugin → Geofence uploader: uses geofence helper
- Geofence uploader → Geofence uploader: uploads events (evidence: `android/app/src/main/java/com/swaya/attendance/GeofenceUploader.java`)
- Authentication and roles → Database connection: connects database (evidence: `src/lib/auth.ts`)
- Authentication and roles → Attendance and workforce records: loads user records (evidence: `src/lib/auth.ts`)
- API access helpers → Authentication and roles: loads auth options (evidence: `src/lib/api-helpers.ts`)
- API access helpers → Database connection: connects database (evidence: `src/lib/api-helpers.ts`)
- API access helpers → Attendance and workforce records: loads active user (evidence: `src/lib/api-helpers.ts`)
