# phatcharanun/project1 architecture

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

- Interactive diagram: https://gitdiagram.com/phatcharanun/project1
- Repository: https://github.com/phatcharanun/project1

## Overview

This repository implements a browser-based geofence and QR-session checking app, served with its API by an Express backend. The principal flow is camera-based QR scanning, session extraction, GPS acquisition, and a POST check whose PostGIS result is shown in the browser. Separate capabilities include local biometric authentication and face scanning, a legacy client-side location check, and PWA installation/offline asset caching. The excerpts support the main API and scanner calls; the README is unreadable, and database schema details and page wiring were not sampled.

Main entry points: [`Frontend/js/camera.js`](https://github.com/phatcharanun/project1/blob/main/Frontend/js/camera.js) (Camera workflow), [`Frontend/js/Geofence.js`](https://github.com/phatcharanun/project1/blob/main/Frontend/js/Geofence.js) (Session geofence check), [`Frontend/qr-code-scanner/scanner.js`](https://github.com/phatcharanun/project1/blob/main/Frontend/qr-code-scanner/scanner.js) (QR decode and results), [`Backend/Node.js`](https://github.com/phatcharanun/project1/blob/main/Backend/Node.js) (Geofence API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser app"]
  node_page["App interface<br/>[index.html]"]
  node_camera["Camera workflow<br/>[camera.js]"]
  node_qr_api["QR scanner API<br/>[index.js]"]
  node_qr_core["QR decode and results<br/>[scanner.js]"]
  node_qr_config["Scanner settings<br/>[config.js]"]
  node_geofence_ui["Session geofence check<br/>[Geofence.js]"]
  node_legacy_location["Legacy local geofence<br/>[location.js]"]
  node_biometrics["Biometric authentication<br/>[webauthn.js]"]
end

subgraph group_backend["API service"]
  node_api["Geofence API<br/>[Node.js]"]
end

subgraph group_data["Geospatial data"]
  node_pool["PostgreSQL connection pool<br/>[database.js]"]
  node_schema[("Geofence schema<br/>[init.sql]")]
end

subgraph group_pwa["PWA support"]
  node_pwa_manager["PWA manager<br/>[pwa.js]"]
  node_service_worker["Service worker<br/>[sw.js]"]
end

node_user(("App user"))
node_browser_location["Browser geolocation"]
node_browser_camera["Browser camera"]
node_browser_auth["Platform authenticator"]
node_cache[("Browser cache")]
node_postgres[("PostgreSQL with PostGIS")]
node_jsqr["jsQR decoder"]

node_camera -->|"opens"| node_browser_camera
node_camera -->|"starts"| node_qr_api
node_qr_api -->|"delegates"| node_qr_core
node_qr_core -->|"reads settings"| node_qr_config
node_qr_core -->|"decodes with"| node_jsqr
node_camera -->|"passes QR result"| node_geofence_ui
node_geofence_ui -->|"requests position"| node_browser_location
node_geofence_ui -->|"POSTs coordinates"| node_api
node_api -->|"queries"| node_pool
node_pool -->|"connects"| node_postgres
node_api -->|"serves static files"| node_page
node_biometrics -->|"authenticates with"| node_browser_auth
node_pwa_manager -->|"registers"| node_service_worker
node_service_worker -->|"reads and writes"| node_cache
node_user -.->|"initiates"| node_camera
node_user -.->|"requests check"| node_geofence_ui
node_user -.->|"requests authentication"| node_biometrics

click node_page "https://github.com/phatcharanun/project1/blob/main/Frontend/index.html"
click node_camera "https://github.com/phatcharanun/project1/blob/main/Frontend/js/camera.js"
click node_qr_api "https://github.com/phatcharanun/project1/blob/main/Frontend/qr-code-scanner/index.js"
click node_qr_core "https://github.com/phatcharanun/project1/blob/main/Frontend/qr-code-scanner/scanner.js"
click node_qr_config "https://github.com/phatcharanun/project1/blob/main/Frontend/qr-code-scanner/config.js"
click node_geofence_ui "https://github.com/phatcharanun/project1/blob/main/Frontend/js/Geofence.js"
click node_legacy_location "https://github.com/phatcharanun/project1/blob/main/Frontend/js/location.js"
click node_biometrics "https://github.com/phatcharanun/project1/blob/main/Frontend/js/webauthn.js"
click node_api "https://github.com/phatcharanun/project1/blob/main/Backend/Node.js"
click node_pool "https://github.com/phatcharanun/project1/blob/main/Backend/database.js"
click node_schema "https://github.com/phatcharanun/project1/blob/main/Backend/init.sql"
click node_pwa_manager "https://github.com/phatcharanun/project1/blob/main/Frontend/pwa/pwa.js"
click node_service_worker "https://github.com/phatcharanun/project1/blob/main/Frontend/sw.js"

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_page,node_camera,node_qr_api,node_qr_core,node_qr_config,node_geofence_ui,node_legacy_location,node_biometrics,node_user,node_browser_location,node_browser_camera toneBlue
class node_api,node_cache,node_postgres toneAmber
class node_pool,node_schema toneMint
class node_pwa_manager,node_service_worker toneRose
class node_browser_auth,node_jsqr toneIndigo
```

## Components

### Browser app

- [App interface](https://github.com/phatcharanun/project1/blob/main/Frontend/index.html): `Frontend/index.html`
- [Camera workflow](https://github.com/phatcharanun/project1/blob/main/Frontend/js/camera.js): `Frontend/js/camera.js`
- [QR scanner API](https://github.com/phatcharanun/project1/blob/main/Frontend/qr-code-scanner/index.js): `Frontend/qr-code-scanner/index.js`
- [QR decode and results](https://github.com/phatcharanun/project1/blob/main/Frontend/qr-code-scanner/scanner.js): `Frontend/qr-code-scanner/scanner.js`
- [Scanner settings](https://github.com/phatcharanun/project1/blob/main/Frontend/qr-code-scanner/config.js): `Frontend/qr-code-scanner/config.js`
- [Session geofence check](https://github.com/phatcharanun/project1/blob/main/Frontend/js/Geofence.js): `Frontend/js/Geofence.js`
- [Legacy local geofence](https://github.com/phatcharanun/project1/blob/main/Frontend/js/location.js): `Frontend/js/location.js`
- [Biometric authentication](https://github.com/phatcharanun/project1/blob/main/Frontend/js/webauthn.js): `Frontend/js/webauthn.js`

### API service

- [Geofence API](https://github.com/phatcharanun/project1/blob/main/Backend/Node.js): `Backend/Node.js`

### Geospatial data

- [PostgreSQL connection pool](https://github.com/phatcharanun/project1/blob/main/Backend/database.js): `Backend/database.js`
- [Geofence schema](https://github.com/phatcharanun/project1/blob/main/Backend/init.sql): `Backend/init.sql`

### PWA support

- [PWA manager](https://github.com/phatcharanun/project1/blob/main/Frontend/pwa/pwa.js): `Frontend/pwa/pwa.js`
- [Service worker](https://github.com/phatcharanun/project1/blob/main/Frontend/sw.js): `Frontend/sw.js`

### Other components

- **App user**
- **Browser geolocation**
- **Browser camera**
- **Platform authenticator**
- **Browser cache**
- **PostgreSQL with PostGIS**
- **jsQR decoder**

## Connections

- Camera workflow → Browser camera: opens (evidence: `Frontend/js/camera.js`)
- Camera workflow → QR scanner API: starts (evidence: `Frontend/js/camera.js`)
- QR scanner API → QR decode and results: delegates (evidence: `Frontend/qr-code-scanner/index.js`)
- QR decode and results → Scanner settings: reads settings (evidence: `Frontend/qr-code-scanner/scanner.js`)
- QR decode and results → jsQR decoder: decodes with (evidence: `Frontend/qr-code-scanner/scanner.js`)
- Camera workflow → Session geofence check: passes QR result (evidence: `Frontend/js/camera.js`)
- Session geofence check → Browser geolocation: requests position (evidence: `Frontend/js/Geofence.js`)
- Session geofence check → Geofence API: POSTs coordinates (evidence: `Frontend/js/Geofence.js`)
- Geofence API → PostgreSQL connection pool: queries (evidence: `Backend/Node.js`)
- PostgreSQL connection pool → PostgreSQL with PostGIS: connects (evidence: `Backend/database.js`)
- Geofence API → App interface: serves static files (evidence: `Backend/Node.js`)
- Biometric authentication → Platform authenticator: authenticates with (evidence: `Frontend/js/webauthn.js`)
- PWA manager → Service worker: registers (evidence: `Frontend/pwa/pwa.js`)
- Service worker → Browser cache: reads and writes (evidence: `Frontend/sw.js`)
- App user → Camera workflow: initiates
- App user → Session geofence check: requests check
- App user → Biometric authentication: requests authentication
