Go Todo Backend Example Using Modular Project Layout for Product Microservice. It's suitable as starting point for a medium to larger project.

Programming language: Go
License: MIT License

go-todo-backend alternatives and similar packages

Based on the "Project Layout" category.
Alternatively, view go-todo-backend alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of go-todo-backend or a related project?

Add another 'Project Layout' Package



GoDoc Build Status Go Report Card Maintainability Test Coverage

Go Todo Backend Example Using Modular Project Layout for Product Microservice. It's suitable as starting point for a medium to larger project.

This example uses Chi for http router and REL for database access.


  • Modular Project Structure.
  • Full example including tests.
  • Docker deployment.
  • Compatible with todobackend.



  1. Install mockery for interface mock generation.
  2. Install rel cli for database migration.


  1. Prepare .env. cp .env.sample .env
  2. Start postgresql and create database. docker-compose up -d
  3. Prepare database schema. rel migrate
  4. Build and Running make

Project Structure

โ”œโ”€โ”€ api
โ”‚   โ”œโ”€โ”€ handler
โ”‚   โ”‚   โ”œโ”€โ”€ todos.go
โ”‚   โ”‚   โ””โ”€โ”€ [other handler].go
โ”‚   โ””โ”€โ”€ middleware
โ”‚       โ””โ”€โ”€ [other middleware].go
โ”œโ”€โ”€ bin
โ”‚   โ”œโ”€โ”€ api
โ”‚   โ””โ”€โ”€ [other executable]
โ”œโ”€โ”€ cmd
โ”‚   โ”œโ”€โ”€ api
โ”‚   โ”‚   โ””โ”€โ”€ main.go
โ”‚   โ””โ”€โ”€ [other cmd]
โ”‚       โ””โ”€โ”€ main.go
โ”œโ”€โ”€ db
โ”‚   โ”œโ”€โ”€ schema.sql
โ”‚   โ””โ”€โ”€ migrations
โ”‚       โ””โ”€โ”€ [migration file]
โ”œโ”€โ”€ todos
โ”‚   โ”œโ”€โ”€ todo.go
โ”‚   โ”œโ”€โ”€ create.go
โ”‚   โ”œโ”€โ”€ update.go
โ”‚   โ”œโ”€โ”€ delete.go
โ”‚   โ”œโ”€โ”€ service.go
โ”‚   โ””โ”€โ”€ todostest
โ”‚       โ”œโ”€โ”€ todo.go
โ”‚       โ””โ”€โ”€ service.go
โ”œโ”€โ”€ [other domain]
โ”‚   โ”œโ”€โ”€ [entity a].go
โ”‚   โ”œโ”€โ”€ [business logic].go
โ”‚   โ”œโ”€โ”€ [other domain]test
โ”‚   โ”‚   โ””โ”€โ”€ service.go
โ”‚   โ””โ”€โ”€ service.go
โ””โ”€โ”€ [other client]
    โ”œโ”€โ”€ [entity b].go
    โ”œโ”€โ”€ client.go
    โ””โ”€โ”€ [other client]test
        โ””โ”€โ”€ client.go

This project structure is based on a modular project structure, with loosely coupled dependencies between domain, Think of making libraries under a single repo that only exports certain functionality that used by other service and http handler. One of domain that present in this example is todos.

Loosely coupled dependency between domain is enforced by avoiding the use of shared entity package, therefore any entity struct should be included inside it's own respective domain. This will prevent cyclic dependency between entity. This shouldn't be a problem in most cases, becasause if you encounter cyclic dependency, there's huge chance that the entity should belongs to the same domain.

For example, consider three structs: user, transaction and transaction items. transaction and its transaction items might need cyclic dependency and items doesn't works standalone (items without transaction should not exists), thus it should be on the same domain. In the other hand, user and transaction shouldn't require cyclic dependency, transaction might have a user field in the struct, but user shouldn't have a slice of transaction field, therefore it should be on a separate domain.

Domain vs Client

Domain and Client folder is very similar, the difference is client folder doesn't actually implement any business logic (service), but instead a client that calls any internal/external API to works with the domain entity.