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
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:frontend/react- React with Vite and TypeScriptfrontend/vue- Vue 3 with Vite and TypeScriptfrontend/svelte- Svelte with Vite and TypeScriptfrontend/htmx- HTMX with Go templates- And more…
Step 2: Create a New Project
Let’s create a React application:- Create the project directory structure
- Generate both Go backend and frontend code
- Initialize Go modules
- 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:- Starts the Go backend server on port 3000
- Starts the frontend dev server (Vite) on port 5173
- Proxies requests through the Go server
- Visit
http://localhost:3000to 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:http://localhost:3000 and you’re ready to go!
Understanding the Code
Let’s look at the key files:Backend: app/server/app.go
frontend.ModeAutoautomatically switches between dev and production- In development, requests proxy to the dev server
- In production, files are served from the embedded
distfolder - API routes (starting with
/api) bypass the frontend middleware
API Routes: app/server/routes.go
Frontend: frontend/src/App.tsx (React example)
Making Changes
Frontend Changes (React/Vue/Svelte)
- Edit any file in
frontend/src/ - Save the file
- See changes instantly in your browser (HMR)
Backend Changes
- Edit any
.gofile - Stop the server (Ctrl+C)
- Restart with
make devorgo run cmd/server/main.go
Building for Production
Build your complete application:- Build the frontend (
npm run build) - Build the Go binary
- Embed the frontend into the Go binary
./bin/server.
Running Production Build
Adding API Endpoints
Let’s add a new API endpoint to list users:1. Update routes.go
2. Call from Frontend
3. Test
- Save both files
- Frontend auto-reloads
- Restart Go server
- 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 inapp/server/config.go:
Dev server won’t connect
-
Make sure the frontend dev server is running:
-
Check the dev server port matches in
config.go: - 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)
- Make sure you restarted the Go server
- Check the terminal for compilation errors