Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

227 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hackernews Backend:

Built in Python programming language with Flask framework.

Backend file structure:

Backend/
    .circleci/
        config.yml
    app/
        test/
        __init__.py
        app.py
        controller.py
        database.py
    .gitignore
    Dockerfile
    README.md
    Requierements.txt

.circleci/config.yaml

The .circleci/config.yml file in the repository branch indicates the use of CircleCI for continuous integration.

For better understanding of the config.yaml file structure, please see circleci-python and closer description on CI in our Ops documentation CI-chain.

Structure of app package

Package app host the application and runs on http://0.0.0.0:5000.

  • init.py - in Python, if a sub-directory includes a init.py file it is considered a package, and can be imported.

  • app.py - in this module we structure our application, set routes and create the application object as an instance of Flask imported from the flask package.

from flask import Flask
...
app = Flask(__name__)
...
@app.route('/')
...

The @app.route decorator creates an association between the URL given as an argument and the function.

  • controller.py - here lays all the logic for each endpoint/route from the app.py. Once app.py receives data from Frontend, it processes data and make queries to the database.

  • database.py - this module, establishes connection to database.

def get_db_conn():
    connection = client[db_name]
    return connection

Prepares collections in "hackernews" database hosted on MongoDB server.

To understand the sequence flow, please see System Sequence Diagram below. SSD

User registration and login

  • Passwords hashed with bcrypt.

Dockerfile

When running docker-compose up --build Docker builds images automatically by reading the instructions from a Dockerfile. Read more detailed about Dockerfile here.

In the Dockerfile, we have specified which tools we want installed on the Docker image. RUN pip install -r requirements.txt command will look for the requirements.txt file and install the listed requirements.

requirements.txt:

Flask==0.12.3
pymongo
bcrypt
pytest
flask_httpauth

About

Python with Flask

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages