Production Configuration
Relevant source files
The following files were used as context for generating this wiki page:- pom.xml
- src/main/java/com/paymaster/backend/presentation/controller/HomeController.java
- src/main/resources/static/js/app.js
- src/main/resources/templates/fragments/layout.html
- src/main/resources/templates/contracts/form.html
- src/main/resources/templates/reports/index.html
- src/main/resources/static/css/style.css
The PayMaster application is a standard Spring Boot project designed as a monolithic web application. It utilizes server-side rendering with Thymeleaf for its primary user interface and enhances user experience with client-side JavaScript for dynamic features and API interactions. The production configuration is defined by the Maven build file, Spring Boot's auto-configuration, and conventions for serving static assets and templates.
The architecture is centered around a Spring Web MVC pattern, handling HTTP requests, interacting with service layers, and rendering HTML views. The application is configured to run with an embedded H2 database, making it a self-contained package.
Backend Configuration
The backend is built on the Spring Boot framework, leveraging Java 21. The core configuration is managed through Maven dependencies and the main application controller.
Build & Dependencies
The project's foundation is defined in the pom.xml file. It uses Spring Boot version 3.2.0 and Java version 21.
The following diagram illustrates the key dependencies and their roles in the application.
Sources: pom.xml:10-11, pom.xml:24-25
Key dependencies for the production environment include:
| Group ID | Artifact ID | Description |
|---|---|---|
org.springframework.boot | spring-boot-starter-web | Provides core functionality for building web applications, including an embedded Tomcat server. |
org.springframework.boot | spring-boot-starter-data-jpa | Used for data persistence with JPA (Java Persistence API) and Hibernate. |
org.springframework.boot | spring-boot-starter-thymeleaf | The server-side templating engine for rendering HTML views. |
com.h2database | h2 | An in-memory/file-based SQL database, configured with runtime scope. |
com.github.mfathi91 | persian-date-time | A library for handling Persian calendar dates. |
Sources: pom.xml:27-58
Application Architecture
The application follows a classic Model-View-Controller (MVC) pattern. The HomeController acts as the central point for handling user requests, delegating business logic to various services, and returning rendered Thymeleaf templates.
This diagram shows the request flow from the user to the database.
Database Configuration
The application is configured to use the H2 database engine. The dependency is declared with a runtime scope in pom.xml, meaning it's available at runtime but not required for compilation. This setup is typical for development or simple, self-contained deployments, but it implies that in a production environment, data is either stored in-memory (and lost on restart) or in a local file, rather than a dedicated, production-grade database server.
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
Sources: pom.xml:42-45
API Endpoints
The HomeController exposes a RESTful endpoint for AJAX calls from the frontend, primarily for calculations.
| Method | Path | Description | Controller Method |
|---|---|---|---|
GET | /api/calculate | Calculates installment details based on principal, rate, and months. | calculateInstallment |
This endpoint is used by the contract creation form to provide a real-time preview of installment calculations without a full page reload.
Sources: src/main/java/com/paymaster/backend/presentation/controller/HomeController.java:433-445, src/main/resources/static/js/app.js:257-259
Frontend Configuration
The frontend is a mix of server-rendered Thymeleaf templates and a client-side JavaScript application that handles dynamic UI updates and API communication.
Asset Management
Static assets like CSS and JavaScript are managed within the project structure and served directly by Spring Boot.
- CSS: Custom styles are located in
src/main/resources/static/css/style.css. - JavaScript: The main application logic is in
src/main/resources/static/js/app.js.
These files are linked in the main layout template.
Sources: src/main/resources/templates/fragments/layout.html:14, src/main/resources/templates/fragments/layout.html:111
External Libraries (CDN)
For common libraries, the application relies on Content Delivery Networks (CDNs) to reduce server load and improve loading times. This is a standard production practice.
| Library | CDN URL | Purpose |
|---|---|---|
| Bootstrap 5.3.2 | cdn.jsdelivr.net | Core CSS framework for styling and layout. |
| Bootstrap Icons 1.11.1 | cdn.jsdelivr.net | Icon set used throughout the UI. |
| Vazirmatn Font | cdn.jsdelivr.net | The primary Persian font for the application. |
| Chart.js 4.4.0 | cdn.jsdelivr.net | Used for rendering charts on the reports and contract pages. |
Sources: src/main/resources/templates/fragments/layout.html:8-15, src/main/resources/templates/fragments/layout.html:110
Client-Side Configuration
The main JavaScript file, app.js, contains a global CONFIG object that centralizes client-side settings. This allows for easy adjustments to frontend behavior without changing the core logic.
const CONFIG = {
apiBaseUrl: '/api',
debounceDelay: 300,
animationDuration: 300,
toastDuration: 5000,
dateFormat: 'YYYY/MM/DD',
currency: 'ریال',
locale: 'fa-IR'
};
Sources: src/main/resources/static/js/app.js:11-19
UI Interaction & API Calls
The frontend uses JavaScript to perform asynchronous API calls for features like the contract calculator. The following sequence diagram illustrates this flow.
Templating and Rendering
The application uses Thymeleaf for server-side HTML rendering, enabling dynamic data to be injected into templates before they are sent to the client.
Thymeleaf Engine
The spring-boot-starter-thymeleaf dependency enables Thymeleaf's auto-configuration. Spring Boot looks for templates in the src/main/resources/templates/ directory.
Sources: pom.xml:35-38
Layout and Fragments
A consistent UI is maintained using a main layout file (fragments/layout.html) that defines the common page structure, including the header, navigation bar, footer, and script includes. Other pages, such as customers/list.html and contracts/list.html, use th:replace to insert these shared fragments.
<!-- In layout.html -->
<nav th:fragment="navbar" class="navbar ...">
...
</nav>
<!-- In customers/list.html -->
<nav th:replace="~{fragments/layout :: navbar}"></nav>
Sources: src/main/resources/templates/fragments/layout.html:18, src/main/resources/templates/customers/list.html:5
This approach promotes code reuse and simplifies maintenance of the application's look and feel.
Summary
The production configuration of PayMaster is that of a self-contained Spring Boot application. It combines a Java backend with a Thymeleaf-powered frontend, enhanced by a small, vanilla JavaScript layer for dynamic interactions. Key characteristics of its configuration include the use of Maven for dependency management, an embedded H2 database for data storage, and reliance on CDNs for major frontend libraries. This setup is straightforward to deploy and manage, suitable for small to medium-scale applications where a single, monolithic deployment is sufficient.