Skip to content

Repository for the course Advanced Software Engineering Spring 2024

Notifications You must be signed in to change notification settings

maettuu/24FS-Advanced-Software-Engineering

Repository files navigation

24FS Advanced Software Engineering (ASE)

This repository includes the semester project of the course ASE (source repository). The backend is written in Python v3.8 using MongoDB and the frontend in Vue with TypeScript.

Main packages: FastAPI, pymongo, boto3, bson, sqlalchemy, passlib, jwt, logging, multiprocessing, pydantic, enum, logging_loki, unittest, pytest, vue, tailwindcss, requests

Microservice-Powered Architecture

This project implements a microservice-powered architecture utilizing Python microservices a Vue.js frontend and Kong as the API gateway. It includes support for local testing through Localstack and uses Grafana and Loki for logging capabilities. Below you'll find setup instructions development notes and testing guidelines to help you get started and manage the development process effectively.

Screenshots

Map Overview Map Location Feed Profile

🛠️ Setup Instructions

Prerequisites

  • Ensure Docker and docker-compose are installed
  • you should have terminal to execute local .sh scripts (On Windows, Cygwin compatible terminal, on Linux and MacOS you don't need anything)
    • Be aware that if you want to run the script to setup the repository you SHOULD be in a POSIX terminal, otherwise you won't see possible error messages from error scripts.
    • This issue can occur on windows, when starting the script from init terminal, however bash takes over the execution
  • Prepare the environment variables:
    cp .env.example .env
    Edit .env to include your secrets.

Initialization

  • Run the initialization script:

    ./init.sh

    This sets up the entire environment.

  • If you encounter issues or if dependencies in the microservices have changed you can force a rebuild with:

    ./init.sh -b
  • if you want to see logs from the bash script and you are using powershell, you need to add flag --ps to the script, like this:

    ./init.sh -p
  • In case of initialization of desired environment you can use <test/dev> as an option to the script, like this:

    ./init.sh <test/dev>

Local Development without initialization script

  • To start local development without the need for manual setups use:
    docker compose -f docker-compose.base.yml -f docker-compose.dev.yml -f docker-compose.support.yml up

Access Points

Shutdown

  • Turn off all infrastructure components with:
    ./down.sh

Swagger Documentation

  • Each microservice is equipped with Swagger documentation accessible at the /docs endpoint for that specific service.

🔄 What Does ./init.sh Do?

  • Creates a Docker network.
  • Launches microservices and databases defined in docker-compose.base.yml.
  • Starts necessary infrastructure such as Kong Grafana and Loki as defined in docker-compose.support.yml.
  • Exposes development ports as specified in docker-compose.dev.yml.
  • Optionally the -b flag triggers a build of all Docker compose files useful for integrating new pip dependencies.

🛠️ How to Create a New Microservice?

  • Create a new folder in the main repository.
  • Add a Dockerfile in this new directory.
  • Update docker-compose.yml with the new service and its dependencies such as the database.
  • Add the service configuration to kong/config/kong.yml for routing and service discovery.

🔧 Development Tips

  • Python development is facilitated through connected volumes with live-refresh enabled.
  • When adding pip packages rebuild the container using the --no-cache flag to ensure new packages are installed immediately, otherwise -b flag for unit should be enough:
    docker compose -f docker-compose.base.yml -f docker-compose.dev.yml build --no-cache
  • If Kong configurations are modified in kong.yml SSH into the Kong container and execute:
    kong reload

🧪 Testing

  • Execute unit tests for a specific microservice:
    ./run_tests.sh --unit-tests <ms>