Skip to content

Running the project manually

Prerequisites

Before you start, you need to have the following tools installed on your machine:

  • Java JDK (version 17 or higher)
  • Maven
  • Node.js (version 18 or higher)
  • Python (version 3.12 or higher)
  • PostgreSQL

Note

Follow the installation guide for your machine included in this documentation: Windows, Ubuntu or MacOS

Installing PostgreSQL

Windows

Via Chocolatey

  1. Open the terminal as Administrator.
  2. Run the following command:
    choco install postgresql
    

Via MSI

  1. Access the PostgreSQL downloads page.
  2. Download the MSI installer.
  3. Follow the wizard's instructions to complete the installation.

Linux

Via APT (Debian/Ubuntu)

  1. Open the terminal.
  2. Update the package index:
    sudo apt update
    
  3. Install PostgreSQL:
    sudo apt install postgresql postgresql-contrib
    

macOS

Via Homebrew

  1. Open the terminal.
  2. Install PostgreSQL using Homebrew:
    brew install postgresql
    
  3. Start the PostgreSQL service:
    brew services start postgresql
    

Docker

  1. Open the bash terminal (WSL on Windows).
  2. Run the command that executes postgres:
    docker run -d --name pgfeedback -e POSTGRES_PASSWORD=root -e POSTGRES_DB=feedback -p 5432:5432 postgres 
    
  3. This command is only for the first time you run the container. For subsequent times, use the command:
    docker start pgfeedback
    

If you install PostgreSQL outside of a Docker environment, you will need to use a database management tool like dbeaver to set up the initial feedback database.

Running the Project Manually

1. Configure the Database

Make sure PostgreSQL is running. You can start the service as per the instructions above, depending on your operating system.

2. Configure Environment Variables

Set the following environment variables:

  • Linux and Mac OS

    export DB_HOST=localhost
    export DB_PORT=5432
    export DB_USER=postgres
    export DB_PASS=root
    export JWT_SECRET_KEY=4Z^XrroxR@dWxqf$!@#qGr4P
    export JWT_ISSUER=user-api
    export DATABASE_URL=postgresql://postgres:root@localhost:5432/feedback
    
  • Windows

    $env:DB_HOST="localhost"
    $env:DB_PORT="5432"
    $env:DB_USER="postgres"
    $env:DB_PASS="root"
    $env:JWT_SECRET_KEY="4Z^XrroxR@dWxqf$!@#qGr4P"
    $env:JWT_ISSUER="user-api"
    $env:DATABASE_URL="postgresql://postgres:root@localhost:5432/feedback"
    

3. Run the Java Microservices

Access the directory of each microservice, build, and start the services:

Enter the JAVA projects folder

cd java_backend

Build the projects

mvn clean install -DskipTests
Run usermanagement
mvn -pl microservices/usermanagement spring-boot:run

Run feedbackrequest

mvn -pl microservices/feedbackrequest spring-boot:run

Run feedbackresponse

mvn -pl microservices/feedbackresponse spring-boot:run

4. Run the Python Microservice

Enter the project folder

# Run feedbackresponseview
cd python_backend/feedbackresponseview

Install the dependencies

poetry install

Running the project

poetry run uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload

5. Run the API Gateway (Node.js)

cd node_backend/api_gateway
npm install
npm run start

6. Run Nginx

Ubuntu

  1. Prerequisites
    Make sure Nginx is installed on Ubuntu. If not, install it with:

    sudo apt update
    sudo apt install nginx
    
  2. Copy the Configuration File
    Assuming the local configuration file is in a gateway folder and is named nginx.conf, copy it to the Nginx configuration directory:

    sudo cp gateway/nginx.conf /etc/nginx/sites-enabled/default
    
  3. Change the Configuration with sed
    If you need to replace values (e.g., change the host to localhost in a configuration line), use:

    sudo sed -Ei 's/(server\s+)[^:]+(:[0-9]+;)/\1localhost\2/g' /etc/nginx/sites-enabled/default
    
    Command explanation:
  4. sed -Ei enables in-place editing mode with extended regular expressions.
  5. The command looks for a line containing server followed by some space and then any value until it finds a port number (e.g., :80;) and replaces that value with localhost while keeping the port.

  6. Restart Nginx
    After making changes, restart the service for the changes to take effect:

    sudo service nginx restart
    

macOS

On macOS, there are some considerations, mainly that sed may have differences (macOS uses BSD sed). Also, Nginx can be installed via Homebrew.

  1. Install Nginx
    Use Homebrew to install Nginx (if it's not already installed):

    brew install nginx
    
    The default Nginx configuration file on macOS (via Homebrew) is usually found at /usr/local/etc/nginx/nginx.conf. If you are using a sites file, you may need to adapt the path, for example:
    /usr/local/etc/nginx/servers/default.conf
    
  2. Copy the Configuration File
    Assuming you want to replace a site's configuration file:

    sudo cp gateway/nginx.conf /usr/local/etc/nginx/servers/default.conf
    
  3. Change the Configuration with sed
    Due to the differences in BSD sed, the syntax may require the -E flag and the use of a backup extension (e.g., .bak). An example:

    sudo sed -i.bak -E 's/(server\s+)[^:]+(:[0-9]+;)/\1localhost\2/g' /usr/local/etc/nginx/servers/default.conf
    
    This command creates a backup of the original file with the .bak extension. You can remove this backup later if you prefer.
  4. Restart Nginx
    If Nginx was installed via Homebrew, restart it with:

    brew services restart nginx
    

Windows

On Windows, there are two approaches you can take to perform these tasks:

Using Chocolatey

Chocolatey is a package manager for Windows. You can use it to install Nginx and run scripts in PowerShell.

Steps:

  1. Install Nginx via Chocolatey
    Open PowerShell with administrator privileges and run:

    choco install nginx -y
    
    Generally, Nginx installed via Chocolatey will be at:
    C:\tools\nginx\conf\nginx.conf or a similar path. Check the package documentation.
  2. Copy the Configuration File
    If your local file is, for example, at C:\projects\gateway\nginx.conf, run:

    Copy-Item -Path "C:\projects\gateway\nginx.conf" -Destination "C:\tools\nginx\conf\nginx.conf" -Force
    
  3. Change the Configuration
    To change the file using a tool similar to sed on Windows, you can use PowerShell with regular expressions. For example:

    (Get-Content "C:\tools\nginx\conf\nginx.conf") -replace '(server\s+)[^:]+(:[0-9]+;)', '$1localhost$2' |
      Set-Content "C:\tools\nginx\conf\nginx.conf"
    
  4. Restart Nginx
    This depends on how Nginx was configured to run. If it's running as a service, restart it. If not, close and start it again using Nginx's own shortcut or script, for example:

    # Assuming you have a script to stop and start:
    Stop-Process -Name nginx -Force
    Start-Process "C:\tools\nginx\nginx.exe"
    

WSL (Windows Subsystem for Linux)

Follow the instructions for Ubuntu.

7. Access the Application

Depending on the ports where you configured the services, you will have to access them through the chosen ports. Be careful when running multiple Spring applications, as they might end up starting on the same port. Modify the application properties to change the desired port for each one.