Previous order was (menu)(theme)(language). Swapped so the row reads logo ... (theme)(language)(menu) and the hamburger sits flush against the right padding edge, which is where the thumb menu is expected. Measured 360/375/414px: brand starts at 14px, menu ends exactly on the right padding edge, 8px gaps, no horizontal overflow.
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:
- หน้าเว็บ: http://localhost:8000
- API: http://localhost:8000/api/route-groups
- ไฟล์ที่อัปโหลด: http://localhost:8000/files/...
Deploy บน Dokploy
ถ้า deploy ผ่าน Dokploy และแยก backend กับ frontend เป็นคนละ service:
- อย่าใช้โหมด
Docker Stack/Swarm - ให้ใช้ service แบบ
DockerfileหรือImage - backend ใช้ build context
backend/และ Dockerfilebackend/Dockerfile - frontend ใช้ build context
frontend/และ Dockerfilefrontend/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
ระบบจะ:
- ส่งไฟล์ไป SeaweedFS filer (
/buckets/transit/<entity_type>/<entity_id>/<filename>) - ตรวจขนาดภาพด้วย crate
image(width/height) และคำนวณ sha256 - บันทึกแถวใน
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)