Getting Started¶
This guide will walk you through installing GMX and building your first application.
Prerequisites¶
- Go 1.21 or later — Download Go
- Basic understanding of HTML and Go (helpful but not required)
Installation¶
Option 1: Build from Source (Current)¶
git clone https://github.com/btouchard/gmx.git
cd gmx
go build -o gmx cmd/gmx/main.go
sudo mv gmx /usr/local/bin/
Option 2: Go Install (Coming Soon)¶
Verify installation:
Your First GMX App¶
Create a file named hello.gmx:
<script>
service Database {
provider: "sqlite"
url: string @env("DATABASE_URL")
}
model Message {
id: uuid @pk @default(uuid_v4)
content: string @min(1) @max(255)
}
func listMessages() error {
let messages = try Message.all()
return render(messages)
}
func createMessage(content: string) error {
if content == "" {
return error("Content cannot be empty")
}
const msg = Message{content: content}
try msg.save()
return render(msg)
}
</script>
<template>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello GMX</title>
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
</head>
<body>
<h1>Messages</h1>
<form hx-post="{{route "createMessage"}}" hx-target="#messages" hx-swap="beforeend">
<input type="text" name="content" placeholder="Type a message" required />
<button type="submit">Send</button>
</form>
<div id="messages">
{{range .Messages}}
<div>{{.Content}}</div>
{{end}}
</div>
</body>
</html>
</template>
Compile Your App¶
This generates a complete Go web server in main.go (approximately 200-300 lines of code).
Run Your App¶
Open your browser to http://localhost:8080 and you'll see your message app running!
What Just Happened?¶
The GMX compiler transformed your .gmx file into:
- GORM Models with validation and UUID generation
- HTTP Handlers with method guards and parameter validation
- Business Logic transpiled from GMX Script to Go
- Template Setup with HTMX route helpers
- Main Function with database initialization and routing
- Security Middleware with CSRF protection
All in a single, compilable Go file.
Project Structure¶
For a real application, organize your code like this:
myapp/
├── components/
│ ├── tasks.gmx
│ ├── users.gmx
│ └── dashboard.gmx
├── generated/
│ └── *.go
├── main.go
└── go.mod
Compile all components:
Next Steps¶
- Components — Learn about the structure of
.gmxfiles - Models — Deep dive into model declarations and annotations
- Script — GMX Script language reference
- Templates — Master HTMX templates and routing
Common Issues¶
"Command not found: gmx"¶
Make sure /usr/local/bin is in your PATH:
Generated Code Doesn't Compile¶
The GMX compiler runs gofmt on generated code. If compilation fails:
- Check for syntax errors in your
.gmxfile - Ensure all GMX Script functions return
error - Verify model field types are valid (
uuid,string,int,bool,datetime)
Database Errors¶
GMX generates code that expects a SQLite database. Make sure:
Getting Help¶
- Issues: github.com/btouchard/gmx/issues
- Discussions: github.com/btouchard/gmx/discussions