# abhisar-else/4thsem_project architecture

> Architecture diagram of the GitHub repository abhisar-else/4thsem_project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhisar-else/4thsem_project
- Repository: https://github.com/abhisar-else/4thsem_project

## Overview

1. **Repository shape**
   - This repo is documented as a two-tier product: a **Flutter mobile client** plus a **Node.js/Express backend**.
   - The actual file tree shown only contains `README.md` and `.gitignore`, so the architecture below is based on the README’s intended design rather than implemented code.

2. **Primary clients**
   - The main user-facing component is the **mobile app** for Android/iOS field workers.
   - A second user role, **admin**, manages surveys, assigns work, and reviews responses through the same system, likely via an admin screen or dashboard in the Flutter app.

3. **Offline-first edge layer**
   - The mobile app is designed to work **without connectivity**.
   - Survey definitions are downloaded from the backend, then response data is stored locally in **SQLite** on the device until sync is possible.
   - This local database is the critical boundary between the UI and unreliable network conditions.

4. **Sync and network boundary**
   - The app uses network detection (`connectivity_plus` per README) to decide when to push queued submissions.
   - Sync is asynchronous and automatic: collected responses remain local until the app detects internet, then they are sent to the server.
   - This makes the mobile client the “edge collector” and the backend the “system of record.”

5. **Backend service**
   - The server is a **REST API built with Node.js + Express**.
   - It exposes endpoints for authentication, survey retrieval/creation, response submission, and export.
   - This backend is the integration boundary for the mobile app and any third-party consumers.

6. **Identity and access control**
   - The architecture uses **JWT-based authentication**.
   - Role-based access separates **admin** capabilities from **field_worker** capabilities.
   - Middleware in the backend likely enforces authorization on survey management and response reporting endpoints.

7. **Core domain data flow**
   - Admin creates surveys and questions → backend persists survey metadata.
   - Field workers fetch assigned surveys → mobile app renders forms.
   - Workers submit answers, GPS coordinates, and optionally images → stored locally first, then posted to `/api/responses`.
   - The backend stores central response records and makes them available for dashboard/reporting.

8. **Data storage layers**
   - **SQLite** is the device-level offline store.
   - The central database is described inconsistently in the README: the tech stack says **MySQL**, while the schema and `.env` examples reference **PostgreSQL** (`DB_PORT=5432`, `JSONB`, `SERIAL`).
   - For diagramming, treat this as a single **central warehouse database**, but note the implementation ambiguity.

9. **Data warehouse responsibilities**
   - The central database holds users, surveys, and responses.
   - Response records include metadata such as timestamps, device ID, and GPS coordinates.
   - The warehouse is intended to support admin analytics, reporting, and CSV/Excel exports.

10. **Mobile app internal boundaries**
   - The README’s Flutter structure suggests these logical layers:
     - **screens** for UI,
     - **services** for API/sync operations,
     - **database** for SQLite access,
     - **models** for domain objects,
     - **config** for backend URL and constants.
   - This indicates a clean separation between presentation, local persistence, and remote communication.

11. **Location and form enrichment**
   - The app can capture **GPS data** through `geolocator`.
   - Survey answers may include text, dropdowns, images, and positional metadata.
   - These enrichments are attached to each response before storage/sync.

12. **Operational concerns**
   - The system expects field devices to be intermittently connected and possibly multiple submissions may arrive late or duplicated.
   - The backend design includes **conflict resolution** for duplicate submissions and timestamps for reconciliation.
   - Sync status is an important user-visible state on the mobile side.

13. **External interface surface**
   - The public API surface is small and explicit: login, surveys, responses, and export.
   - That makes the backend the central integration point for future clients such as reporting tools or third-party data consumers.

14. **Key architecture takeaway**
   - This is an **offline-first distributed data collection system** with a mobile edge, central REST API, and warehouse database.
   - The most important diagram boundaries are: **Flutter app ↔ local SQLite**, **Flutter app ↔ Node/Express API**, and **API ↔ central DB**.

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Flutter app"]
  node_mobile_ui["Screens<br/>Flutter UI"]
  node_mobile_services["Services<br/>Flutter service layer"]
  node_mobile_db[("SQLite store<br/>offline database")]
  node_mobile_models["Models"]
  node_mobile_config["Config"]
  node_mobile_gps(("GPS capture<br/>location capture"))
  node_mobile_connectivity(("Network check<br/>connectivity gate"))
end

subgraph group_backend["Node backend"]
  node_api_gateway["REST API<br/>Express server"]
  node_auth_layer["Auth guard<br/>JWT middleware"]
  node_survey_api["Survey API<br/>survey endpoints"]
  node_response_api["Response API<br/>ingest endpoints"]
  node_export_api["Export API<br/>reporting endpoints"]
  node_admin_workflows["Admin flows<br/>role workflow"]
end

subgraph group_data["Data stores"]
  node_system_db[("Warehouse DB<br/>central database")]
  node_local_sync["Queued sync<br/>offline-first flow"]
  node_reporting_store[("Analytics data<br/>reporting store")]
end

node_mobile_ui -->|"uses"| node_mobile_services
node_mobile_ui -->|"reads/writes"| node_mobile_db
node_mobile_services -->|"reads"| node_mobile_config
node_mobile_services -->|"checks"| node_mobile_connectivity
node_mobile_services -->|"enriches"| node_mobile_gps
node_mobile_services -->|"queues"| node_local_sync
node_local_sync -->|"persists"| node_mobile_db
node_local_sync -->|"syncs"| node_api_gateway
node_mobile_services -->|"calls"| node_api_gateway
node_mobile_models -->|"shapes"| node_mobile_ui
node_api_gateway -->|"protects"| node_auth_layer
node_auth_layer -->|"allows"| node_survey_api
node_auth_layer -->|"allows"| node_response_api
node_auth_layer -->|"allows"| node_export_api
node_survey_api -->|"stores"| node_system_db
node_response_api -->|"stores"| node_system_db
node_response_api -->|"feeds"| node_reporting_store
node_export_api -->|"reads"| node_reporting_store
node_admin_workflows -->|"uses"| node_survey_api
node_admin_workflows -->|"reviews"| node_response_api
node_system_db -->|"supports"| node_reporting_store

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_ui,node_mobile_services,node_mobile_db,node_mobile_models,node_mobile_config,node_mobile_gps,node_mobile_connectivity toneBlue
class node_api_gateway,node_auth_layer,node_survey_api,node_response_api,node_export_api,node_admin_workflows toneAmber
class node_system_db,node_local_sync,node_reporting_store toneMint
```

## Components

### Flutter app

Offline-first mobile client for field workers and admins.

- **Screens**: Flutter UI · Field worker and admin interfaces for surveys, responses, and sync status.
- **Services**: Flutter service layer · API calls, sync orchestration, connectivity checks, and submission queueing.
- **SQLite store**: offline database · On-device persistence for surveys, responses, and queued uploads.
- **Models**: domain models · Survey, response, user, and sync state objects used by the app.
- **Config**: app config · Backend URL, constants, and environment-specific settings.
- **GPS capture**: location capture · Geolocation enrichment attached to collected responses.
- **Network check**: connectivity gate · Detects internet availability before pushing queued submissions.

### Node backend

REST API, auth, survey handling, response ingestion, and exports.

- **REST API**: Express server · Public HTTP boundary for authentication, surveys, responses, and exports.
- **Auth guard**: JWT middleware · Validates tokens and enforces admin versus field_worker permissions.
- **Survey API**: survey endpoints · Creates, assigns, and retrieves survey definitions and questions.
- **Response API**: ingest endpoints · Accepts submitted answers, metadata, and duplicate-aware response writes.
- **Export API**: reporting endpoints · Produces CSV or Excel outputs for admin reporting and analysis.
- **Admin flows**: role workflow · Survey management, assignment, and response review behavior exposed to admins.

### Data stores

Local and central persistence layers.

- **Warehouse DB**: central database · System of record for users, surveys, responses, and analytics data.
- **Queued sync**: offline-first flow · Local-first submission path that stores data until connectivity returns.
- **Analytics data**: reporting store · Centralized response history used for admin dashboards and exports.

## Connections

- Screens → Services: uses · Screens request survey loading, submission, and sync actions.
- Screens → SQLite store: reads/writes · UI reflects locally stored surveys, responses, and sync state.
- Services → Config: reads · Service layer uses configured backend settings.
- Services → Network check: checks · Connectivity detection gates background submission.
- Services → GPS capture: enriches · Collected responses may include location metadata.
- Services → Queued sync: queues · Responses are staged locally before network submission.
- Queued sync → SQLite store: persists · Offline queue and cached survey data live in SQLite.
- Queued sync → REST API: syncs · Queued submissions are pushed when connectivity is available.
- Services → REST API: calls · Mobile app fetches surveys and posts responses through REST.
- Models → Screens: shapes · Domain objects feed forms, lists, and sync status display.
- REST API → Auth guard: protects · Endpoints are guarded by token validation and role checks.
- Auth guard → Survey API: allows · Authorized users can manage survey definitions and assignments.
- Auth guard → Response API: allows · Authorized users can submit and review responses.
- Auth guard → Export API: allows · Admin-only access for reporting and exports.
- Survey API → Warehouse DB: stores · Survey metadata and questions are persisted centrally.
- Response API → Warehouse DB: stores · Submitted response records are written to the warehouse database.
- Response API → Analytics data: feeds · Response history supports reporting and analytics views.
- Export API → Analytics data: reads · Exports are generated from centralized reporting data.
- Admin flows → Survey API: uses · Admin operations create and assign surveys.
- Admin flows → Response API: reviews · Admin workflows inspect received responses.
- Warehouse DB → Analytics data: supports · Core warehouse data is reused for analytics and exports.
