Rath Backend Template
This repository holds the boilerplate for the Rath backend. It wraps Spring Boot, the Tranz Technologies rathorm ORM and rath-common utilities to provide a JWT-secured REST API, datagrid helpers and a cacheable select service out of the box.
Table of Contents
- Overview
- Architecture
- Security
- Persistence & Schema
- Configuration
- Running the Application
- Public Endpoints
- Select Cache Service
- Deployment
- Development Notes
Overview
- Spring Boot 4 powers the REST controllers, filters and exception handling.
- JWT authentication is stored in a secure cookie named
rathand refreshed automatically when the token approaches expiration. rathorm+ ActiveJDBC manages schema-driven models (User,UserType) and datagrid helpers.- Controllers live under
com.tranztechnologies.controller, services underservice, security helpers undersecurityandsecurity.iam, and error customization inerror.
Architecture
| Layer | Purpose |
|---|---|
controller | REST entry points (AuthController, UserController, SelectController). |
service | Business logic and data retrieval; SelectService extends RathSelectService and UserService wraps OrmHandler datagrid helpers. |
security.iam | JWT utilities (JwtTokenUtil, JwtRequestFilter, Authenticator, RathUserDetailsService), cookie-based refresh, and Spring Security wiring via RathSecurityConfiguration. |
model | ActiveJDBC models that mirror the users and user_types tables. |
error | RathErrorAttributes injects the application name and request URL for any /error responses. |
rathorm | RathOrmInitializer seeds User and UserType records during development, wiring into Tranz Technologies tooling (rathorm library). |
Security
RathSecurityConfigurationdisables CSRF, enforces stateless sessions, enables CORS for localhost origins, and wiresJwtRequestFilterahead of the Spring Security filter chain.JwtRequestFilterskips the select/listing endpoints, reads therathcookie, validates the token, refreshes the cookie when the expiry is within 30 minutes, and populatesSecurityContext.AuthenticatorusesAuthenticationManagerandRathUserDetailsServiceto validate credentials; success writes aJwtResponseto the response cookie.JwtTokenUtilcreates and verifies signed tokens, exposes helper methods (validateToken,checkThreshold,construct), and centralizes the shared secret and expiration thresholds.UserUtilexposes the currently logged-inRathUserDetailsfrom the security context for controllers.
Persistence & Schema
rathorm.properties(src/main/resources) configures the database connection (jdbc:postgresql://localhost:5432/rath) and scanscom.tranztechnologies.modelfor entities.Usermaps touserswith fields such asusername,password, andtype_id.UserTypemaps touser_typeswith a uniquetypecolumn.RathOrmInitializerseeds anADMINuser for smoke testing; run it directly viamvn -pl :backend -DskipTests -Dspring.profiles.active=seed exec:java(or call the main class from your IDE) before using the app on a fresh schema.
Configuration
src/main/resources/application.propertiescurrently sets onlyspring.application.name; replace the placeholder with a meaningful identifier.rathorm.propertiesmust match your PostgreSQL credentials; you can override allrathorm.db.*values with system properties or environment variables when launching the app.JwtTokenUtil.secretandJwtTokenUtil.TOKEN_NAMEare hard-coded; rotate the secret and align the cookie name with your frontend security policy before deployment.
Running the Application
- Install prerequisites: Java 21+, PostgreSQL (accessible via the JDBC URL in
rathorm.properties). - Build:
./mvnw -B -ntp clean packageproduces a WAR intarget/. - Run (development):
./mvnw spring-boot:runpicks upapplication.properties+rathorm.properties. - Database seed: Run
com.tranztechnologies.rathorm.RathOrmInitializeronce to populate theusersanduser_typestables, then comment/remove it if you run migrations elsewhere.
Public Endpoints
| Method | Path | Description |
|---|---|---|
POST | /authenticate | JSON payload { "username": "...", "password": "..." }. Authenticates via Authenticator, sets the JWT cookie, and returns user metadata plus roles. |
GET | /api/auth | Requires authentication; returns the current user details from UserUtil. |
GET | /api/users | Data grid read for users. Accepts the standard DataGridParams query string (page, size, sort, etc.) handled by OrmHandler.toDataGrid. |
GET | /api/users/{id} | Returns a single user record via OrmHandler.findFirst. |
GET | /api/select/{key} | Delegates to SelectService.cachedSelect to run configured selects (see Select Cache section). Protects every request via the JWT filter except well-known read-only selects. |
DELETE | /api/select/{key} | Drops the cached result set for the requested key. |
DELETE | /api/select | Clears the entire select cache. |
Select Cache Service
SelectService extends RathSelectService and registers the users select (id + first_name). Add more cached selects by passing additional SQL entries to the parent constructor.
Deployment
The provided deploy.sh performs a compact deploy:
- Builds the project (unless
SKIP_BUILD=true). - Copies the generated WAR to
/tmpon the remote host viarsync. - Remotes into the host, unpacks the WAR into the configured Tomcat
webappsdirectory, fixes ownership, and optionally restarts Tomcat (RESTART_TOMCAT=true).
Adjust the following environment variables to match your server: REMOTE_HOST, REMOTE_USER, REMOTE_TOMCAT_WEBAPPS, REMOTE_TOMCAT_OWNER, PROJECT_DIR, BUILD_DIR, RESTART_TOMCAT, and SKIP_BUILD.
Development Notes
- Keep
JwtRequestFilterin sync with any added public endpoints that should bypass authentication (currently/api/select/*and/api/listing/*). - Add new selects/queries through
SelectServiceor new service classes that wrapOrmHandler. - Expand
AuthServiceonce you need password resets, registration flows, or integration with external identity providers. - Update
rathorm.propertiesbefore running integration tests so the test database matches your CI environment.
Feel free to extend this template by adding DTOs, custom exception handlers, or Swagger/OpenAPI metadata as required.