Bkk1234 0cf391afba PWA: publish an app version so stale shells are detectable
The service worker version had never moved past 1.0.0 and nothing on the page
said which build was loaded, so an old cached shell looked identical to a
fresh one.

- public/version.json: app, version, builtAt, pwa
- sw.js VERSION -> 2026.10.24.1 (new cache name, old caches dropped on activate)
- next.config: sw.js and version.json are served no-cache, no-store, plus
  Service-Worker-Allowed: / ; ui-manifest.json must-revalidate
- layout: <html data-app-version> read from version.json at build time
- PwaBoot: paints the version into the footer badge, polls /version.json
  (1.5s then every 5 min) and reloads once when it differs; guards against
  reload loops
- footer shows v2026.10.24.1 in mono next to the copyright

Verified: sw.js, /version.json and <html data-app-version> all report
2026.10.24.1, the footer badge shows it, and /stops renders the three search
tabs with the near-me panel in its own tab.
2026-10-24 00:27:23 +07:00
2026-05-24 22:55:17 +07:00

AT Transit — Full Stack

ระบบค้นเส้นทางรถโดยสาร / ตู้รถ / จุดจอด ภาคใต้
Postgres (PostGIS + JSONB) · SeaweedFS · Rust + Axum · Next.js · nginx

เริ่มต้นใช้งานเร็วสุด

cd web-at-transit
cp .env.example .env             # ตรวจ SQL_DB_PASSWORD ฯลฯ
docker compose up --build

ตัวอย่าง endpoint:

Deploy บน Dokploy

ถ้า deploy ผ่าน Dokploy และแยก backend กับ frontend เป็นคนละ service:

  • อย่าใช้โหมด Docker Stack / Swarm
  • ให้ใช้ service แบบ Dockerfile หรือ Image
  • backend ใช้ build context backend/ และ Dockerfile backend/Dockerfile
  • frontend ใช้ build context frontend/ และ Dockerfile frontend/Dockerfile

สาเหตุของ error นี้:

This node is not a swarm manager

คือ Dokploy กำลังพยายาม deploy แบบ Swarm (docker stack / docker service) แต่เครื่อง target ไม่ได้เปิด Swarm manager และ repo นี้ไม่ได้ต้องการ Swarm

Backend service

ตั้งค่า internal port เป็น 8080

env ที่ต้องมี:

SQL_DB_URL=postgres://itmeadmin:Admin%40Pass001%23%21@infra-postgres:5432/at-transit
STORAGE_URL=http://seaweed-filer:8888
STORAGE_BUCKET=transit
STORAGE_PUBLIC_BASE=/files
BIND_ADDR=0.0.0.0:8080
RUST_LOG=info,sqlx=warn,tower_http=info
CORS_ALLOW_ORIGINS=https://<your-frontend-domain>
SEED_ASSETS_DIR=/seed-assets

ถ้าจะ mount รูป seed ให้ mount path storage/seed-assets ไปที่ /seed-assets แบบ read-only

Frontend service

ตั้งค่า internal port เป็น 3000

build args / env ที่ต้องมี:

NEXT_PUBLIC_API_BASE=/api
NEXT_PUBLIC_FILE_BASE=/files
INTERNAL_API_BASE=http://<backend-service-name>:8080/api
BACKEND_INTERNAL_URL=http://<backend-service-name>:8080
STORAGE_INTERNAL_URL=http://seaweed-filer:8888
STORAGE_BUCKET_PATH=/buckets/transit
PORT=3000

ถ้ามี reverse proxy หน้า Dokploy ให้ route:

  • /api ไป backend
  • /files ไป backend
  • / ไป frontend

โครงสร้างโฟลเดอร์

app/
├─ docker-compose.yml      5 services: db, seaweedfs, backend, frontend, proxy
├─ nginx.conf              reverse-proxy + /files cache 1 ปี
├─ backend/                Rust + Axum + SQLx (1 endpoint = 1 folder)
│  └─ src/api/<endpoint>/{mod,dto,repo,service,handler}.rs
├─ frontend/               Next.js App Router + react-leaflet
└─ storage/seed-assets/    วางรูปเพื่อ ingest ครั้งแรกอัตโนมัติ

Backend ↔ Frontend แยกขาด

ทั้งสองฝั่งถูกแยก codebase, Dockerfile, และ env
และ "คุย" กันด้วย REST JSON ผ่าน nginx เท่านั้น
ไม่มีการแชร์โค้ดหรือ type ระหว่างกัน (frontend ประกาศ type ใน src/lib/api.ts ตาม contract)

Endpoint Map (15 เส้น)

