Project Structure

If we create application with default options, the top-level directory structure like this:

.
├── app/
│  ├── configs/
│  ├── core/
│  ├── models/
│  ├── schemas/
│  ├── views/
│  └── ...
├── instance/
├── log/
├── test/
├── Pipfile
├── Pipfile.lock
├── README.md
├── logging.ini
└── pytest.ini

Horn consider such a structure is best practice for flask application.

  • app/ - main directory contains most of the codes
  • instance/ - contains secret configs that MUST NOT be committed to VCS
  • test/ - contains unit test codes
  • log/ - the default directory to store log files
  • Pipfile Pipfile.lock - generated by pipenv
  • logging.ini - configure file for logging
  • pytest.ini - configure file for pytest
  • README.md - simple notes about this project

As you can see, most of the codes will placed in the app folder, It looks like this when expanded:

.
├── configs
│  ├── __init__.py
│  ├── default.py
│  ├── development.py
│  ├── production.py
│  └── testing.py
├── core
│  ├── __init__.py
│  ├── database.py
│  ├── errors.py
│  └── schema.py
├── models
│  ├── __init__.py
│  ├── helpers.py
│  └── user.py
├── schemas
│  ├── __init__.py
│  ├── helpers.py
│  └── user.py
├── views
│  ├── __init__.py
│  ├── home.py
│  ├── session.py
│  └── user.py
├── __init__.py
├── cmds.py
├── exts.py
├── helpers.py
├── router.py
├── run.py
└── swagger.py
  • configs/ - configures of our application
  • core/ - provide core functions
  • models/ - models created through sqlalchemy saved here, and Horn provide some helper functions for model in helpers.py
  • schemas/ - schemas created through marshmallow saved here, and Horn provide some helper functions for schema in helpers.py
  • views/ - views more like controllers in other mvc frameworks, contains most of the bussiness layer codes. home.py performs a hello world as example
  • cmds.py - custom flask commands saved here
  • exts.py - flask extensions configures saved here
  • helpers.py - global helper functions
  • router.py - the application's routers saved here, in flask, also called blueprints
  • run.py - the entry of the application
  • swagger.py - swagger configures saved here