A RESTful API for a food delivery application built with Go, Gin, and Firestore (NoSQL).
- User authentication with JWT
- Product management (CRUD operations)
- Category management
- Shopping cart functionality
- Swagger API documentation
- Firestore NoSQL database
- Environment-based configuration
- Go 1.21+
- Gin Web Framework
- Firestore (NoSQL)
- JWT for authentication
- Swagger for API documentation
- Go 1.21 or higher
- Google Cloud Project with Firestore enabled (Native mode)
- Service account JSON key with Firestore permissions
- Make sure you have the following environment variables set:
GCP_PROJECT_ID
(your GCP project ID)GOOGLE_APPLICATION_CREDENTIALS
(path to your service account JSON key)JWT_SECRET
(required for JWT signing)PORT
(default: 8080)
- Clone the repository:
git clone https://github.com/shihabkandil/eatsy-backend.git
cd eatsy-backend
- Install dependencies:
go mod download
- Set up environment variables:
export GCP_PROJECT_ID=your-gcp-project-id
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/serviceAccount.json
export JWT_SECRET=your-very-long-random-secret-key
export PORT=8080 # optional
- Run the application:
go run main.go
The API documentation is available at http://localhost:8080/swagger/index.html
when the server is running.
All protected endpoints require a JWT token in the Authorization header:
Authorization: Bearer <your-token>
POST /auth/register
- Register a new userPOST /auth/login
- Login and get JWT token
GET /products
- Get all productsGET /products/:id
- Get a specific productPOST /products
- Create a new productPUT /products/:id
- Update a productDELETE /products/:id
- Delete a product
GET /cart
- Get user's cartPOST /cart/items
- Add item to cartPUT /cart/items/:id
- Update cart item quantityDELETE /cart/items/:id
- Remove item from cart
All responses follow a consistent format:
{
"status_code": 200,
"message": "Operation completed successfully",
"data": { ... }
}
{
"status_code": 400,
"message": "Invalid input",
"error": "Detailed error message"
}
- id (int64)
- email (string)
- password (string)
- name (string)
- role (string)
- created_at (timestamp)
- updated_at (timestamp)
- id (int64)
- name (string)
- description (string)
- price (float64)
- image_url (string)
- category_id (int64)
- created_at (timestamp)
- updated_at (timestamp)
- id (int64)
- name (string)
- description (string)
- created_at (timestamp)
- updated_at (timestamp)
- id (int64)
- user_id (int64)
- created_at (timestamp)
- updated_at (timestamp)
- items (subcollection: Cart Items)
- id (int64)
- cart_id (int64)
- product_id (int64)
- quantity (int)
- price (float64)
go test ./...
# Generate Swagger documentation
swag init
- Always use environment variables for configuration
- Keep sensitive information in environment variables
- Use proper error handling and logging
- Follow REST API best practices
- Use proper HTTP status codes
- Implement proper input validation
- Use proper authentication and authorization
- Keep the code modular and maintainable
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.