This project demonstrates a multi‑tenant SaaS platform built with Spring Boot, PostgreSQL, Redis and Rqueue for asynchronous task processing. It supports tenant sign‑up, JWT authentication, CRUD operations on contacts, soft deletion with audit logging, sharded databases and background tasks. Database schemas are managed using Liquibase for both the central database and each shard.
- Java 17 or higher
- Maven 3.8+
- PostgreSQL 13+ with databases created for the central schema and one or more shards. By default the application expects databases named
central_db,shard1_dbandshard2_dbonlocalhostwith username/passwordpostgres/postgres. Adjustsrc/main/resources/application.ymlas needed. - Redis 6+. An embedded Redis server is started automatically on port 6379 if none is available. For production use, configure
spring.redis.hostandspring.redis.portto point to an external Redis instance.
-
Initialize the databases. Ensure the central and shard databases exist. Liquibase will create the required tables on first run:
psql -U postgres -c 'CREATE DATABASE central_db;' psql -U postgres -c 'CREATE DATABASE shard1_db;' psql -U postgres -c 'CREATE DATABASE shard2_db;'
-
Build the project. From the
saas-appdirectory run:mvn clean package
This compiles the application, runs the tests and packages an executable JAR in
target/.
The application can be run in different modes depending on your needs.
This is the standard mode for development. It runs the web application and the Rqueue message workers in the same process.
java -jar target/saas-app-*.jarThis mode runs the web application without the Rqueue message workers. This is useful for running a dedicated web server instance.
java -jar target/saas-app-*.jar --spring.profiles.active=webThis mode runs only the Rqueue message workers, without the web server. This is ideal for running dedicated, scalable worker instances.
java -jar target/saas-app-*.jar --spring.profiles.active=workerTo run a worker that only processes specific queues, you can use the rqueue.queues property. For example, to run a worker that only processes the testQueue:
java -jar target/saas-app-*.jar --spring.profiles.active=worker --rqueue.queues=testQueueYou can also specify multiple queues as a comma-separated list:
java -jar target/saas-app-*.jar --spring.profiles.active=worker --rqueue.queues=testQueue,contactEventQueueSwagger UI is available at http://localhost:8080/swagger-ui.html for detailed API documentation and testing.
The Rqueue dashboard is available at http://localhost:8080/rqueue for monitoring and managing message queues.
To run the unit and integration tests, use the following Maven command:
mvn testThis project uses the JaCoCo plugin to generate test coverage reports. To generate the report, run the following command:
mvn clean verify