Skip to content

ruauka/booking-service-py

Repository files navigation

Booking service

Coverage Status build

Overview

Booking hotels pet-project service. Service allows:

  • book a hotel room
  • notify the customer about the booking by Email
  • manage booking orders and other entities using Admin Panel

Content

Start

To start service run in terminal:

docker-compose up -d

Service swagger is available at link - http://localhost/docs

To fill the database with test data:

  • register new user with admin role
  • login new user
  • upload test data file with uploader
  • file with test data is in directory: testdata/data.sql

Other links:

Stop service:

docker-compose stop

Usage

  • register new user with you actual Email
  • login new user

Sample steps for booking a hotel room:

CI

Service has DevOps pipeline using GitHub-Actions.

Stages:

  • Testing: raising test PostgeSQL in docker in pipeline
  • Linting: flake8

Architecture

Router

Service based on the Fastapi framework and Gunicorn as WSGI server. Pydantic validation.

Lib - https://fastapi.tiangolo.com/

Database

PostgreSQL is used as database. All interactions with database are executed with ORM SQLAlchemy. Migrations executes automatically when the service starts.

Lib - https://www.sqlalchemy.org/

Entities

Auth

JWT Authorization. User can have an administrator role, which gives the opportunity to edit entities.

Lib - https://pypi.org/project/python-jose/

Cache

Redis is used for caching:

  • Heavy requests: getting a list of hotels according to the specified parameters (for example by location)
  • Background tasks

Lib - https://pypi.org/project/fastapi-cache2/

Background tasks

Celery

Celery is used to execute a background task: send an email notification to the customer after booking a room.

Lib - https://pypi.org/project/celery/

Flower

Flower is used for administration of background tasks.

Lib - https://pypi.org/project/flower/

Logging

Logger can be configured by log-levels by env file:

  • DEBUG
  • INFO
  • WARNING
  • ERROR
  • CRITICAL

Logs are output to console.

Lib - https://pypi.org/project/python-json-logger/

Testing

Service is covered with unit and integration tests. For local testing, it is necessary to raise test database (PostgeSQL) in docker with terminal command:

make pytest_db_up

Lib - https://pypi.org/project/pytest/

Admin-panel

Admin-panel is used for database administration. Only for a user with the admin role.

Lib - https://aminalaee.dev/sqladmin

Monitoring

Monitoring tools are Prometheus and Grafana.

To demonstrate the work of dashboards, in docker is running a script, which polls the service.

Lib - https://pypi.org/project/prometheus-fastapi-instrumentator/

About

Python booking service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages