A complete restaurant management backend built with Go, Gin, MongoDB, and JWT authentication.
- 🔐 JWT Authentication & Authorization
- 👥 User Management (Admin & Regular Users)
- 🍔 Food Items Management
- 📋 Menu Management
- 🪑 Table Management
- 📝 Order Management
- 🧾 Invoice Management
- 🔒 Role-based Access Control
- Language: Go
- Web Framework: Gin
- Database: MongoDB
- Authentication: JWT
- Password Hashing: bcrypt
- Environment Variables: godotenv
- Go 1.20 or higher
- MongoDB (local or Atlas)
- Clone the repository
- Install dependencies:
go mod tidy- Create a
.envfile in the root directory:
PORT=8080
MONGODB_URI=mongodb://localhost:27017
DATABASE_NAME=restaurant
JWT_SECRET=your_super_secret_jwt_key_change_this_in_productiongo run main.goThe server will start on http://localhost:8080
POST /auth/signup- Register a new userPOST /auth/login- Login userGET /auth/user- Get current user (requires authentication)
GET /swagger/index.html- Open the interactive API documentation (Swagger UI).
After you run the server, open the URL below in your browser to explore and try your API endpoints:
http://localhost:8080/swagger/index.html
Notes:
- The Swagger docs are generated by
swagand written to thedocs/directory. - Do NOT edit
docs/docs.go,docs/swagger.json, ordocs/swagger.yamldirectly — they are generated and will be overwritten.
To regenerate the Swagger documentation after changing annotations or models, run:
swag initIf you want to override runtime metadata (title, host, schemes) without editing generated files, set docs.SwaggerInfo in main.go after importing the generated docs package:
import (
_ "restroBackend/docs"
docs "restroBackend/docs"
)
func main() {
docs.SwaggerInfo.Title = "Restaurant Management API"
docs.SwaggerInfo.Version = "1.0"
docs.SwaggerInfo.Host = "localhost:8080"
docs.SwaggerInfo.BasePath = "/"
docs.SwaggerInfo.Schemes = []string{"http", "https"}
// ...rest of your setup
}GET /foods- Get all foodsGET /foods/:id- Get food by IDPOST /foods- Create food (Admin only)PUT /foods/:id- Update food (Admin only)DELETE /foods/:id- Delete food (Admin only)
GET /menus- Get all menusGET /menus/:id- Get menu by IDPOST /menus- Create menu (Admin only)PUT /menus/:id- Update menu (Admin only)DELETE /menus/:id- Delete menu (Admin only)
GET /tables- Get all tablesGET /tables/:id- Get table by IDPOST /tables- Create table (Admin only)PUT /tables/:id- Update table (Admin only)DELETE /tables/:id- Delete table (Admin only)
GET /orders- Get all orders (authenticated)GET /orders/:id- Get order by ID (authenticated)POST /orders- Create order (authenticated)PUT /orders/:id- Update order (authenticated)
GET /invoices- Get all invoices (authenticated)GET /invoices/:id- Get invoice by ID (authenticated)POST /invoices- Create invoice (authenticated)PUT /invoices/:id- Update invoice (Admin only)
Include the JWT token in the request header:
token: your_jwt_token_here
ADMIN- Full access to all administrative resources, maps, and menusSTAFF- Access to floor maps, active kitchen ticket board, and billing/invoice verificationUSER- Guest customer access (can create orders, view menus, and manage reservations)