Skip to main content
Understanding Mizu’s architecture helps you make better decisions when building applications. This guide explains the design principles, component relationships, and extension points.

Design Principles

1. Standard Library First

Mizu is built on Go’s net/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 main github.com/go-mizu/mizu package:

Middlewares

Separate packages in github.com/go-mizu/mizu/middlewares/*:
  • Each middleware is independent
  • Install only what you need
  • Consistent configuration pattern

Contract

Transport-neutral API definitions in github.com/go-mizu/mizu/contract:
  • Define services as Go structs
  • Generate handlers for REST, JSON-RPC, MCP
  • Generate client SDKs

View

Server-side rendering in github.com/go-mizu/mizu/view:
  • Template engine with layouts
  • Live for real-time updates
  • Sync for state synchronization

Frontend

SPA integration in github.com/go-mizu/mizu/frontend:
  • Development proxy
  • Asset embedding
  • SPA routing

Request Lifecycle

Detailed Flow

  1. HTTP arrives: Go’s net/http parses the request
  2. Ctx created: Mizu wraps request/response in Ctx
  3. Middleware chain: Each middleware can:
    • Modify the request
    • Stop processing (return early)
    • Modify the response
    • Pass to next handler
  4. Router matches: URL pattern matched to handler
  5. Handler executes: Your business logic runs
  6. Response written: Via Ctx methods or raw Writer()
  7. 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

vs. Microframeworks

vs. Enterprise Frameworks

Best Practices

Project Structure

Handler Organization

Dependency Injection

Learn More

Core Concepts

Detailed concept documentation.

Contributing

Contribute to Mizu.