engine

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 9 Imported by: 0

README

mbu-id/engine

Engine is a powerful, production-ready framework for rapidly developing Go microservices at mbu-id.

Engine accelerates microservice delivery by providing robust, integrated libraries for essential infrastructure, including databases (MongoDB, PostgreSQL, Redis), message brokers (RabbitMQ), and transport protocols (REST, gRPC). Its built-in lifecycle management, structured logging, and unified architecture eliminate boilerplate and complexity.

With Engine, development can confidently build, deploy, and scale microservices faster—focusing purely on delivering impactful business logic, not managing infrastructure.

✨ Features

  • Lifecycle hooks: Register OnStart and OnStop functions for any dependency.
  • Signal handling: Handles SIGINT/SIGTERM for graceful shutdown.
  • Centralized config and structured logging: Built-in logger with zap.
  • Modular libraries: Built-in for MongoDB, PostgreSQL, Redis, RabbitMQ, REST, gRPC, and more.

📡 Built-in Communication Libraries

This engine package provides robust, production-ready libraries for working with external systems and inter-service communication, including:

  • Data Stores:
    • MongoDB: engine/ds/mongo — Full-featured library for MongoDB operations and lifecycle management.
    • PostgreSQL: engine/ds/postgres — Abstraction for PostgreSQL with connection pooling and helpers.
    • Redis: engine/ds/redis — Fast access and management of Redis with ready-to-use utilities.
  • Message Brokers:
    • RabbitMQ: engine/broker/rabbitmq — Complete AMQP (RabbitMQ) client with publisher/subscriber abstractions and reliability features.
    • NATS: engine/broker/nats — NATS client integration for lightweight messaging.
  • Transport Protocols:
    • gRPC: engine/transport/grpc — Idiomatic server/client layer, service discovery, and registry integration.
    • REST: engine/transport/rest — Flexible HTTP/REST server with built-in middleware and error handling.
    • WebSockets: engine/transport/ws — WebSocket server implementation for real-time communication.

🛠 Core & Utilities

  • Common: engine/common — Base repositories, use cases, and shared utilities.
  • Validation: engine/validate — Input validation and assertions.
  • Logging: engine/log — Environment-aware structure logging.

📝 Example: main.go

package main

import (
    "context"
    "os"

    "github.com/joho/godotenv"

    "github.com/mbu-id/engine"
    "github.com/mbu-id/engine/ds/mongo"
    "github.com/mbu-id/engine/broker/rabbitmq"
    "github.com/mbu-id/engine/transport/rest"

    "github.com/yourrepo/service/proto"
)

func init() {
    godotenv.Load()
	engine.Init("service-name", "v1.0.0", false)
}

func main() {
    engine.OnStart(func(ctx context.Context) error {
		mongo.NewConnection(mongo.ConfigDefault(os.Getenv("MONGODB_DATABASE")), engine.Logger)

		return rabbitmq.NewConnection(rabbitmq.ConfigDefault(engine.Config.Name), engine.Logger)
    })

    engine.OnStop(func(ctx context.Context) {
        rabbitmq.CloseConnection()
         mongo.CloseConnection()
    })

    engine.Run(func(ctx context.Context) {
        restServer := rest.NewServer(&rest.Config{
            Server:    os.Getenv("REST_SERVER"),
            IsDev:     engine.Config.IsDev,
            JwtSecret: os.Getenv("JWT_SECRET"),
        }, engine.Logger, registerRoutes)
        go restServer.Start(ctx)
        defer restServer.Shutdown(ctx)

        <-ctx.Done()
    })
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Config *config
	Logger *zap.Logger
)

Functions

func Init

func Init(name string, version string, isDev bool)

func OnStart

func OnStart(hook StartHook)

func OnStop

func OnStop(hook StopHook)

Register a shutdown hook (LIFO)

func Run

func Run(appMain func(ctx context.Context))

Orchestrate startup/shutdown and run main app logic

Types

type Lifecycle

type Lifecycle struct {
	// contains filtered or unexported fields
}

type StartHook

type StartHook func(ctx context.Context) error

type StopHook

type StopHook func(ctx context.Context)

Directories

Path Synopsis
broker
rabbitmq
Package rabbitmq provides a RabbitMQ client for publishing and subscribing to messages.
Package rabbitmq provides a RabbitMQ client for publishing and subscribing to messages.
ds
postgres
Package postgres provides PostgreSQL database connectivity and repository patterns using Bun ORM with integrated logging and generic base repository functionality.
Package postgres provides PostgreSQL database connectivity and repository patterns using Bun ORM with integrated logging and generic base repository functionality.
transport
ws
Package ws provides WebSocket transport logic for message sending via RabbitMQ.
Package ws provides WebSocket transport logic for message sending via RabbitMQ.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL