Skip to content

gbe3hunna/backend-challenge

 
 

Repository files navigation

💕 ECG Analyzer Service

ECG Analyzer is distributed, scalable, secure and containerized web application built on top of FastAPI and Celery. For the sake of this challenge, it can be deployed locally with Docker Compose and provides a friendly API Documentation.

Getting Started

The service has been designed with scalability in mind, that's why Celery is the core here. FastAPI (with uvicorn workers) and Celery (with native worker approach) can be horizontally scaled whenever is needed. At the same time the API level just enqueue the tasks in the Celery broker (RabbitMQ) and perform some basic DB transactions.

The business logic is decoupled from the API and attached to the Celery Workers (or RabbitMQ consumers), which are the responsible for analyzing an ECG and performing the operations. In order to perform actions in a completely asynchronous manner, you will find some Celery Canvas implementations.

Prerequisites

  • Docker / Docker Compose
  • .env file (Following good practices it has not been included in the repo but can be found here). Copy this file to the project root.

Services

Service Name Description
api FastAPI service
analyzer Celery service
rabbitmq RabbitMQ service used as a broker within Celery
redis Redis service used as a backend within Celery
db PostgreSQL database service
pgadmin (Optional) PGAdmin service (UI for PostgreSQL database)

Proposed Architecture/Workflow for Production approach

Workflow/Architecture

Database: SQL Tables and relationships

SQL Tables

  • User passwords are hashed and persisted using Argon2.

Running the application

Once all prerequisites are satisfied, navigate to the root directory of the project and run the following commands in order to deploy the services locally:

Building containers:

docker compose build

Running containers:

docker compose up

Analyzer core

Providing an Analyzer interface (Abstract Class) is key for supporting new analyzers in the future. The interface and its implementation can be found on: ./src/analyzer.py.

There are 2 implementations that could analyze signals and return the count of zero-crossings.

API

ECG API has been designed with versioning pattern, so can easily be extended in the future with more functionalities. Explore the API and its endpoints using OpenAPI and Redoc documentation:

The authentication type is Basic Authentication (username and password)

Admin: Creating users

  1. Authenticate as Admin with Basic Auth (credentials can be found on the .env file)
  2. Perform a POST request to /v1/admin/register_user with the username and password to create.
  3. This user can now perform ECG submissions and result retrievals (check API documentation).

Running the tests

pip install -r requirements-dev.txt
pytest ./tests

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published