Design Principles
1. Standard Library First
Mizu is built on Go’snet/http package:
2. Thin Abstractions
Mizu adds minimal layers on top of the standard library:3. Composition Over Inheritance
Everything composes through functions:4. Explicit Over Magic
No reflection-based routing, no DI containers, no hidden behavior:Component Architecture
Core
The maingithub.com/go-mizu/mizu package:
| Component | Responsibility |
|---|---|
| App | Server lifecycle, configuration |
| Router | URL pattern matching |
| Handler | Request processing signature |
| Ctx | Request/response wrapper |
Middlewares
Separate packages ingithub.com/go-mizu/mizu/middlewares/*:
- Each middleware is independent
- Install only what you need
- Consistent configuration pattern
Contract
Transport-neutral API definitions ingithub.com/go-mizu/mizu/contract:
- Define services as Go structs
- Generate handlers for REST, JSON-RPC, MCP
- Generate client SDKs
View
Server-side rendering ingithub.com/go-mizu/mizu/view:
- Template engine with layouts
- Live for real-time updates
- Sync for state synchronization
Frontend
SPA integration ingithub.com/go-mizu/mizu/frontend:
- Development proxy
- Asset embedding
- SPA routing
Request Lifecycle
Detailed Flow
- HTTP arrives: Go’s
net/httpparses the request - Ctx created: Mizu wraps request/response in
Ctx - Middleware chain: Each middleware can:
- Modify the request
- Stop processing (return early)
- Modify the response
- Pass to next handler
- Router matches: URL pattern matched to handler
- Handler executes: Your business logic runs
- Response written: Via
Ctxmethods or rawWriter() - Middleware unwinds: Post-processing in reverse order
Extension Points
Custom Middleware
Custom Error Handler
Custom Not Found
Custom Transports
Implement the transport interface for Contract:Custom SDK Generators
Implement the generator interface:Performance Characteristics
Memory
- Ctx is pooled and reused
- Minimal allocations per request
- No reflection in hot paths
Latency
- Router uses radix tree (O(n) where n = path length)
- Middleware adds ~100ns per layer
- No regex matching in routes
Concurrency
- Each request runs in its own goroutine
- No global locks in hot paths
- Ctx is not safe for concurrent use
Comparison with Other Architectures
vs. MVC Frameworks
| Aspect | MVC (Rails, Django) | Mizu |
|---|---|---|
| Structure | Opinionated | Flexible |
| ORM | Included | Bring your own |
| Views | Included | Optional (View package) |
| Learning curve | Steeper | Gentler |
vs. Microframeworks
| Aspect | Microframeworks (Flask, Sinatra) | Mizu |
|---|---|---|
| Core size | Similar | Similar |
| Ecosystem | External | Integrated |
| Type safety | Dynamic | Static |
vs. Enterprise Frameworks
| Aspect | Enterprise (Spring, ASP.NET) | Mizu |
|---|---|---|
| DI container | Yes | No |
| Configuration | Heavy | Minimal |
| Startup time | Slower | Fast |
| Memory | More | Less |