This project serves as a starting point for my future backend side-projects in Go. It comes with a fairly well-organized structure, including services, concrete repository implementations, custom application errors, API boilerplate, and integration tests. A lot of things in this setup are still experimental and are likely to change overtime. If you happen to recognise any pattern that you believe might not scale well in production, feel free to open am issue and we can discuss it there.
Before getting started, ensure you have the following installed:
- Go: Version 1.23.1 or higher (download)
- Task: A command runner for automating tasks (installation instructions)
- Docker: For containerizing your environment (download)
-
cmd/
Contains the application entry points.- The cmd/server/main.go file starts the server.
- Other command folders (e.g., cmd/goose/main.go) handle tasks like database migrations.
-
internal/app/
Contains different services such as authentication (internal/app/auth) and user management (internal/app/users).db/
Provides the concrete repository implementations for interacting with the database. Check out the implementations in internal/db/database.go and related files.apperrors/
Contains custom application errors (internal/apperrors/error.go).domain/
Holds foundational models and interfaces, including repositories and database interfaces, and paging logic.oapi/
Contains generated boilerplate code from the openapi.yml specification, ensuring consistency between your API and code.server/
Implements HTTP handlers for incoming requests. Handlers often import request and response definitions from theoapipackage and facilitate business logic.- Other folders such as
mail,rbac,vcs, andworkersprovide additional supporting functionality.
-
tests/
Includes integration tests for the project. The test environment setup is detailed in tests/integration/testenv/testenv.go. -
Other Files
docker-compose.ymland Dockerfiles (api.Dockerfile, docs.Dockerfile) help configure and run containers.Taskfile.ymldefines tasks for code generation, migrations, and running the application..envand.env.localcontain environment variables. Copy.env.localto.envto configure your local environment.
To run the project locally, follow these steps:
-
Set Up Environment Variables:
Copy over the.env.localfile as.env:cp .env.local .env
-
Start Docker Containers: Bring up the necessary containers with:
task docker/up
-
Run the Application: Finally, start the server:
task run
-
API Generation:
The Taskfile includes tasks to generate API models and boilerplate code from your OpenAPI definitions.task generate/api
-
Database Code Generation:
Generate SQLC code for database queries and models:task generate/db
-
Database Migrations:
Run migrations using Goose:task migrations/up
There are still a couple of features that I'd like to implement and will do over the next few months
- Background workers
- Auth setup (OAuth and Session tokens)
- Automated CI/CD pipeline setup using Dagger
Feel free to fork this repository and submit pull requests. For any issues or questions, please open an issue in the repository.