Features at a Glance
Everything included out of the box when you scaffold a project with GoForge (Go 1.25+), organized by subsystem with direct links to deep-dive documentation.
1. Core Architecture & Pure-Go DI (core/di, boot)
- Pure-Go Reflection DI Container: Zero external DI runtime dependencies; topological dependency resolution with 3-color DFS cycle detection (
A -> B -> A). - Modular Composition:
di.Module(Providers,Invokes,Models, nestedModules),di.Bind[I],di.BindBoth[I],di.AutoCollect[I], anddi.CollectModels. - Lifecycle Hooks:
di.Lifecycle(OnStartwith reverse rollback on failure;OnStopin LIFO order soEventBus.Shutdowndrains beforeDatabase.Close). - Multi-Server Runner:
boot.New/boot.NewWithConfigruns HTTP and gRPC concurrently undererrgroupwithSIGINT/SIGTERMgraceful shutdown.
→ Architecture & Lifecycle · Dependency Injection
2. HTTP Server & Huma v2 OpenAPI (boot/server)
- 6-Layer Hardened Middleware Pipeline:
Recovery()→RequestID()→CustomLogger()→CORSWithConfig()→RateLimiterWithStore()→ErrorHandler(), followed by globalAppKeyWithConfig(). - Kubernetes-Ready Probes: Public
GET /health(liveness) andGET /ready(2s-timeoutdb.Pingreadiness check). - Hardened Defaults:
SetTrustedProxies(nil)unlessTRUSTED_PROXIESis set, configurableReadHeaderTimeout(10s),ReadTimeout(30s),WriteTimeout(30s),IdleTimeout(120s),1 MiBMaxHeaderBytes, and TLS 1.2+. - Huma v2 OpenAPI 3.1: Per-service interactive docs (
/api/docs/<svc>),.jsonspecs, and/schemasviaserver.NewHumaConfig.
3. Security & Limen Authentication
- Constant-Time
X-App-KeyAuth:crypto/subtle.ConstantTimeComparewith fail-closed startup (ValidateForServe()rejects emptyAPP_KEY). - Debug-Gated Docs:
/api/docs*,/openapi*,/docs*bypassX-App-Keyonly whenAPP_DEBUG=true. - Strict CORS: Wildcard
*never sendsAccess-Control-Allow-Credentials; explicitCORS_ALLOWED_ORIGINSecho exact origins +Vary: Origin+ credentials. - Bounded Rate Limiter:
LimiterStorecapped at10,000clients with3midle TTL eviction and cleanClose()lifecycle. - Request Correlation & Masking: Validated/generated 128-bit
X-Request-ID; sanitized 500 JSON responses without leaking internals. - Limen User Sessions: Built-in
.agent/skills/limen-auth/workflow (github.com/thecodearcher/limen, GORM adapter, bcryptcredential-password,/register,/login,/me,/logout,SessionFromRequest).
→ Security & Authentication · Tutorial Ch. 2: Limen Auth
4. gRPC Server & Interceptors (boot/server/grpc.go)
- Auto-Collected Registries: Services implementing
server.GRPCRegistryare collected viadi.AutoCollect[server.GRPCRegistry](). - Full Unary & Stream Interceptors: Recovery → Logger →
x-app-keymetadata auth → per-IP port-stripped RateLimit (net.SplitHostPort). - TLS, Health & Reflection:
GRPC_TLS_ENABLEDcert/key support, standardgrpc_health_v1(SERVING/NOT_SERVING), and optionalGRPC_REFLECTION.
5. Multi-Driver Database, Migrations, SQLC & Seeders (core/database)
- 4 Database Drivers:
sqlite(CGO, WAL mode +_foreign_keys=on+_busy_timeout=5000),postgres(pgx/v5),mysql, andsqlserver— unused drivers are pruned bygoforge new. - Injection-Safe DSNs & Pooling:
mysqldriver.Config.FormatDSN()andurl.URL/url.UserPasswordescaping,DB_SSL_MODE,MaxOpenConns,MaxIdleConns,ConnMaxLifetime, and 5s startup ping. - Dual Migration Modes: Schema-driven Atlas SQL migrations (
go run ./app/main.go loader) or GORM AutoMigrate (DB_MIGRATOR=gorm). - SQLC v2: Type-safe Go queries generated from
internal/database/queries/*.sql. - Transactional Seeder Framework:
database.Seederregistry (RegisterSeeder,ResolveSeeder,database.Callinside a singledb.Transaction) +DatabaseSeeder&TodoSeeder.
→ Database, Migrations & Seeders
6. Generic Event Bus (core/events)
- Type-Safe Pub/Sub: Generic
Listener[T],On[T],Off[T],ListenerCount. - Async & Sync Dispatch: Non-blocking buffered
Dispatch[T](context.WithoutCancel(ctx)safe) and blockingDispatchSync[T](errors.Join+ctx.Done()). - Resilience:
invokeSafepanic recovery, pointer-identity deduplication, andShutdown(ctx)draining onSIGTERM.
7. Errors, Validation & Configuration
- Canonical
AppError(core/errors): 10 named constructors (400–503),Wrap,WithDetails,Respond,ErrorHandler, and inspection helpers (IsNotFound, etc.). - Dedicated Validation (
core/validator): Standalonevalidator/v10(validate:tags, decoupled from Ginbinding:), English translations, JSON field names (stripping,omitempty), andRegisterRuleWithMessage. - Viper Configuration (
core/config): 44+ typed env vars acrossApp,HTTP,GRPC,DB,Encrypt, andLogwithValidate()&ValidateForServe().
→ Error Handling · Validation · Configuration
8. Typed Clients (boot/client)
- HTTP Client:
NewHttpClientwithWithTimeout,WithHttpAppKey, non-mutatingDo()(clones requests),GetWithContext,PostWithContext. - gRPC Client:
NewGrpcClientviagrpc.NewClientwith overridable TLS credentials,WithAppKey, andWithStreamAppKey.
9. Observability, Pretty Logger & Interactive TUI (core/console)
- Zerolog Pipeline:
LOG_TYPE(terminal/file/both),LOG_FORMAT(log/json),LOG_COLOR(auto/always/never,NO_COLOR,FORCE_COLOR). prettyWriter& Gin Redirect: Colorized HTTP/gRPC/Route logs with latency color thresholds (<100ms,<500ms,>=500ms).- Bubble Tea TUI Dashboard: Full-screen split-panel dashboard (
All logs,HTTP,gRPC,System) with live server status, request/route/error counters, 5,000-line ring buffer, and--no-tuiflag.
10. 24-Command CLI & App Console (goforge-cli)
- Interactive Command Center: Run
goforgewith no args to browse scaffolding commands in a Bubble Tea TUI. - Full Scaffolding Suite:
new,app serve,gen:service/rem:service,gen:event,gen:command/rem:command,gen:config,gen:proto/rem:proto,rem:grpc,migrate,loader,gen:migration/rem:migration,db:seed/gen:seeder/rem:seeder,gen:sqlc/rem:sqlc,gen:key/rem:key,version,readme.
11. AI-Agent Native Workspace (AGENT.md & .agent/)
- Agent-Agnostic Guidance:
AGENT.md+.agent/settings.jsonwork out of the box with Antigravity, Claude Code, Cursor, Codex, and other AI assistants. - 4 Binding Rule Files:
architecture.md,api-design.md,database.md,testing.md+ 10 non-negotiable rules. - 6 Workflow Commands:
context,next,review,ship-feature,state,session-end. - 10 Domain Skills & 12 Scripts:
cli-commands,configuration,database-migrations,error-handling,goforge-core,http-grpc,limen-auth,testing,tls,validation.
→ AI Agent Workspace, Rules & Skills
12. Testing & Production Deployment
- Test Patterns (
internal/tests/): Isolatedt.TempDir()SQLite unit, HTTP middleware, gRPC client, andboot.NewWithConfigintegration tests. - Dev & Prod Tooling:
air.tomllive reload,-tags prodbuilds (excludingloader), and multi-stagegolang:1.25-alpine→alpine:3.21non-root Docker builds withHEALTHCHECK.
