GoBricks

Enterprise-grade building blocks for Go microservices
GoBricks is an open-source, enterprise-grade Go framework for building robust microservices with modular, reusable components. It provides a complete foundation for developing production-ready applications with built-in support for HTTP servers, AMQP messaging, multi-database connectivity, and clean architecture patterns.
π Features
- ποΈ Modular Architecture: Component-based design with dependency injection
- π HTTP Server: Echo-based server with comprehensive middleware ecosystem
- ποΈ Multi-Database Support: PostgreSQL and Oracle with unified interface
- π¨ AMQP Messaging: RabbitMQ integration with automatic reconnection
- βοΈ Configuration Management: Koanf-based config with multiple sources (YAML, env vars)
- π Built-in Observability: Request tracking, performance metrics, structured logging
- π§ Database Migrations: Flyway integration for schema management
- π§© Plugin System: Easy module registration and lifecycle management
- π Production Ready: Used in enterprise environments
π¦ Installation
go mod init your-service
go get github.com/gaborage/go-bricks@latest
π Quick Start
1. Create Your Application
// cmd/main.go
package main
import (
"log"
"github.com/gaborage/go-bricks/app"
)
func main() {
framework, err := app.New()
if err != nil {
log.Fatal(err)
}
// Register your modules here
if err := framework.Run(); err != nil {
log.Fatal(err)
}
}
2. Create Configuration
# config.yaml
app:
name: "my-service"
version: "v1.0.0"
env: "development"
server:
port: 8080
database:
type: "postgresql"
host: "localhost"
port: 5432
database: "mydb"
username: "postgres"
password: "password"
log:
level: "info"
pretty: true
3. Create a Module
// internal/modules/example/module.go
package example
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/gaborage/go-bricks/app"
)
type Module struct {
deps *app.ModuleDeps
}
func (m *Module) Name() string {
return "example"
}
func (m *Module) Init(deps *app.ModuleDeps) error {
m.deps = deps
return nil
}
func (m *Module) RegisterRoutes(e *echo.Echo) error {
e.GET("/hello", m.hello)
return nil
}
func (m *Module) Shutdown() error {
return nil
}
func (m *Module) hello(c echo.Context) error {
return c.JSON(http.StatusOK, map[string]string{
"message": "Hello from GoBricks!",
})
}
4. Register and Run
// cmd/main.go (updated)
func main() {
framework, err := app.New()
if err != nil {
log.Fatal(err)
}
// Register modules
framework.RegisterModule(&example.Module{})
if err := framework.Run(); err != nil {
log.Fatal(err)
}
}
ποΈ Architecture
GoBricks follows a modular architecture where each business domain is implemented as a module:
βββββββββββββββββββββββββββββββββββββββββββ
β GoBricks App β
βββββββββββββββββββββββββββββββββββββββββββ€
β Module A β Module B β Module C β
βββββββββββββββββββββββββββββββββββββββββββ€
β HTTP Server β Database β Messaging β
βββββββββββββββββββββββββββββββββββββββββββ€
β Logger β Config β Migrations β Utils β
βββββββββββββββββββββββββββββββββββββββββββ
Module System
Each module implements the Module interface:
type Module interface {
Name() string
Init(deps *ModuleDeps) error
RegisterRoutes(e *echo.Echo) error
Shutdown() error
}
Modules have access to shared dependencies:
type ModuleDeps struct {
DB database.Interface // Database connection
Logger logger.Logger // Structured logger
Messaging messaging.Client // AMQP client
}
ποΈ Database Support
GoBricks supports multiple databases through a unified interface:
PostgreSQL
database:
type: "postgresql"
host: "localhost"
port: 5432
database: "myapp"
username: "postgres"
password: "password"
ssl_mode: "disable"
Oracle
database:
type: "oracle"
host: "localhost"
port: 1521
service_name: "ORCL"
username: "system"
password: "password"
π¨ Messaging
AMQP messaging with RabbitMQ:
messaging:
broker_url: "amqp://guest:guest@localhost:5672/"
exchange: "my-service"
routing_key: "events"
virtual_host: "/"
βοΈ Configuration
Configuration management with multiple sources (priority order):
- Environment Variables (highest priority)
- Environment-specific YAML (
config.production.yaml)
- Base YAML (
config.yaml)
- Default Values (lowest priority)
Environment Variables
export APP_NAME="my-service"
export DATABASE_HOST="prod-db.company.com"
export DATABASE_PASSWORD="secure_password"
export LOG_LEVEL="info"
π Observability
Structured Logging
deps.Logger.Info().
Str("user_id", userID).
Int("count", items).
Msg("Processing user items")
Request Tracking
Automatic tracking of:
- HTTP request/response metrics
- Database query performance
- AMQP message statistics
- Request correlation IDs
Health Checks
Built-in endpoints:
/health - Basic health check
/ready - Readiness probe with database connectivity
π Production Features
- Graceful Shutdown: Coordinated shutdown of all components
- Connection Pooling: Optimized database connection management
- Rate Limiting: Built-in request rate limiting
- CORS Support: Configurable cross-origin resource sharing
- Request Validation: Automatic request validation with go-playground/validator
- Security Headers: Essential security headers included
- Recovery Middleware: Panic recovery with logging
π Documentation
π οΈ Examples
See the examples/ directory for complete examples:
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
GoBricks was extracted from production enterprise applications and battle-tested in real-world microservice architectures.
Built with β€οΈ for the Go community