Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

dannyxnda/be-flask

Repository files navigation

FLASK RESTFUL API BOILERPLATE

Start app with docker

Prerequisites

  • Os: Windows or Linux
  • Docker
  • Docker-compose

Start app for development

Deployment

  • Copy .env.example => .env
  • Edit mapping port, or environment if need
  • Copy docker-compose.override.sample.yml => docker-compose.override.yml
  • Run docker-compose up

Database Migrations

  • Create new migration: docker-compose exec app flask db migrate -m "add_user"
  • Upgrade: docker-compose exec app flask db upgrade
  • Downgrade: docker-compose exec app flask db downgrade

Console commands

  • To run application: flask run

Database migration

  1. Initiate a migration folder (once only)
flask db init
  1. Create migration script from detected changes in the model
flask db migrate --message 'initial database migration'
  1. Apply the migration script to the database
flask db upgrade

Viewing the app

Open the following url on your browser to view swagger documentation http://127.0.0.1:5000/

Application error monitoring

Using https://sentry.io for error report. Error report is disabled by default.
To enable

  • Go to https://sentry.io register new account, create new flask project, get new dsn
  • Replace SENTRY_DSN by new dsn
  • Set SEND_REPORT variable in .env to true

Application folder structure

Split by modules

Separate components of our app into a group of inter-connected modules
📁 /docs: external documentation
📁 /etc: app configurations, gunicorn config, logging, nginx
📁 /migrations: db migration scripts
📁 /module 1: sources of module 1
📁 /module 2: sources of module 2

Module structure

Each module is spitted by repository pattern

Repository Pattern

alt text

Module folder structure

📁 /api: define api url, request body, params
📁 /commands: define flask command
📁 /extensions: setup base configuration
📁 /helpers: define helper function
📁 /models: define orm model
📁 /repositories: define repository to access data
📁 /services: handle business logic
📁 /tests: app test script

📙 Resource

Libraries

Contributing

If you want to contribute to this boilerplate, clone the repository and just start making pull requests.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages