Project Structure - benhall/flask-demo

In this explanation, we will cover the project structure of the Flask demo project located at https://github.com/benhall/flask-demo/. The project structure is as follows:

  • .git/
  • .git/branches/
  • .git/hooks/
  • .git/info/
  • .git/logs/
  • .git/objects/
  • .git/refs/
  • .git/HEAD
  • .git/config
  • .git/description
  • .git/index
  • .git/packed-refs
  • .git/shallow
  • .vscode/
  • .vscode/extensions.json
  • blueprints/
  • blueprints/init.py
  • blueprints/data.py
  • blueprints/greetings.py
  • tests/
  • tests/init.py
  • tests/test_app.py
  • tests/test_app_single.py
  • .gitignore
  • Makefile
  • README.md
  • app.py
  • conftest.py
  • coverage-single.json
  • requirements.txt

The project structure can be divided into several categories:

  1. Git repository: The .git/ directory contains the version control information for the project.
  2. IDE settings: The .vscode/ directory contains settings and debug configuration files for Visual Studio Code.
  3. Application code: The blueprints/ directory contains the Flask application code, organized into blueprints. The app.py file is the entry point for the application.
  4. Test code: The tests/ directory contains the unit tests for the application.
  5. Project metadata: The .gitignore, Makefile, README.md, conftest.py, coverage-single.json, and requirements.txt files contain metadata and configuration information for the project.

Here are some possible options for organizing the application code and test code, along with examples from the Flask demo project:

  1. Organize application code by feature or functionality: In the Flask demo project, the application code is organized into blueprints, with each blueprint representing a different feature or functionality of the application. For example, the greetings.py file contains code for handling greetings-related requests, and the data.py file contains code for handling data-related requests.
  2. Organize test code by test type: In the Flask demo project, the test code is organized into separate files for unit tests and functional tests. The test_app.py file contains unit tests for the application, while the test_app_single.py file contains functional tests for a single-page version of the application.
  3. Use a common base template for similar pages: In the Flask demo project, the views.py file contains code for rendering similar pages using a common base template. This makes it easier to maintain and update the pages, as changes to the base template will automatically be reflected in all pages that use it.
  4. Separate application code from configuration code: In the Flask demo project, the app.py file contains the entry point for the application, while the init.py file in the blueprints/ directory contains the configuration code for the application. This makes it easier to manage the application configuration and separates it from the application code.

Sources: