Blog API โ Clean Architecture in Go
A production-ready Blog API built using Golang and Clean Architecture principles, focusing on scalability, observability, and maintainability.
The project demonstrates real-world backend patterns such as async structured logging, Redis caching, hot-reloadable configuration, and database migrations.
โจ Features
๐ฟ Branch Strategy
| Branch |
Description |
main |
API implemented using Fiber |
migration-echo |
Same API implemented using Echo |
The domain and usecase layers remain unchanged across branches, showcasing framework portability.
๐ Getting Started
Prerequisites
- Go 1.24+
- PostgreSQL
- Redis
- Docker (optional)
Clone the Repository
git clone https://github.com/your-username/blog-api.git
cd blog-api
โ๏ธ Configuration
Configuration is managed using Koanf v2 with support for:
YAML / JSON files
Environment variables
Runtime hot reloads
Configuration updates are applied using atomic pointer swaps, ensuring:
Lock-free reads
Zero downtime reloads
๐๏ธ Database Migrations
Run migrations using Goose:
make migrate-up
Rollback:
make migrate-down
โถ๏ธ Run the Application
Local
make run
Docker
docker build -t blog-api .
docker run -p 8080:8080 blog-api
๐ Swagger API Docs
Once the server is running:
http://localhost:8080/swagger/index.html
๐งช Validation
Request payloads validated using validator v10
Validation errors are standardized and user-friendly
๐งต Logging
Uber Zap with async log writes
Structured JSON logs
Correlation-friendly fields (request ID, method, latency)
๐ง Architectural Goals
Framework independence
Explicit dependencies
Predictable behavior under load
Observability-first design
Minimal runtime overhead
๐ Future Improvements
Distributed tracing
Rate limiting
Background workers
Metrics via Prometheus