Hot Coffee is a RESTful coffee shop management system built in Go.
The application allows managing orders, menu items, and inventory using a layered architecture and JSON file storage.
# Build
go build -o hot-coffee ./cmd
# Run
./hot-coffee
# Custom configuration
./hot-coffee --port 8080 --dir ./dataServer starts at http://localhost:8080
- Order Management - Create, update, close orders with automatic inventory deduction
- Menu Management - Add menu items with ingredients and pricing
- Inventory Tracking - Real-time ingredient quantity management
- Sales Reports - Total sales and popular items analytics
- JSON Storage - File-based persistence with atomic operations
- Structured Logging - Comprehensive logging with slog
3-Layer Architecture:
- Handler Layer - HTTP request/response
- Service Layer - Business rules & validation
- Repository Layer - Data persistence
hot-coffee/
├── bin
│ └── air
├── cmd
│ └── main.go
├── data
│ ├── inventory.json
│ ├── menu_items.json
│ └── orders.json
├── go.mod
├── go.sum
├── internal
│ ├── config
│ │ └── config.go
│ ├── dal
│ │ ├── inventory_repository.go
│ │ ├── menu_repository.go
│ │ ├── order_repository.go
│ │ ├── report_repository.go
│ │ └── repository.go
│ ├── handler
│ │ ├── handler.go
│ │ ├── inventory_handler.go
│ │ ├── menu_handler.go
│ │ ├── order_handler.go
│ │ └── report_handler.go
│ ├── models
│ │ ├── inventory_item.go
│ │ ├── menu_item.go
│ │ └── order.go
│ ├── server
│ │ ├── router.go
│ │ └── server.go
│ ├── service
│ │ ├── inventory_service.go
│ │ ├── menu_service.go
│ │ ├── order_service.go
│ │ ├── report_service.go
│ │ └── service.go
│ └── utils
│ └── http.go
├── readme.md
GET /menu - List all menu items
POST /menu - Create menu item
GET /menu/{id} - Get menu item
PUT /menu/{id} - Update menu item
DELETE /menu/{id} - Delete menu item
GET /inventory - List all inventory
POST /inventory - Add inventory item
GET /inventory/{id} - Get inventory item
PUT /inventory/{id} - Update inventory
DELETE /inventory/{id} - Delete inventory item
GET /orders - List all orders
POST /orders - Create order
GET /orders/{id} - Get order
PUT /orders/{id} - Update order
DELETE /orders/{id} - Delete order
POST /orders/{id}/close - Close order
GET /reports/total-sales - Total sales amount
GET /reports/popular-items - Top 3 popular items
# 1. Add menu item
curl -X POST http://localhost:8080/menu \
-H "Content-Type: application/json" \
-d '{
"product_id": "espresso",
"name": "Эсперссо",
"price": 1100,
"ingredients": [
{"ingredient_id": "beans", "quantity": 0.1},
{"ingredient_id": "water", "quantity": 0.2}
]
}'
# 2. Stock inventory
curl -X POST http://localhost:8080/inventory \
-H "Content-Type: application/json" \
-d '{
"ingredient_id": "milk",
"name": "Milk",
"quantity": 5,
"unit": "l"
}'
# 3. Create order
curl -X POST http://localhost:8080/orders \
-H "Content-Type: application/json" \
-d '{
"order_id": "1",
"customer_name": "Alice",
"items": [
{"product_id": "espresso", "quantity": 2}
]
}'
# 4. Close order
curl -X POST http://localhost:8080/orders/1/close
# 5. View total sales
curl http://localhost:8080/reports/total-sales./hot-coffee [OPTIONS]
Options:
--port N Port number (default: 8080)
--dir S Data directory path (default: ./data)
--help Show help message# Development
./hot-coffee --port 8080 --dir ./data
# Production
./hot-coffee --port 80 --dir /var/coffee-data
# Testing
./hot-coffee --port 3000 --dir /tmp/test-data- Language: Go 1.22
- Storage: JSON files
- Logging: slog (structured logging)
- Architecture: 3-layer separation
- Concurrency: RWMutex for safe operations
- Atomic Writes - Data integrity with temp file + rename
- Automatic Inventory - Deducts ingredients on order creation
- Validation - Multi-layer input validation
- Structured Logs - Easy debugging with key-value pairs
View application logs:
# Run with logs
./hot-coffee 2>&1 | tee server.log
# Filter errors
grep "ERROR" server.log
# Monitor orders
grep "order" server.log
# View inventory changes
grep "Deducting inventory" server.logLog Levels:
INFO- Normal operationsWARN- Potential issuesERROR- Actual errors
| Code | Meaning | Usage |
|---|---|---|
| 200 | OK | Successful GET |
| 201 | Created | Successful POST |
| 204 | No Content | Successful PUT/DELETE |
| 400 | Bad Request | Validation error |
| 404 | Not Found | Resource not found |
| 500 | Internal Error | Server error |
Port already in use:
./hot-coffee --port 8081Permission denied:
# Use port > 1024 or run with sudo
./hot-coffee --port 8080Insufficient inventory error:
# Check current inventory
curl http://localhost:8080/inventory
# Add more stock
curl -X POST http://localhost:8080/inventory \
-d '{"ingredient_id":"milk","quantity":10000,...}'nuramazannualdaber