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 codesinstance/- contains secret configs that MUST NOT be committed to VCStest/- contains unit test codeslog/- the default directory to store log filesPipfilePipfile.lock- generated bypipenvlogging.ini- configure file for loggingpytest.ini- configure file for pytestREADME.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 applicationcore/- provide core functionsmodels/- models created through sqlalchemy saved here, and Horn provide some helper functions for model in helpers.pyschemas/- schemas created through marshmallow saved here, and Horn provide some helper functions for schema in helpers.pyviews/- views more like controllers in other mvc frameworks, contains most of the bussiness layer codes. home.py performs a hello world as examplecmds.py- custom flask commands saved hereexts.py- flask extensions configures saved herehelpers.py- global helper functionsrouter.py- the application's routers saved here, in flask, also calledblueprintsrun.py- the entry of the applicationswagger.py- swagger configures saved here