Skip to content

Repository files navigation

modkit logo modkit

Go ReferenceCIcodecovGo Report CardCodeRabbit Pull Request ReviewsLicense: MITStatus: Alpha

A Go framework for building modular backend services, inspired by NestJS.

Note: modkit is in early development. Read the Stability and Compatibility Policy before adopting in production.

modkit brings NestJS-style module organization to Go—without reflection, decorators, or magic. Define modules with explicit imports, providers, controllers, and exports. The kernel builds a dependency graph, enforces visibility, and bootstraps your app deterministically.

⭐ If modkit helps you build modular services, consider giving it a star!

What it does

modkit takes module definitions and deterministically bootstraps a dependency graph into runnable controllers:

flowchart LR
A["Module definitions\n(imports, providers, controllers, exports)"] --> B["Kernel\n(graph + visibility)"]
B --> C["Container\n(lazy singletons)"]
C --> D["Controllers"]
D --> E["HTTP adapter\n(chi router)"]
Loading
  • Module system: explicit imports / exports boundaries
  • Explicit DI: resolve via tokens (module.Get[T](r, token)), no reflection
  • Visibility enforcement: only exported tokens are accessible to importers
  • Deterministic bootstrap: predictable init order with clear errors
  • Thin HTTP adapter: register controllers on a chi router

Why modkit?

modkit is a Go-idiomatic alternative to decorator-driven frameworks. It keeps wiring explicit, avoids reflection, and makes module boundaries and dependencies visible in code.

If you want...modkit gives you...
NestJS-style modules in Goimports, providers, controllers, exports
Explicit dependency injectionString tokens + resolver, no reflection
Debuggable bootstrapDeterministic graph construction with clear errors
Minimal framework overheadThin HTTP adapter on chi, no ORM, no config magic

Compared to Other Go Frameworks

If you use...modkit is different because...
google/wiremodkit adds module boundaries + visibility enforcement
uber-go/fxNo reflection, explicit Build functions
samber/doFull module system with imports/exports
No frameworkStructured module organization without boilerplate

See the full comparison for details.

Requirements

  • Go 1.25.x (CI pinned to 1.25.7)

Installation

Library

go get github.com/go-modkit/modkit

CLI Tool

Install the modkit CLI using go install:

go install github.com/go-modkit/modkit/cmd/modkit@latest

Or download a pre-built binary from the releases page.

Quickstart (CLI)

Use this as the canonical first-run path:

modkit new app myapp
cd myapp
go run cmd/api/main.go
curl http://localhost:8080/health

Expected output:

ok

If this path fails, use the troubleshooting section in Getting Started.

Quick Example

// Define a moduletypeUsersModulestruct{}
func (m*UsersModule) Definition() module.ModuleDef {
return module.ModuleDef{
Name: "users",
Providers: []module.ProviderDef{{
Token: "users.service",
Build: func(r module.Resolver) (any, error) {
returnNewUsersService(), nil
},
}},
Controllers: []module.ControllerDef{{
Name: "UsersController",
Build: func(r module.Resolver) (any, error) {
svc, err:=module.Get[UsersService](r, "users.service")
iferr!=nil {
returnnil, err
}
returnNewUsersController(svc), nil
},
}},
Exports: []module.Token{"users.service"},
}
}
// Bootstrap and servefuncmain() {
app, err:=kernel.Bootstrap(&UsersModule{})
iferr!=nil {
log.Fatal(err)
}
router:=mkhttp.NewRouter()
mkhttp.RegisterRoutes(mkhttp.AsRouter(router), app.Controllers)
mkhttp.Serve(":8080", router)
}

Features

  • Module System — Compose apps from self-contained modules with explicit boundaries
  • Dependency Injection — Providers built on first access, cached as singletons
  • Visibility Enforcement — Only exported tokens are accessible to importers
  • HTTP Adapter — Chi-based router with explicit route registration
  • No Reflection — Everything is explicit and type-safe
  • Deterministic Bootstrap — Predictable initialization order with clear error messages

Feature Matrix

PatternGuideExample CodeExample Tests
AuthenticationAuthentication Guideexamples/hello-mysql/internal/modules/auth/examples/hello-mysql/internal/modules/auth/integration_test.go
ValidationValidation Guideexamples/hello-mysql/internal/validation/ + examples/hello-mysql/internal/modules/users/types.goexamples/hello-mysql/internal/modules/users/validation_test.go
MiddlewareMiddleware Guideexamples/hello-mysql/internal/middleware/ + examples/hello-mysql/internal/httpserver/server.goexamples/hello-mysql/internal/middleware/middleware_test.go
Lifecycle and CleanupLifecycle Guideexamples/hello-mysql/internal/lifecycle/cleanup.go + examples/hello-mysql/cmd/api/main.goexamples/hello-mysql/internal/lifecycle/lifecycle_test.go
Database ProvidersDatabase Providers Guideexamples/hello-postgres/ + examples/hello-sqlite/examples/hello-postgres/internal/smoke/smoke_test.go + examples/hello-sqlite/internal/smoke/smoke_test.go

Migration note: if you used the MySQL example tokens (database.TokenDB), prefer the shared SQL contract tokens (sqlmodule.TokenDB, sqlmodule.TokenDialect) going forward. The MySQL example preserves backward compatibility via token aliases.

Packages

PackageDescription
modkit/moduleModule metadata types (ModuleDef, ProviderDef, Token)
modkit/configTyped environment config module helpers
modkit/kernelGraph builder, visibility enforcer, bootstrap
modkit/httpHTTP adapter for chi router
modkit/loggingLogging interface with slog adapter
modkit/testkitTest harness for bootstrap, overrides, and typed test helpers

Architecture

flowchart LR
subgraph Input
A[📦 Module Definitions]
end
subgraph Kernel
B[🔗 Graph Builder]
C[📦 Container]
end
subgraph Output
D[🎮 Controllers]
E[🌐 HTTP Adapter]
end
A --> B
B --> C
C --> D
D --> E
style A fill:#e1f5fe,stroke:#01579b,color:#01579b
style B fill:#fff3e0,stroke:#e65100,color:#e65100
style C fill:#fff3e0,stroke:#e65100,color:#e65100
style D fill:#e8f5e9,stroke:#2e7d32,color:#2e7d32
style E fill:#e8f5e9,stroke:#2e7d32,color:#2e7d32
Loading

See Architecture Guide for details.

Documentation

Guides:

Reference:

Examples:

How It Compares to NestJS

ConceptNestJSmodkit
Module definition@Module() decoratorModuleDef struct
Dependency injectionConstructor injection via metadataExplicit module.Get[T](r, token)
Route binding@Get(), @Post() decoratorsRegisterRoutes(router) method
MiddlewareNestMiddleware interfacefunc(http.Handler) http.Handler
Guards/Pipes/InterceptorsFramework abstractionsStandard Go middleware

Support

Branding

Branding assets (logo + social preview images) are in assets/branding/stacked-modules/.

Development

make fmt
make lint
make vuln
make test
make test-coverage

Community

Questions? Start a Discussion.

Contributing

See CONTRIBUTING.md. We welcome issues, discussions, and PRs.

Contributors

Contributors

License

MIT — see LICENSE

About

Go-idiomatic modular backend framework with deterministic bootstrapping

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages