Working examples for user management, e-commerce, multi-tenant SaaS, event logging, and more. All under 300 lines of code.
Start with these to understand core concepts
~200 lines • Simple API
Complete authentication system with email lookups, role-based queries, and automatic Redis indexing. Perfect starting point for learning SmarterBase.
// Create user with auto-indexing
user, _ := userManager.CreateUser(ctx,
"alice@example.com",
"Alice Smith",
"admin",
)
// Indexes updated automatically:
// ✅ email → user_id (O(1) lookup)
// ✅ role → [user_ids] (multi-value)
// O(1) email lookup via Redis
user, _ := userManager.GetUserByEmail(ctx,
"alice@example.com",
)
// O(1) role-based query
admins, _ := userManager.ListUsersByRole(ctx,
"admin",
)
// Returns all admin users instantly
// Type-safe batch loading (v1.6)
users, _ := smarterbase.BatchGet[User](
ctx, store, userKeys,
)
// 🚀 10-100x faster than loops
// 🎯 Replaces 15 lines of boilerplate
// ✅ Compile-time type safety
~250 lines • Core API
Order management with atomic status transitions, distributed locks, and revenue calculations. Learn how to handle critical operations safely.
// Atomic status update with distributed lock
err := smarterbase.WithAtomicUpdate(
ctx, store, lock,
"orders/"+orderID, 10*time.Second,
func(ctx context.Context) error {
var order Order
store.GetJSON(ctx, key, &order)
// Validate transition
if !isValid(order.Status, "shipped") {
return errors.New("invalid transition")
}
order.Status = "shipped"
return store.PutJSON(ctx, key, &order)
},
)
// ✅ No race conditions
// ✅ Automatic retry on conflict
// ✅ TTL prevents deadlocks
Choose based on your use case or learning goals
Redis fallback patterns with QueryWithFallback. Automatic profiling, graceful degradation, and resilience best practices.
SaaS configuration management with per-tenant isolation, plan upgrades, and feature flags.
Append-only event logs with JSONL format. Perfect for audit trails and activity tracking.
Evolve schemas without downtime using versioning and lazy migrations on read.
Prometheus metrics integration with operation counters, latency histograms, and error tracking.
4 progressive examples: Quickstart, CRUD, Indexing, and Versioning. Perfect for rapid development.
Choose the right example for your needs
| Example | Lines | API | Complexity | Key Features | Best For |
|---|---|---|---|---|---|
|
User Management
View →
|
~200 | Simple |
Beginner |
Indexes
BatchGet
CRUD
|
Auth systems, User profiles |
|
E-Commerce Orders
View →
|
~250 | Core |
Intermediate |
Locks
Atomic
Indexes
|
Orders, Invoices, Fulfillment |
|
Multi-Tenant Config
View →
|
~300 | Core |
Advanced |
SaaS
Isolation
Plans
|
SaaS Config, Feature Flags |
|
Event Logging
View →
|
~150 | Core |
Beginner |
JSONL
Streaming
Append
|
Audit Trails, Activity Logs |
|
Schema Migrations
View →
|
~180 | Core |
Intermediate |
Versioning
Migration
|
Schema Evolution |
|
Metrics Dashboard
View →
|
~120 | Core |
Beginner |
Prometheus
Metrics
|
Production Monitoring |
Progress from basics to advanced patterns
Start here to learn CRUD operations, indexes, and BatchGet[T]
Master distributed locks, atomic updates, and transactions
Advanced SaaS patterns with tenant isolation and plan management
After completing these examples, you'll understand 90% of SmarterBase patterns. Check out the full documentation for production deployment.
View Full DocumentationGet started in under 1 minute
go get github.com/adrianmcphee/smarterbase
docker run -d -p 6379:6379 redis:7-alpine
git clone https://github.com/adrianmcphee/smarterbase.git
cd smarterbase/examples/user-management
go run main.go