swipetoeat-backend is a microservice built with Spring Boot, responsible for managing user Dietary Preferences. It serves as a core component of the SwipeToEat project, providing personalized filtering for restaurant and food recommendations, now secured by enterprise-grade identity management.
- Core Framework: Spring Boot 4.0.2
- Language: Java 21
- Security: Spring Security, OAuth 2.0 Resource Server, AWS Cognito (JWT Validation)
- Persistence: Spring Data JPA
- Database: H2 Database (In-memory for rapid development and testing)
- API Documentation: SpringDoc OpenAPI (Swagger UI)
- Testing: JUnit 5, JaCoCo (Code Coverage)
- Validation: Spring Boot Validation
src/main/java/com/swipetoeat/backend/
├── config/ # Security & App Configuration (SecurityConfig)
├── controller/ # API Layer: Handles HTTP requests (DietaryController, AuthTestController)
├── model/ # Entity Layer: Allergen, DietType, UserPreference
├── repository/ # Data Access Layer: Database interactions (DietaryRepository)
└── service/ # Service Layer: Business logic (DietaryService)
This service acts as an OAuth 2.0 Resource Server. It relies on AWS Cognito for identity management.
- Client applications (e.g., Flutter) must obtain an
IdToken(JWT) from AWS Cognito. - Secured endpoints (like
PUT /users/{userId}) require the JWT to be passed in theAuthorization: Bearer <token>HTTP header. - CSRF protection is explicitly disabled as the API is stateless and token-based.
- JDK 21 or higher
- Maven 3.x
- AWS Cognito Configuration: Ensure
spring.security.oauth2.resourceserver.jwt.issuer-uriis correctly set insrc/main/resources/application.properties.
- Clone the repository:
git clone [https://github.com/NUS-MTechSE-DMSS/dietary-service.git](https://github.com/NUS-MTechSE-DMSS/dietary-service.git)
cd dietary-service
- Build and Run:
./mvnw spring-boot:run
- Access API Documentation:
Once started, visit:
http://localhost:8080/swagger-ui/index.html
Execute all unit tests and generate a JaCoCo coverage report:
./mvnw test
The report will be generated at: target/site/jacoco/index.html.
This service maintains the following core domains:
- Dietary Preference: User-set dietary restrictions (e.g., Vegan, Keto).
- Allergens: User allergy information (e.g., Peanuts, Seafood).
For detailed API definitions and integration instructions, please refer to the following files in the root directory:
Frontend Integration Guide (API Reference).markdownBackend Developer Guide (Module Documentation).markdown
Local
curl http://localhost:8080/dietary/actuator/health | jq
curl http://localhost:8080/dietary/actuator/info | jq
curl http://localhost:8080/dietary/actuator/metrics | jq