A Go web application using SQLite for data storage and Templ for HTML templating. It provides a practical example for a very simple and fast DX and UX.
This application provides user authentication and a "tasks" interface where users can create and modify a task list. It uses:
- SQLite for data storage
- Templ for HTML templating
- SQLC for type-safe SQL queries
- Go HTTP Router for routing
- Prometheus for metrics
Clone the repository and install dependencies:
git clone <repository-url>
cd sqlite
go mod downloadTo build and run the application:
make runThis will:
- Generate Go code from SQL queries using sqlc
- Generate Go code from templ templates
- Run the application on port 8000
Run tests with:
make testTo create a new database migration:
./scripts/new-migration.sh migration_nameThis creates a timestamped SQL file in the db/migrations directory that you can edit to define your schema changes.
assets/- Static assets like CSScmd/server/- Application entry pointdb/- Database related filesmigrations/- SQL migration filesqueries/- SQLC query definitions
model/- Generated Go types and query methodsscripts/- Utility scriptstemplates/- Templ template files
The application has three main tables:
user- User authentication datadial- User-specific dial objectssession- Authentication sessions
The project uses two code generation tools:
- sqlc - Generates type-safe Go code from SQL in
db/queries/ - templ - Generates Go code from HTML templates in
templates/
The application provides user signup, login, and session management.
To deploy the application:
make deployThis script:
- Builds a statically-linked Linux binary
- Copies it to the remote server (
silva.world) - Stops the current service
- Replaces the binary
- Restarts the service
ENV=prod- Set to "prod" for production mode with TLS support
In production mode, the application:
- Serves on ports 80 (redirects to HTTPS) and 443 (HTTPS)
- Uses Let's Encrypt for automatic TLS certificate management
- Requires the domain
silva.world
In development mode, the application:
- Serves on port 8000
- Does not use TLS
Prometheus metrics are available at /metrics on port 6060.