Skip to content

e-safeworkArchitecture & Deployment

Bun/ElysiaJS API, two Vue SPAs, one VM behind a Cloudflare Tunnel.

ภาษาไทย — เอกสารส่วนที่อธิบายความหมายของระบบมีฉบับภาษาไทยแล้วที่ หน้าเอกสารภาษาไทย หรือใช้ปุ่มเปลี่ยนภาษาบนแถบด้านบน

Read this first

If you are new to the project, start at Why this system exists — the goal, the risks it exists to remove, and how success is judged. Then what each role has to do for the three journeys end to end.

If you are deploying today, start at Current state & blockers. The stack deploys cleanly and you will still not be able to log in from the two *.pages.dev URLs — that is a cookie-domain constraint, not a bug, and it is covered there.

How this site is organised

SectionWhat it answers
Why this system existsThe goal, the objectives behind it, and how you would know it worked
Domain contextThe vocabulary, the bounded contexts, and which part owns which rule
What each role doesContractor, safety officer and inspector — what each must do, and what they are refused
Using the Contractor appEvery module of the contractor app, and the steps to use each one
Using the Safety appEvery module of the other app, both the officer and the inspector halves
System architectureWhere things run, how a request travels, why the box has no open ports
Data model / ERThe 25 tables, what actually relates to what, and what only looks like it does
Permit lifecycleThe status machine and who may move it
CI/CD pipelinesThe three workflows, their gates, and the secrets each needs
Deployment 10–13The normative deploy files, mirrored into all three repos
Current state & blockersWhat is live, what is pending, what will bite you
Open items — needs a humanEverything waiting on a person: a decision to make, or an action code cannot take
Doc driftWhere the normative files no longer match production

Reading these docs on another machine

The built site is a folder of static files. It must be served over HTTP — double-clicking index.html will not work, because every asset is referenced by an absolute path (/assets/...) which file:// resolves to your filesystem root.

Build and package (on a machine with this repo):

bash
bun install
bun run docs:build
cd docs/.vitepress && zip -r ~/e-safework-docs.zip dist

That produces a ~12 MB zip. Copy it anywhere.

Open it (on the other Mac or PC — nothing from this repo needed):

bash
unzip e-safework-docs.zip && cd dist
npx serve            # or: bunx serve

Then open the URL it prints, usually http://localhost:3000.

Use serve rather than python3 -m http.server: this site uses clean URLs, and Python's server does not fall back to .html, so every direct link and every page refresh answers 404. Tested — serve handles it, http.server does not.

If you need documents rather than a website

dist/ is a website and has to be served. To hand someone actual files they can double-click — no server, no install — export the human-facing pages as PDFs:

bash
bun run docs:pdf          # writes docs-pdf/, English and Thai

Renders through headless Chrome, so the mermaid diagrams come out drawn rather than blank. Pass paths to pick your own pages: ./scripts/export-docs-pdf.sh /guide/ci-cd.

Three repos

RepoRuns asReaches production via
smart-work-permit-apiDocker image on the VMGHCR image → SSH → docker compose up -d --wait
smart-work-permit-contractor-frontendStatic SPACloudflare Pages project esw-contractor
smart-work-permit-frontend (Safety + Inspector)Static SPACloudflare Pages project esw-safety

The umbrella repo you are reading holds the docs and the cross-repo glue only — all three application repos are gitignored here and are independent git repositories.