Production-ready HTMX starter with Java, Spring Boot, Thymeleaf, and MySQL. One-click deploy to Railway.
HTMX + Spring Boot + MySQL Starter is a production-ready template for hypermedia-driven web apps. It uses HTMX for partial updates, Spring Web + Thymeleaf for server-rendered HTML, JPA + Flyway for persistence, and MySQL. DATABASE_URL must be a mysql://user:pass@host:3306/db string (Railway’s MySQL plugin exposes MYSQL_URL — map it on the web service). RailwayDataSourceConfig parses it into a HikariCP JDBC URL with SSL for non-local hosts. Tailwind and HTMX load from CDN.
Multi-stage Dockerfile (Maven build, JRE runtime). Flyway runs migrations on startup. GET /health returns JSON and checks the database. PORT defaults to 8080.
- Railway MySQL (or any compatible
mysql://URL inDATABASE_URL) - On the web service:
DATABASE_URL=${{MySQL.MYSQL_URL}}
Railway hosts your stack with minimal configuration and scales as you grow.
| Layer | Technology | Role |
|---|---|---|
| Frontend | HTMX 2.0.7 + Tailwind (CDN) | Partial page updates |
| Templating | Thymeleaf | SSR + fragments for HTMX swaps |
| API | Spring Web | REST + HTML responses |
| Database | MySQL 8 + JPA + Flyway | Entities, migrations |
.
├── src/main/java/com/atoolz/htmx/
│ ├── HtmxApplication.java
│ ├── config/RailwayDataSourceConfig.java
│ └── todo/ # Entity, repository, controller
├── src/main/resources/
│ ├── application.yaml
│ ├── db/migration/V1__todos.sql
│ └── templates/
│ ├── home.html
│ └── fragments/todo-item.html
├── pom.xml
└── Dockerfile
hx-post,hx-patch,hx-deletewithhx-target/hx-swap- Health check —
GET /health
- Fork this repo (or connect it)
- New project → add MySQL
- Add a web service from this repo (Dockerfile root)
- Set
DATABASE_URL=${{MySQL.MYSQL_URL}} - Health check path:
/health
# Java 21 + Maven + local MySQL
export DATABASE_URL="mysql://root:pass@127.0.0.1:3306/htmx"
mvn spring-boot:runOpen http://localhost:8080.
| Variable | Required | Default | Description |
|---|---|---|---|
DATABASE_URL |
Yes | - | MySQL URL (mysql://…); on Railway reference ${{MySQL.MYSQL_URL}} |
PORT |
No | 8080 |
HTTP port |
Use one variable per line when defining the MySQL plugin service. The web service sets DATABASE_URL from the plugin’s MYSQL_URL. Example shape (adjust MYSQL_DATABASE / user; generate MYSQL_ROOT_PASSWORD with Railway’s secret helper — do not paste real passwords into the repo).
Template icon (Railway): assets/icon.png · assets/icon.svg
MYSQLHOST="${{RAILWAY_PRIVATE_DOMAIN}}" # private hostname on Railway’s internal network for other services in the project
MYSQLPORT="" # leave empty for default 3306, or set an explicit port
MYSQLUSER="" # database login (often root); align with your image/plugin bootstrap user
MYSQL_URL="mysql://${{MYSQLUSER}}:${{MYSQL_ROOT_PASSWORD}}@${{RAILWAY_PRIVATE_DOMAIN}}:3306/${{MYSQL_DATABASE}}" # in-cluster mysql:// URL; web service uses ${{MySQL.MYSQL_URL}} as DATABASE_URL
MYSQLDATABASE="${{MYSQL_DATABASE}}" # plugin-style alias for the database name (no underscore)
MYSQLPASSWORD="${{MYSQL_ROOT_PASSWORD}}" # password for MYSQLUSER (typically the same as root in one-click templates)
MYSQL_DATABASE="" # logical database/schema name created on first init
MYSQL_PUBLIC_URL="mysql://${{MYSQLUSER}}:${{MYSQL_ROOT_PASSWORD}}@${{RAILWAY_TCP_PROXY_DOMAIN}}:${{RAILWAY_TCP_PROXY_PORT}}/${{MYSQL_DATABASE}}" # mysql:// via Railway TCP proxy for clients outside the private network
MYSQL_ROOT_PASSWORD="${{ secret(32, \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\") }}" # generated secret at provision; never commit real values to git
# Web service (Spring Boot) — reference the MySQL plugin variable:
DATABASE_URL="${{MySQL.MYSQL_URL}}" # must be mysql://…; parsed by RailwayDataSourceConfigThis is one of 15 HTMX starter templates covering different backend stacks, all following the same pattern and ready for Railway deployment:
| Stack | Status |
|---|---|
| Bun + Elysia | Coming soon |
| .NET + Razor | Coming soon |
| Elixir + Phoenix | Coming soon |
| Go + Chi | Live |
| Go + Echo | Live |
| Go + Fiber | Live |
| Java + Spring Boot (MySQL) | This repo |
| Java + Spring Boot (PostgreSQL) | Live |
| Node + Express | Live |
| Node + Hono | Live |
| PHP + Laravel | Live |
| Python + Django | Live |
| Python + FastAPI | Live |
| Ruby + Rails 8 | Live |
| Rust + Axum + Askama | Live |
Built by AToolZ for the HTMX community
