Welcome to the Go Clean Architecture Backend Starter! This project provides a robust foundation for building scalable, maintainable, and testable backend services in Go, following the principles of Clean Architecture.
- Clean Architecture: Separation of concerns with clear boundaries between controllers, use cases, repositories, and models.
- Modular Structure: Easy to extend and maintain, with each layer in its own package.
- SQLite Integration: Out-of-the-box support for SQLite, but easily adaptable to other databases.
- User Management: Includes user CRUD operations and authentication logic.
- Mockable Repositories: Swap real and mock repositories for easy testing.
- JWT Authentication: Secure user login and protected endpoints.
- Idiomatic Go: Follows Go best practices for clarity and simplicity.
- Ready for Testing: Includes sample unit tests for core logic.
├── controllers/ # HTTP handlers and route setup
│ ├── users_controller.go
│ └── controller_utils.go
├── repositories/ # Data access interfaces and implementations
│ ├── user_repository.go
│ ├── mock_user_repo.go
│ ├── repository_interfaces.go
│ └── errors.go
├── use_cases/ # Business logic and validation
│ ├── user_use_cases.go
│ ├── auth_use_cases.go
│ └── errors.go
├── models/ # Domain models
│ ├── user.go
│ ├── order.go
│ └── stock_item.go
├── main.go # Application entry point
├── go.mod
└── README.md
- Clone the repository
git clone https://github.com/yourusername/go-clean-arch-backend-starter.git cd go-clean-arch-backend-starter - Install dependencies
go mod tidy
- Run the application
go run main.go
- Test the endpoints
GET /users- List all usersPOST /users- Create a new userGET /users/{id}- Get user by IDPUT /users- Update userDELETE /users/{id}- Delete userPOST /users/login- User login
- Add new domain models in
models/ - Implement new use cases in
use_cases/ - Create new controllers for additional resources
- Swap out the database by implementing the repository interfaces
Run unit tests with:
go test ./...Clean Architecture helps you:
- Decouple business logic from frameworks and drivers
- Make your codebase easier to test and maintain
- Enable flexible, future-proof design
MIT License
Contributions and suggestions are welcome! Feel free to open issues or submit pull requests.
Created by Vipul Lal
Enjoy building your next Go backend with Clean Architecture!