Documentation β’ Quick Start β’ Features β’ Examples
Lokstra is a versatile Go web framework that works in two ways:
Use Lokstra as a fast, flexible HTTP router with elegant middleware support.
r := lokstra.NewRouter("api")
r.GET("/", func() string {
return "Hello, Lokstra!"
})
app := lokstra.NewApp("hello", ":3000", r)
app.Run(30 * time.Second)Leverage lazy dependency injection, auto-generated routers, and configuration-driven deployment.
// Type-safe lazy DI
var userService = service.LazyLoad[*UserService]("user-service")
func handler() {
users := userService.MustGet().GetAll()
}1. Install CLI:
go install github.com/primadi/lokstra/cmd/lokstra@latest2. Create Project:
# Interactive template selection
lokstra new myapp
# Or choose specific template
lokstra new blog-api -template 02_app_framework/01_medium_system3. Run:
cd myapp
go run .Done! Your app is running with routes already set up.
go get github.com/primadi/lokstrapackage main
import "github.com/primadi/lokstra"
func main() {
r := lokstra.NewRouter("api")
r.GET("/", func() string {
return "Hello, Lokstra!"
})
app := lokstra.NewApp("hello", ":3000", r)
app.Run(30 * time.Second)
}- π¦ 6+ Production Templates - Router patterns & enterprise frameworks
- π§ Auto-fix Imports - No manual configuration needed
- π Code Generation - Built-in
autogencommand for annotation-based templates - π Always Updated - Templates downloaded from GitHub
lokstra new myapp # Interactive
lokstra new myapp -template 01_router/... # Specific template
lokstra autogen ./myproject # Generate codeType-safe service loading with zero overhead:
var db = service.LazyLoad[*Database]("database")
users := db.MustGet().GetAll() // Loaded once, cached foreverGenerate REST APIs from service definitions:
service-definitions:
user-service:
type: user-service-factory
deployments:
production:
servers:
api:
published-services: [user-service] # Auto-creates REST router!One codebase, multiple topologies:
# Monolith
servers:
all-in-one:
published-services: [user-service, order-service]
# Microservices
servers:
user-api:
published-services: [user-service]
order-api:
published-services: [order-service]Automatic validation with struct tags:
type CreateUserParams struct {
Name string `json:"name" validate:"required"`
Email string `json:"email" validate:"required,email"`
}
func createUser(ctx *request.Context, params *CreateUserParams) error {
// params already validated!
user := db.CreateUser(params.Name, params.Email)
return ctx.Api.Ok(user)
}- 01_router/01_router_only - Pure routing basics
- 01_router/02_single_app - Production single app
- 01_router/03_multi_app - Multiple apps server
- 02_app_framework/01_medium_system - Domain-driven (2-10 entities)
- 02_app_framework/02_enterprise_modular - DDD with bounded contexts
- 02_app_framework/03_enterprise_router_service - Annotation-based enterprise
- π Full Documentation - Complete guide
- π€ AI Agent Guide - For AI assistants (Copilot, Claude, ChatGPT)
- β‘ Quick Reference - Cheatsheet for common patterns
- π Quick Start - Get started in 5 minutes
- π― Router Guide - Use as router (like Echo/Gin)
- ποΈ Framework Guide - Full framework (like NestJS)
- π‘ Examples - Working code samples
- π API Reference - Technical docs
- β‘ CLI Documentation - CLI tool usage
β
29+ handler signatures - Ultimate flexibility
β
Clean middleware - Easy to compose
β
Type-safe DI - Optional, when you need it
β
Auto-generated routes - From services
β
Type-safe - No any casting
β
Zero reflection - In hot path
β
Lazy loading - Memory efficient
β
Optional config - Start with code, scale with YAML
β
Simpler - No decorators, no code generation required
β
Flexible - Use as router OR framework
β
Go-native - Idiomatic Go patterns
β
Deployment agnostic - Monolith β microservices without code changes
lokstra/
βββ cmd/lokstra/ # CLI tool for scaffolding
βββ core/ # Core framework
β βββ deploy/ # Deployment & config
β βββ registry/ # Service registry
β βββ request/ # Request handling
β βββ router/ # HTTP routing
βββ project_templates/ # Project templates
β βββ templates.json # Template registry
β βββ 01_router/ # Router patterns
β βββ 02_app_framework/ # Framework patterns
βββ services/ # Built-in services
βββ middleware/ # Standard middleware
βββ docs/ # Documentation site
- π Documentation
- π‘ Examples
- π Issues
- πΊοΈ Roadmap
Apache 2.0 License - see LICENSE file for details.
Made with β€οΈ by Primadi