Method Path Folder
GET /api/provinces list_provinces
GET /api/route-groups list_route_groups
GET /api/routes?group=&province= list_routes
GET /api/routes/:route_id get_route
GET /api/routes/:route_id/stops list_route_stops
GET /api/stops?bbox=&q= list_stops
GET /api/stops/:stop_code get_stop
GET /api/schedules?route_id=&stop_id=&stop_code= list_schedules
POST /api/images (multipart) upload_image
GET /api/images?entity_type=&entity_id= list_images
DELETE /api/images/:id delete_image
GET /files/*path proxy_file
POST /api/visits record_visit
GET /api/visits/summary get_visits_summary
GET /api/visits/by-page?path=&since= get_visits_by_page

JSONB Field Guide

ตาราง คอลัมน์ ตัวอย่างคีย์
routes contact phones[{label,number}], email, line_id, office_hours
routes metadata headway_minutes, first_departure, last_departure, fare_baht, notes, tags[]
stations attributes has_ticketing, has_restroom, cover_type, landmark_note
stations metadata alias_names[], nearest_landmark, accessibility
schedules variants weekday_only, weekend_only, holiday_only, notes
images meta mime, size_bytes, width, height, alt_th, sha256, pending_gc
sponsors meta description_th, tier, display_url

ทุกคอลัมน์ JSONB มี GIN jsonb_path_ops index สำหรับ @> / @? queries.

วิธีอัปโหลดรูป

หนึ่ง multipart POST:

curl -X POST http://localhost:8000/api/images \
  -F entity_type=route \
  -F entity_id=SU01 \
  -F kind=photo \
  -F alt_th="รถตู้สาย SU01" \
  -F display_order=0 \
  -F file=@/path/to/photo.jpg

ระบบจะ:

  1. ส่งไฟล์ไป SeaweedFS filer (/buckets/transit/<entity_type>/<entity_id>/<filename>)
  2. ตรวจขนาดภาพด้วย crate image (width/height) และคำนวณ sha256
  3. บันทึกแถวใน transit.images พร้อม metadata JSONB

หรือวางไฟล์ลง storage/seed-assets/<entity_type>/<entity_id>/...
แล้ว backend จะ ingest อัตโนมัติเมื่อ images ยังว่าง

UI (frontend) — พอร์ตจาก mock

หน้าเว็บทั้งหมดพอร์ตมาจาก D:\Git\workspace\web-at-transit-mock แบบ 1:1 (มาร์กอัป + CSS + ตรรกะ) แต่เปลี่ยนจาก hash router เป็น route จริงของ Next.js

Route หน้า ไฟล์
/ หน้าแรก — เลือกจังหวัด → สถานี, การ์ดตามหมวดเส้นทาง src/app/page.tsx
/stops ค้นหาป้าย (รหัส 5 หลัก / ชื่อสถานที่) + ป้ายใกล้ฉัน src/app/stops/page.tsx
/stops/[code] รายละเอียดป้าย + ตารางเดินรถ + แผนที่ src/app/stops/[code]/page.tsx
/routes, /routes/[routeId] รายละเอียดสาย + รูปรถ + แผนที่เส้นทาง src/app/routes/...
/check, /check/[routeId] เช็กเวลาเดินรถทุกจุดจอด src/app/check/...
/blog, /blog/[postId] บทความ + แผนที่ในบทความ src/app/blog/...
/about, /credits เกี่ยวกับเรา / เครดิต src/app/{about,credits}
  • มาร์กอัปอยู่ที่ frontend/src/components/views/*.tsx
  • ตรรกะ (เดิม ui/*.js) อยู่ที่ frontend/src/lib/ui/*.ts และถูกเรียกผ่าน PageRuntime
  • CSS: frontend/src/styles/ (_shared, map, shell, responsive) + styles/pages/*.css ต้อง import CSS ของหน้าใน view ของหน้านั้น (รายละเอียดใน docs/UI-PORT.md)
  • ข้อมูล/รูป: frontend/public/resource/data/, frontend/public/image/, frontend/public/content/, frontend/public/locales/
  • ดีไซน์: DESIGN.md (รัฐธรรมนูญของ UI)

การเชื่อมกับ core_management

docker-compose.yml ใช้ internal-network (external) และคุยกับบริการที่รันโดย D:\Git\core_management:

  • Postgres: compose.internal.db.yaml → ตั้ง SQL_DB_URL ใน .env
  • ไฟล์/รูป: compose.storage.yaml → STORAGE_URL=http://seaweed-filer:8888 (frontend อ่านผ่าน /files/... ที่ proxy ไป backend)
  • ไม่มี container ใหม่สำหรับ db/storage ใน repo นี้

อัปโหลดรูปที่มีอยู่เข้า SeaweedFS (ทำครั้งเดียวหลัง backend พร้อม):

python script/import_assets_to_storage.py --api http://localhost:8080/api   --dir frontend/public/image --map script/asset_entity_map.json

Image Flow Overview

ดูภาพรวมการไหลของหน้าและ action ทั้งหมดใน flow-overview.md (mermaid diagram)

S
Description
No description provided
Readme
39 MiB
0 Stars 1 Watchers 0 Forks
demo
Latest
2026-10-08 18:17:32 +07:00
Languages
TypeScript 54.9%
CSS 16.8%
HTML 13.3%
Python 6%
Rust 6%
Other 3%