A Go-based HTTP service for managing accounts and todos, built as a practice run project with various TODOs to be implemented.
This is a backend service that demonstrates a typical Go web application structure with authentication, database integration, and RESTful API design. The repository contains a skeleton for an API of Todos application.
The project follows a clean architecture pattern with the following structure:
- cmd/: CLI commands and HTTP server setup
- internal/app/: Application initialization and routing
- internal/config/: Configuration management
- internal/controllers/: HTTP handlers
- internal/model/: Data models and business logic
- database/: Database schema and migrations
- ✅ HTTP server with graceful shutdown
- ✅ Status endpoint for health checks
- ✅ Panic recovery middleware
- ✅ Request logging middleware
- ✅ Configuration management with environment variables
- ✅ Docker support with MySQL database
- ✅ Access token model structure
- Language: Go 1.24.4
- Web Framework: Gorilla Mux
- CLI Framework: Cobra
- Database: MySQL 8.0.39
- Containerization: Docker & Docker Compose
- Logging: Structured logging with slog
github.com/gorilla/mux v1.8.1
github.com/spf13/cobra v1.10.1
github.com/spf13/pflag v1.0.9- Go 1.24.4 or later
- Docker and Docker Compose
- Make (optional, for using Makefile commands)
-
Clone the repository
git clone <repository-url> cd accounts-backend-practice-run
-
Start the database
make prepare
This will start a MySQL container with the required configuration.
-
Run database migrations (after implementing schema)
make migrate
-
Start the application
make run
The server will start on port 8080 (default) or the port specified in the
PORTenvironment variable.
If you prefer not to use Make:
# Start MySQL container
docker compose -p acc up -d mysql --wait
# Run the application
go run . publicThe application uses environment variables for configuration:
PORT: HTTP server port (default: 8080)MYSQLDSN: MySQL connection string (format:mysql://user:password@host:port/database)
GET /status- Health check endpoint
POST /todos- Create a new todoGET /todos- List all todosGET /todos/{id}- Get a specific todoPUT /todos/{id}- Update a todoDELETE /todos/{id}- Delete a todo
.
├── cmd/ # CLI commands
│ ├── public_http.go # HTTP server command
│ └── root.go # Root command setup
├── internal/
│ ├── app/
│ │ ├── app.go # Application initialization
│ │ └── router.go # Route setup (TODO: add todo routes)
│ ├── config/
│ │ └── config.go # Configuration management
│ ├── controllers/
│ │ ├── common.go # Common controller utilities
│ │ ├── status.go # Status controller
│ │ └── middlewares/
│ │ ├── panic_recover.go # Panic recovery middleware
│ │ ├── request_logger.go # Request logging middleware
│ │ └── token.go # Token authentication (TODO)
│ └── model/
│ ├── access_token.go # Access token model
│ └── context.go # Context utilities
├── database/
│ └── schema.sql # Database schema (TODO)
├── docker-compose.yml # Development environment
├── docker-compose.prod.yml # Production environment
├── Dockerfile # Application container
├── Makefile # Development commands
└── main.go # Application entry point
make prepare- Start required containers (MySQL)make migrate- Run database migrationsmake run- Start the applicationmake clean- Clean up containers and volumes
The project includes Docker configuration for both development and production:
- Development:
docker-compose.ymlwith MySQL and volume mounting - Production:
docker-compose.prod.ymlwith optimized settings
This project serves as a practice run with the following key tasks to complete:
- 🔄 Database Schema (
database/schema.sql) Model the following entities in the database:
-
Todo
id- UUID (primary key)title- Stringdescription- Stringcompleted- BooleanorganizationId- UUIDaccountId- UUIDcreatedAt- TimestampupdatedAt- Timestamp
-
Comment
id- UUID (primary key)text- StringtodoId- UUID (foreign key referencing Todo)accountId- UUIDcreatedAt- Timestamp
-
🔄 Authentication Middleware (
internal/controllers/middlewares/token.go): The server should verify the access token and obtain its details. -
🔄 Todo API (
internal/app/router.go,internal/controllers/,internal/models,internal/repositories) Implement the following API endpoints. Each endpoint should be protected using thebearer-authplugin and should only allow access to todos and comments for the current organization:GET /todos- Get all todosPOST /todos- Create a new todoPATCH /todos/:id- Update a todoDELETE /todos/:id- Delete a todoGET /todos/:id- Get a todo by id together with all commentsPOST /todos/:id/comments- Create a new comment for a todo
-
🔄 Websockets API Implement WebSocket support. Every change made by a user, should be propagated to every user from the same organization that is currently connected via websocket.
-
🔄 Dockerization (
./Dockerfile) Prepare the application for containerization using Docker. Seedocker-compose.prod.ymlfor the expected configuration.
This project is for educational and practice purposes.