From cd73becf03ab9cb3754a4ec451dc28c252241cb4 Mon Sep 17 00:00:00 2001 From: ML-47 Date: Sat, 30 May 2026 23:03:11 +0200 Subject: [PATCH 1/5] split server into services, requests through api gateway --- .github/workflows/deploy-k8s.yml | 4 +- .github/workflows/test-build-push.yml | 29 +- README.md | 37 ++- api-gateway/.dockerignore | 6 + api-gateway/.gitattributes | 2 + api-gateway/.gitignore | 33 ++ .../.mvn/wrapper/maven-wrapper.properties | 3 + api-gateway/Dockerfile | 19 ++ api-gateway/README.md | 32 ++ api-gateway/mvnw | 295 ++++++++++++++++++ api-gateway/mvnw.cmd | 189 +++++++++++ api-gateway/pom.xml | 71 +++++ .../bytebite/server/GenerateController.java | 61 ++++ .../com/bytebite/server/HealthController.java | 15 + .../bytebite/server/ServerApplication.java | 13 + .../java/com/bytebite/server/WebConfig.java | 16 + .../bytebite/server/dto/GenerateRequest.java | 3 + .../bytebite/server/dto/IngredientDTO.java | 3 + .../server/dto/RecipeResponseDTO.java | 5 + .../src/main/resources/application.properties | 3 + .../server/ServerApplicationTests.java | 13 + client/nginx.conf | 4 +- compose.yaml | 7 +- grocery-service/.dockerignore | 6 + grocery-service/.gitattributes | 2 + grocery-service/.gitignore | 33 ++ .../.mvn/wrapper/maven-wrapper.properties | 3 + grocery-service/Dockerfile | 19 ++ grocery-service/README.md | 32 ++ grocery-service/mvnw | 295 ++++++++++++++++++ grocery-service/mvnw.cmd | 189 +++++++++++ grocery-service/pom.xml | 71 +++++ .../java/com/bytebite/server/GenAiClient.java | 18 ++ .../bytebite/server/GenerateController.java | 58 ++++ .../com/bytebite/server/HealthController.java | 15 + .../bytebite/server/ServerApplication.java | 13 + .../java/com/bytebite/server/WebConfig.java | 16 + .../bytebite/server/dto/GenerateRequest.java | 3 + .../bytebite/server/dto/IngredientDTO.java | 3 + .../server/dto/RecipeResponseDTO.java | 5 + .../src/main/resources/application.properties | 2 + .../server/ServerApplicationTests.java | 13 + helm/bytebite/README.md | 6 +- .../templates/api-gateway-deployment.yaml | 33 ++ .../templates/api-gateway-service.yaml | 13 + helm/bytebite/templates/client-configmap.yaml | 6 + ...t.yaml => grocery-service-deployment.yaml} | 16 +- .../templates/grocery-service-service.yaml | 13 + helm/bytebite/templates/ingress.yaml | 6 +- helm/bytebite/templates/server-service.yaml | 13 - .../templates/user-service-deployment.yaml | 28 ++ .../templates/user-service-service.yaml | 13 + helm/bytebite/values.yaml | 26 +- user-service/.dockerignore | 6 + user-service/.gitattributes | 2 + user-service/.gitignore | 33 ++ .../.mvn/wrapper/maven-wrapper.properties | 3 + user-service/Dockerfile | 19 ++ user-service/README.md | 32 ++ user-service/mvnw | 295 ++++++++++++++++++ user-service/mvnw.cmd | 189 +++++++++++ user-service/pom.xml | 71 +++++ .../com/bytebite/server/HealthController.java | 15 + .../bytebite/server/ServerApplication.java | 13 + .../java/com/bytebite/server/WebConfig.java | 16 + .../src/main/resources/application.properties | 1 + .../server/ServerApplicationTests.java | 13 + 67 files changed, 2493 insertions(+), 47 deletions(-) create mode 100644 api-gateway/.dockerignore create mode 100644 api-gateway/.gitattributes create mode 100644 api-gateway/.gitignore create mode 100644 api-gateway/.mvn/wrapper/maven-wrapper.properties create mode 100644 api-gateway/Dockerfile create mode 100644 api-gateway/README.md create mode 100755 api-gateway/mvnw create mode 100644 api-gateway/mvnw.cmd create mode 100644 api-gateway/pom.xml create mode 100644 api-gateway/src/main/java/com/bytebite/server/GenerateController.java create mode 100644 api-gateway/src/main/java/com/bytebite/server/HealthController.java create mode 100644 api-gateway/src/main/java/com/bytebite/server/ServerApplication.java create mode 100644 api-gateway/src/main/java/com/bytebite/server/WebConfig.java create mode 100644 api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java create mode 100644 api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java create mode 100644 api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java create mode 100644 api-gateway/src/main/resources/application.properties create mode 100644 api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java create mode 100644 grocery-service/.dockerignore create mode 100644 grocery-service/.gitattributes create mode 100644 grocery-service/.gitignore create mode 100644 grocery-service/.mvn/wrapper/maven-wrapper.properties create mode 100644 grocery-service/Dockerfile create mode 100644 grocery-service/README.md create mode 100755 grocery-service/mvnw create mode 100644 grocery-service/mvnw.cmd create mode 100644 grocery-service/pom.xml create mode 100644 grocery-service/src/main/java/com/bytebite/server/GenAiClient.java create mode 100644 grocery-service/src/main/java/com/bytebite/server/GenerateController.java create mode 100644 grocery-service/src/main/java/com/bytebite/server/HealthController.java create mode 100644 grocery-service/src/main/java/com/bytebite/server/ServerApplication.java create mode 100644 grocery-service/src/main/java/com/bytebite/server/WebConfig.java create mode 100644 grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java create mode 100644 grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java create mode 100644 grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java create mode 100644 grocery-service/src/main/resources/application.properties create mode 100644 grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java create mode 100644 helm/bytebite/templates/api-gateway-deployment.yaml create mode 100644 helm/bytebite/templates/api-gateway-service.yaml rename helm/bytebite/templates/{server-deployment.yaml => grocery-service-deployment.yaml} (52%) create mode 100644 helm/bytebite/templates/grocery-service-service.yaml delete mode 100644 helm/bytebite/templates/server-service.yaml create mode 100644 helm/bytebite/templates/user-service-deployment.yaml create mode 100644 helm/bytebite/templates/user-service-service.yaml create mode 100644 user-service/.dockerignore create mode 100644 user-service/.gitattributes create mode 100644 user-service/.gitignore create mode 100644 user-service/.mvn/wrapper/maven-wrapper.properties create mode 100644 user-service/Dockerfile create mode 100644 user-service/README.md create mode 100755 user-service/mvnw create mode 100644 user-service/mvnw.cmd create mode 100644 user-service/pom.xml create mode 100644 user-service/src/main/java/com/bytebite/server/HealthController.java create mode 100644 user-service/src/main/java/com/bytebite/server/ServerApplication.java create mode 100644 user-service/src/main/java/com/bytebite/server/WebConfig.java create mode 100644 user-service/src/main/resources/application.properties create mode 100644 user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java diff --git a/.github/workflows/deploy-k8s.yml b/.github/workflows/deploy-k8s.yml index 0f52412..4750a32 100644 --- a/.github/workflows/deploy-k8s.yml +++ b/.github/workflows/deploy-k8s.yml @@ -57,7 +57,9 @@ jobs: helm upgrade --install bytebite ./helm/bytebite \ --namespace team-bytebite \ --set client.image.tag=${{ steps.vars.outputs.image_tag }} \ - --set server.image.tag=${{ steps.vars.outputs.image_tag }} \ + --set apiGateway.image.tag=${{ steps.vars.outputs.image_tag }} \ + --set userService.image.tag=${{ steps.vars.outputs.image_tag }} \ + --set groceryService.image.tag=${{ steps.vars.outputs.image_tag }} \ --set genai.image.tag=${{ steps.vars.outputs.image_tag }} \ --set genai.openaiApiKey="${{ secrets.OPENAI_API_KEY }}" \ --atomic \ diff --git a/.github/workflows/test-build-push.yml b/.github/workflows/test-build-push.yml index efa2b3d..43f067f 100644 --- a/.github/workflows/test-build-push.yml +++ b/.github/workflows/test-build-push.yml @@ -15,6 +15,9 @@ jobs: test: name: Run Java Tests runs-on: ubuntu-latest + strategy: + matrix: + service: [api-gateway, user-service, grocery-service] steps: - name: Checkout uses: actions/checkout@v4 @@ -27,15 +30,29 @@ jobs: cache: maven - name: Run tests with Maven - run: cd server && ./mvnw -B test + run: cd ${{ matrix.service }} && ./mvnw -B test build: - name: Build ${{ matrix.service }} + name: Build ${{ matrix.image }} needs: test runs-on: ubuntu-latest strategy: matrix: - service: [client, server, gen-ai] + include: + - image: client + context: ./client + - image: api-gateway + context: ./api-gateway + - image: user-service + context: ./user-service + - image: grocery-service + context: ./grocery-service + - image: gen-ai + context: ./gen-ai + - image: user-db + context: ./docker/user-db + - image: grocery-db + context: ./docker/grocery-db steps: - name: Checkout uses: actions/checkout@v4 @@ -57,7 +74,7 @@ jobs: uses: docker/metadata-action@v5 with: # metadata-action lowercases the image name for ghcr.io automatically. - images: ghcr.io/${{ github.repository }}/${{ matrix.service }} + images: ghcr.io/${{ github.repository }}/${{ matrix.image }} tags: | type=raw,value=latest,enable={{is_default_branch}} type=ref,event=branch @@ -66,8 +83,8 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v6 with: - context: ./${{ matrix.service }} - file: ./${{ matrix.service }}/Dockerfile + context: ${{ matrix.context }} + file: ${{ matrix.context }}/Dockerfile push: ${{ github.ref == 'refs/heads/main' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/README.md b/README.md index e874f41..e1e00e1 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,12 @@ Unlike traditional apps that rely on rigid "If/Then" logic or specific formattin ``` team-bytebite/ -├── client/ # React + Vite frontend -├── server/ # Java Spring Boot backend API -└── gen-ai/ # Python FastAPI service for AI-based recipe and shopping list generation +├── client/ # React + Vite frontend +├── api-gateway/ # Java Spring Boot public backend entrypoint +├── user-service/ # Java Spring Boot user domain service +├── grocery-service/ # Java Spring Boot grocery and recipe domain service +├── gen-ai/ # Python FastAPI service for AI-based recipe and shopping list generation +└── docker/ # Database image definitions and init schemas ``` ## Services @@ -48,8 +51,14 @@ team-bytebite/ ### `client` — React / Vite The user-facing web application. Provides a dish name input and displays the generated shopping list. Communicates with the backend via REST. -### `server` — Java Spring Boot -The core backend API. Manages users, recipes, and shopping lists. Orchestrates requests between the client and the gen-ai service. +### `api-gateway` — Java Spring Boot +The public backend entrypoint. Receives frontend API requests and forwards them to the owning backend service. + +### `user-service` — Java Spring Boot +Owns user-related data and connects to the user database. + +### `grocery-service` — Java Spring Boot +Owns recipes, grocery lists, and grocery items. Connects to the grocery database and calls the gen-ai service when ingredient generation is needed. ### `gen-ai` — Python FastAPI The AI generation service. Receives a dish name from the server and returns a shopping list with all required ingredients using LLM integrations. @@ -71,13 +80,25 @@ pip install -r requirements.txt uvicorn main:app --reload ``` -**2. Server** (port 8080) +**2. User Service** (port 8083) +```bash +cd user-service +SERVER_PORT=8083 ./mvnw spring-boot:run +``` + +**3. Grocery Service** (port 8082) +```bash +cd grocery-service +SERVER_PORT=8082 ./mvnw spring-boot:run +``` + +**4. API Gateway** (port 8080) ```bash -cd server +cd api-gateway ./mvnw spring-boot:run ``` -**3. Client** (port 5173) +**5. Client** (port 5173) ```bash cd client npm install diff --git a/api-gateway/.dockerignore b/api-gateway/.dockerignore new file mode 100644 index 0000000..1be2196 --- /dev/null +++ b/api-gateway/.dockerignore @@ -0,0 +1,6 @@ +target +.idea +.git +*.iml +.DS_Store +.mvn \ No newline at end of file diff --git a/api-gateway/.gitattributes b/api-gateway/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/api-gateway/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/api-gateway/.gitignore b/api-gateway/.gitignore new file mode 100644 index 0000000..667aaef --- /dev/null +++ b/api-gateway/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/api-gateway/.mvn/wrapper/maven-wrapper.properties b/api-gateway/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..5291372 --- /dev/null +++ b/api-gateway/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.15/apache-maven-3.9.15-bin.zip diff --git a/api-gateway/Dockerfile b/api-gateway/Dockerfile new file mode 100644 index 0000000..533a08b --- /dev/null +++ b/api-gateway/Dockerfile @@ -0,0 +1,19 @@ +# Build stage +FROM maven:3.9-eclipse-temurin-21 AS build +WORKDIR /app + +COPY pom.xml . +RUN mvn dependency:go-offline + +COPY src ./src +RUN mvn clean package -DskipTests + +# Runtime stage +FROM eclipse-temurin:21-jre +WORKDIR /app + +COPY --from=build /app/target/*.jar app.jar + +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/api-gateway/README.md b/api-gateway/README.md new file mode 100644 index 0000000..f159c37 --- /dev/null +++ b/api-gateway/README.md @@ -0,0 +1,32 @@ +# server + +Java Spring Boot backend API for ByteBite. + +## Prerequisites + +- Java 21 + +## Setup & Run + +**macOS / Linux** +```bash +./mvnw spring-boot:run # starts on http://localhost:8080 +``` + +**Windows** +```cmd +mvnw.cmd spring-boot:run +``` + +## Other Commands + +| | macOS / Linux | Windows | +|-|---------------|---------| +| Build | `./mvnw package` | `mvnw.cmd package` | +| Test | `./mvnw test` | `mvnw.cmd test` | + +## Endpoints + +| Method | Path | Description | +|--------|-----------|---------------| +| GET | /health | Health check | diff --git a/api-gateway/mvnw b/api-gateway/mvnw new file mode 100755 index 0000000..bd8896b --- /dev/null +++ b/api-gateway/mvnw @@ -0,0 +1,295 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/api-gateway/mvnw.cmd b/api-gateway/mvnw.cmd new file mode 100644 index 0000000..92450f9 --- /dev/null +++ b/api-gateway/mvnw.cmd @@ -0,0 +1,189 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' + +$MAVEN_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/api-gateway/pom.xml b/api-gateway/pom.xml new file mode 100644 index 0000000..92ef458 --- /dev/null +++ b/api-gateway/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.5 + + + com.bytebite + api-gateway + 0.0.1-SNAPSHOT + api-gateway + + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.mockito + mockito-core + + + org.mockito + mockito-junit-jupiter + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + -Djdk.attach.allowAttachSelf=true + + + + + + diff --git a/api-gateway/src/main/java/com/bytebite/server/GenerateController.java b/api-gateway/src/main/java/com/bytebite/server/GenerateController.java new file mode 100644 index 0000000..9ee1f36 --- /dev/null +++ b/api-gateway/src/main/java/com/bytebite/server/GenerateController.java @@ -0,0 +1,61 @@ +package com.bytebite.server; + +import com.bytebite.server.dto.GenerateRequest; +import com.bytebite.server.dto.RecipeResponseDTO; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; +import org.springframework.web.client.ResourceAccessException; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.server.ResponseStatusException; +import org.springframework.web.util.DefaultUriBuilderFactory; + +import java.util.Map; + +@RestController +public class GenerateController { + + private final RestTemplate groceryServiceRestTemplate; + + public GenerateController(@Value("${GROCERY_SERVICE_BASE_URL:${grocery-service.base-url}}") String groceryServiceBaseUrl) { + this.groceryServiceRestTemplate = new RestTemplate(); + this.groceryServiceRestTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(groceryServiceBaseUrl)); + } + + @PostMapping(value = "/api/recipes/generate", + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + public RecipeResponseDTO generate(@RequestBody GenerateRequest request) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity> entity = new HttpEntity<>(Map.of("dish", request.dish()), headers); + + RecipeResponseDTO response; + try { + response = groceryServiceRestTemplate.postForObject("/api/recipes/generate", entity, RecipeResponseDTO.class); + } catch (HttpClientErrorException e) { + throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, + "Grocery service rejected the request: " + e.getMessage()); + } catch (HttpServerErrorException e) { + throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, + "Grocery service encountered an error: " + e.getMessage()); + } catch (ResourceAccessException e) { + throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, + "Grocery service is unreachable"); + } + + if (response == null || response.ingredients() == null || response.ingredients().isEmpty()) { + throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, + "Grocery service returned no ingredients for the given input"); + } + + return response; + } +} diff --git a/api-gateway/src/main/java/com/bytebite/server/HealthController.java b/api-gateway/src/main/java/com/bytebite/server/HealthController.java new file mode 100644 index 0000000..d57cdec --- /dev/null +++ b/api-gateway/src/main/java/com/bytebite/server/HealthController.java @@ -0,0 +1,15 @@ +package com.bytebite.server; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +public class HealthController { + + @GetMapping("/health") + public Map health() { + return Map.of("status", "ok"); + } +} diff --git a/api-gateway/src/main/java/com/bytebite/server/ServerApplication.java b/api-gateway/src/main/java/com/bytebite/server/ServerApplication.java new file mode 100644 index 0000000..13d5438 --- /dev/null +++ b/api-gateway/src/main/java/com/bytebite/server/ServerApplication.java @@ -0,0 +1,13 @@ +package com.bytebite.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ServerApplication { + + public static void main(String[] args) { + SpringApplication.run(ServerApplication.class, args); + } + +} diff --git a/api-gateway/src/main/java/com/bytebite/server/WebConfig.java b/api-gateway/src/main/java/com/bytebite/server/WebConfig.java new file mode 100644 index 0000000..4b79ea3 --- /dev/null +++ b/api-gateway/src/main/java/com/bytebite/server/WebConfig.java @@ -0,0 +1,16 @@ +package com.bytebite.server; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOriginPatterns("*") + .allowedMethods("GET", "POST"); + } +} diff --git a/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java b/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java new file mode 100644 index 0000000..e911f2f --- /dev/null +++ b/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java @@ -0,0 +1,3 @@ +package com.bytebite.server.dto; + +public record GenerateRequest(String dish) {} diff --git a/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java b/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java new file mode 100644 index 0000000..f52e4de --- /dev/null +++ b/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java @@ -0,0 +1,3 @@ +package com.bytebite.server.dto; + +public record IngredientDTO(String name, String quantity, String unit, String category) {} diff --git a/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java b/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java new file mode 100644 index 0000000..e4ea6a0 --- /dev/null +++ b/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java @@ -0,0 +1,5 @@ +package com.bytebite.server.dto; + +import java.util.List; + +public record RecipeResponseDTO(String dish, List ingredients) {} diff --git a/api-gateway/src/main/resources/application.properties b/api-gateway/src/main/resources/application.properties new file mode 100644 index 0000000..27680a1 --- /dev/null +++ b/api-gateway/src/main/resources/application.properties @@ -0,0 +1,3 @@ +spring.application.name=api-gateway +grocery-service.base-url=http://localhost:8082 +user-service.base-url=http://localhost:8083 diff --git a/api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java b/api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java new file mode 100644 index 0000000..2d6d85b --- /dev/null +++ b/api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java @@ -0,0 +1,13 @@ +package com.bytebite.server; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ServerApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/client/nginx.conf b/client/nginx.conf index 2a55370..2a44253 100644 --- a/client/nginx.conf +++ b/client/nginx.conf @@ -8,8 +8,8 @@ server { try_files $uri $uri/ /index.html; } - location /generate { - proxy_pass http://server:8080; + location /api/ { + proxy_pass http://api-gateway:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/compose.yaml b/compose.yaml index ef50db8..cdf533d 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,5 +1,6 @@ services: user-db: + image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/user-db:${IMAGE_TAG:-latest} build: context: ./docker/user-db container_name: bytebite-user-db @@ -16,6 +17,7 @@ services: retries: 5 grocery-db: + image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/grocery-db:${IMAGE_TAG:-latest} build: context: ./docker/grocery-db container_name: bytebite-grocery-db @@ -44,6 +46,7 @@ services: user-service: + image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/user-service:${IMAGE_TAG:-latest} build: context: ./user-service container_name: bytebite-user-service @@ -59,6 +62,7 @@ services: condition: service_healthy grocery-service: + image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/grocery-service:${IMAGE_TAG:-latest} build: context: ./grocery-service container_name: bytebite-grocery-service @@ -77,6 +81,7 @@ services: condition: service_started api-gateway: + image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/api-gateway:${IMAGE_TAG:-latest} build: context: ./api-gateway container_name: bytebite-api-gateway @@ -91,8 +96,6 @@ services: condition: service_started grocery-service: condition: service_started - gen-ai: - condition: service_started client: image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/client:${IMAGE_TAG:-latest} diff --git a/grocery-service/.dockerignore b/grocery-service/.dockerignore new file mode 100644 index 0000000..1be2196 --- /dev/null +++ b/grocery-service/.dockerignore @@ -0,0 +1,6 @@ +target +.idea +.git +*.iml +.DS_Store +.mvn \ No newline at end of file diff --git a/grocery-service/.gitattributes b/grocery-service/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/grocery-service/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/grocery-service/.gitignore b/grocery-service/.gitignore new file mode 100644 index 0000000..667aaef --- /dev/null +++ b/grocery-service/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/grocery-service/.mvn/wrapper/maven-wrapper.properties b/grocery-service/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..5291372 --- /dev/null +++ b/grocery-service/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.15/apache-maven-3.9.15-bin.zip diff --git a/grocery-service/Dockerfile b/grocery-service/Dockerfile new file mode 100644 index 0000000..533a08b --- /dev/null +++ b/grocery-service/Dockerfile @@ -0,0 +1,19 @@ +# Build stage +FROM maven:3.9-eclipse-temurin-21 AS build +WORKDIR /app + +COPY pom.xml . +RUN mvn dependency:go-offline + +COPY src ./src +RUN mvn clean package -DskipTests + +# Runtime stage +FROM eclipse-temurin:21-jre +WORKDIR /app + +COPY --from=build /app/target/*.jar app.jar + +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/grocery-service/README.md b/grocery-service/README.md new file mode 100644 index 0000000..f159c37 --- /dev/null +++ b/grocery-service/README.md @@ -0,0 +1,32 @@ +# server + +Java Spring Boot backend API for ByteBite. + +## Prerequisites + +- Java 21 + +## Setup & Run + +**macOS / Linux** +```bash +./mvnw spring-boot:run # starts on http://localhost:8080 +``` + +**Windows** +```cmd +mvnw.cmd spring-boot:run +``` + +## Other Commands + +| | macOS / Linux | Windows | +|-|---------------|---------| +| Build | `./mvnw package` | `mvnw.cmd package` | +| Test | `./mvnw test` | `mvnw.cmd test` | + +## Endpoints + +| Method | Path | Description | +|--------|-----------|---------------| +| GET | /health | Health check | diff --git a/grocery-service/mvnw b/grocery-service/mvnw new file mode 100755 index 0000000..bd8896b --- /dev/null +++ b/grocery-service/mvnw @@ -0,0 +1,295 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/grocery-service/mvnw.cmd b/grocery-service/mvnw.cmd new file mode 100644 index 0000000..92450f9 --- /dev/null +++ b/grocery-service/mvnw.cmd @@ -0,0 +1,189 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' + +$MAVEN_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/grocery-service/pom.xml b/grocery-service/pom.xml new file mode 100644 index 0000000..43845e4 --- /dev/null +++ b/grocery-service/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.5 + + + com.bytebite + grocery-service + 0.0.1-SNAPSHOT + grocery-service + + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.mockito + mockito-core + + + org.mockito + mockito-junit-jupiter + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + -Djdk.attach.allowAttachSelf=true + + + + + + diff --git a/grocery-service/src/main/java/com/bytebite/server/GenAiClient.java b/grocery-service/src/main/java/com/bytebite/server/GenAiClient.java new file mode 100644 index 0000000..d79fc41 --- /dev/null +++ b/grocery-service/src/main/java/com/bytebite/server/GenAiClient.java @@ -0,0 +1,18 @@ +package com.bytebite.server; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.DefaultUriBuilderFactory; + +@Configuration +public class GenAiClient { + + @Bean + public RestTemplate genAiRestTemplate(@Value("${genai.base-url}") String baseUrl) { + RestTemplate template = new RestTemplate(); + template.setUriTemplateHandler(new DefaultUriBuilderFactory(baseUrl)); + return template; + } +} diff --git a/grocery-service/src/main/java/com/bytebite/server/GenerateController.java b/grocery-service/src/main/java/com/bytebite/server/GenerateController.java new file mode 100644 index 0000000..23e1e53 --- /dev/null +++ b/grocery-service/src/main/java/com/bytebite/server/GenerateController.java @@ -0,0 +1,58 @@ +package com.bytebite.server; + +import com.bytebite.server.dto.GenerateRequest; +import com.bytebite.server.dto.RecipeResponseDTO; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; +import org.springframework.web.client.ResourceAccessException; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Map; + +@RestController +public class GenerateController { + + private final RestTemplate genAiRestTemplate; + + public GenerateController(RestTemplate genAiRestTemplate) { + this.genAiRestTemplate = genAiRestTemplate; + } + + @PostMapping(value = "/api/recipes/generate", + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + public RecipeResponseDTO generate(@RequestBody GenerateRequest request) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity> entity = new HttpEntity<>(Map.of("dish", request.dish()), headers); + + RecipeResponseDTO response; + try { + response = genAiRestTemplate.postForObject("/api/ai/parse", entity, RecipeResponseDTO.class); + } catch (HttpClientErrorException e) { + throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, + "AI service rejected the request: " + e.getMessage()); + } catch (HttpServerErrorException e) { + throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, + "AI service encountered an error: " + e.getMessage()); + } catch (ResourceAccessException e) { + throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, + "AI service is unreachable"); + } + + if (response == null || response.ingredients() == null || response.ingredients().isEmpty()) { + throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, + "AI service returned no ingredients for the given input"); + } + + return response; + } +} diff --git a/grocery-service/src/main/java/com/bytebite/server/HealthController.java b/grocery-service/src/main/java/com/bytebite/server/HealthController.java new file mode 100644 index 0000000..d57cdec --- /dev/null +++ b/grocery-service/src/main/java/com/bytebite/server/HealthController.java @@ -0,0 +1,15 @@ +package com.bytebite.server; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +public class HealthController { + + @GetMapping("/health") + public Map health() { + return Map.of("status", "ok"); + } +} diff --git a/grocery-service/src/main/java/com/bytebite/server/ServerApplication.java b/grocery-service/src/main/java/com/bytebite/server/ServerApplication.java new file mode 100644 index 0000000..13d5438 --- /dev/null +++ b/grocery-service/src/main/java/com/bytebite/server/ServerApplication.java @@ -0,0 +1,13 @@ +package com.bytebite.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ServerApplication { + + public static void main(String[] args) { + SpringApplication.run(ServerApplication.class, args); + } + +} diff --git a/grocery-service/src/main/java/com/bytebite/server/WebConfig.java b/grocery-service/src/main/java/com/bytebite/server/WebConfig.java new file mode 100644 index 0000000..4b79ea3 --- /dev/null +++ b/grocery-service/src/main/java/com/bytebite/server/WebConfig.java @@ -0,0 +1,16 @@ +package com.bytebite.server; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOriginPatterns("*") + .allowedMethods("GET", "POST"); + } +} diff --git a/grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java b/grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java new file mode 100644 index 0000000..e911f2f --- /dev/null +++ b/grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java @@ -0,0 +1,3 @@ +package com.bytebite.server.dto; + +public record GenerateRequest(String dish) {} diff --git a/grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java b/grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java new file mode 100644 index 0000000..f52e4de --- /dev/null +++ b/grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java @@ -0,0 +1,3 @@ +package com.bytebite.server.dto; + +public record IngredientDTO(String name, String quantity, String unit, String category) {} diff --git a/grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java b/grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java new file mode 100644 index 0000000..e4ea6a0 --- /dev/null +++ b/grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java @@ -0,0 +1,5 @@ +package com.bytebite.server.dto; + +import java.util.List; + +public record RecipeResponseDTO(String dish, List ingredients) {} diff --git a/grocery-service/src/main/resources/application.properties b/grocery-service/src/main/resources/application.properties new file mode 100644 index 0000000..078dc96 --- /dev/null +++ b/grocery-service/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.application.name=grocery-service +genai.base-url=http://localhost:8000 diff --git a/grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java b/grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java new file mode 100644 index 0000000..2d6d85b --- /dev/null +++ b/grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java @@ -0,0 +1,13 @@ +package com.bytebite.server; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ServerApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/helm/bytebite/README.md b/helm/bytebite/README.md index d476341..a8e1157 100644 --- a/helm/bytebite/README.md +++ b/helm/bytebite/README.md @@ -1,6 +1,6 @@ # ByteBite Helm Chart -Deploys the ByteBite application (client, server, gen-ai) to Kubernetes. +Deploys the ByteBite application (client, api-gateway, user-service, grocery-service, gen-ai) to Kubernetes. ## Prerequisites @@ -29,5 +29,7 @@ helm uninstall bytebite --namespace team-bytebite | `ingress.tls` | Enable TLS via cert-manager | `true` | | `genai.openaiApiKey` | OpenAI API key for the gen-ai service | `""` | | `client.image.tag` | Client image tag | `latest` | -| `server.image.tag` | Server image tag | `latest` | +| `apiGateway.image.tag` | API gateway image tag | `latest` | +| `userService.image.tag` | User service image tag | `latest` | +| `groceryService.image.tag` | Grocery service image tag | `latest` | | `genai.image.tag` | Gen-AI image tag | `latest` | diff --git a/helm/bytebite/templates/api-gateway-deployment.yaml b/helm/bytebite/templates/api-gateway-deployment.yaml new file mode 100644 index 0000000..84d2f67 --- /dev/null +++ b/helm/bytebite/templates/api-gateway-deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: bytebite-api-gateway + namespace: {{ .Values.namespace }} +spec: + replicas: {{ .Values.apiGateway.replicaCount }} + selector: + matchLabels: + app: bytebite-api-gateway-selector + template: + metadata: + labels: + app: bytebite-api-gateway-selector + spec: + containers: + - name: api-gateway + image: "{{ .Values.apiGateway.image.repository }}:{{ .Values.apiGateway.image.tag }}" + imagePullPolicy: {{ .Values.apiGateway.image.pullPolicy }} + resources: + limits: + cpu: "500m" + memory: "512Mi" + requests: + cpu: "200m" + memory: "256Mi" + ports: + - containerPort: {{ .Values.apiGateway.service.targetPort }} + env: + - name: GROCERY_SERVICE_BASE_URL + value: "http://grocery-service:{{ .Values.groceryService.service.port }}" + - name: USER_SERVICE_BASE_URL + value: "http://user-service:{{ .Values.userService.service.port }}" diff --git a/helm/bytebite/templates/api-gateway-service.yaml b/helm/bytebite/templates/api-gateway-service.yaml new file mode 100644 index 0000000..11d8f0e --- /dev/null +++ b/helm/bytebite/templates/api-gateway-service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: api-gateway-service + namespace: {{ .Values.namespace }} +spec: + selector: + app: bytebite-api-gateway-selector + ports: + - port: {{ .Values.apiGateway.service.port }} + targetPort: {{ .Values.apiGateway.service.targetPort }} + protocol: TCP + type: {{ .Values.apiGateway.service.type }} diff --git a/helm/bytebite/templates/client-configmap.yaml b/helm/bytebite/templates/client-configmap.yaml index df9a622..0c9b3cd 100644 --- a/helm/bytebite/templates/client-configmap.yaml +++ b/helm/bytebite/templates/client-configmap.yaml @@ -12,4 +12,10 @@ data: location / { try_files $uri $uri/ /index.html; } + location /api/ { + proxy_pass http://api-gateway-service:{{ .Values.apiGateway.service.port }}; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } } diff --git a/helm/bytebite/templates/server-deployment.yaml b/helm/bytebite/templates/grocery-service-deployment.yaml similarity index 52% rename from helm/bytebite/templates/server-deployment.yaml rename to helm/bytebite/templates/grocery-service-deployment.yaml index 3011432..1e759f2 100644 --- a/helm/bytebite/templates/server-deployment.yaml +++ b/helm/bytebite/templates/grocery-service-deployment.yaml @@ -1,22 +1,22 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: bytebite-server + name: bytebite-grocery-service namespace: {{ .Values.namespace }} spec: - replicas: {{ .Values.server.replicaCount }} + replicas: {{ .Values.groceryService.replicaCount }} selector: matchLabels: - app: bytebite-server-selector + app: bytebite-grocery-service-selector template: metadata: labels: - app: bytebite-server-selector + app: bytebite-grocery-service-selector spec: containers: - - name: server - image: "{{ .Values.server.image.repository }}:{{ .Values.server.image.tag }}" - imagePullPolicy: {{ .Values.server.image.pullPolicy }} + - name: grocery-service + image: "{{ .Values.groceryService.image.repository }}:{{ .Values.groceryService.image.tag }}" + imagePullPolicy: {{ .Values.groceryService.image.pullPolicy }} resources: limits: cpu: "500m" @@ -25,7 +25,7 @@ spec: cpu: "200m" memory: "256Mi" ports: - - containerPort: {{ .Values.server.service.targetPort }} + - containerPort: {{ .Values.groceryService.service.targetPort }} env: - name: GENAI_BASE_URL value: "http://genai-service:{{ .Values.genai.service.port }}" diff --git a/helm/bytebite/templates/grocery-service-service.yaml b/helm/bytebite/templates/grocery-service-service.yaml new file mode 100644 index 0000000..ee7b6ef --- /dev/null +++ b/helm/bytebite/templates/grocery-service-service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: grocery-service + namespace: {{ .Values.namespace }} +spec: + selector: + app: bytebite-grocery-service-selector + ports: + - port: {{ .Values.groceryService.service.port }} + targetPort: {{ .Values.groceryService.service.targetPort }} + protocol: TCP + type: {{ .Values.groceryService.service.type }} diff --git a/helm/bytebite/templates/ingress.yaml b/helm/bytebite/templates/ingress.yaml index 817ab6d..6790331 100644 --- a/helm/bytebite/templates/ingress.yaml +++ b/helm/bytebite/templates/ingress.yaml @@ -27,11 +27,11 @@ spec: name: client-service port: number: {{ .Values.client.service.port }} - - path: /generate + - path: /api pathType: Prefix backend: service: - name: server-service + name: api-gateway-service port: - number: {{ .Values.server.service.port }} + number: {{ .Values.apiGateway.service.port }} {{- end }} diff --git a/helm/bytebite/templates/server-service.yaml b/helm/bytebite/templates/server-service.yaml deleted file mode 100644 index f3190e2..0000000 --- a/helm/bytebite/templates/server-service.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: server-service - namespace: {{ .Values.namespace }} -spec: - selector: - app: bytebite-server-selector - ports: - - port: {{ .Values.server.service.port }} - targetPort: {{ .Values.server.service.targetPort }} - protocol: TCP - type: {{ .Values.server.service.type }} diff --git a/helm/bytebite/templates/user-service-deployment.yaml b/helm/bytebite/templates/user-service-deployment.yaml new file mode 100644 index 0000000..64e5a56 --- /dev/null +++ b/helm/bytebite/templates/user-service-deployment.yaml @@ -0,0 +1,28 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: bytebite-user-service + namespace: {{ .Values.namespace }} +spec: + replicas: {{ .Values.userService.replicaCount }} + selector: + matchLabels: + app: bytebite-user-service-selector + template: + metadata: + labels: + app: bytebite-user-service-selector + spec: + containers: + - name: user-service + image: "{{ .Values.userService.image.repository }}:{{ .Values.userService.image.tag }}" + imagePullPolicy: {{ .Values.userService.image.pullPolicy }} + resources: + limits: + cpu: "500m" + memory: "512Mi" + requests: + cpu: "200m" + memory: "256Mi" + ports: + - containerPort: {{ .Values.userService.service.targetPort }} diff --git a/helm/bytebite/templates/user-service-service.yaml b/helm/bytebite/templates/user-service-service.yaml new file mode 100644 index 0000000..ab5e62f --- /dev/null +++ b/helm/bytebite/templates/user-service-service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: user-service + namespace: {{ .Values.namespace }} +spec: + selector: + app: bytebite-user-service-selector + ports: + - port: {{ .Values.userService.service.port }} + targetPort: {{ .Values.userService.service.targetPort }} + protocol: TCP + type: {{ .Values.userService.service.type }} diff --git a/helm/bytebite/values.yaml b/helm/bytebite/values.yaml index d5ae8f6..977973b 100644 --- a/helm/bytebite/values.yaml +++ b/helm/bytebite/values.yaml @@ -12,9 +12,31 @@ client: targetPort: 80 replicaCount: 1 -server: +apiGateway: image: - repository: ghcr.io/aet-devops26/team-bytebite/server + repository: ghcr.io/aet-devops26/team-bytebite/api-gateway + tag: latest + pullPolicy: Always + service: + type: ClusterIP + port: 8080 + targetPort: 8080 + replicaCount: 1 + +userService: + image: + repository: ghcr.io/aet-devops26/team-bytebite/user-service + tag: latest + pullPolicy: Always + service: + type: ClusterIP + port: 8080 + targetPort: 8080 + replicaCount: 1 + +groceryService: + image: + repository: ghcr.io/aet-devops26/team-bytebite/grocery-service tag: latest pullPolicy: Always service: diff --git a/user-service/.dockerignore b/user-service/.dockerignore new file mode 100644 index 0000000..1be2196 --- /dev/null +++ b/user-service/.dockerignore @@ -0,0 +1,6 @@ +target +.idea +.git +*.iml +.DS_Store +.mvn \ No newline at end of file diff --git a/user-service/.gitattributes b/user-service/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/user-service/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/user-service/.gitignore b/user-service/.gitignore new file mode 100644 index 0000000..667aaef --- /dev/null +++ b/user-service/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/user-service/.mvn/wrapper/maven-wrapper.properties b/user-service/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..5291372 --- /dev/null +++ b/user-service/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.15/apache-maven-3.9.15-bin.zip diff --git a/user-service/Dockerfile b/user-service/Dockerfile new file mode 100644 index 0000000..533a08b --- /dev/null +++ b/user-service/Dockerfile @@ -0,0 +1,19 @@ +# Build stage +FROM maven:3.9-eclipse-temurin-21 AS build +WORKDIR /app + +COPY pom.xml . +RUN mvn dependency:go-offline + +COPY src ./src +RUN mvn clean package -DskipTests + +# Runtime stage +FROM eclipse-temurin:21-jre +WORKDIR /app + +COPY --from=build /app/target/*.jar app.jar + +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/user-service/README.md b/user-service/README.md new file mode 100644 index 0000000..f159c37 --- /dev/null +++ b/user-service/README.md @@ -0,0 +1,32 @@ +# server + +Java Spring Boot backend API for ByteBite. + +## Prerequisites + +- Java 21 + +## Setup & Run + +**macOS / Linux** +```bash +./mvnw spring-boot:run # starts on http://localhost:8080 +``` + +**Windows** +```cmd +mvnw.cmd spring-boot:run +``` + +## Other Commands + +| | macOS / Linux | Windows | +|-|---------------|---------| +| Build | `./mvnw package` | `mvnw.cmd package` | +| Test | `./mvnw test` | `mvnw.cmd test` | + +## Endpoints + +| Method | Path | Description | +|--------|-----------|---------------| +| GET | /health | Health check | diff --git a/user-service/mvnw b/user-service/mvnw new file mode 100755 index 0000000..bd8896b --- /dev/null +++ b/user-service/mvnw @@ -0,0 +1,295 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/user-service/mvnw.cmd b/user-service/mvnw.cmd new file mode 100644 index 0000000..92450f9 --- /dev/null +++ b/user-service/mvnw.cmd @@ -0,0 +1,189 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' + +$MAVEN_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/user-service/pom.xml b/user-service/pom.xml new file mode 100644 index 0000000..ab18d00 --- /dev/null +++ b/user-service/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.5 + + + com.bytebite + user-service + 0.0.1-SNAPSHOT + user-service + + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.mockito + mockito-core + + + org.mockito + mockito-junit-jupiter + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + -Djdk.attach.allowAttachSelf=true + + + + + + diff --git a/user-service/src/main/java/com/bytebite/server/HealthController.java b/user-service/src/main/java/com/bytebite/server/HealthController.java new file mode 100644 index 0000000..d57cdec --- /dev/null +++ b/user-service/src/main/java/com/bytebite/server/HealthController.java @@ -0,0 +1,15 @@ +package com.bytebite.server; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +public class HealthController { + + @GetMapping("/health") + public Map health() { + return Map.of("status", "ok"); + } +} diff --git a/user-service/src/main/java/com/bytebite/server/ServerApplication.java b/user-service/src/main/java/com/bytebite/server/ServerApplication.java new file mode 100644 index 0000000..13d5438 --- /dev/null +++ b/user-service/src/main/java/com/bytebite/server/ServerApplication.java @@ -0,0 +1,13 @@ +package com.bytebite.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ServerApplication { + + public static void main(String[] args) { + SpringApplication.run(ServerApplication.class, args); + } + +} diff --git a/user-service/src/main/java/com/bytebite/server/WebConfig.java b/user-service/src/main/java/com/bytebite/server/WebConfig.java new file mode 100644 index 0000000..4b79ea3 --- /dev/null +++ b/user-service/src/main/java/com/bytebite/server/WebConfig.java @@ -0,0 +1,16 @@ +package com.bytebite.server; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOriginPatterns("*") + .allowedMethods("GET", "POST"); + } +} diff --git a/user-service/src/main/resources/application.properties b/user-service/src/main/resources/application.properties new file mode 100644 index 0000000..79b5bda --- /dev/null +++ b/user-service/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=user-service diff --git a/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java b/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java new file mode 100644 index 0000000..2d6d85b --- /dev/null +++ b/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java @@ -0,0 +1,13 @@ +package com.bytebite.server; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ServerApplicationTests { + + @Test + void contextLoads() { + } + +} From f50e17cb2a7d5c49df6d779439c59b9b646093f6 Mon Sep 17 00:00:00 2001 From: ML-47 Date: Sun, 31 May 2026 10:23:26 +0200 Subject: [PATCH 2/5] simplified project structre --- .github/workflows/test-build-push.yml | 14 +- README.md | 21 +- compose.yaml | 12 +- server/pom.xml | 54 ---- .../java/com/bytebite/server/GenAiClient.java | 18 -- .../bytebite/server/GenerateController.java | 58 ---- .../bytebite/server/dto/GenerateRequest.java | 3 - .../bytebite/server/dto/IngredientDTO.java | 3 - .../server/dto/RecipeResponseDTO.java | 5 - .../src/main/resources/application.properties | 2 - .../api-gateway}/.dockerignore | 0 .../api-gateway}/.gitattributes | 0 .../api-gateway}/.gitignore | 0 .../.mvn/wrapper/maven-wrapper.properties | 0 .../api-gateway}/Dockerfile | 0 .../api-gateway}/README.md | 0 {api-gateway => services/api-gateway}/mvnw | 0 .../api-gateway}/mvnw.cmd | 0 {api-gateway => services/api-gateway}/pom.xml | 0 .../bytebite/server/GenerateController.java | 0 .../com/bytebite/server/HealthController.java | 0 .../bytebite/server/ServerApplication.java | 0 .../java/com/bytebite/server/WebConfig.java | 0 .../bytebite/server/dto/GenerateRequest.java | 0 .../bytebite/server/dto/IngredientDTO.java | 0 .../server/dto/RecipeResponseDTO.java | 0 .../src/main/resources/application.properties | 0 .../server/ServerApplicationTests.java | 0 .../databases}/grocery-db/Dockerfile | 0 .../databases}/grocery-db/init.sql | 0 .../databases}/user-db/Dockerfile | 0 .../databases}/user-db/init.sql | 0 {gen-ai => services/gen-ai}/.dockerignore | 0 {gen-ai => services/gen-ai}/.env.example | 0 {gen-ai => services/gen-ai}/.gitignore | 0 {gen-ai => services/gen-ai}/Dockerfile | 0 {gen-ai => services/gen-ai}/README.md | 0 {gen-ai => services/gen-ai}/main.py | 0 {gen-ai => services/gen-ai}/requirements.txt | 0 .../grocery-service}/.dockerignore | 0 .../grocery-service}/.gitattributes | 0 .../grocery-service}/.gitignore | 0 .../.mvn/wrapper/maven-wrapper.properties | 0 .../grocery-service}/Dockerfile | 0 .../grocery-service}/README.md | 0 .../grocery-service}/mvnw | 0 .../grocery-service}/mvnw.cmd | 0 .../grocery-service}/pom.xml | 0 .../java/com/bytebite/server/GenAiClient.java | 0 .../bytebite/server/GenerateController.java | 0 .../com/bytebite/server/HealthController.java | 0 .../bytebite/server/ServerApplication.java | 0 .../java/com/bytebite/server/WebConfig.java | 0 .../bytebite/server/dto/GenerateRequest.java | 0 .../bytebite/server/dto/IngredientDTO.java | 0 .../server/dto/RecipeResponseDTO.java | 0 .../src/main/resources/application.properties | 0 .../server/ServerApplicationTests.java | 0 .../user-service}/.dockerignore | 0 .../user-service}/.gitattributes | 0 {server => services/user-service}/.gitignore | 0 .../.mvn/wrapper/maven-wrapper.properties | 0 {server => services/user-service}/Dockerfile | 0 {server => services/user-service}/README.md | 0 {server => services/user-service}/mvnw | 0 {server => services/user-service}/mvnw.cmd | 0 .../user-service}/pom.xml | 0 .../com/bytebite/server/HealthController.java | 0 .../bytebite/server/ServerApplication.java | 0 .../java/com/bytebite/server/WebConfig.java | 0 .../src/main/resources/application.properties | 0 .../server/ServerApplicationTests.java | 0 user-service/.dockerignore | 6 - user-service/.gitattributes | 2 - user-service/.gitignore | 33 -- .../.mvn/wrapper/maven-wrapper.properties | 3 - user-service/Dockerfile | 19 -- user-service/README.md | 32 -- user-service/mvnw | 295 ------------------ user-service/mvnw.cmd | 189 ----------- .../com/bytebite/server/HealthController.java | 15 - .../bytebite/server/ServerApplication.java | 13 - .../java/com/bytebite/server/WebConfig.java | 16 - .../server/ServerApplicationTests.java | 13 - 84 files changed, 24 insertions(+), 802 deletions(-) delete mode 100644 server/pom.xml delete mode 100644 server/src/main/java/com/bytebite/server/GenAiClient.java delete mode 100644 server/src/main/java/com/bytebite/server/GenerateController.java delete mode 100644 server/src/main/java/com/bytebite/server/dto/GenerateRequest.java delete mode 100644 server/src/main/java/com/bytebite/server/dto/IngredientDTO.java delete mode 100644 server/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java delete mode 100644 server/src/main/resources/application.properties rename {api-gateway => services/api-gateway}/.dockerignore (100%) rename {api-gateway => services/api-gateway}/.gitattributes (100%) rename {api-gateway => services/api-gateway}/.gitignore (100%) rename {api-gateway => services/api-gateway}/.mvn/wrapper/maven-wrapper.properties (100%) rename {api-gateway => services/api-gateway}/Dockerfile (100%) rename {api-gateway => services/api-gateway}/README.md (100%) rename {api-gateway => services/api-gateway}/mvnw (100%) rename {api-gateway => services/api-gateway}/mvnw.cmd (100%) rename {api-gateway => services/api-gateway}/pom.xml (100%) rename {api-gateway => services/api-gateway}/src/main/java/com/bytebite/server/GenerateController.java (100%) rename {api-gateway => services/api-gateway}/src/main/java/com/bytebite/server/HealthController.java (100%) rename {api-gateway => services/api-gateway}/src/main/java/com/bytebite/server/ServerApplication.java (100%) rename {api-gateway => services/api-gateway}/src/main/java/com/bytebite/server/WebConfig.java (100%) rename {api-gateway => services/api-gateway}/src/main/java/com/bytebite/server/dto/GenerateRequest.java (100%) rename {api-gateway => services/api-gateway}/src/main/java/com/bytebite/server/dto/IngredientDTO.java (100%) rename {api-gateway => services/api-gateway}/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java (100%) rename {api-gateway => services/api-gateway}/src/main/resources/application.properties (100%) rename {api-gateway => services/api-gateway}/src/test/java/com/bytebite/server/ServerApplicationTests.java (100%) rename {docker => services/databases}/grocery-db/Dockerfile (100%) rename {docker => services/databases}/grocery-db/init.sql (100%) rename {docker => services/databases}/user-db/Dockerfile (100%) rename {docker => services/databases}/user-db/init.sql (100%) rename {gen-ai => services/gen-ai}/.dockerignore (100%) rename {gen-ai => services/gen-ai}/.env.example (100%) rename {gen-ai => services/gen-ai}/.gitignore (100%) rename {gen-ai => services/gen-ai}/Dockerfile (100%) rename {gen-ai => services/gen-ai}/README.md (100%) rename {gen-ai => services/gen-ai}/main.py (100%) rename {gen-ai => services/gen-ai}/requirements.txt (100%) rename {grocery-service => services/grocery-service}/.dockerignore (100%) rename {grocery-service => services/grocery-service}/.gitattributes (100%) rename {grocery-service => services/grocery-service}/.gitignore (100%) rename {grocery-service => services/grocery-service}/.mvn/wrapper/maven-wrapper.properties (100%) rename {grocery-service => services/grocery-service}/Dockerfile (100%) rename {grocery-service => services/grocery-service}/README.md (100%) rename {grocery-service => services/grocery-service}/mvnw (100%) rename {grocery-service => services/grocery-service}/mvnw.cmd (100%) rename {grocery-service => services/grocery-service}/pom.xml (100%) rename {grocery-service => services/grocery-service}/src/main/java/com/bytebite/server/GenAiClient.java (100%) rename {grocery-service => services/grocery-service}/src/main/java/com/bytebite/server/GenerateController.java (100%) rename {grocery-service => services/grocery-service}/src/main/java/com/bytebite/server/HealthController.java (100%) rename {grocery-service => services/grocery-service}/src/main/java/com/bytebite/server/ServerApplication.java (100%) rename {grocery-service => services/grocery-service}/src/main/java/com/bytebite/server/WebConfig.java (100%) rename {grocery-service => services/grocery-service}/src/main/java/com/bytebite/server/dto/GenerateRequest.java (100%) rename {grocery-service => services/grocery-service}/src/main/java/com/bytebite/server/dto/IngredientDTO.java (100%) rename {grocery-service => services/grocery-service}/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java (100%) rename {grocery-service => services/grocery-service}/src/main/resources/application.properties (100%) rename {grocery-service => services/grocery-service}/src/test/java/com/bytebite/server/ServerApplicationTests.java (100%) rename {server => services/user-service}/.dockerignore (100%) rename {server => services/user-service}/.gitattributes (100%) rename {server => services/user-service}/.gitignore (100%) rename {server => services/user-service}/.mvn/wrapper/maven-wrapper.properties (100%) rename {server => services/user-service}/Dockerfile (100%) rename {server => services/user-service}/README.md (100%) rename {server => services/user-service}/mvnw (100%) rename {server => services/user-service}/mvnw.cmd (100%) rename {user-service => services/user-service}/pom.xml (100%) rename {server => services/user-service}/src/main/java/com/bytebite/server/HealthController.java (100%) rename {server => services/user-service}/src/main/java/com/bytebite/server/ServerApplication.java (100%) rename {server => services/user-service}/src/main/java/com/bytebite/server/WebConfig.java (100%) rename {user-service => services/user-service}/src/main/resources/application.properties (100%) rename {server => services/user-service}/src/test/java/com/bytebite/server/ServerApplicationTests.java (100%) delete mode 100644 user-service/.dockerignore delete mode 100644 user-service/.gitattributes delete mode 100644 user-service/.gitignore delete mode 100644 user-service/.mvn/wrapper/maven-wrapper.properties delete mode 100644 user-service/Dockerfile delete mode 100644 user-service/README.md delete mode 100755 user-service/mvnw delete mode 100644 user-service/mvnw.cmd delete mode 100644 user-service/src/main/java/com/bytebite/server/HealthController.java delete mode 100644 user-service/src/main/java/com/bytebite/server/ServerApplication.java delete mode 100644 user-service/src/main/java/com/bytebite/server/WebConfig.java delete mode 100644 user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java diff --git a/.github/workflows/test-build-push.yml b/.github/workflows/test-build-push.yml index 43f067f..52e73ba 100644 --- a/.github/workflows/test-build-push.yml +++ b/.github/workflows/test-build-push.yml @@ -30,7 +30,7 @@ jobs: cache: maven - name: Run tests with Maven - run: cd ${{ matrix.service }} && ./mvnw -B test + run: cd services/${{ matrix.service }} && ./mvnw -B test build: name: Build ${{ matrix.image }} @@ -42,17 +42,17 @@ jobs: - image: client context: ./client - image: api-gateway - context: ./api-gateway + context: ./services/api-gateway - image: user-service - context: ./user-service + context: ./services/user-service - image: grocery-service - context: ./grocery-service + context: ./services/grocery-service - image: gen-ai - context: ./gen-ai + context: ./services/gen-ai - image: user-db - context: ./docker/user-db + context: ./services/databases/user-db - image: grocery-db - context: ./docker/grocery-db + context: ./services/databases/grocery-db steps: - name: Checkout uses: actions/checkout@v4 diff --git a/README.md b/README.md index e1e00e1..4c3748f 100644 --- a/README.md +++ b/README.md @@ -39,11 +39,12 @@ Unlike traditional apps that rely on rigid "If/Then" logic or specific formattin ``` team-bytebite/ ├── client/ # React + Vite frontend -├── api-gateway/ # Java Spring Boot public backend entrypoint -├── user-service/ # Java Spring Boot user domain service -├── grocery-service/ # Java Spring Boot grocery and recipe domain service -├── gen-ai/ # Python FastAPI service for AI-based recipe and shopping list generation -└── docker/ # Database image definitions and init schemas +└── services/ + ├── api-gateway/ # Java Spring Boot public backend entrypoint + ├── user-service/ # Java Spring Boot user domain service + ├── grocery-service/ # Java Spring Boot grocery and recipe domain service + ├── gen-ai/ # Python FastAPI service for AI-based recipe and shopping list generation + └── databases/ # Database image definitions and init schemas ``` ## Services @@ -71,9 +72,9 @@ Each service has its own detailed setup instructions in its respective directory Requires Java 21, Node 22, and Python 3.12. Each service runs in its own terminal. -**1. Gen-AI** (port 8000) — create `gen-ai/.env` with `OPENAI_API_KEY=sk-...` first +**1. Gen-AI** (port 8000) — create `services/gen-ai/.env` with `OPENAI_API_KEY=sk-...` first ```bash -cd gen-ai +cd services/gen-ai python -m venv .venv .venv/Scripts/Activate.ps1 # Windows pip install -r requirements.txt @@ -82,19 +83,19 @@ uvicorn main:app --reload **2. User Service** (port 8083) ```bash -cd user-service +cd services/user-service SERVER_PORT=8083 ./mvnw spring-boot:run ``` **3. Grocery Service** (port 8082) ```bash -cd grocery-service +cd services/grocery-service SERVER_PORT=8082 ./mvnw spring-boot:run ``` **4. API Gateway** (port 8080) ```bash -cd api-gateway +cd services/api-gateway ./mvnw spring-boot:run ``` diff --git a/compose.yaml b/compose.yaml index cdf533d..769ed9c 100644 --- a/compose.yaml +++ b/compose.yaml @@ -2,7 +2,7 @@ services: user-db: image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/user-db:${IMAGE_TAG:-latest} build: - context: ./docker/user-db + context: ./services/databases/user-db container_name: bytebite-user-db environment: POSTGRES_DB: ${USER_DB_NAME:-bytebite_user} @@ -19,7 +19,7 @@ services: grocery-db: image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/grocery-db:${IMAGE_TAG:-latest} build: - context: ./docker/grocery-db + context: ./services/databases/grocery-db container_name: bytebite-grocery-db environment: POSTGRES_DB: ${GROCERY_DB_NAME:-bytebite_grocery} @@ -37,7 +37,7 @@ services: # `up --build` builds this locally; on the VM `pull` fetches it from GHCR. image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/gen-ai:${IMAGE_TAG:-latest} build: - context: ./gen-ai + context: ./services/gen-ai container_name: bytebite-gen-ai ports: - "8000:8000" @@ -48,7 +48,7 @@ services: user-service: image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/user-service:${IMAGE_TAG:-latest} build: - context: ./user-service + context: ./services/user-service container_name: bytebite-user-service expose: - "8080" @@ -64,7 +64,7 @@ services: grocery-service: image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/grocery-service:${IMAGE_TAG:-latest} build: - context: ./grocery-service + context: ./services/grocery-service container_name: bytebite-grocery-service expose: - "8080" @@ -83,7 +83,7 @@ services: api-gateway: image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/api-gateway:${IMAGE_TAG:-latest} build: - context: ./api-gateway + context: ./services/api-gateway container_name: bytebite-api-gateway ports: - "8080:8080" diff --git a/server/pom.xml b/server/pom.xml deleted file mode 100644 index 0634534..0000000 --- a/server/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.4.5 - - - com.bytebite - server - 0.0.1-SNAPSHOT - server - - - - - - - - - - - - - - - - 21 - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/server/src/main/java/com/bytebite/server/GenAiClient.java b/server/src/main/java/com/bytebite/server/GenAiClient.java deleted file mode 100644 index d79fc41..0000000 --- a/server/src/main/java/com/bytebite/server/GenAiClient.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.bytebite.server; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.DefaultUriBuilderFactory; - -@Configuration -public class GenAiClient { - - @Bean - public RestTemplate genAiRestTemplate(@Value("${genai.base-url}") String baseUrl) { - RestTemplate template = new RestTemplate(); - template.setUriTemplateHandler(new DefaultUriBuilderFactory(baseUrl)); - return template; - } -} diff --git a/server/src/main/java/com/bytebite/server/GenerateController.java b/server/src/main/java/com/bytebite/server/GenerateController.java deleted file mode 100644 index 23e1e53..0000000 --- a/server/src/main/java/com/bytebite/server/GenerateController.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.bytebite.server; - -import com.bytebite.server.dto.GenerateRequest; -import com.bytebite.server.dto.RecipeResponseDTO; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.HttpServerErrorException; -import org.springframework.web.client.ResourceAccessException; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.server.ResponseStatusException; - -import java.util.Map; - -@RestController -public class GenerateController { - - private final RestTemplate genAiRestTemplate; - - public GenerateController(RestTemplate genAiRestTemplate) { - this.genAiRestTemplate = genAiRestTemplate; - } - - @PostMapping(value = "/api/recipes/generate", - consumes = MediaType.APPLICATION_JSON_VALUE, - produces = MediaType.APPLICATION_JSON_VALUE) - public RecipeResponseDTO generate(@RequestBody GenerateRequest request) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity> entity = new HttpEntity<>(Map.of("dish", request.dish()), headers); - - RecipeResponseDTO response; - try { - response = genAiRestTemplate.postForObject("/api/ai/parse", entity, RecipeResponseDTO.class); - } catch (HttpClientErrorException e) { - throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, - "AI service rejected the request: " + e.getMessage()); - } catch (HttpServerErrorException e) { - throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, - "AI service encountered an error: " + e.getMessage()); - } catch (ResourceAccessException e) { - throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, - "AI service is unreachable"); - } - - if (response == null || response.ingredients() == null || response.ingredients().isEmpty()) { - throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, - "AI service returned no ingredients for the given input"); - } - - return response; - } -} diff --git a/server/src/main/java/com/bytebite/server/dto/GenerateRequest.java b/server/src/main/java/com/bytebite/server/dto/GenerateRequest.java deleted file mode 100644 index e911f2f..0000000 --- a/server/src/main/java/com/bytebite/server/dto/GenerateRequest.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.bytebite.server.dto; - -public record GenerateRequest(String dish) {} diff --git a/server/src/main/java/com/bytebite/server/dto/IngredientDTO.java b/server/src/main/java/com/bytebite/server/dto/IngredientDTO.java deleted file mode 100644 index f52e4de..0000000 --- a/server/src/main/java/com/bytebite/server/dto/IngredientDTO.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.bytebite.server.dto; - -public record IngredientDTO(String name, String quantity, String unit, String category) {} diff --git a/server/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java b/server/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java deleted file mode 100644 index e4ea6a0..0000000 --- a/server/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.bytebite.server.dto; - -import java.util.List; - -public record RecipeResponseDTO(String dish, List ingredients) {} diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties deleted file mode 100644 index 823f225..0000000 --- a/server/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -spring.application.name=server -genai.base-url=http://localhost:8000 diff --git a/api-gateway/.dockerignore b/services/api-gateway/.dockerignore similarity index 100% rename from api-gateway/.dockerignore rename to services/api-gateway/.dockerignore diff --git a/api-gateway/.gitattributes b/services/api-gateway/.gitattributes similarity index 100% rename from api-gateway/.gitattributes rename to services/api-gateway/.gitattributes diff --git a/api-gateway/.gitignore b/services/api-gateway/.gitignore similarity index 100% rename from api-gateway/.gitignore rename to services/api-gateway/.gitignore diff --git a/api-gateway/.mvn/wrapper/maven-wrapper.properties b/services/api-gateway/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from api-gateway/.mvn/wrapper/maven-wrapper.properties rename to services/api-gateway/.mvn/wrapper/maven-wrapper.properties diff --git a/api-gateway/Dockerfile b/services/api-gateway/Dockerfile similarity index 100% rename from api-gateway/Dockerfile rename to services/api-gateway/Dockerfile diff --git a/api-gateway/README.md b/services/api-gateway/README.md similarity index 100% rename from api-gateway/README.md rename to services/api-gateway/README.md diff --git a/api-gateway/mvnw b/services/api-gateway/mvnw similarity index 100% rename from api-gateway/mvnw rename to services/api-gateway/mvnw diff --git a/api-gateway/mvnw.cmd b/services/api-gateway/mvnw.cmd similarity index 100% rename from api-gateway/mvnw.cmd rename to services/api-gateway/mvnw.cmd diff --git a/api-gateway/pom.xml b/services/api-gateway/pom.xml similarity index 100% rename from api-gateway/pom.xml rename to services/api-gateway/pom.xml diff --git a/api-gateway/src/main/java/com/bytebite/server/GenerateController.java b/services/api-gateway/src/main/java/com/bytebite/server/GenerateController.java similarity index 100% rename from api-gateway/src/main/java/com/bytebite/server/GenerateController.java rename to services/api-gateway/src/main/java/com/bytebite/server/GenerateController.java diff --git a/api-gateway/src/main/java/com/bytebite/server/HealthController.java b/services/api-gateway/src/main/java/com/bytebite/server/HealthController.java similarity index 100% rename from api-gateway/src/main/java/com/bytebite/server/HealthController.java rename to services/api-gateway/src/main/java/com/bytebite/server/HealthController.java diff --git a/api-gateway/src/main/java/com/bytebite/server/ServerApplication.java b/services/api-gateway/src/main/java/com/bytebite/server/ServerApplication.java similarity index 100% rename from api-gateway/src/main/java/com/bytebite/server/ServerApplication.java rename to services/api-gateway/src/main/java/com/bytebite/server/ServerApplication.java diff --git a/api-gateway/src/main/java/com/bytebite/server/WebConfig.java b/services/api-gateway/src/main/java/com/bytebite/server/WebConfig.java similarity index 100% rename from api-gateway/src/main/java/com/bytebite/server/WebConfig.java rename to services/api-gateway/src/main/java/com/bytebite/server/WebConfig.java diff --git a/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java b/services/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java similarity index 100% rename from api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java rename to services/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java diff --git a/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java b/services/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java similarity index 100% rename from api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java rename to services/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java diff --git a/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java b/services/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java similarity index 100% rename from api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java rename to services/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java diff --git a/api-gateway/src/main/resources/application.properties b/services/api-gateway/src/main/resources/application.properties similarity index 100% rename from api-gateway/src/main/resources/application.properties rename to services/api-gateway/src/main/resources/application.properties diff --git a/api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java b/services/api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java similarity index 100% rename from api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java rename to services/api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java diff --git a/docker/grocery-db/Dockerfile b/services/databases/grocery-db/Dockerfile similarity index 100% rename from docker/grocery-db/Dockerfile rename to services/databases/grocery-db/Dockerfile diff --git a/docker/grocery-db/init.sql b/services/databases/grocery-db/init.sql similarity index 100% rename from docker/grocery-db/init.sql rename to services/databases/grocery-db/init.sql diff --git a/docker/user-db/Dockerfile b/services/databases/user-db/Dockerfile similarity index 100% rename from docker/user-db/Dockerfile rename to services/databases/user-db/Dockerfile diff --git a/docker/user-db/init.sql b/services/databases/user-db/init.sql similarity index 100% rename from docker/user-db/init.sql rename to services/databases/user-db/init.sql diff --git a/gen-ai/.dockerignore b/services/gen-ai/.dockerignore similarity index 100% rename from gen-ai/.dockerignore rename to services/gen-ai/.dockerignore diff --git a/gen-ai/.env.example b/services/gen-ai/.env.example similarity index 100% rename from gen-ai/.env.example rename to services/gen-ai/.env.example diff --git a/gen-ai/.gitignore b/services/gen-ai/.gitignore similarity index 100% rename from gen-ai/.gitignore rename to services/gen-ai/.gitignore diff --git a/gen-ai/Dockerfile b/services/gen-ai/Dockerfile similarity index 100% rename from gen-ai/Dockerfile rename to services/gen-ai/Dockerfile diff --git a/gen-ai/README.md b/services/gen-ai/README.md similarity index 100% rename from gen-ai/README.md rename to services/gen-ai/README.md diff --git a/gen-ai/main.py b/services/gen-ai/main.py similarity index 100% rename from gen-ai/main.py rename to services/gen-ai/main.py diff --git a/gen-ai/requirements.txt b/services/gen-ai/requirements.txt similarity index 100% rename from gen-ai/requirements.txt rename to services/gen-ai/requirements.txt diff --git a/grocery-service/.dockerignore b/services/grocery-service/.dockerignore similarity index 100% rename from grocery-service/.dockerignore rename to services/grocery-service/.dockerignore diff --git a/grocery-service/.gitattributes b/services/grocery-service/.gitattributes similarity index 100% rename from grocery-service/.gitattributes rename to services/grocery-service/.gitattributes diff --git a/grocery-service/.gitignore b/services/grocery-service/.gitignore similarity index 100% rename from grocery-service/.gitignore rename to services/grocery-service/.gitignore diff --git a/grocery-service/.mvn/wrapper/maven-wrapper.properties b/services/grocery-service/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from grocery-service/.mvn/wrapper/maven-wrapper.properties rename to services/grocery-service/.mvn/wrapper/maven-wrapper.properties diff --git a/grocery-service/Dockerfile b/services/grocery-service/Dockerfile similarity index 100% rename from grocery-service/Dockerfile rename to services/grocery-service/Dockerfile diff --git a/grocery-service/README.md b/services/grocery-service/README.md similarity index 100% rename from grocery-service/README.md rename to services/grocery-service/README.md diff --git a/grocery-service/mvnw b/services/grocery-service/mvnw similarity index 100% rename from grocery-service/mvnw rename to services/grocery-service/mvnw diff --git a/grocery-service/mvnw.cmd b/services/grocery-service/mvnw.cmd similarity index 100% rename from grocery-service/mvnw.cmd rename to services/grocery-service/mvnw.cmd diff --git a/grocery-service/pom.xml b/services/grocery-service/pom.xml similarity index 100% rename from grocery-service/pom.xml rename to services/grocery-service/pom.xml diff --git a/grocery-service/src/main/java/com/bytebite/server/GenAiClient.java b/services/grocery-service/src/main/java/com/bytebite/server/GenAiClient.java similarity index 100% rename from grocery-service/src/main/java/com/bytebite/server/GenAiClient.java rename to services/grocery-service/src/main/java/com/bytebite/server/GenAiClient.java diff --git a/grocery-service/src/main/java/com/bytebite/server/GenerateController.java b/services/grocery-service/src/main/java/com/bytebite/server/GenerateController.java similarity index 100% rename from grocery-service/src/main/java/com/bytebite/server/GenerateController.java rename to services/grocery-service/src/main/java/com/bytebite/server/GenerateController.java diff --git a/grocery-service/src/main/java/com/bytebite/server/HealthController.java b/services/grocery-service/src/main/java/com/bytebite/server/HealthController.java similarity index 100% rename from grocery-service/src/main/java/com/bytebite/server/HealthController.java rename to services/grocery-service/src/main/java/com/bytebite/server/HealthController.java diff --git a/grocery-service/src/main/java/com/bytebite/server/ServerApplication.java b/services/grocery-service/src/main/java/com/bytebite/server/ServerApplication.java similarity index 100% rename from grocery-service/src/main/java/com/bytebite/server/ServerApplication.java rename to services/grocery-service/src/main/java/com/bytebite/server/ServerApplication.java diff --git a/grocery-service/src/main/java/com/bytebite/server/WebConfig.java b/services/grocery-service/src/main/java/com/bytebite/server/WebConfig.java similarity index 100% rename from grocery-service/src/main/java/com/bytebite/server/WebConfig.java rename to services/grocery-service/src/main/java/com/bytebite/server/WebConfig.java diff --git a/grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java b/services/grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java similarity index 100% rename from grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java rename to services/grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java diff --git a/grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java b/services/grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java similarity index 100% rename from grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java rename to services/grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java diff --git a/grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java b/services/grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java similarity index 100% rename from grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java rename to services/grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java diff --git a/grocery-service/src/main/resources/application.properties b/services/grocery-service/src/main/resources/application.properties similarity index 100% rename from grocery-service/src/main/resources/application.properties rename to services/grocery-service/src/main/resources/application.properties diff --git a/grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java b/services/grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java similarity index 100% rename from grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java rename to services/grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java diff --git a/server/.dockerignore b/services/user-service/.dockerignore similarity index 100% rename from server/.dockerignore rename to services/user-service/.dockerignore diff --git a/server/.gitattributes b/services/user-service/.gitattributes similarity index 100% rename from server/.gitattributes rename to services/user-service/.gitattributes diff --git a/server/.gitignore b/services/user-service/.gitignore similarity index 100% rename from server/.gitignore rename to services/user-service/.gitignore diff --git a/server/.mvn/wrapper/maven-wrapper.properties b/services/user-service/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from server/.mvn/wrapper/maven-wrapper.properties rename to services/user-service/.mvn/wrapper/maven-wrapper.properties diff --git a/server/Dockerfile b/services/user-service/Dockerfile similarity index 100% rename from server/Dockerfile rename to services/user-service/Dockerfile diff --git a/server/README.md b/services/user-service/README.md similarity index 100% rename from server/README.md rename to services/user-service/README.md diff --git a/server/mvnw b/services/user-service/mvnw similarity index 100% rename from server/mvnw rename to services/user-service/mvnw diff --git a/server/mvnw.cmd b/services/user-service/mvnw.cmd similarity index 100% rename from server/mvnw.cmd rename to services/user-service/mvnw.cmd diff --git a/user-service/pom.xml b/services/user-service/pom.xml similarity index 100% rename from user-service/pom.xml rename to services/user-service/pom.xml diff --git a/server/src/main/java/com/bytebite/server/HealthController.java b/services/user-service/src/main/java/com/bytebite/server/HealthController.java similarity index 100% rename from server/src/main/java/com/bytebite/server/HealthController.java rename to services/user-service/src/main/java/com/bytebite/server/HealthController.java diff --git a/server/src/main/java/com/bytebite/server/ServerApplication.java b/services/user-service/src/main/java/com/bytebite/server/ServerApplication.java similarity index 100% rename from server/src/main/java/com/bytebite/server/ServerApplication.java rename to services/user-service/src/main/java/com/bytebite/server/ServerApplication.java diff --git a/server/src/main/java/com/bytebite/server/WebConfig.java b/services/user-service/src/main/java/com/bytebite/server/WebConfig.java similarity index 100% rename from server/src/main/java/com/bytebite/server/WebConfig.java rename to services/user-service/src/main/java/com/bytebite/server/WebConfig.java diff --git a/user-service/src/main/resources/application.properties b/services/user-service/src/main/resources/application.properties similarity index 100% rename from user-service/src/main/resources/application.properties rename to services/user-service/src/main/resources/application.properties diff --git a/server/src/test/java/com/bytebite/server/ServerApplicationTests.java b/services/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java similarity index 100% rename from server/src/test/java/com/bytebite/server/ServerApplicationTests.java rename to services/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java diff --git a/user-service/.dockerignore b/user-service/.dockerignore deleted file mode 100644 index 1be2196..0000000 --- a/user-service/.dockerignore +++ /dev/null @@ -1,6 +0,0 @@ -target -.idea -.git -*.iml -.DS_Store -.mvn \ No newline at end of file diff --git a/user-service/.gitattributes b/user-service/.gitattributes deleted file mode 100644 index 3b41682..0000000 --- a/user-service/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/mvnw text eol=lf -*.cmd text eol=crlf diff --git a/user-service/.gitignore b/user-service/.gitignore deleted file mode 100644 index 667aaef..0000000 --- a/user-service/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -HELP.md -target/ -.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ diff --git a/user-service/.mvn/wrapper/maven-wrapper.properties b/user-service/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index 5291372..0000000 --- a/user-service/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,3 +0,0 @@ -wrapperVersion=3.3.4 -distributionType=only-script -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.15/apache-maven-3.9.15-bin.zip diff --git a/user-service/Dockerfile b/user-service/Dockerfile deleted file mode 100644 index 533a08b..0000000 --- a/user-service/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -# Build stage -FROM maven:3.9-eclipse-temurin-21 AS build -WORKDIR /app - -COPY pom.xml . -RUN mvn dependency:go-offline - -COPY src ./src -RUN mvn clean package -DskipTests - -# Runtime stage -FROM eclipse-temurin:21-jre -WORKDIR /app - -COPY --from=build /app/target/*.jar app.jar - -EXPOSE 8080 - -ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/user-service/README.md b/user-service/README.md deleted file mode 100644 index f159c37..0000000 --- a/user-service/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# server - -Java Spring Boot backend API for ByteBite. - -## Prerequisites - -- Java 21 - -## Setup & Run - -**macOS / Linux** -```bash -./mvnw spring-boot:run # starts on http://localhost:8080 -``` - -**Windows** -```cmd -mvnw.cmd spring-boot:run -``` - -## Other Commands - -| | macOS / Linux | Windows | -|-|---------------|---------| -| Build | `./mvnw package` | `mvnw.cmd package` | -| Test | `./mvnw test` | `mvnw.cmd test` | - -## Endpoints - -| Method | Path | Description | -|--------|-----------|---------------| -| GET | /health | Health check | diff --git a/user-service/mvnw b/user-service/mvnw deleted file mode 100755 index bd8896b..0000000 --- a/user-service/mvnw +++ /dev/null @@ -1,295 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Apache Maven Wrapper startup batch script, version 3.3.4 -# -# Optional ENV vars -# ----------------- -# JAVA_HOME - location of a JDK home dir, required when download maven via java source -# MVNW_REPOURL - repo url base for downloading maven distribution -# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output -# ---------------------------------------------------------------------------- - -set -euf -[ "${MVNW_VERBOSE-}" != debug ] || set -x - -# OS specific support. -native_path() { printf %s\\n "$1"; } -case "$(uname)" in -CYGWIN* | MINGW*) - [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" - native_path() { cygpath --path --windows "$1"; } - ;; -esac - -# set JAVACMD and JAVACCMD -set_java_home() { - # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched - if [ -n "${JAVA_HOME-}" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - JAVACCMD="$JAVA_HOME/jre/sh/javac" - else - JAVACMD="$JAVA_HOME/bin/java" - JAVACCMD="$JAVA_HOME/bin/javac" - - if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then - echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 - echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 - return 1 - fi - fi - else - JAVACMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v java - )" || : - JAVACCMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v javac - )" || : - - if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then - echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 - return 1 - fi - fi -} - -# hash string like Java String::hashCode -hash_string() { - str="${1:-}" h=0 - while [ -n "$str" ]; do - char="${str%"${str#?}"}" - h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) - str="${str#?}" - done - printf %x\\n $h -} - -verbose() { :; } -[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } - -die() { - printf %s\\n "$1" >&2 - exit 1 -} - -trim() { - # MWRAPPER-139: - # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. - # Needed for removing poorly interpreted newline sequences when running in more - # exotic environments such as mingw bash on Windows. - printf "%s" "${1}" | tr -d '[:space:]' -} - -scriptDir="$(dirname "$0")" -scriptName="$(basename "$0")" - -# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties -while IFS="=" read -r key value; do - case "${key-}" in - distributionUrl) distributionUrl=$(trim "${value-}") ;; - distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; - esac -done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" -[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" - -case "${distributionUrl##*/}" in -maven-mvnd-*bin.*) - MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ - case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in - *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; - :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; - :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; - :Linux*x86_64*) distributionPlatform=linux-amd64 ;; - *) - echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 - distributionPlatform=linux-amd64 - ;; - esac - distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" - ;; -maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; -*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; -esac - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" -distributionUrlName="${distributionUrl##*/}" -distributionUrlNameMain="${distributionUrlName%.*}" -distributionUrlNameMain="${distributionUrlNameMain%-bin}" -MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" -MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" - -exec_maven() { - unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : - exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" -} - -if [ -d "$MAVEN_HOME" ]; then - verbose "found existing MAVEN_HOME at $MAVEN_HOME" - exec_maven "$@" -fi - -case "${distributionUrl-}" in -*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; -*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; -esac - -# prepare tmp dir -if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then - clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } - trap clean HUP INT TERM EXIT -else - die "cannot create temp dir" -fi - -mkdir -p -- "${MAVEN_HOME%/*}" - -# Download and Install Apache Maven -verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -verbose "Downloading from: $distributionUrl" -verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -# select .zip or .tar.gz -if ! command -v unzip >/dev/null; then - distributionUrl="${distributionUrl%.zip}.tar.gz" - distributionUrlName="${distributionUrl##*/}" -fi - -# verbose opt -__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' -[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v - -# normalize http auth -case "${MVNW_PASSWORD:+has-password}" in -'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; -has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; -esac - -if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then - verbose "Found wget ... using wget" - wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" -elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then - verbose "Found curl ... using curl" - curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" -elif set_java_home; then - verbose "Falling back to use Java to download" - javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" - targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" - cat >"$javaSource" <<-END - public class Downloader extends java.net.Authenticator - { - protected java.net.PasswordAuthentication getPasswordAuthentication() - { - return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); - } - public static void main( String[] args ) throws Exception - { - setDefault( new Downloader() ); - java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); - } - } - END - # For Cygwin/MinGW, switch paths to Windows format before running javac and java - verbose " - Compiling Downloader.java ..." - "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" - verbose " - Running Downloader.java ..." - "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" -fi - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -if [ -n "${distributionSha256Sum-}" ]; then - distributionSha256Result=false - if [ "$MVN_CMD" = mvnd.sh ]; then - echo "Checksum validation is not supported for maven-mvnd." >&2 - echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - elif command -v sha256sum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then - distributionSha256Result=true - fi - elif command -v shasum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - else - echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 - echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - fi - if [ $distributionSha256Result = false ]; then - echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 - echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 - exit 1 - fi -fi - -# unzip and move -if command -v unzip >/dev/null; then - unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" -else - tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" -fi - -# Find the actual extracted directory name (handles snapshots where filename != directory name) -actualDistributionDir="" - -# First try the expected directory name (for regular distributions) -if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then - if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then - actualDistributionDir="$distributionUrlNameMain" - fi -fi - -# If not found, search for any directory with the Maven executable (for snapshots) -if [ -z "$actualDistributionDir" ]; then - # enable globbing to iterate over items - set +f - for dir in "$TMP_DOWNLOAD_DIR"/*; do - if [ -d "$dir" ]; then - if [ -f "$dir/bin/$MVN_CMD" ]; then - actualDistributionDir="$(basename "$dir")" - break - fi - fi - done - set -f -fi - -if [ -z "$actualDistributionDir" ]; then - verbose "Contents of $TMP_DOWNLOAD_DIR:" - verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" - die "Could not find Maven distribution directory in extracted archive" -fi - -verbose "Found extracted Maven distribution directory: $actualDistributionDir" -printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" -mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" - -clean || : -exec_maven "$@" diff --git a/user-service/mvnw.cmd b/user-service/mvnw.cmd deleted file mode 100644 index 92450f9..0000000 --- a/user-service/mvnw.cmd +++ /dev/null @@ -1,189 +0,0 @@ -<# : batch portion -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.3.4 -@REM -@REM Optional ENV vars -@REM MVNW_REPOURL - repo url base for downloading maven distribution -@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output -@REM ---------------------------------------------------------------------------- - -@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) -@SET __MVNW_CMD__= -@SET __MVNW_ERROR__= -@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% -@SET PSModulePath= -@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( - IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) -) -@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% -@SET __MVNW_PSMODULEP_SAVE= -@SET __MVNW_ARG0_NAME__= -@SET MVNW_USERNAME= -@SET MVNW_PASSWORD= -@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) -@echo Cannot start maven from wrapper >&2 && exit /b 1 -@GOTO :EOF -: end batch / begin powershell #> - -$ErrorActionPreference = "Stop" -if ($env:MVNW_VERBOSE -eq "true") { - $VerbosePreference = "Continue" -} - -# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties -$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl -if (!$distributionUrl) { - Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" -} - -switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { - "maven-mvnd-*" { - $USE_MVND = $true - $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" - $MVN_CMD = "mvnd.cmd" - break - } - default { - $USE_MVND = $false - $MVN_CMD = $script -replace '^mvnw','mvn' - break - } -} - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -if ($env:MVNW_REPOURL) { - $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } - $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" -} -$distributionUrlName = $distributionUrl -replace '^.*/','' -$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' - -$MAVEN_M2_PATH = "$HOME/.m2" -if ($env:MAVEN_USER_HOME) { - $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" -} - -if (-not (Test-Path -Path $MAVEN_M2_PATH)) { - New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null -} - -$MAVEN_WRAPPER_DISTS = $null -if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { - $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" -} else { - $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" -} - -$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" -$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' -$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" - -if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { - Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" - Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" - exit $? -} - -if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { - Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" -} - -# prepare tmp dir -$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile -$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" -$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null -trap { - if ($TMP_DOWNLOAD_DIR.Exists) { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } - } -} - -New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null - -# Download and Install Apache Maven -Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -Write-Verbose "Downloading from: $distributionUrl" -Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -$webclient = New-Object System.Net.WebClient -if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { - $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) -} -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum -if ($distributionSha256Sum) { - if ($USE_MVND) { - Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." - } - Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash - if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { - Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." - } -} - -# unzip and move -Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null - -# Find the actual extracted directory name (handles snapshots where filename != directory name) -$actualDistributionDir = "" - -# First try the expected directory name (for regular distributions) -$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" -$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" -if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { - $actualDistributionDir = $distributionUrlNameMain -} - -# If not found, search for any directory with the Maven executable (for snapshots) -if (!$actualDistributionDir) { - Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { - $testPath = Join-Path $_.FullName "bin/$MVN_CMD" - if (Test-Path -Path $testPath -PathType Leaf) { - $actualDistributionDir = $_.Name - } - } -} - -if (!$actualDistributionDir) { - Write-Error "Could not find Maven distribution directory in extracted archive" -} - -Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" -Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null -try { - Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null -} catch { - if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { - Write-Error "fail to move MAVEN_HOME" - } -} finally { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } -} - -Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/user-service/src/main/java/com/bytebite/server/HealthController.java b/user-service/src/main/java/com/bytebite/server/HealthController.java deleted file mode 100644 index d57cdec..0000000 --- a/user-service/src/main/java/com/bytebite/server/HealthController.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.bytebite.server; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Map; - -@RestController -public class HealthController { - - @GetMapping("/health") - public Map health() { - return Map.of("status", "ok"); - } -} diff --git a/user-service/src/main/java/com/bytebite/server/ServerApplication.java b/user-service/src/main/java/com/bytebite/server/ServerApplication.java deleted file mode 100644 index 13d5438..0000000 --- a/user-service/src/main/java/com/bytebite/server/ServerApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.bytebite.server; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class ServerApplication { - - public static void main(String[] args) { - SpringApplication.run(ServerApplication.class, args); - } - -} diff --git a/user-service/src/main/java/com/bytebite/server/WebConfig.java b/user-service/src/main/java/com/bytebite/server/WebConfig.java deleted file mode 100644 index 4b79ea3..0000000 --- a/user-service/src/main/java/com/bytebite/server/WebConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.bytebite.server; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -public class WebConfig implements WebMvcConfigurer { - - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOriginPatterns("*") - .allowedMethods("GET", "POST"); - } -} diff --git a/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java b/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java deleted file mode 100644 index 2d6d85b..0000000 --- a/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.bytebite.server; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class ServerApplicationTests { - - @Test - void contextLoads() { - } - -} From cc4e5a22ac9b76d2c07c8c489d9ddb16998f2c14 Mon Sep 17 00:00:00 2001 From: timn Date: Sun, 31 May 2026 13:01:14 +0200 Subject: [PATCH 3/5] reorder directory structure --- .github/workflows/test-build-push.yml | 14 +++++++------- .gitignore | 6 +++--- compose.yaml | 12 ++++++------ .../databases => databases}/grocery-db/Dockerfile | 0 .../databases => databases}/grocery-db/init.sql | 0 .../databases => databases}/user-db/Dockerfile | 0 .../databases => databases}/user-db/init.sql | 0 .../{database => }/DBSchemaDiagram.drawio | 0 .../SchemaDiagram.jpg => DBSchemaDiagram.jpg} | Bin {services/gen-ai => gen-ai}/.dockerignore | 0 {services/gen-ai => gen-ai}/.env.example | 0 {services/gen-ai => gen-ai}/.gitignore | 0 {services/gen-ai => gen-ai}/Dockerfile | 0 {services/gen-ai => gen-ai}/README.md | 0 {services/gen-ai => gen-ai}/main.py | 0 {services/gen-ai => gen-ai}/requirements.txt | 0 {services => server}/api-gateway/.dockerignore | 0 {services => server}/api-gateway/.gitattributes | 0 {services => server}/api-gateway/.gitignore | 0 .../.mvn/wrapper/maven-wrapper.properties | 0 {services => server}/api-gateway/Dockerfile | 0 {services => server}/api-gateway/README.md | 0 {services => server}/api-gateway/mvnw | 0 {services => server}/api-gateway/mvnw.cmd | 0 {services => server}/api-gateway/pom.xml | 0 .../com/bytebite/server/GenerateController.java | 0 .../com/bytebite/server/HealthController.java | 0 .../com/bytebite/server/ServerApplication.java | 0 .../main/java/com/bytebite/server/WebConfig.java | 0 .../com/bytebite/server/dto/GenerateRequest.java | 0 .../com/bytebite/server/dto/IngredientDTO.java | 0 .../bytebite/server/dto/RecipeResponseDTO.java | 0 .../src/main/resources/application.properties | 0 .../bytebite/server/ServerApplicationTests.java | 0 .../grocery-service/.dockerignore | 0 .../grocery-service/.gitattributes | 0 {services => server}/grocery-service/.gitignore | 0 .../.mvn/wrapper/maven-wrapper.properties | 0 {services => server}/grocery-service/Dockerfile | 0 {services => server}/grocery-service/README.md | 0 {services => server}/grocery-service/mvnw | 0 {services => server}/grocery-service/mvnw.cmd | 0 {services => server}/grocery-service/pom.xml | 0 .../java/com/bytebite/server/GenAiClient.java | 0 .../com/bytebite/server/GenerateController.java | 0 .../com/bytebite/server/HealthController.java | 0 .../com/bytebite/server/ServerApplication.java | 0 .../main/java/com/bytebite/server/WebConfig.java | 0 .../com/bytebite/server/dto/GenerateRequest.java | 0 .../com/bytebite/server/dto/IngredientDTO.java | 0 .../bytebite/server/dto/RecipeResponseDTO.java | 0 .../src/main/resources/application.properties | 0 .../bytebite/server/ServerApplicationTests.java | 0 {services => server}/user-service/.dockerignore | 0 {services => server}/user-service/.gitattributes | 0 {services => server}/user-service/.gitignore | 0 .../.mvn/wrapper/maven-wrapper.properties | 0 {services => server}/user-service/Dockerfile | 0 {services => server}/user-service/README.md | 0 {services => server}/user-service/mvnw | 0 {services => server}/user-service/mvnw.cmd | 0 {services => server}/user-service/pom.xml | 0 .../com/bytebite/server/HealthController.java | 0 .../com/bytebite/server/ServerApplication.java | 0 .../main/java/com/bytebite/server/WebConfig.java | 0 .../src/main/resources/application.properties | 0 .../bytebite/server/ServerApplicationTests.java | 0 67 files changed, 16 insertions(+), 16 deletions(-) rename {services/databases => databases}/grocery-db/Dockerfile (100%) rename {services/databases => databases}/grocery-db/init.sql (100%) rename {services/databases => databases}/user-db/Dockerfile (100%) rename {services/databases => databases}/user-db/init.sql (100%) rename documentation/{database => }/DBSchemaDiagram.drawio (100%) rename documentation/{database/SchemaDiagram.jpg => DBSchemaDiagram.jpg} (100%) rename {services/gen-ai => gen-ai}/.dockerignore (100%) rename {services/gen-ai => gen-ai}/.env.example (100%) rename {services/gen-ai => gen-ai}/.gitignore (100%) rename {services/gen-ai => gen-ai}/Dockerfile (100%) rename {services/gen-ai => gen-ai}/README.md (100%) rename {services/gen-ai => gen-ai}/main.py (100%) rename {services/gen-ai => gen-ai}/requirements.txt (100%) rename {services => server}/api-gateway/.dockerignore (100%) rename {services => server}/api-gateway/.gitattributes (100%) rename {services => server}/api-gateway/.gitignore (100%) rename {services => server}/api-gateway/.mvn/wrapper/maven-wrapper.properties (100%) rename {services => server}/api-gateway/Dockerfile (100%) rename {services => server}/api-gateway/README.md (100%) rename {services => server}/api-gateway/mvnw (100%) rename {services => server}/api-gateway/mvnw.cmd (100%) rename {services => server}/api-gateway/pom.xml (100%) rename {services => server}/api-gateway/src/main/java/com/bytebite/server/GenerateController.java (100%) rename {services => server}/api-gateway/src/main/java/com/bytebite/server/HealthController.java (100%) rename {services => server}/api-gateway/src/main/java/com/bytebite/server/ServerApplication.java (100%) rename {services => server}/api-gateway/src/main/java/com/bytebite/server/WebConfig.java (100%) rename {services => server}/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java (100%) rename {services => server}/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java (100%) rename {services => server}/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java (100%) rename {services => server}/api-gateway/src/main/resources/application.properties (100%) rename {services => server}/api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java (100%) rename {services => server}/grocery-service/.dockerignore (100%) rename {services => server}/grocery-service/.gitattributes (100%) rename {services => server}/grocery-service/.gitignore (100%) rename {services => server}/grocery-service/.mvn/wrapper/maven-wrapper.properties (100%) rename {services => server}/grocery-service/Dockerfile (100%) rename {services => server}/grocery-service/README.md (100%) rename {services => server}/grocery-service/mvnw (100%) rename {services => server}/grocery-service/mvnw.cmd (100%) rename {services => server}/grocery-service/pom.xml (100%) rename {services => server}/grocery-service/src/main/java/com/bytebite/server/GenAiClient.java (100%) rename {services => server}/grocery-service/src/main/java/com/bytebite/server/GenerateController.java (100%) rename {services => server}/grocery-service/src/main/java/com/bytebite/server/HealthController.java (100%) rename {services => server}/grocery-service/src/main/java/com/bytebite/server/ServerApplication.java (100%) rename {services => server}/grocery-service/src/main/java/com/bytebite/server/WebConfig.java (100%) rename {services => server}/grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java (100%) rename {services => server}/grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java (100%) rename {services => server}/grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java (100%) rename {services => server}/grocery-service/src/main/resources/application.properties (100%) rename {services => server}/grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java (100%) rename {services => server}/user-service/.dockerignore (100%) rename {services => server}/user-service/.gitattributes (100%) rename {services => server}/user-service/.gitignore (100%) rename {services => server}/user-service/.mvn/wrapper/maven-wrapper.properties (100%) rename {services => server}/user-service/Dockerfile (100%) rename {services => server}/user-service/README.md (100%) rename {services => server}/user-service/mvnw (100%) rename {services => server}/user-service/mvnw.cmd (100%) rename {services => server}/user-service/pom.xml (100%) rename {services => server}/user-service/src/main/java/com/bytebite/server/HealthController.java (100%) rename {services => server}/user-service/src/main/java/com/bytebite/server/ServerApplication.java (100%) rename {services => server}/user-service/src/main/java/com/bytebite/server/WebConfig.java (100%) rename {services => server}/user-service/src/main/resources/application.properties (100%) rename {services => server}/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java (100%) diff --git a/.github/workflows/test-build-push.yml b/.github/workflows/test-build-push.yml index 52e73ba..1b8cbbd 100644 --- a/.github/workflows/test-build-push.yml +++ b/.github/workflows/test-build-push.yml @@ -30,7 +30,7 @@ jobs: cache: maven - name: Run tests with Maven - run: cd services/${{ matrix.service }} && ./mvnw -B test + run: cd server/${{ matrix.service }} && ./mvnw -B test build: name: Build ${{ matrix.image }} @@ -42,17 +42,17 @@ jobs: - image: client context: ./client - image: api-gateway - context: ./services/api-gateway + context: ./server/api-gateway - image: user-service - context: ./services/user-service + context: ./server/user-service - image: grocery-service - context: ./services/grocery-service + context: ./server/grocery-service - image: gen-ai - context: ./services/gen-ai + context: ./gen-ai - image: user-db - context: ./services/databases/user-db + context: ./databases/user-db - image: grocery-db - context: ./services/databases/grocery-db + context: ./databases/grocery-db steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.gitignore b/.gitignore index 1856b3f..66c2978 100644 --- a/.gitignore +++ b/.gitignore @@ -17,9 +17,9 @@ client/node_modules/ client/dist/ client/.vite/ -# ── server (Java Spring Boot) ───────────────────────────────── -server/target/ -server/.mvn/wrapper/maven-wrapper.jar +# ── server (Java microservices) ─────────────────────────────── +server/*/target/ +server/*/.mvn/wrapper/maven-wrapper.jar *.class *.jar *.war diff --git a/compose.yaml b/compose.yaml index 769ed9c..f164219 100644 --- a/compose.yaml +++ b/compose.yaml @@ -2,7 +2,7 @@ services: user-db: image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/user-db:${IMAGE_TAG:-latest} build: - context: ./services/databases/user-db + context: ./databases/user-db container_name: bytebite-user-db environment: POSTGRES_DB: ${USER_DB_NAME:-bytebite_user} @@ -19,7 +19,7 @@ services: grocery-db: image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/grocery-db:${IMAGE_TAG:-latest} build: - context: ./services/databases/grocery-db + context: ./databases/grocery-db container_name: bytebite-grocery-db environment: POSTGRES_DB: ${GROCERY_DB_NAME:-bytebite_grocery} @@ -37,7 +37,7 @@ services: # `up --build` builds this locally; on the VM `pull` fetches it from GHCR. image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/gen-ai:${IMAGE_TAG:-latest} build: - context: ./services/gen-ai + context: ./gen-ai container_name: bytebite-gen-ai ports: - "8000:8000" @@ -48,7 +48,7 @@ services: user-service: image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/user-service:${IMAGE_TAG:-latest} build: - context: ./services/user-service + context: ./server/user-service container_name: bytebite-user-service expose: - "8080" @@ -64,7 +64,7 @@ services: grocery-service: image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/grocery-service:${IMAGE_TAG:-latest} build: - context: ./services/grocery-service + context: ./server/grocery-service container_name: bytebite-grocery-service expose: - "8080" @@ -83,7 +83,7 @@ services: api-gateway: image: ${REGISTRY:-ghcr.io/aet-devops26/team-bytebite}/api-gateway:${IMAGE_TAG:-latest} build: - context: ./services/api-gateway + context: ./server/api-gateway container_name: bytebite-api-gateway ports: - "8080:8080" diff --git a/services/databases/grocery-db/Dockerfile b/databases/grocery-db/Dockerfile similarity index 100% rename from services/databases/grocery-db/Dockerfile rename to databases/grocery-db/Dockerfile diff --git a/services/databases/grocery-db/init.sql b/databases/grocery-db/init.sql similarity index 100% rename from services/databases/grocery-db/init.sql rename to databases/grocery-db/init.sql diff --git a/services/databases/user-db/Dockerfile b/databases/user-db/Dockerfile similarity index 100% rename from services/databases/user-db/Dockerfile rename to databases/user-db/Dockerfile diff --git a/services/databases/user-db/init.sql b/databases/user-db/init.sql similarity index 100% rename from services/databases/user-db/init.sql rename to databases/user-db/init.sql diff --git a/documentation/database/DBSchemaDiagram.drawio b/documentation/DBSchemaDiagram.drawio similarity index 100% rename from documentation/database/DBSchemaDiagram.drawio rename to documentation/DBSchemaDiagram.drawio diff --git a/documentation/database/SchemaDiagram.jpg b/documentation/DBSchemaDiagram.jpg similarity index 100% rename from documentation/database/SchemaDiagram.jpg rename to documentation/DBSchemaDiagram.jpg diff --git a/services/gen-ai/.dockerignore b/gen-ai/.dockerignore similarity index 100% rename from services/gen-ai/.dockerignore rename to gen-ai/.dockerignore diff --git a/services/gen-ai/.env.example b/gen-ai/.env.example similarity index 100% rename from services/gen-ai/.env.example rename to gen-ai/.env.example diff --git a/services/gen-ai/.gitignore b/gen-ai/.gitignore similarity index 100% rename from services/gen-ai/.gitignore rename to gen-ai/.gitignore diff --git a/services/gen-ai/Dockerfile b/gen-ai/Dockerfile similarity index 100% rename from services/gen-ai/Dockerfile rename to gen-ai/Dockerfile diff --git a/services/gen-ai/README.md b/gen-ai/README.md similarity index 100% rename from services/gen-ai/README.md rename to gen-ai/README.md diff --git a/services/gen-ai/main.py b/gen-ai/main.py similarity index 100% rename from services/gen-ai/main.py rename to gen-ai/main.py diff --git a/services/gen-ai/requirements.txt b/gen-ai/requirements.txt similarity index 100% rename from services/gen-ai/requirements.txt rename to gen-ai/requirements.txt diff --git a/services/api-gateway/.dockerignore b/server/api-gateway/.dockerignore similarity index 100% rename from services/api-gateway/.dockerignore rename to server/api-gateway/.dockerignore diff --git a/services/api-gateway/.gitattributes b/server/api-gateway/.gitattributes similarity index 100% rename from services/api-gateway/.gitattributes rename to server/api-gateway/.gitattributes diff --git a/services/api-gateway/.gitignore b/server/api-gateway/.gitignore similarity index 100% rename from services/api-gateway/.gitignore rename to server/api-gateway/.gitignore diff --git a/services/api-gateway/.mvn/wrapper/maven-wrapper.properties b/server/api-gateway/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from services/api-gateway/.mvn/wrapper/maven-wrapper.properties rename to server/api-gateway/.mvn/wrapper/maven-wrapper.properties diff --git a/services/api-gateway/Dockerfile b/server/api-gateway/Dockerfile similarity index 100% rename from services/api-gateway/Dockerfile rename to server/api-gateway/Dockerfile diff --git a/services/api-gateway/README.md b/server/api-gateway/README.md similarity index 100% rename from services/api-gateway/README.md rename to server/api-gateway/README.md diff --git a/services/api-gateway/mvnw b/server/api-gateway/mvnw similarity index 100% rename from services/api-gateway/mvnw rename to server/api-gateway/mvnw diff --git a/services/api-gateway/mvnw.cmd b/server/api-gateway/mvnw.cmd similarity index 100% rename from services/api-gateway/mvnw.cmd rename to server/api-gateway/mvnw.cmd diff --git a/services/api-gateway/pom.xml b/server/api-gateway/pom.xml similarity index 100% rename from services/api-gateway/pom.xml rename to server/api-gateway/pom.xml diff --git a/services/api-gateway/src/main/java/com/bytebite/server/GenerateController.java b/server/api-gateway/src/main/java/com/bytebite/server/GenerateController.java similarity index 100% rename from services/api-gateway/src/main/java/com/bytebite/server/GenerateController.java rename to server/api-gateway/src/main/java/com/bytebite/server/GenerateController.java diff --git a/services/api-gateway/src/main/java/com/bytebite/server/HealthController.java b/server/api-gateway/src/main/java/com/bytebite/server/HealthController.java similarity index 100% rename from services/api-gateway/src/main/java/com/bytebite/server/HealthController.java rename to server/api-gateway/src/main/java/com/bytebite/server/HealthController.java diff --git a/services/api-gateway/src/main/java/com/bytebite/server/ServerApplication.java b/server/api-gateway/src/main/java/com/bytebite/server/ServerApplication.java similarity index 100% rename from services/api-gateway/src/main/java/com/bytebite/server/ServerApplication.java rename to server/api-gateway/src/main/java/com/bytebite/server/ServerApplication.java diff --git a/services/api-gateway/src/main/java/com/bytebite/server/WebConfig.java b/server/api-gateway/src/main/java/com/bytebite/server/WebConfig.java similarity index 100% rename from services/api-gateway/src/main/java/com/bytebite/server/WebConfig.java rename to server/api-gateway/src/main/java/com/bytebite/server/WebConfig.java diff --git a/services/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java b/server/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java similarity index 100% rename from services/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java rename to server/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java diff --git a/services/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java b/server/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java similarity index 100% rename from services/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java rename to server/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java diff --git a/services/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java b/server/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java similarity index 100% rename from services/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java rename to server/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java diff --git a/services/api-gateway/src/main/resources/application.properties b/server/api-gateway/src/main/resources/application.properties similarity index 100% rename from services/api-gateway/src/main/resources/application.properties rename to server/api-gateway/src/main/resources/application.properties diff --git a/services/api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java b/server/api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java similarity index 100% rename from services/api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java rename to server/api-gateway/src/test/java/com/bytebite/server/ServerApplicationTests.java diff --git a/services/grocery-service/.dockerignore b/server/grocery-service/.dockerignore similarity index 100% rename from services/grocery-service/.dockerignore rename to server/grocery-service/.dockerignore diff --git a/services/grocery-service/.gitattributes b/server/grocery-service/.gitattributes similarity index 100% rename from services/grocery-service/.gitattributes rename to server/grocery-service/.gitattributes diff --git a/services/grocery-service/.gitignore b/server/grocery-service/.gitignore similarity index 100% rename from services/grocery-service/.gitignore rename to server/grocery-service/.gitignore diff --git a/services/grocery-service/.mvn/wrapper/maven-wrapper.properties b/server/grocery-service/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from services/grocery-service/.mvn/wrapper/maven-wrapper.properties rename to server/grocery-service/.mvn/wrapper/maven-wrapper.properties diff --git a/services/grocery-service/Dockerfile b/server/grocery-service/Dockerfile similarity index 100% rename from services/grocery-service/Dockerfile rename to server/grocery-service/Dockerfile diff --git a/services/grocery-service/README.md b/server/grocery-service/README.md similarity index 100% rename from services/grocery-service/README.md rename to server/grocery-service/README.md diff --git a/services/grocery-service/mvnw b/server/grocery-service/mvnw similarity index 100% rename from services/grocery-service/mvnw rename to server/grocery-service/mvnw diff --git a/services/grocery-service/mvnw.cmd b/server/grocery-service/mvnw.cmd similarity index 100% rename from services/grocery-service/mvnw.cmd rename to server/grocery-service/mvnw.cmd diff --git a/services/grocery-service/pom.xml b/server/grocery-service/pom.xml similarity index 100% rename from services/grocery-service/pom.xml rename to server/grocery-service/pom.xml diff --git a/services/grocery-service/src/main/java/com/bytebite/server/GenAiClient.java b/server/grocery-service/src/main/java/com/bytebite/server/GenAiClient.java similarity index 100% rename from services/grocery-service/src/main/java/com/bytebite/server/GenAiClient.java rename to server/grocery-service/src/main/java/com/bytebite/server/GenAiClient.java diff --git a/services/grocery-service/src/main/java/com/bytebite/server/GenerateController.java b/server/grocery-service/src/main/java/com/bytebite/server/GenerateController.java similarity index 100% rename from services/grocery-service/src/main/java/com/bytebite/server/GenerateController.java rename to server/grocery-service/src/main/java/com/bytebite/server/GenerateController.java diff --git a/services/grocery-service/src/main/java/com/bytebite/server/HealthController.java b/server/grocery-service/src/main/java/com/bytebite/server/HealthController.java similarity index 100% rename from services/grocery-service/src/main/java/com/bytebite/server/HealthController.java rename to server/grocery-service/src/main/java/com/bytebite/server/HealthController.java diff --git a/services/grocery-service/src/main/java/com/bytebite/server/ServerApplication.java b/server/grocery-service/src/main/java/com/bytebite/server/ServerApplication.java similarity index 100% rename from services/grocery-service/src/main/java/com/bytebite/server/ServerApplication.java rename to server/grocery-service/src/main/java/com/bytebite/server/ServerApplication.java diff --git a/services/grocery-service/src/main/java/com/bytebite/server/WebConfig.java b/server/grocery-service/src/main/java/com/bytebite/server/WebConfig.java similarity index 100% rename from services/grocery-service/src/main/java/com/bytebite/server/WebConfig.java rename to server/grocery-service/src/main/java/com/bytebite/server/WebConfig.java diff --git a/services/grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java b/server/grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java similarity index 100% rename from services/grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java rename to server/grocery-service/src/main/java/com/bytebite/server/dto/GenerateRequest.java diff --git a/services/grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java b/server/grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java similarity index 100% rename from services/grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java rename to server/grocery-service/src/main/java/com/bytebite/server/dto/IngredientDTO.java diff --git a/services/grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java b/server/grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java similarity index 100% rename from services/grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java rename to server/grocery-service/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java diff --git a/services/grocery-service/src/main/resources/application.properties b/server/grocery-service/src/main/resources/application.properties similarity index 100% rename from services/grocery-service/src/main/resources/application.properties rename to server/grocery-service/src/main/resources/application.properties diff --git a/services/grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java b/server/grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java similarity index 100% rename from services/grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java rename to server/grocery-service/src/test/java/com/bytebite/server/ServerApplicationTests.java diff --git a/services/user-service/.dockerignore b/server/user-service/.dockerignore similarity index 100% rename from services/user-service/.dockerignore rename to server/user-service/.dockerignore diff --git a/services/user-service/.gitattributes b/server/user-service/.gitattributes similarity index 100% rename from services/user-service/.gitattributes rename to server/user-service/.gitattributes diff --git a/services/user-service/.gitignore b/server/user-service/.gitignore similarity index 100% rename from services/user-service/.gitignore rename to server/user-service/.gitignore diff --git a/services/user-service/.mvn/wrapper/maven-wrapper.properties b/server/user-service/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from services/user-service/.mvn/wrapper/maven-wrapper.properties rename to server/user-service/.mvn/wrapper/maven-wrapper.properties diff --git a/services/user-service/Dockerfile b/server/user-service/Dockerfile similarity index 100% rename from services/user-service/Dockerfile rename to server/user-service/Dockerfile diff --git a/services/user-service/README.md b/server/user-service/README.md similarity index 100% rename from services/user-service/README.md rename to server/user-service/README.md diff --git a/services/user-service/mvnw b/server/user-service/mvnw similarity index 100% rename from services/user-service/mvnw rename to server/user-service/mvnw diff --git a/services/user-service/mvnw.cmd b/server/user-service/mvnw.cmd similarity index 100% rename from services/user-service/mvnw.cmd rename to server/user-service/mvnw.cmd diff --git a/services/user-service/pom.xml b/server/user-service/pom.xml similarity index 100% rename from services/user-service/pom.xml rename to server/user-service/pom.xml diff --git a/services/user-service/src/main/java/com/bytebite/server/HealthController.java b/server/user-service/src/main/java/com/bytebite/server/HealthController.java similarity index 100% rename from services/user-service/src/main/java/com/bytebite/server/HealthController.java rename to server/user-service/src/main/java/com/bytebite/server/HealthController.java diff --git a/services/user-service/src/main/java/com/bytebite/server/ServerApplication.java b/server/user-service/src/main/java/com/bytebite/server/ServerApplication.java similarity index 100% rename from services/user-service/src/main/java/com/bytebite/server/ServerApplication.java rename to server/user-service/src/main/java/com/bytebite/server/ServerApplication.java diff --git a/services/user-service/src/main/java/com/bytebite/server/WebConfig.java b/server/user-service/src/main/java/com/bytebite/server/WebConfig.java similarity index 100% rename from services/user-service/src/main/java/com/bytebite/server/WebConfig.java rename to server/user-service/src/main/java/com/bytebite/server/WebConfig.java diff --git a/services/user-service/src/main/resources/application.properties b/server/user-service/src/main/resources/application.properties similarity index 100% rename from services/user-service/src/main/resources/application.properties rename to server/user-service/src/main/resources/application.properties diff --git a/services/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java b/server/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java similarity index 100% rename from services/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java rename to server/user-service/src/test/java/com/bytebite/server/ServerApplicationTests.java From 433c3f146a449d5bfbec69e2a9cf6ba772657c14 Mon Sep 17 00:00:00 2001 From: timn Date: Sun, 31 May 2026 13:45:19 +0200 Subject: [PATCH 4/5] reworked gateway and routing --- compose.yaml | 4 +- server/api-gateway/pom.xml | 16 ++++- .../bytebite/server/GenerateController.java | 61 ------------------- .../com/bytebite/server/HealthController.java | 15 ----- .../java/com/bytebite/server/WebConfig.java | 16 ----- .../bytebite/server/dto/GenerateRequest.java | 3 - .../bytebite/server/dto/IngredientDTO.java | 3 - .../server/dto/RecipeResponseDTO.java | 5 -- .../src/main/resources/application.properties | 3 - .../src/main/resources/application.yml | 17 ++++++ .../java/com/bytebite/server/WebConfig.java | 16 ----- .../java/com/bytebite/server/WebConfig.java | 16 ----- 12 files changed, 33 insertions(+), 142 deletions(-) delete mode 100644 server/api-gateway/src/main/java/com/bytebite/server/GenerateController.java delete mode 100644 server/api-gateway/src/main/java/com/bytebite/server/HealthController.java delete mode 100644 server/api-gateway/src/main/java/com/bytebite/server/WebConfig.java delete mode 100644 server/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java delete mode 100644 server/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java delete mode 100644 server/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java delete mode 100644 server/api-gateway/src/main/resources/application.properties create mode 100644 server/api-gateway/src/main/resources/application.yml delete mode 100644 server/grocery-service/src/main/java/com/bytebite/server/WebConfig.java delete mode 100644 server/user-service/src/main/java/com/bytebite/server/WebConfig.java diff --git a/compose.yaml b/compose.yaml index f164219..193d019 100644 --- a/compose.yaml +++ b/compose.yaml @@ -39,8 +39,8 @@ services: build: context: ./gen-ai container_name: bytebite-gen-ai - ports: - - "8000:8000" + expose: + - "8000" environment: OPENAI_API_KEY: ${OPENAI_API_KEY} diff --git a/server/api-gateway/pom.xml b/server/api-gateway/pom.xml index 92ef458..f3d3cc0 100644 --- a/server/api-gateway/pom.xml +++ b/server/api-gateway/pom.xml @@ -28,11 +28,23 @@ 21 + 2024.0.1 + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + - org.springframework.boot - spring-boot-starter-web + org.springframework.cloud + spring-cloud-starter-gateway diff --git a/server/api-gateway/src/main/java/com/bytebite/server/GenerateController.java b/server/api-gateway/src/main/java/com/bytebite/server/GenerateController.java deleted file mode 100644 index 9ee1f36..0000000 --- a/server/api-gateway/src/main/java/com/bytebite/server/GenerateController.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.bytebite.server; - -import com.bytebite.server.dto.GenerateRequest; -import com.bytebite.server.dto.RecipeResponseDTO; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.HttpServerErrorException; -import org.springframework.web.client.ResourceAccessException; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.server.ResponseStatusException; -import org.springframework.web.util.DefaultUriBuilderFactory; - -import java.util.Map; - -@RestController -public class GenerateController { - - private final RestTemplate groceryServiceRestTemplate; - - public GenerateController(@Value("${GROCERY_SERVICE_BASE_URL:${grocery-service.base-url}}") String groceryServiceBaseUrl) { - this.groceryServiceRestTemplate = new RestTemplate(); - this.groceryServiceRestTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(groceryServiceBaseUrl)); - } - - @PostMapping(value = "/api/recipes/generate", - consumes = MediaType.APPLICATION_JSON_VALUE, - produces = MediaType.APPLICATION_JSON_VALUE) - public RecipeResponseDTO generate(@RequestBody GenerateRequest request) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity> entity = new HttpEntity<>(Map.of("dish", request.dish()), headers); - - RecipeResponseDTO response; - try { - response = groceryServiceRestTemplate.postForObject("/api/recipes/generate", entity, RecipeResponseDTO.class); - } catch (HttpClientErrorException e) { - throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, - "Grocery service rejected the request: " + e.getMessage()); - } catch (HttpServerErrorException e) { - throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, - "Grocery service encountered an error: " + e.getMessage()); - } catch (ResourceAccessException e) { - throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, - "Grocery service is unreachable"); - } - - if (response == null || response.ingredients() == null || response.ingredients().isEmpty()) { - throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, - "Grocery service returned no ingredients for the given input"); - } - - return response; - } -} diff --git a/server/api-gateway/src/main/java/com/bytebite/server/HealthController.java b/server/api-gateway/src/main/java/com/bytebite/server/HealthController.java deleted file mode 100644 index d57cdec..0000000 --- a/server/api-gateway/src/main/java/com/bytebite/server/HealthController.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.bytebite.server; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Map; - -@RestController -public class HealthController { - - @GetMapping("/health") - public Map health() { - return Map.of("status", "ok"); - } -} diff --git a/server/api-gateway/src/main/java/com/bytebite/server/WebConfig.java b/server/api-gateway/src/main/java/com/bytebite/server/WebConfig.java deleted file mode 100644 index 4b79ea3..0000000 --- a/server/api-gateway/src/main/java/com/bytebite/server/WebConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.bytebite.server; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -public class WebConfig implements WebMvcConfigurer { - - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOriginPatterns("*") - .allowedMethods("GET", "POST"); - } -} diff --git a/server/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java b/server/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java deleted file mode 100644 index e911f2f..0000000 --- a/server/api-gateway/src/main/java/com/bytebite/server/dto/GenerateRequest.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.bytebite.server.dto; - -public record GenerateRequest(String dish) {} diff --git a/server/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java b/server/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java deleted file mode 100644 index f52e4de..0000000 --- a/server/api-gateway/src/main/java/com/bytebite/server/dto/IngredientDTO.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.bytebite.server.dto; - -public record IngredientDTO(String name, String quantity, String unit, String category) {} diff --git a/server/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java b/server/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java deleted file mode 100644 index e4ea6a0..0000000 --- a/server/api-gateway/src/main/java/com/bytebite/server/dto/RecipeResponseDTO.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.bytebite.server.dto; - -import java.util.List; - -public record RecipeResponseDTO(String dish, List ingredients) {} diff --git a/server/api-gateway/src/main/resources/application.properties b/server/api-gateway/src/main/resources/application.properties deleted file mode 100644 index 27680a1..0000000 --- a/server/api-gateway/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -spring.application.name=api-gateway -grocery-service.base-url=http://localhost:8082 -user-service.base-url=http://localhost:8083 diff --git a/server/api-gateway/src/main/resources/application.yml b/server/api-gateway/src/main/resources/application.yml new file mode 100644 index 0000000..adda9c1 --- /dev/null +++ b/server/api-gateway/src/main/resources/application.yml @@ -0,0 +1,17 @@ +server: + port: 8080 + +spring: + application: + name: api-gateway + cloud: + gateway: + routes: + - id: grocery-service + uri: ${GROCERY_SERVICE_BASE_URL:http://localhost:8082} + predicates: + - Path=/api/recipes/** + - id: user-service + uri: ${USER_SERVICE_BASE_URL:http://localhost:8083} + predicates: + - Path=/api/users/** \ No newline at end of file diff --git a/server/grocery-service/src/main/java/com/bytebite/server/WebConfig.java b/server/grocery-service/src/main/java/com/bytebite/server/WebConfig.java deleted file mode 100644 index 4b79ea3..0000000 --- a/server/grocery-service/src/main/java/com/bytebite/server/WebConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.bytebite.server; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -public class WebConfig implements WebMvcConfigurer { - - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOriginPatterns("*") - .allowedMethods("GET", "POST"); - } -} diff --git a/server/user-service/src/main/java/com/bytebite/server/WebConfig.java b/server/user-service/src/main/java/com/bytebite/server/WebConfig.java deleted file mode 100644 index 4b79ea3..0000000 --- a/server/user-service/src/main/java/com/bytebite/server/WebConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.bytebite.server; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -public class WebConfig implements WebMvcConfigurer { - - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOriginPatterns("*") - .allowedMethods("GET", "POST"); - } -} From fd4325652e3fbdbc3ac43dfb79db4a0168e047a7 Mon Sep 17 00:00:00 2001 From: timn Date: Sun, 31 May 2026 14:35:06 +0200 Subject: [PATCH 5/5] add kubernetes instructions to readme --- .github/workflows/deploy-k8s.yml | 3 +- README.md | 56 ++++++++++++++----- .../src/main/resources/application.properties | 1 + .../src/main/resources/application.properties | 1 + 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/.github/workflows/deploy-k8s.yml b/.github/workflows/deploy-k8s.yml index 4750a32..78719fa 100644 --- a/.github/workflows/deploy-k8s.yml +++ b/.github/workflows/deploy-k8s.yml @@ -62,5 +62,4 @@ jobs: --set groceryService.image.tag=${{ steps.vars.outputs.image_tag }} \ --set genai.image.tag=${{ steps.vars.outputs.image_tag }} \ --set genai.openaiApiKey="${{ secrets.OPENAI_API_KEY }}" \ - --atomic \ - --timeout 5m + --atomic diff --git a/README.md b/README.md index 4c3748f..6de601b 100644 --- a/README.md +++ b/README.md @@ -39,12 +39,12 @@ Unlike traditional apps that rely on rigid "If/Then" logic or specific formattin ``` team-bytebite/ ├── client/ # React + Vite frontend -└── services/ - ├── api-gateway/ # Java Spring Boot public backend entrypoint - ├── user-service/ # Java Spring Boot user domain service - ├── grocery-service/ # Java Spring Boot grocery and recipe domain service - ├── gen-ai/ # Python FastAPI service for AI-based recipe and shopping list generation - └── databases/ # Database image definitions and init schemas +├── gen-ai/ # Python FastAPI AI generation service +├── server/ # Java Spring Boot microservices +│ ├── api-gateway/ # Public entrypoint — routes requests to backend services +│ ├── user-service/ # User domain service +│ └── grocery-service/ # Grocery and recipe domain service +└── databases/ # Database image definitions and init schemas ``` ## Services @@ -72,9 +72,9 @@ Each service has its own detailed setup instructions in its respective directory Requires Java 21, Node 22, and Python 3.12. Each service runs in its own terminal. -**1. Gen-AI** (port 8000) — create `services/gen-ai/.env` with `OPENAI_API_KEY=sk-...` first +**1. Gen-AI** (port 8000) — create `gen-ai/.env` with `OPENAI_API_KEY=sk-...` first ```bash -cd services/gen-ai +cd gen-ai python -m venv .venv .venv/Scripts/Activate.ps1 # Windows pip install -r requirements.txt @@ -83,19 +83,19 @@ uvicorn main:app --reload **2. User Service** (port 8083) ```bash -cd services/user-service -SERVER_PORT=8083 ./mvnw spring-boot:run +cd server/user-service +./mvnw spring-boot:run ``` **3. Grocery Service** (port 8082) ```bash -cd services/grocery-service -SERVER_PORT=8082 ./mvnw spring-boot:run +cd server/grocery-service +./mvnw spring-boot:run ``` **4. API Gateway** (port 8080) ```bash -cd services/api-gateway +cd server/api-gateway ./mvnw spring-boot:run ``` @@ -122,3 +122,33 @@ docker compose up --build Open http://localhost:8081 Drop `--build` on subsequent starts if nothing has changed. To stop: `docker compose down`. + +--- + +### Kubernetes + +#### Local Kubernetes Deployment +... + + +#### Kubernetes Deployment to the AET cluster + +Prerequisite: The `team-bytebite` namespace must exist in the cluster. + +Deployment is automated via GitHub Actions: + +- **Automatic:** every push to `main` triggers the build workflow, which triggers the deploy workflow on success. +- **Manual:** go to Actions → *Deploy to Kubernetes* → *Run workflow* to manually start the deploy workflow. + + +Alternatively, you can do manual deployment with Helm: +(Requires `helm` and a valid kubeconfig) + +```bash +helm upgrade --install bytebite ./helm/bytebite \ + --namespace team-bytebite \ + --set genai.openaiApiKey="sk-..." \ + --atomic +``` + +The app is available at https://team-bytebite.stud.k8s.aet.cit.tum.de diff --git a/server/grocery-service/src/main/resources/application.properties b/server/grocery-service/src/main/resources/application.properties index 078dc96..6920a85 100644 --- a/server/grocery-service/src/main/resources/application.properties +++ b/server/grocery-service/src/main/resources/application.properties @@ -1,2 +1,3 @@ spring.application.name=grocery-service +server.port=8082 genai.base-url=http://localhost:8000 diff --git a/server/user-service/src/main/resources/application.properties b/server/user-service/src/main/resources/application.properties index 79b5bda..fb46f13 100644 --- a/server/user-service/src/main/resources/application.properties +++ b/server/user-service/src/main/resources/application.properties @@ -1 +1,2 @@ spring.application.name=user-service +server.port=8083