# toeng2002/longtest-police architecture

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

- Interactive diagram: https://gitdiagram.com/toeng2002/longtest-police
- Repository: https://github.com/toeng2002/longtest-police

## Overview

This repository implements a Thai police-exam practice web application. The main workflow is for a user to sign in, choose an agency, level, and subject, take an exam, and review results and history. Admins manage exam questions and related settings, with CSV import as a separate management capability. The source excerpts show several browser modules making direct Supabase requests; they do not establish all page-loading or module-wiring relationships, so those are omitted.

Main entry points: [`js/app-auth.js`](https://github.com/toeng2002/longtest-police/blob/main/js/app-auth.js) (Authentication), [`js/app-quiz.js`](https://github.com/toeng2002/longtest-police/blob/main/js/app-quiz.js) (Quiz and results), [`js/app-admin.js`](https://github.com/toeng2002/longtest-police/blob/main/js/app-admin.js) (Question administration), [`js/app-settings.js`](https://github.com/toeng2002/longtest-police/blob/main/js/app-settings.js) (Admin settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and identity"]
  node_auth["Authentication<br/>[app-auth.js]"]
  node_profile["Profile and preferences"]
end

subgraph group_exam["Exam experience"]
  node_quiz["Quiz and results<br/>[app-quiz.js]"]
  node_security["Exam protections<br/>[anti-cheat.js]"]
end

subgraph group_management["Exam administration"]
  node_admin_ops["Question administration<br/>[app-admin.js]"]
  node_settings["Admin settings<br/>[app-settings.js]"]
  node_csv["CSV import<br/>[app-csv.js]"]
end

subgraph group_platform["Runtime support"]
  node_data_access["Exam data access<br/>[exam-db.js]"]
  node_worker["Offline cache<br/>[sw.js]"]
end

node_user(("Exam taker"))
node_admin(("Administrator"))
node_supabase[("Supabase")]

node_user -->|"signs in"| node_auth
node_auth -->|"reads and writes"| node_supabase
node_user -->|"takes exam"| node_quiz
node_quiz -->|"loads and saves"| node_supabase
node_admin -->|"manages questions"| node_admin_ops
node_admin_ops -->|"manages questions"| node_supabase
node_admin -->|"manages settings"| node_settings
node_settings -->|"updates settings"| node_supabase
node_admin -->|"imports questions"| node_csv
node_csv -->|"reads and imports"| node_supabase

click node_auth "https://github.com/toeng2002/longtest-police/blob/main/js/app-auth.js"
click node_profile "https://github.com/toeng2002/longtest-police/blob/main/js/app-profile-settings.js"
click node_quiz "https://github.com/toeng2002/longtest-police/blob/main/js/app-quiz.js"
click node_security "https://github.com/toeng2002/longtest-police/blob/main/js/anti-cheat.js"
click node_admin_ops "https://github.com/toeng2002/longtest-police/blob/main/js/app-admin.js"
click node_settings "https://github.com/toeng2002/longtest-police/blob/main/js/app-settings.js"
click node_csv "https://github.com/toeng2002/longtest-police/blob/main/js/app-csv.js"
click node_data_access "https://github.com/toeng2002/longtest-police/blob/main/js/exam-db.js"
click node_worker "https://github.com/toeng2002/longtest-police/blob/main/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_auth,node_profile toneBlue
class node_quiz,node_security,node_supabase toneAmber
class node_admin_ops,node_settings,node_csv toneMint
class node_data_access,node_worker toneRose
class node_user,node_admin toneIndigo
```

## Components

### Access and identity

- [Authentication](https://github.com/toeng2002/longtest-police/blob/main/js/app-auth.js): `js/app-auth.js`
- [Profile and preferences](https://github.com/toeng2002/longtest-police/blob/main/js/app-profile-settings.js): `js/app-profile-settings.js`

### Exam experience

- [Quiz and results](https://github.com/toeng2002/longtest-police/blob/main/js/app-quiz.js): `js/app-quiz.js`
- [Exam protections](https://github.com/toeng2002/longtest-police/blob/main/js/anti-cheat.js): `js/anti-cheat.js`

### Exam administration

- [Question administration](https://github.com/toeng2002/longtest-police/blob/main/js/app-admin.js): `js/app-admin.js`
- [Admin settings](https://github.com/toeng2002/longtest-police/blob/main/js/app-settings.js): `js/app-settings.js`
- [CSV import](https://github.com/toeng2002/longtest-police/blob/main/js/app-csv.js): `js/app-csv.js`

### Runtime support

- [Exam data access](https://github.com/toeng2002/longtest-police/blob/main/js/exam-db.js): `js/exam-db.js`
- [Offline cache](https://github.com/toeng2002/longtest-police/blob/main/sw.js): `sw.js`

### Other components

- **Exam taker**
- **Administrator**
- **Supabase**

## Connections

- Exam taker → Authentication: signs in (evidence: `js/app-auth.js`)
- Authentication → Supabase: reads and writes (evidence: `js/app-auth.js`)
- Exam taker → Quiz and results: takes exam (evidence: `js/app-quiz.js`)
- Quiz and results → Supabase: loads and saves (evidence: `js/app-quiz.js`)
- Administrator → Question administration: manages questions (evidence: `js/app-admin.js`)
- Question administration → Supabase: manages questions (evidence: `js/app-admin.js`)
- Administrator → Admin settings: manages settings (evidence: `js/app-settings.js`)
- Admin settings → Supabase: updates settings (evidence: `js/app-settings.js`)
- Administrator → CSV import: imports questions (evidence: `js/app-csv.js`)
- CSV import → Supabase: reads and imports (evidence: `js/app-csv.js`)
