Skip to content

atoolz/railway-htmx-java-spring-thymeleaf-mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

HTMX + Spring Boot + Thymeleaf + MySQL Railway Template

Production-ready HTMX starter with Java, Spring Boot, Thymeleaf, and MySQL. One-click deploy to Railway.

Deploy on Railway

License Java 21 Spring Boot HTMX 2.0.7 MySQL


Deploy and Host HTMX + Spring Boot + MySQL Starter on 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.

About Hosting

Multi-stage Dockerfile (Maven build, JRE runtime). Flyway runs migrations on startup. GET /health returns JSON and checks the database. PORT defaults to 8080.

Dependencies for Hosting

  • Railway MySQL (or any compatible mysql:// URL in DATABASE_URL)
  • On the web service: DATABASE_URL = ${{MySQL.MYSQL_URL}}

Deployment Dependencies

Why Deploy on Railway?

Railway hosts your stack with minimal configuration and scales as you grow.


What's Inside

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

Project Structure

.
├── 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

HTMX Patterns Demonstrated

  • hx-post, hx-patch, hx-delete with hx-target / hx-swap
  • Health checkGET /health

Deploy to Railway

  1. Fork this repo (or connect it)
  2. New project → add MySQL
  3. Add a web service from this repo (Dockerfile root)
  4. Set DATABASE_URL = ${{MySQL.MYSQL_URL}}
  5. Health check path: /health

Local Development

# Java 21 + Maven + local MySQL
export DATABASE_URL="mysql://root:pass@127.0.0.1:3306/htmx"
mvn spring-boot:run

Open http://localhost:8080.


Environment Variables

Variable Required Default Description
DATABASE_URL Yes - MySQL URL (mysql://…); on Railway reference ${{MySQL.MYSQL_URL}}
PORT No 8080 HTTP port

Railway template: MySQL service variables

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 RailwayDataSourceConfig

Part of the HTMX Railway Collection

This 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

License

MIT


Built by AToolZ for the HTMX community

About

HTMX + Java + Spring Boot + Thymeleaf + MySQL starter for Railway

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors