Prerequisites
Before setting up the project locally, ensure you have the following installed:- Go: Version 1.22.2 or higher
- Tailwind CSS: For styling compilation
- Templ: For Go template generation
- Air: For hot-reloading during development (optional)
- MongoDB: For database (or use Docker Compose)
Environment Configuration
Create environment file
Create a
.env file in the project root with the following variables:The
load_env.sh script will automatically load these variables when using Makefile commands.Choose your development workflow
You have several options for running the application locally:This command:This runs Terminal 2 - Watch Templ templates:Terminal 3 - Run the application:
Option 1: Run with Hot Reload (Recommended)
Use Air for automatic reloading on code changes. This will also generate templates automatically:- Loads environment variables from
.env - Watches for changes in
.go,.templ,.htmlfiles - Automatically runs
templ generatebefore building - Rebuilds and restarts the server on changes
Air is configured to exclude test files and generated template files from the build.
Option 2: Run Directly
Run the application without hot-reload:go run ./cmd/web/main.go with environment variables loaded.Option 3: Development with Live CSS/Template Updates
For frontend-heavy development, run these commands in separate terminals:Terminal 1 - Watch Tailwind CSS:Building the Application
To create a production build:./bin/web.
Testing
coverage target generates a coverage report and displays function-level coverage statistics.
Project Structure
Key directories for local development:cmd/web/main.go- Application entry pointinternal/- Internal application codeinternal/config/- Configuration managementinternal/web/static/css/- Stylesheets (Tailwind).air.toml- Air configuration for hot-reload
Troubleshooting
Common Issues
Environment variables not loading:- Ensure
.envfile exists in the project root - Check that
load_env.shhas execute permissions - Verify all required variables are set (DB_URL, PORT, LOG_LEVEL, ENV)
- Install Templ CLI:
go install github.com/a-h/templ/cmd/templ@latest - Run
templ generatemanually to see detailed errors
- Ensure MongoDB is running on the configured port
- Verify the DB_URL connection string format
- Check MongoDB authentication credentials if using auth
Next Steps
Docker Deployment
Deploy with Docker Compose including MongoDB, Prometheus, and Grafana
Configuration
Learn about all available environment variables and settings