Skip to content

S-Sahanii0/backend-assesment

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flights back-end recruitment test

This repo is a proposed solution to the AuxoDev backend take-home test. Problem statement can be found here.


Architecture & Design 📖

Link to the API Documentation. [Note: Not hosted yet]

Assumptions

  1. The given url is the only source of data and it's good to have a robust solution to fetch and interact with this data.
  2. The schema presented by the external data source will be maintained.
  3. Authentication is not required for the API.
  4. All airlines will have a different agent entity.

High Level Overview

alt 'text'

The different components for this system and how they interact with each other is shown in the form of a ~ C2 level diagram. See more: C4 diagrams.

Boundaries: The flights url provided in the assessment can be considered as an external boundary of the system. The internal boundaries are the database and the cache, SQLite and Redis for now.

Application: The Django application is the core component of our system. It provides the API to interact with the data and also provides the admin panel to manage the data. On top of this, it is responsible for delegating the default and custom tasks (created from the admin panel) to celery.

The only application logic in the system is the celery task which runs every day at 5am to fetch data from the external source.

Worker: Using the redis server as Message Broker, celery workers are responsible for searching and executing the tasks in our application.

The tasks can be customized from main app's settings.py and all scheduled tasks are defined under the CELERY_BEAT_SCHEDULE variable as shown below.

CELERY_BEAT_SCHEDULE = {
    # This is the only default scheduled task responsible for 
    # fetching the data from the external source and storing it in the database. 
    'daily-import-external-data': { 
         'task': 'flights.tasks.import_external_data', 
         'schedule': crontab(minute='0', hour='5'),
        },          
}

App Models [Generated]

alt text

Features

  1. Pragmatic and well documented Flights API created from the given source of data.
  2. Improved admin panel utility, including a way to fetch up-to-date data on demand and also schedule tasks for different usecases.

Improvements

  1. Containerize the application when before starting to work in a team.
  2. Try to achieve better code test coverage, follow TDD.
  3. Separate development and production environments/dependencies.
  4. Add secrets to environment variables.
  5. Deploy in development/staging server. (Find an alternative to the heroku free tier 😜)
  6. Add/explain folder structure in README.

Resources


Getting Started 🚀

Note: Make sure you have python installed

Setup your dependencies:

python3 -m venv env && source env/bin/activate && \
pip3 install -r requirements.txt

Start a redis server:

$ redis-server 

Run the application:

cd src && \ 
  python manage.py makemigrations && \
  python manage.py migrate && \
  python manage.py runserver

Run celery workers & beats (to run and schedule tasks):

cd src && \ 
    python -m celery -A config worker && \
    python -m celery -A config beat

Create a superuser:

$ python manage.py createsupersuer

Useful commands:

$ redis-cli monitor # monitor cache

$ python manage.py runserver_plus # better debugging tools
$ python manage.py shell_plus # auto import models in shell

$ pip install graphviz pyparsing && \ 
  python manage.py graph_models -a -o ../images/entity_diagram.png` # generate models diagram

Running Tests 🧪

Run test in an app and check test coverage:

$ cd src
$ coverage run manage.py test flights
$ coverage html
$ open htmlcov/index.html

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%