This project is a microservices-based application built with Spring Boot and Java 17. It utilizes Maven for dependency management and Docker for containerized deployment.
The system architecture consists of two primary microservices and a relational database:
- Auth API (
auth-service): Built from theauth_apimodule, this service handles user authentication, JWT signing, and database operations. It connects directly to the PostgreSQL database and communicates with the Data API via HTTP requests (SERVICE_B_URL). - Data API (
data-service): Built from thedata_apimodule, this service is responsible for data transformation and processing. It runs independently and relies on anINTERNAL_TOKENto securely communicate with the Auth API. - Database (
postgres_db): A PostgreSQL container that stores the application's persistent data (such as users and process logs). It is automatically initialized using theinit.sqlscript on startup.
Before we start, configure project variables(use .env.example as a template)
- Compile the project and build the executable JAR files for both modules using Maven:
mvn clean package -DskipTests
- Build the Docker images for the microservices:
docker-compose up -d --build
Handles user authentication and processes client requests.
1. User Registration
- Method:
POST - URL:
/api/auth/register - Request Body (JSON):
{ "email": "user@example.com", "password": "yourpassword" }
2. User Login
- Method:
POST - URL:
/api/auth/register - Request Body (JSON):
{ "email": "user@example.com", "password": "yourpassword" } - On success, you will get a JWT token:
{ "token": "..." }
3. Text Processing (Requires Authentication)
- Method:
POST - URL:
/api/process - Headers: Authorization: Bearer <your_jwt_token>
- Request Body (JSON):
{ "text": "text to process" } - On success, you will get a reversed string:
{ "result": "ssecorp ot txet" }
4. Text Transformation (Internal Endpoint)
- Method:
POST - URL:
/api/transform - Headers: X-Internal-Token: <secret_internal_token> (default is super-secret-key-123)
- Request Body (JSON):
{ "text": "Hello" } - On success, you will get a reversed string:
{ "text": "olleH" }