Skip to main content
This guide walks you through creating a frontend application with Mizu using the CLI. You’ll have a working app with hot reload in under 5 minutes.

Prerequisites

Before starting, make sure you have:
  • Go 1.22 or later - Download Go
  • Node.js 18 or later - Download Node.js (for SPA frameworks)
  • Mizu CLI - Install with go install github.com/go-mizu/mizu/cmd/cli@latest
Verify your installation:

Create Your First App

The fastest way to get started is using the Mizu CLI to scaffold a new project.

Step 1: List Available Templates

See all available frontend templates:
You’ll see templates for:
  • frontend/react - React with Vite and TypeScript
  • frontend/vue - Vue 3 with Vite and TypeScript
  • frontend/svelte - Svelte with Vite and TypeScript
  • frontend/htmx - HTMX with Go templates
  • And more…

Step 2: Create a New Project

Let’s create a React application:
Or create an HTMX application:
The CLI will:
  1. Create the project directory structure
  2. Generate both Go backend and frontend code
  3. Initialize Go modules
  4. Install npm dependencies (for SPA frameworks)

Step 3: Navigate to Your Project

Project Structure

Your new project has a clear structure:

React/Vue/Svelte Projects

HTMX Projects

Running in Development

For SPA Projects (React/Vue/Svelte)

The easiest way is using the Makefile:
This command:
  1. Starts the Go backend server on port 3000
  2. Starts the frontend dev server (Vite) on port 5173
  3. Proxies requests through the Go server
What’s happening:
  • Visit http://localhost:3000 to see your app
  • The Go server proxies frontend requests to Vite
  • Changes to frontend code hot-reload instantly
  • Changes to Go code require restarting the server

Manual Development

You can also run the servers separately:

For HTMX Projects

HTMX projects don’t need a separate dev server:
Or:
Visit http://localhost:3000 and you’re ready to go!

Understanding the Code

Let’s look at the key files:

Backend: app/server/app.go

Key points:
  • frontend.ModeAuto automatically switches between dev and production
  • In development, requests proxy to the dev server
  • In production, files are served from the embedded dist folder
  • API routes (starting with /api) bypass the frontend middleware

API Routes: app/server/routes.go

These routes are always handled by Go, never proxied to the frontend.

Frontend: frontend/src/App.tsx (React example)

The frontend calls the Go backend API and displays the response.

Making Changes

Frontend Changes (React/Vue/Svelte)

  1. Edit any file in frontend/src/
  2. Save the file
  3. See changes instantly in your browser (HMR)
No rebuild or refresh needed!

Backend Changes

  1. Edit any .go file
  2. Stop the server (Ctrl+C)
  3. Restart with make dev or go run cmd/server/main.go
Tip: Use air for auto-reload:

Building for Production

Build your complete application:
This will:
  1. Build the frontend (npm run build)
  2. Build the Go binary
  3. Embed the frontend into the Go binary
The output is a single executable in ./bin/server.

Running Production Build

Or:
The server now serves the embedded frontend files instead of proxying.

Adding API Endpoints

Let’s add a new API endpoint to list users:

1. Update routes.go

2. Call from Frontend

3. Test

  1. Save both files
  2. Frontend auto-reloads
  3. Restart Go server
  4. Visit your app and see the users!

Common Tasks

Install a new npm package

Install a new Go package

Clear the build

Run tests

Troubleshooting

Port already in use

If port 3000 is taken, change it in app/server/config.go:

Dev server won’t connect

  1. Make sure the frontend dev server is running:
  2. Check the dev server port matches in config.go:
  3. Check the console for errors

Changes not appearing

Frontend changes:
  • Make sure you’re editing files in frontend/src/
  • Check the browser console for errors
  • Try a hard refresh (Ctrl+Shift+R or Cmd+Shift+R)
Backend changes:
  • Make sure you restarted the Go server
  • Check the terminal for compilation errors

Next Steps

You’ve created your first Mizu frontend application! Here’s what to explore next:

Development Mode

Deep dive into how dev mode works

Production Mode

Learn about optimization and deployment

Framework Guides

Detailed guides for each framework

API Integration

Best practices for frontend-backend communication