FormPilot is a comprehensive, microservices-based fitness application designed to handle user management, activity tracking, and AI-driven recommendations.
The system utilizes a polyglot persistence architecture (PostgreSQL & MongoDB) and event-driven architecture via Spring Cloud Stream and Apache Kafka to ensure scalability and decoupling. It features a modern React frontend with Material-UI and secured access via OAuth2/OpenID Connect (Keycloak).
- Language: Java 21
- Framework: Spring Boot 4.0.1
- Cloud Architecture: Spring Cloud 2025.1.0 (Spring Cloud Stream)
- Build Tool: Maven
- Databases: PostgreSQL (User), MongoDB (Activity & AI)
- Message Broker: Apache Kafka (Dockerized)
- AI Integration: Google Gemini API
- Framework: React (Vite)
- UI Library: Material-UI (MUI)
- State Management: Redux Toolkit
- Routing: React Router
- HTTP Client: Axios (Interceptors for Auth)
- Security: OAuth2 PKCE (
react-oauth2-code-pkce)
The backend follows a microservices architecture with the following components:
| Service | Port | Description | DB/Tech |
|---|---|---|---|
| Config Server | 8888 |
Centralized configuration for all services. | Local Classpath |
| Eureka Server | 8761 |
Service Discovery Registry. | Netflix Eureka |
| API Gateway | 8080 |
Entry point, routing, and OAuth2 Resource Server. | Spring Cloud Gateway |
| User Service | 8081 |
Manages user profiles. | PostgreSQL |
| Activity Service | 8082 |
Tracks fitness activities (Producer). | MongoDB / Kafka |
| AI Service | 8083 |
Generates AI recommendations (Consumer). | MongoDB / Kafka |
- Apache Kafka: Used for the
fitness-topicto decouple Activity tracking from AI analysis. - Keycloak: Runs on port
8181handling Identity Management. - Docker Compose: Orchestrates Kafka, Zookeeper, Kafka UI, and Keycloak containers.
Before running the application, ensure the following are installed:
- Java 21 SDK
- Node.js & npm
- Docker Desktop (Required for Kafka & Keycloak)
- PostgreSQL (Port
5432- Running locally or via Docker) - MongoDB (Port
27017- Running locally or via Docker)
We use docker-compose to start the required infrastructure (Kafka, Zookeeper, Kafka UI, Keycloak).
- Open a terminal in the project root.
- Run the following command:
docker-compose up -d
- Verify the services are running:
- Kafka UI: http://localhost:8090
- Keycloak: http://localhost:8181
Create the following databases before starting services:
- Postgres:
formpilot_user_db - MongoDB:
formpilot_activity_db,formpilot_ai_db
The application uses Spring Cloud Stream to abstract the message broker.
- Topic:
fitness-topic(Auto-created by Spring Cloud Stream on first message). - Consumer Group:
ai-service-group(Ensures durability and load balancing).
The AI Service requires access to the Google Gemini API.
| Service | Variable | Description |
|---|---|---|
aiservice |
GEMINI_API_URL |
URL for the Gemini API endpoint. |
aiservice |
GEMINI_API_KEY |
Your Google Gemini API Key. |
To ensure service discovery and configuration loading work correctly, start the microservices in this exact order:
- Start Infrastructure: Run
docker-compose up -d(Kafka, Keycloak). - Config Server (
configserver) - Eureka Server (
eureka) - Ensure Postgres and Mongo are running.
- Core Services:
- User Service (
userservice) - Activity Service (
activityservice) - AI Service (
aiservice)
- User Service (
- API Gateway (
gateway)
- Navigate to the frontend directory:
cd frontend - Install dependencies:
npm install
- Start the development server:
npm run dev
- Access the app at
http://localhost:5173(default Vite port).
src/main.jsx: Entry point, Redux & AuthProvider setup.src/store/: Redux store andauthSlicefor token management.src/services/api.js: Centralized Axios instance with Auth interceptors.src/authConfig.js: OAuth2 PKCE config for Keycloak.src/components/:ActivityList.jsxActivityForm.jsxActivityDetail.jsx
- Authentication: The frontend uses OAuth2 PKCE flow to communicate with Keycloak (running on port
8181). - Authorization: The API Gateway validates JWTs via the JWK Set URI:
http://localhost:8181/realms/{your-realm}/protocol/openid-connect/certs