Giter VIP home page Giter VIP logo

interview_task_stats_app's Introduction

Stats app prototype

About

This repository contains the prototype of a stats app.

Architecture and features:

  • two services: backend and database
  • two RestAPI endpoints:
    • POST /messages - adds a message to the database
    • GET /stats - retrieves the required stats
  • the app can be started with an empty database, or it can populate the database at start time with pre-defined or random data (for more see: backend/main.py and backend/fill_db.py)

Tech stack:

  • docker - containerize the services
  • docker compose - orchestrate the services
  • PostgreSQL - database
  • Python - language
  • FastAPI - web framework
  • SQLAlchemy - library for database interaction
  • Pydantic - library for model definition and validation

Usage

Quick start

Step 1:

  • inside your terminal run docker compose up
    • starts the backend and database services
    • populates the database with pre-defined messages (see: backend/main.py and backend/fill_db.py)

Step 2:

  • inside your browser access http://localhost/docs
    • interact with the API using the documentation generated by Swagger UI

Note:
If you want to start the application with an empty database or to populate the database with random data, please follow steps:

  1. reset the database using the instructions below
  2. follow the instructions inside backend/main.py and backend/fill_db.py to run the app with the desired configurations

Basic commands

Start the app

docker compose up - start the database and the backend services

Stop the app

docker compose down - stop the services, removes the associated containers and the docker network

Reset the database

docker volume ls                                        # list the docker volumes
docker compose down                                     # stop the services and removes the docker network
docker volume rm interview_task_stats_app_storage-vol   # remove the storage and the database

Tests

The application has been manually tested with a bunch of various inputs. Besides this, it has been also tested with 1.000.000 database entries.

While Pydantic does various validations ensuring the type checks for the endpoints (see main.py), the database operations (see crud.py) would have benefited from a suite of unit tests.

Further improvements

This section highlights a few of the further improvements that can be added:

  • hide the credentials from .env file
  • make use of the async functionality of FastAPI
  • write unit tests and integration tests
  • run tests automatically for every pull-request with tools like GitHub actions or Travis CI
  • setup deployment pipelines

interview_task_stats_app's People

Contributors

andreivaduva avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.