Skip to content

vipullal-github/golang_starter_clean_architecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Clean Architecture Backend Starter

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.


🚀 Features

  • 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.

📁 Project Structure

├── 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

🏁 Getting Started

  1. Clone the repository
    git clone https://github.com/yourusername/go-clean-arch-backend-starter.git
    cd go-clean-arch-backend-starter
  2. Install dependencies
    go mod tidy
  3. Run the application
    go run main.go
  4. Test the endpoints
    • GET /users - List all users
    • POST /users - Create a new user
    • GET /users/{id} - Get user by ID
    • PUT /users - Update user
    • DELETE /users/{id} - Delete user
    • POST /users/login - User login

🧩 Extending the Project

  • 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

🧪 Testing

Run unit tests with:

go test ./...

📚 References


💡 Why Clean Architecture?

Clean Architecture helps you:

  • Decouple business logic from frameworks and drivers
  • Make your codebase easier to test and maintain
  • Enable flexible, future-proof design

📝 License

MIT License


✨ Contributing

Contributions and suggestions are welcome! Feel free to open issues or submit pull requests.


👤 Author

Created by Vipul Lal


Enjoy building your next Go backend with Clean Architecture!

About

Starter project for Golang backends using Clean architecture

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages