Skip to main content
This guide presents recommended patterns for structuring Mizu projects, from simple scripts to production applications.

Simple projects

For small projects or prototypes, everything can live in a single file:
This is fine for scripts, tools, and learning. No ceremony needed.

Standard layout

For larger applications, separate concerns into packages:

main.go

The entry point sets up the app and routes:

handlers/users.go

Handlers focus on HTTP concerns:

services/user_service.go

Services contain business logic:

models/user.go

Models define data structures:

Clean architecture

For complex applications, use a layered architecture:

Benefits

Dependency injection

Pass dependencies explicitly:

Static files and templates

Include static files and templates:

embed.go

main.go

Configuration

Use environment variables with sensible defaults:

Testing

Keep tests next to the code they test:
Or use a separate test directory for integration tests:

Best practices

  1. Keep main.go small - Only setup and wiring
  2. Handlers are thin - Extract business logic to services
  3. One package per concern - Don’t mix handlers with models
  4. Use interfaces at boundaries - Makes testing easier
  5. Prefer explicit over implicit - Pass dependencies, don’t use globals
  6. Group related routes - Use app.Group() for organization

Anti-patterns to avoid

  • God packages - utils, helpers, common
  • Circular imports - Usually means wrong package boundaries
  • Business logic in handlers - Keep handlers focused on HTTP
  • Global state - Makes testing difficult

Next steps

Testing

Write tests for your handlers.

Deployment

Deploy to production.