Skip to content

Latest commit

Β 

History

History
118 lines (88 loc) Β· 5.79 KB

File metadata and controls

118 lines (88 loc) Β· 5.79 KB

Go Modulith Template πŸš€

Go Modulith Architecture

Tests Coverage Go License

This is a professional, production-ready template for building Go applications following the Modular Monolith (Modulith) pattern. Designed for high-performance, maintainability, and scalability, it allows your application to evolve from a monolith to microservices without architectural friction.

✨ Key Features

  • πŸ—οΈ Modular Architecture: Clean domain boundaries with decoupling via an internal Event Bus.
  • πŸ“¦ Registry Pattern: Explicit dependency injection without magic for maximum control and testability.
  • πŸ” gRPC & Protobuf: High-performance, type-safe RPC communication with automated generation via buf.
  • πŸ—„οΈ SQLC & Migrations: Type-safe data access and multi-module schema management with golang-migrate.
  • ⚑ High-Performance Caching: Native support for Valkey (the open-source Valkey alternative) for sessions and rate limiting.
  • πŸ” Complete Auth System: Passwordless login, sessions, JWT, refresh tokens, and RBAC.
  • πŸ”— OAuth/Social Login: Integrated with Goth for Google, Facebook, GitHub, Apple, Microsoft, and Twitter/X.
  • πŸ€– Messaging Bot Engine: Built-in support for WhatsApp and Telegram provider integrations.
  • πŸ”Œ WebSocket Real-Time: Bidirectional communication integrated with the event bus for instant notifications.
  • πŸ“Š Observability Stack: Native integration with OpenTelemetry, Jaeger (Tracing), Prometheus (Metrics), and Grafana dashboards.
  • βš™οΈ Flexible Configuration: Hierarchy-based system (PORT > YAML > .env > system ENV > defaults) with source logging.
  • ⚑ Resilience & Errors: Integrated circuit breakers, retries, and a domain-specific error system mapped to gRPC codes.
  • πŸ“§ Notification System: Extensible providers (SendGrid, Twilio, AWS SES/SNS) with template support.
  • πŸ“Š Optional GraphQL: Advanced support with gqlgen for flexible frontend APIs (subscriptions included).
  • πŸ§ͺ Test Utilities: Comprehensive suite (internal/testutil) for integration tests with Testcontainers, gRPC servers, and mocks.
  • πŸ› οΈ DevX Excellence: Hot reload with Air, task automation with Just, and environment diagnostics with doctor.

πŸ› οΈ Prerequisites

  • Go 1.25+
  • Docker & Docker Compose
  • Development tools: sqlc, buf, migrate, air, golangci-lint, just.

πŸš€ Quick Start

1. Automated Setup & Run (Recommended)

The fastest way to get started is using the integrated setup and run command:

git clone https://github.com/LoopContext/go-modulith-template.git my-project
cd my-project
just dev

This single command will:

  1. Start the minimal Docker infrastructure (DB + Valkey).
  2. Wait for the database to be ready.
  3. Run all database migrations.
  4. Seed the database with test users (admin, system, user).
  5. Install frontend dependencies (web/solid-example).
  6. Start the full stack (Backend + Frontend) with Hot Reload in a 3-pane tmux session.

2. See it in Action

To run a complete representative flow (E2E) and see how the system handles Auth, Events, and Logic:

just example

πŸ’‘ Tip: For a full "setup + example" demo in one go, use just demo.

3. Development Mode

Run the monolith with hot reload (monitors code, proto, sql, and configs):

just dev

Run a specific module (e.g., auth):

just dev-module auth

πŸ—οΈ Project Structure

  • cmd/: Main entry points (server, worker, admin tasks, migration ops).
  • internal/: Core shared services (registry, cache, events, authz, telemetry).
  • modules/: Domain-specific modules (auth, stock, etc.). Each module is independent.
  • proto/: Protobuf definitions for gRPC and Event schemas.
  • scripts/: Utility scripts for DevX (scaffolding, validation, e2e).
  • web/: Documentation site and optional frontend examples.

πŸ“– Complete Documentation

πŸ› οΈ Main Commands (just)

  • just proto: Generate gRPC and OpenAPI code.
  • just sqlc: Generate type-safe SQL code.
  • just new-module <name>: Scaffold a new domain module.
  • just setup: Automated, non-interactive setup (infra + migrate + seed).
  • just example: Run a representative example flow (E2E) to see the system in action.
  • just demo: Complete end-to-end demo (setup + example).
  • just test: Run all unit and integration tests.
  • just lint: Run strict linter (MANDATORY for quality).
  • just visualize: Generate an interactive module graph (docs/module-graph.html) with modules (gRPC + event bus) and database (tables from migrations) views; also FORMAT=json|dot for machine-readable output.
  • just admin TASK=<name>: Execute maintenance tasks (e.g., cleanup-sessions).

Made with ❀️ for developers seeking operational excellence.