Enterprise-ready Go boilerplate implementing Clean Architecture, RBAC with Casbin, Modular Audit Logging, and Distributed WebSocket scaling.
- Clean Architecture: Strict separation of concerns (Delivery, UseCase, Repository, Entity).
- Advanced RBAC with Casbin: Fine-grained access control using GORM adapter. Policies are stored in the database for dynamic updates.
- Multi-Tenancy (Organization Module): Complete organization-based data isolation with member management, tenant middleware, and GORM scopes for secure multi-tenant operations.
- Distributed WebSockets: Scalable WebSocket management using Redis Pub/Sub backplane, allowing multi-node synchronization.
- Modular Audit Logging: Synchronous activity tracking (LOGIN, REGISTER, UPDATE, DELETE) integrated directly into business UseCases.
- Multi-Provider File Storage: Pluggable storage abstraction supporting Local Disk, AWS S3, MinIO, and Cloudflare R2.
- Automated Cleanup Jobs: Integrated background worker scheduler for database maintenance (token pruning, soft-delete cleanup, log rotation).
- Distributed Tracing (OTEL): Full visibility with OpenTelemetry integration, tracking request flow across HTTP, Database, and Workers.
- Dynamic Search & Filtering: Secure, reusable query builder supporting complex clauses, range filters, and dynamic sorting.
- Secure Authentication: JWT-based auth with stateful session management in Redis for instant token revocation.
- Real-time SSE: Server-Sent Events manager for live one-way data streaming.
- Hardened Security:
- UseCase-level validation (Regex email, password strength).
- Automatic HTTP security headers.
- Go 1.25.5 for critical security fixes.
- Comprehensive Testing:
- Unit Tests: Fast, mock-based verification of logic.
- Integration Tests: Lightweight testing using Singleton Testcontainers pattern.
- E2E Tests: Full HTTP lifecycle validation.
This project is designed with high flexibility. Many core features can be enabled/disabled via environment variables (.env).
| Feature | Env Variable | Default | Description |
|---|---|---|---|
| RBAC Authorization | CASBIN_ENABLED |
false |
Enables Casbin authorization checks. If false, authorization is bypassed. |
| Casbin Sync | CASBIN_WATCHER_ENABLED |
false |
Enables policy sync across instances via Redis. Required for multi-replica setups. |
| Rate Limiter | RATE_LIMIT_ENABLED |
true |
Limits requests per second (RPS) per IP to prevent DoS/Brute Force. |
| Distributed WS | WEBSOCKET_DISTRIBUTED_ENABLED |
false |
Enables WebSocket message sync via Redis Pub/Sub. Required for horizontal scaling. |
| Configuration | Env Variable | Default | Description |
|---|---|---|---|
| Trusted Proxies | SERVER_TRUSTED_PROXIES |
Empty | Comma-separated list of trusted Load Balancer IPs/CIDRs. |
| CORS Origins | CORS_ALLOWED_ORIGINS |
* |
Allowed domains for CORS. |
| JWT Secrets | JWT_ACCESS_SECRETJWT_REFRESH_SECRET |
- | Critical: Must be random strings (min 32 chars). |
| Configuration | Env Variable | Default | Description |
|---|---|---|---|
| OTEL Tracing | OTEL_ENABLED |
false |
Enables OpenTelemetry tracing. |
| OTEL Service | OTEL_SERVICE_NAME |
queue-base-api |
Service name shown in Jaeger/Tempo. |
| Collector URL | OTEL_COLLECTOR_URL |
localhost:4317 |
OTLP gRPC collector endpoint (e.g. Jaeger). |
| Configuration | Env Variable | Default | Description |
|---|---|---|---|
| Driver | STORAGE_DRIVER |
local |
Storage strategy: local or s3. |
| Root Path | STORAGE_LOCAL_ROOT_PATH |
./uploads |
Local directory for file storage. |
| S3 Endpoint | STORAGE_S3_ENDPOINT |
- | Custom S3 endpoint (required for MinIO/R2). |
| Configuration | Env Variable | Default | Description |
|---|---|---|---|
| Rate Limit Store | RATE_LIMIT_STORE |
memory |
Counter storage: memory (single instance) or redis (distributed). |
| WS Ping Period | WEBSOCKET_PING_PERIOD |
Auto | Keep-alive ping interval (default: 90% of Pong Wait). |
Choose the configuration that matches your infrastructure scale.
Suitable for development, small VPS, or simple deployments.
# No need for distributed sync
RATE_LIMIT_STORE=memory
WEBSOCKET_DISTRIBUTED_ENABLED=false
CASBIN_WATCHER_ENABLED=falseSuitable for high-availability setups with multiple API replicas. Requires a shared Redis instance.
# Sync state via Redis
RATE_LIMIT_STORE=redis
WEBSOCKET_DISTRIBUTED_ENABLED=true
CASBIN_WATCHER_ENABLED=true
# Security behind Load Balancer
SERVER_TRUSTED_PROXIES=10.0.0.0/8,172.16.0.0/12 # IPs of your LB/Ingress| Category | Technology | Description |
|---|---|---|
| Language | Go 1.25.5+ | Core programming language |
| Framework | Gin Gonic | High-performance HTTP framework |
| Database | MySQL 8.0 | Primary relational database |
| Cache/Session | Redis 7 | Session storage & WS Pub/Sub backplane |
| Authorization | Casbin | RBAC model & Policy enforcement |
| Migrations | golang-migrate | Database schema management |
| Testing | Testcontainers | Real instances for integration tests |
- Go: Version 1.25.5 or higher.
- Docker & Docker Compose: For running MySQL and Redis services easily.
- Make: For running automation commands defined in
Makefile. - Air (Optional): For live reloading during development.
go install github.com/air-verse/air@latest
- Swag CLI (Optional): For regenerating API docs.
go install github.com/swaggo/swag/cmd/swag@latest
- Golang Migrate (Optional): If you want to run migrations manually without the Makefile helper.
- Clone & Configure:
git clone https://github.com/Roisfaozi/queue-base.git cd queue-base cp .env.example .env.local - Recommended Branch Model:
main= production-readystaging= release candidate / pre-release integrationdev= daily integration branch
- Create Worktree For Daily Development:
Notes:
make wt-new feat/my-feature
- branch name can be passed directly after
wt-new - base branch defaults to current checked out branch
- optional arg kedua override base branch, contoh
make wt-new feat/my-feature staging - default worktree root is
.worktrees/inside repo - each worktree gets its own
.env.local - if you prefer sibling folders, override
WORKTREE_ROOT
- branch name can be passed directly after
- Start Infrastructure:
Auto behavior:
make dev-up
- initializes
.env.localwhen missing - syncs missing keys from
.env.example - uses worktree-specific compose project name and ports
- initializes
- Run Migrations & Seeding:
make migrate-up-local make seed-up
- Run Application:
make run
If you want old single-checkout flow:
cp .env.example .env.local
make docker-dev
make migrate-up
make runThis repo supports worktree-based parallel development.
Primary use cases:
- split frontend and caller logic into separate branches
- run multiple feature streams from
dev - isolate docker ports and local env per branch
- avoid branch switching churn in one checkout
- default worktree root is
.worktrees/inside repo - each worktree gets branch-specific
.env.local - compose project name is unique per worktree
- local ports are derived per worktree slug
wt-new,wt-enter,dev-up, anddev-statusauto-manage env setup
| Command | Function | Main Use |
|---|---|---|
make wt-new feat/x [base] |
Create new git worktree and bootstrap env | Start new feature stream from current branch or explicit base |
make wt-list |
List all git worktrees | Inspect active worktrees |
make wt-path feat/x |
Print worktree path for branch | Quick path lookup |
make wt-enter feat/x |
Ensure env for target worktree and print path | Re-open existing worktree safely |
make wt-rm feat/x |
Stop local stack if needed and remove worktree | Clean finished feature stream |
make wt-prune |
Prune stale worktree metadata | Cleanup broken or removed entries |
make env-init |
Create .env.local and assign isolated ports |
Bootstrap env in current worktree |
make env-sync |
Append missing keys from .env.example |
Keep local env aligned after template changes |
make dev-up |
Start docker compose stack for current worktree | Daily local development start |
make dev-down |
Stop docker compose stack for current worktree | Stop only current branch stack |
make dev-reset |
Stop stack and remove local volumes | Reset local DB/cache state |
make dev-status |
Show branch, compose project, ports, and container state | Debug local worktree environment |
make migrate-up-local |
Run DB migrations against current .env.local |
Prepare schema for current worktree |
make migrate-down-local |
Roll back one migration against current .env.local |
Local rollback |
make test-local |
Run narrow local tests | Fast loop in current worktree |
make doctor |
Check git, docker, pnpm, go, and env state | Validate development readiness |
feat/frontend-dashboard- focus:
apps/web,apps/client,packages/*
- focus:
feat/caller-runtime- focus: counter/station runtime, queue serving, realtime
feat/queue-core- focus: queue lifecycle, queue journeys, domain rules
make wt-new feat/frontend-dashboard
cd .worktrees/feat-frontend-dashboard
make dev-up
make migrate-up-local
make test-localOverride base branch:
make wt-new feat/caller-runtime staging
cd .worktrees/feat-caller-runtime
make dev-upFor existing worktree:
make wt-enter feat/frontend-dashboard
cd .worktrees/feat-frontend-dashboard
make dev-upTo use sibling worktree root instead of .worktrees/:
make wt-new feat/frontend-dashboardWe use a layered testing strategy optimized for both speed and reliability.
| Command | Type | Description |
|---|---|---|
make test-unit |
Unit | Runs mock-based tests for internal/pkg logic. |
make test-integration |
Integration | Uses Singleton Containers for DB/Redis logic. |
make test-e2e |
E2E | Validates full HTTP request/response flows. |
make test-all |
Full Suite | Executes all test layers sequentially. |
make test-coverage |
Coverage | Generates an interactive HTML coverage report. |
Note: Integration and E2E tests require Docker. We use a Singleton Container Pattern to reuse a single database/redis instance across the entire suite, drastically reducing execution time and resource usage.
The project follows a standard Go project layout suitable for scalable microservices or monolithic APIs.
.
βββ .air.toml # Configuration for Air (live reloading)
βββ Makefile # Automation commands (build, test, migrate, run, mocks)
βββ README.md # Main project documentation
βββ docker-compose.yml # Docker services definition (MySQL, Redis)
βββ go.mod # Go dependency definitions
β
βββ apps/
β βββ web/ # Next.js Frontend (Legacy)
β βββ client/ # React Router 7 Frontend (New)
β
βββ packages/
β βββ ui/ # Shared React UI components (@casbin/ui)
β
βββ cmd/
β βββ api/ # Application entry point (main.go)
β
βββ db/
β βββ migrations/ # Database schema migration files (.sql)
β βββ seeds/ # Initial data seeding scripts (e.g. bootstrapping)
β
βββ docs/ # Auto-generated Swagger/OpenAPI documentation files
β
βββ documentation/ # Project guides and additional documentation
β βββ architecture/ # System design and architecture blueprints
β βββ guides/ # Developer guides (API, Storage, Testing, SSE/WS, etc.)
β βββ ops/ # Operations runbooks and project roadmaps
β βββ productplan/ # PRDs, wireframes, and UI specs
β
βββ postman/ # Postman collections for testing
β βββ Casbin Project API.postman_collection.json # Main collection
β βββ Casbin Project API - Dynamic Search.postman_collection.json # Dynamic search tests
β βββ Casbin Project API - Realtime.postman_collection.json # Realtime features (WS, SSE)
β βββ ...
β
ββββinternal/ # Private application code (not importable by other apps)
βββ config/ # Configuration loading & app initialization wiring
βββ middleware/ # HTTP Middlewares (Auth, Casbin Enforcer, CORS, OTEL)
βββ router/ # Gin router setup and route registration
βββ worker/ # Background tasks, handlers & scheduler
β
βββ modules/ # Domain-specific modules following Clean Architecture
βββ auth/ # Authentication logic & JWT handling
βββ user/ # User management (CRUD) & Avatar Upload
βββ role/ # Role management
βββ permission/ # Permission/Policy management (Casbin)
βββ access/ # Access Right & Endpoint management
- Documentation Index
- System Architecture
- Developer Flow
- Getting Started
- API Usage Guide
- API Access & RBAC
- Multi-Tenancy Architecture
- Testing Strategy
- Real-time (WS & SSE)
- Dynamic Search
- Multi-Provider Storage
- Observability (Tracing/Metrics)
- Maintenance & Scheduler
- Frontend Structure
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.