Skip to content

NUS-MTechSE-DMSS/dietary-service

Repository files navigation

Swipetoeat Backend (Dietary Service)

Java Spring Boot Security Build

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.

🚀 Tech Stack

  • 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

📁 Core Project Structure

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)

🔐 Security & Authentication

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 the Authorization: Bearer <token> HTTP header.
  • CSRF protection is explicitly disabled as the API is stateless and token-based.

🛠️ Quick Start

Prerequisites

  • JDK 21 or higher
  • Maven 3.x
  • AWS Cognito Configuration: Ensure spring.security.oauth2.resourceserver.jwt.issuer-uri is correctly set in src/main/resources/application.properties.

Run Locally

  1. 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
  1. Build and Run:
./mvnw spring-boot:run
  1. Access API Documentation: Once started, visit: http://localhost:8080/swagger-ui/index.html

Run Tests

Execute all unit tests and generate a JaCoCo coverage report:

./mvnw test

The report will be generated at: target/site/jacoco/index.html.

📖 API Overview

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).markdown
  • Backend Developer Guide (Module Documentation).markdown

Actuator Endpoints

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

About

Module that manages user's dietary options including diet type(e.g. HALAL, VEGAN, etc.)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages