Development Commands
Development server and tools for local development
Development Commands
The forge dev command provides development tools and server management for local development. It supports hot reload, app discovery, and interactive development workflows.
Main Command
forge dev
Start development server and tools.
forge dev # Interactive app selection
forge dev -a api-gateway # Run specific app
forge dev -a api -p 8080 # Run on specific port
forge dev --watch # With hot reload (default)Flags:
-a, --app- App to run-w, --watch- Watch for changes (default: true)-p, --port- Port number
Behavior:
- If no app is specified, shows an interactive app selector
- Automatically discovers apps in your project
- Supports both single-module and multi-module layouts
- Sets PORT environment variable if specified
Subcommands
forge dev list (aliases: ls)
List all available apps in your project.
forge dev list
forge dev lsOutput: Shows a table with app information:
- Name: App name
- Type: App type (usually "app")
- Location: Path to app directory
- Status: Ready status
Example Output:
┌─────────────┬──────┬─────────────────┬────────┐
│ Name │ Type │ Location │ Status │
├─────────────┼──────┼─────────────────┼────────┤
│ api-gateway │ app │ cmd/api-gateway │ ✓ Ready│
│ auth-service│ app │ cmd/auth-service│ ✓ Ready│
└─────────────┴──────┴─────────────────┴────────┘forge dev build
Build app for development.
forge dev build -a api-gateway
forge dev build --app auth-serviceFlags:
-a, --app- App to build (required)
Behavior:
- Builds the specified app using
go build - Outputs to
bin/<app-name>directory - Shows build progress with spinner
- Displays success/failure status
App Discovery
Forge automatically discovers apps in your project based on the layout:
Single-Module Layout
For single-module projects, Forge scans the cmd/ directory:
my-project/
├── cmd/
│ ├── api-gateway/
│ │ └── main.go
│ ├── auth-service/
│ │ └── main.go
│ └── worker/
│ └── main.go
└── .forge.yamlMulti-Module Layout
For multi-module projects, Forge scans the apps/ directory:
my-project/
├── apps/
│ ├── api-gateway/
│ │ └── cmd/
│ │ └── server/
│ │ └── main.go
│ ├── auth-service/
│ │ └── cmd/
│ │ └── server/
│ │ └── main.go
│ └── worker/
│ └── cmd/
│ └── server/
│ └── main.go
└── .forge.yamlDevelopment Features
Hot Reload
Hot reload automatically restarts your application when files change:
forge dev --watchNote: Hot reload is currently in development. The command will show a warning and run in normal mode.
Port Configuration
Set a custom port for your application:
forge dev -p 3000
forge dev --port 8080This sets the PORT environment variable that your application can read.
Interactive App Selection
When no app is specified, Forge shows an interactive selector:
forge devOutput:
? Select app to run:
▸ api-gateway
auth-service
workerProject Requirements
Forge Project
The forge dev command requires a Forge project with a .forge.yaml file:
# If not in a Forge project
forge dev
# Error: no .forge.yaml found in current directory or any parent
# This doesn't appear to be a Forge project.
# To initialize a new project, run:
# forge initApp Structure
Each app must have a main.go file with a main() function:
package main
import (
"log"
"github.com/xraph/forge"
)
func main() {
app := forge.NewApp(forge.AppConfig{
Name: "my-app",
Version: "0.1.0",
})
// Register routes
app.Router().GET("/", func(c forge.Context) error {
return c.JSON(200, forge.Map{
"message": "Hello from my-app!",
})
})
// Start server
if err := app.Run(); err != nil {
log.Fatal(err)
}
}Configuration
Development Configuration
Configure development settings in .forge.yaml:
dev:
port: 8080
hot_reload: true
debug: true
extensions:
- auth
- databaseEnvironment Variables
Set environment variables for development:
export PORT=3000
export DEBUG=true
export LOG_LEVEL=debug
forge devTroubleshooting
No Apps Found
If no apps are found:
forge dev
# Warning: No apps found. Create one with: forge generate appSolution:
forge generate app --name=my-appApp Not Found
If the specified app doesn't exist:
forge dev -a nonexistent-app
# Error: app not found: nonexistent-appSolution:
# List available apps
forge dev list
# Or create the app
forge generate app --name=nonexistent-appBuild Failures
If app build fails:
forge dev build -a my-app
# ✗ Build failedCommon causes:
- Missing dependencies
- Syntax errors in code
- Missing main.go file
Solution:
# Check for syntax errors
go build ./cmd/my-app
# Install dependencies
go mod tidy
# Verify main.go exists
ls cmd/my-app/main.goBest Practices
- Use Interactive Mode: Let Forge discover and select apps automatically
- Set Custom Ports: Use
-pflag for port conflicts - Enable Hot Reload: Use
--watchfor faster development - Check App Status: Use
forge dev listto verify apps - Build Before Dev: Use
forge dev buildto catch build errors early
For more information about code generation, see the Code Generation Commands documentation.
How is this guide?
Last updated on