Skip to content

Latest commit

 

History

History
130 lines (90 loc) · 3.66 KB

README.md

File metadata and controls

130 lines (90 loc) · 3.66 KB

Async API for movies Service

Core Stack

  • FastAPI
  • PostgreSQL
  • Elasticsearch
  • Redis
  • Pytest & aiohttp

About

The project follows a microservice architecture. This particular service (Movies Service) is responsible for implementing API endpoints to access data from the data warehouse. It utilizes Elasticsearch as the data source and Redis as a caching.

The ETL data warehouse service is a separate service. It is responsible for continuously extracting, transforming and loading data from PostgreSQL into the Elasticsearch DB.

Auth Service is an implicit dependency for this service, as some API endpoints may require authentication. The authentication is based on JWT tokens. Instead of constantly querying the authentication service for each user access attempt, the service validates the provided JWT token using a shared secret with the authentication service. This approach allows the service to authenticate users without needing to interact with the authentication service every time.

Services interaction scheme:

services-integration_schema.svg

Requirements

  1. ETL & data warehouse service

  2. Auth Service

Installation & Launching

  1. Before running this service, start the dependent services specified in the requirements.

  2. Configure & activate virtual environment using provided requirements.txt or Pipfile.

  3. Configure environment in ./fastapi-solutions/.env

    • Use .env.sample to set expected environment in .env
  4. Use docker-compose to launch project:

    docker-compose up
  5. The service is available on localhost: 80.

Tests

Tests are written using pytest and aiohttp libraries.

Configuration:

  1. Configure & activate virtual environment using provided requirements.txt.

    pip install -r ./fastapi-solution/tests/functional/requirements.txt
  2. Setup environment in the file fastapi-solution/tests/.env

    • Use fastapi-solution/tests/.env.sample to set expected environment in .env

Tests launch:

  1. Build & Run Test docker-compose docker-compose.test.yaml

    docker-compose -f docker-compose.test.yaml up --build
  2. Run tests:

    pytest fastapi-solution/tests --docker-compose=docker-compose.test.yaml --docker-compose-no-build --use-running-containers -v

Debugging

Project debugging

  1. Configure launcher .vscode\launch.json

    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "Python: Remote Attach",
          "type": "python",
          "request": "attach",
          "port": 5678,
          "host": "localhost",
          "pathMappings": [
            {
              "localRoot": "${workspaceFolder}/fastapi-solution",
              "remoteRoot": "/opt/app"
            }
          ]
        }
      ]
    }
  2. Launch debugging docker-compose docker-compose.debug.yaml

    docker-compose -f docker-compose.debug.yaml up --build
  3. Launch the before configured launcher (remote attach)

  4. The service is available on localhost:8000

Tests debugging

  1. Setup configuration in VsCode Settings:

    {
      "python.testing.pytestArgs": [
        "--rootdir",
        "fastapi-solution/tests",
        "--docker-compose=docker-compose.test.yaml",
        "--docker-compose-no-build",
        "--use-running-containers",
        "-v"
      ],
      "python.analysis.extraPaths": ["fastapi-solution/src/"],
      "python.testing.unittestEnabled": false,
      "python.testing.pytestEnabled": true,
    }