|
1 | 1 | # Seed Multi module demo
|
2 | 2 |
|
| 3 | +# Spring boot multi module boiler plate <a id="introduction"></a> |
| 4 | + |
| 5 | +This repository contains boiler-plate codebase using Java, Spring boot as core technology. |
| 6 | + |
| 7 | +# Developer Documentation |
| 8 | + |
| 9 | +To run application locally, this section describes the tooling as well as |
| 10 | +the local development setup. |
| 11 | + |
| 12 | +# Module Information |
| 13 | + |
| 14 | +ss-api : It contains utilities like constants, dtos, validators, utility classes. |
| 15 | +ss-dao : It contains database entities and repositories. |
| 16 | +ss-service : It contains abstraction of business logic. |
| 17 | +ss-service-impl : It contains business login. |
| 18 | +ss-web : It contains application Configs, Db-migration files, Exception handler, API definition. |
| 19 | + |
| 20 | +## Tooling |
| 21 | + |
| 22 | +| Area | Tool | Download Link | Comment | |
| 23 | +|----------|----------|-------------------------------------------------|---------------------------------------------------------------------------------------------------| |
| 24 | +| IDE | IntelliJ | https://www.jetbrains.com/idea/download/ | Additionally the [envfile plugin](https://plugins.jetbrains.com/plugin/7861-envfile) is suggested | |
| 25 | +| Build | Gradle | https://gradle.org/install/ | |
| 26 | +| Runtime | Docker | https://www.docker.com/products/docker-desktop/ | | |
| 27 | +| Database | DBeaver | https://dbeaver.io/ | |
| 28 | +| IAM | Keycloak | https://www.keycloak.org/ | | |
| 29 | + |
| 30 | +## Local Development Setup |
| 31 | + |
| 32 | +1. Run keycloak and database server |
| 33 | +2. Import realm file [app-test-realm.json](src%2Ftest%2Fresources%2Fapp-test-realm.json) |
| 34 | +3. Update your env variable in application.yaml file |
| 35 | +4. Run [MainApplication.java](src%2Fmain%2Fjava%2Fss%2Fmod%2Fdemo%2FMainApplication.java) |
| 36 | + in IDE |
| 37 | +5. Open API doc on http://localhost:8080 |
| 38 | +6. Click on Authorize on swagger UI and on the dialog click again on Authorize. |
| 39 | +7. Login with username=valid-user and password=password |
| 40 | + |
| 41 | +## Build application locally |
| 42 | + |
| 43 | +Build with test cases |
| 44 | + |
| 45 | +``` |
| 46 | +./gradlew build |
| 47 | +``` |
| 48 | + |
| 49 | +Build without test cases |
| 50 | + |
| 51 | +``` |
| 52 | +./gradlew build -i -x test |
| 53 | +``` |
| 54 | + |
| 55 | +## Test Coverage |
| 56 | + |
| 57 | +Jacoco is used to generate the coverage report. The report generation |
| 58 | +and the coverage verification are automatically executed after tests. |
| 59 | + |
| 60 | +The generated HTML report can be found under `jacoco-report/html/` |
| 61 | + |
| 62 | +To generate the report run the command |
| 63 | + |
| 64 | +``` |
| 65 | +./gradlew jacocoTestReport |
| 66 | +``` |
| 67 | + |
| 68 | +To check the coverage run the command |
| 69 | + |
| 70 | +``` |
| 71 | +./gradlew jacocoTestCoverageVerification |
| 72 | +``` |
| 73 | + |
| 74 | +## Common issues and solutions during local setup |
| 75 | + |
| 76 | +#### 1. Can not build with test cases |
| 77 | + |
| 78 | +Test cases are written using the Spring Boot integration test frameworks. These test frameworks start the Spring Boot |
| 79 | +test context, which allows us to perform integration testing. In our tests, we utilize the Testcontainers |
| 80 | +library (https://java.testcontainers.org/) for managing Docker containers. Specifically, we use Testcontainers to start |
| 81 | +PostgreSQL and Keycloak Docker containers locally. |
| 82 | + |
| 83 | +Before running the tests, please ensure that you have Docker runtime installed and that you have the necessary |
| 84 | +permissions to run containers. |
| 85 | + |
| 86 | +Alternative, you can skip test during the build with ``` ./gradlew clean build -x test``` |
| 87 | + |
| 88 | +#### 2. Database migration related issue |
| 89 | + |
| 90 | +We have implemented database migration using Liquibase (https://www.liquibase.org/). Liquibase allows us to manage |
| 91 | +database schema changes effectively. |
| 92 | + |
| 93 | +In case you encounter any database-related issues, you can resolve them by following these steps: |
| 94 | + |
| 95 | +1. Delete all tables from the database. |
| 96 | +2. Restart the application. |
| 97 | +3. Upon restart, the application will recreate the database schema from scratch. |
| 98 | + |
| 99 | +This process ensures that any issues with the database schema are resolved by recreating it in a fresh state. |
| 100 | + |
| 101 | +## Environment Variables <a id= "environmentVariables"></a> |
| 102 | + |
| 103 | +| name | description | default value | |
| 104 | +|--------------------------------|-------------------------------------------------|----------------------------| |
| 105 | +| APP_PORT | port number of application | 8080 | |
| 106 | +| SECURITY_ENABLE | To keep spring security enable/disable | true | |
| 107 | +| KEYCLOAK_REALM_NAME | Realm name of keycloak | SWD | |
| 108 | +| KEYCLOAK_CLIENT_ID | Keycloak public client id | pb_backend | |
| 109 | +| KEYCLOAK_ROLE_CLIENT_ID | Keycloak private client id | pb_backend | |
| 110 | +| KEYCLOAK_AUTH_URL | Keycloak server url | http://localhost:9090/auth | |
| 111 | +| DB_HOST | Database host | localhost | |
| 112 | +| DB_PORT | Port of database | 5432 | |
| 113 | +| DB_NAME | Database name | multi-module-demo | |
| 114 | +| USE_SSL | Whether SSL is enabled in database server | false | |
| 115 | +| DB_USER | Database username | | |
| 116 | +| DB_PASSWORD | Database password | | |
| 117 | +| MULTIPART_MAX_FILE_SIZE | Max multiple file size | 50 MB | |
| 118 | +| MULTIPART_MAX_REQUEST_SIZE | Max multiple part request size | 51 MB | |
| 119 | +| RETRY_CONNECTION_TIMEOUT_MILLI | Duration in millis for retry connection timeout | 200 | |
| 120 | +| RETRY_READ_TIMEOUT_MILLI | Duration for read timeout | 500 | |
| 121 | +| RETRY_MAX_IDLE_CONNECTION | Duration for idle connection | 10 | |
| 122 | +| RETRY_ALIVE_DURATION_MIN | Duration for retry alive | 5 | |
| 123 | +| RETRY_MAX_ATTEMPT | Max retry attempt | 5 | |
| 124 | +| RETRY_INTERVAL_MILLI | Duration between retry | 2000 | |
| 125 | + |
| 126 | +## Reference of external lib |
| 127 | + |
| 128 | +1. https://www.testcontainers.org/modules/databases/postgres/ |
| 129 | +2. https://github.com/dasniko/testcontainers-keycloak |
| 130 | +3. https://github.com/smartSenseSolutions/smartsense-java-commons |
| 131 | + |
0 commit comments