โปรเจกต์ Backend ของระบบจัดการร้านอาหาร (Restaurant Management System) พัฒนาด้วย Go + Fiber + PostgreSQL + Docker
- โครงสร้างแยกชั้นชัดเจน: Handler, Service, Repository, Model
- ระบบยืนยันตัวตนด้วย JWT (Login, Me, Logout)
- ระบบสิทธิ์การใช้งานตาม Role (ADMIN, CASHIER, CHEF)
- API จัดการพนักงาน (สร้าง, ค้นหา, แก้ไข, ปิด/เปิดใช้งาน)
- API จัดการโต๊ะ (ดูรายการ, ดูรายตัว, สร้าง, แก้ไข)
- API เมนูสำหรับลูกค้า
- API คำสั่งซื้อของลูกค้าผ่าน QR และคำสั่งซื้อของ cashier
- SQL seed สำหรับสร้าง schema และข้อมูลตั้งต้น
- รองรับการรันแบบ Docker ทั้งระบบ หรือรัน Go local + DB ใน Docker
- Go 1.25
- Fiber v2
- PostgreSQL 17
- pgx/v5
- JWT (golang-jwt)
- Docker Compose
cmd/
main.go
internal/
config/
env.go
database/
postgres.go
handlers/
auth_handler.go
employee_handler.go
health_handler.go
menu_handler.go
role_handler.go
table_handler.go
table_session_handler.go
qr_session_handler.go
order_handler.go
category_handler.go
middleware/
auth_middleware.go
models/
auth.go
common.go
employee.go
menu.go
role.go
table.go
table_session.go
qr_session.go
order.go
category.go
repositories/
auth_repository.go
employee_repository.go
menu_repository.go
role_repository.go
table_repository.go
table_session_repository.go
qr_session_repository.go
order_repository.go
category_repository.go
routes/
routes.go
services/
auth_service.go
employee_service.go
menu_service.go
role_service.go
table_service.go
table_session_service.go
qr_session_service.go
order_service.go
category_service.go
utils/
jwt.go
password.go
seeds/
01_schema.sql
02_seed.sql
docker-compose.yml
Dockerfile
go.mod
README.md
README_API_TEST.md
Handler: รับ HTTP request, validate input, ส่ง responseService: รวม business logicRepository: คุยกับฐานข้อมูลโดยตรงModel: โครงสร้าง request/response/entityRoute: ผูก endpoint กับ handler และ middleware
- Go 1.25 ขึ้นไป
- Docker Desktop
สร้างไฟล์ .env ที่ root โปรเจกต์
APP_NAME=RMS Backend
APP_PORT=8080
APP_ENV=development
DB_HOST=localhost
DB_PORT=5435
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=rms
DB_SSLMODE=disable
DB_MAX_CONNS=10
DB_HOST_DOCKER=postgres
DB_PORT_CONTAINER=5432
DB_PORT_HOST=5435
JWT_SECRET=super-secret-rms-key
JWT_EXPIRES_IN_SECONDS=3600ความหมายค่า DB ที่ใช้บ่อย
DB_HOST+DB_PORT: ใช้ตอนรัน API บนเครื่อง localDB_HOST_DOCKER+DB_PORT_CONTAINER: ใช้ตอนรัน API ใน DockerDB_PORT_HOST: พอร์ต DB ที่ expose ออกมาให้ local ต่อเข้าได้
docker compose up --build -dระบบจะพร้อมใช้งานที่
- API:
http://localhost:8080 - PostgreSQL:
localhost:5435
docker compose up -d postgres
go mod tidy
go run ./cmd/main.gocurl http://localhost:8080/healthExpected Response:
{
"success": true,
"message": "server is running",
"data": {
"status": "ok"
}
}รันและดูสถานะ container:
docker compose ps
docker compose logs -f postgresเช็กว่าโค้ด build ได้:
go build ./...รีเซ็ตฐานข้อมูลทั้งหมด (ลบ volume เดิม):
docker compose down -v
docker compose up --build -dGET /healthGET /api/v1/customer/menus?qrToken=xxxGET /api/v1/customer/orders?qrToken=xxxPOST /api/v1/customer/ordersPOST /api/v1/auth/loginGET /api/v1/qr/:tokenGET /api/v1/categories
GET /api/v1/auth/mePOST /api/v1/auth/logout
GET /api/v1/rolesPOST /api/v1/employeesGET /api/v1/employeesGET /api/v1/employees/:employeeIdPATCH /api/v1/employees/:employeeIdPATCH /api/v1/employees/:employeeId/statusPOST /api/v1/tablesPATCH /api/v1/tables/:tableIdPOST /api/v1/categoriesPATCH /api/v1/categories/:categoryIdPOST /api/v1/menusPATCH /api/v1/menus/:menuIdPATCH /api/v1/menus/:menuId/statusGET /api/v1/dashboard/summaryGET /api/v1/reports/salesGET /api/v1/reports/top-menus
GET /api/v1/tablesGET /api/v1/tables/:tableIdGET /api/v1/tables/:tableId/current-sessionGET /api/v1/table-sessions/:sessionIdGET /api/v1/qr-sessions/:qrSessionIdGET /api/v1/menusGET /api/v1/menus/:menuIdGET /api/v1/table-sessions/:sessionId/orders
GET /api/v1/orders/:orderId
POST /api/v1/table-sessions/openPATCH /api/v1/table-sessions/:sessionId/closePOST /api/v1/qr-sessionsPOST /api/v1/ordersGET /api/v1/cashier/tables/overviewGET /api/v1/cashier/sessions/:sessionId/checkoutPOST /api/v1/cashier/checkout
หมายเหตุ: ต้องตั้ง password_hash ให้บัญชี seed ก่อนตามขั้นตอนใน README_API_TEST.md
ดูที่ไฟล์ README_API_TEST.md
ไฟล์นี้จัดเป็นลำดับทดสอบสำหรับ Postman พร้อมตัวอย่าง Method, URL, Headers, Body และ Expected Response ของทุก endpoint