A modern RESTful API for managing todos efficiently, built with Go using clean architecture principles.
- Go 1.21
- Gin v1.10.0 (Web Framework)
- GORM v1.25.7 (ORM)
- MySQL (Database)
- Uber FX v1.20.1 (Dependency Injection)
- Viper v1.18.2 (Configuration Management)
- Zerolog v1.32.0 (Logging)
- Swagger v1.16.3 (API Documentation)
.
├── cmd
│ └── main.go # Application entry point
├── config
│ └── config.go # Configuration management
├── database
│ └── db.go # Database connection setup
├── internal
│ ├── controller # HTTP handlers
│ ├── dto # Data Transfer Objects
│ ├── logger # Logging configuration
│ ├── model # Data models
│ ├── repository # Database operations
│ └── service # Business logic
├── docs # Swagger documentation
├── docker-compose.yml # Docker compose configuration
├── Dockerfile # Docker build configuration
├── go.mod # Go module file
├── go.sum # Go module checksums
└── README.md # Project documentation
- Go 1.21 or higher
- Docker and Docker Compose
- MySQL (if running locally)
- Clone the repository:
git clone https://github.com/tuannguyensn2001/skeleton-bootcamp-backend
cd skeleton-bootcamp-backend- Start the application using Docker Compose:
docker-compose up -dThe application will be available at http://localhost:8080
- Clone the repository
- Create a
.envfile based on.env.example:
SERVER_PORT=8080
DATABASE_HOST=localhost
DATABASE_PORT=3306
DATABASE_USER=root
DATABASE_PASSWORD=password
DATABASE_NAME=todo_db- Run MySQL database (or use Docker Compose for database only)
- Run the application:
go run cmd/main.goGET /health- Check API health status
GET /api/v1/todos- Get all todosGET /api/v1/todos/:id- Get a specific todoPOST /api/v1/todos- Create a new todoPUT /api/v1/todos/:id- Update a todoDELETE /api/v1/todos/:id- Delete a todo
POST /api/v1/todos
{
"title": "Complete project",
"description": "Finish the todo app",
"status": "pending"
}{
"message": "Todo created successfully",
"data": {
"id": 1,
"title": "Complete project",
"description": "Finish the todo app",
"status": "pending",
"created_at": "2024-03-12T10:00:00Z",
"updated_at": "2024-03-12T10:00:00Z"
}
}The API is documented using Swagger/OpenAPI. To access the documentation:
- Install Swagger tools:
go install github.com/swaggo/swag/cmd/swag@latest- Generate Swagger documentation:
swag init -g cmd/main.go- Access the Swagger UI:
- Start the application
- Visit
http://localhost:8080/swagger/index.html
The Swagger UI provides interactive documentation where you can:
- View all available endpoints
- Read detailed API descriptions
- Test API endpoints directly from the browser
- View request/response schemas
- Clean Architecture implementation
- Dependency Injection using Uber FX
- Structured logging with Zerolog
- Configuration management with Viper
- CORS support
- Swagger API documentation
- Docker support
- Health check endpoint
- MySQL database integration
- GORM ORM for database operations