Skip to content

Flask application boilerplate based on clean architecture, domain-driven design (DDD), SOLID principle, CQRS pattern, DTO pattern, test-driven development (TDD) for building production-grade applications πŸš€

License

Notifications You must be signed in to change notification settings

cedric57/flask-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

595 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Flask Boilerplate πŸ”₯

Description

This boilerplate is a robust starting point for creating production-ready Flask applications. Although tailored for Flask, its core principles are versatile enough for other frameworks and languages. These include maintaining clean architecture, implementing domain-driven design (DDD), and adhering to the SOLID principles for object-oriented design. The project also incorporates the Command Query Responsibility Segregation (CQRS) and Data Transfer Object (DTO) patterns, which enhance data management and system clarity. Embracing test-driven development (TDD), the boilerplate ensures high-quality, reliable code. By applying these best practices, developers can create scalable, maintainable applications that align with modern software engineering standards.

Badges

Project Status

CI Feature & Develop CD Release CD Production Hotfixes Release License Pre-commit

Used Languages

Python Flask

Code Quality

pre-commit.ci status Ruff Mypy Codecov Check Links

Security

Dependabot security: bandit Snyk

Documentation

Documentation Status CITATION en fr Sphinx PyCharm

Contributions

cedric57 github Contributors Last Commit Code of Conduct GitHub Sponsors Buy Me A Coffee Paypal

⚑ Features

πŸ‘‰ Table of Contents

✨ Getting Started

Set python to UTF8 encoding in Windows shells (cp1252) to avoid conflicts with Git. In administrator powershell :

[Environment]::SetEnvironmentVariable("PYTHONUTF8", "1", "Machine")

Configure a Poetry environment : Documentation JetBrains

(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -

[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";%APPDATA%\Python\Scripts", "User")
git clone https://github.com/cedric57/flask-boilerplate.git my-app
cd my-app

# To enable poetry follow the instruction here: https://python-poetry.org/docs/#installing-with-the-official-installer
poetry install #Install dependencies.

Common Commands

  • poetry install - Installation with poetry
  • poetry install --extras "web cli" - Installation with extras
  • poetry install --with dev - Installation for development
  • poetry install --with docs - Installation for documentation
  • poetry run ruff . - Format the code
  • poetry run mypy . - Check types
  • poetry run pre-commit run --all-files - Run pre-commit
  • poetry run pytest - Run tests
  • poetry run flask-boilerplate - Start application
  • poetry add requests - Add a dependency
  • poetry add --group dev pytest - Add a dev dependency
  • poetry remove requests - Remove a dependency

🧱 Principles

πŸ›  Git Flow Workflow

This project follows the Git Flow strategy to ensure organized and secure development. The main branches (main, develop) and release branches (release/*) are protected: changes must go through Pull Requests (PRs) validated by code reviews, automated tests, and security checks. Below is the workflow:

graph LR
    A[Feature Branch] -->|PR + Tests| B[Develop]
    B -->|PR + Tests| C[Release Branch]
    C -->|Staging Deployment| D[Staging]
    C -->|PR + Tests| E[Main]
    E -->|Prod Deployment + Tag| F[Production]
    F -->|Hotfix| G[Hotfix Branch]
    G -->|PR + Tests| E
Loading

Key Steps

  1. Development:

    • feature/* branches are created from develop and merged via PR after passing tests (pytest, pre-commit).
    • hotfix/* branches address critical issues in main and require an urgent PR.
  2. Release Preparation:

    • A release/* branch is created from develop for final testing and staging deployment.
    • After validation, a PR merges the release into main.
  3. Production Deployment:

    • Merging into main triggers an automated production deployment (Docker) and a semantic tag (v1.2.3).
    • Hotfixes deployed to production generate a new tag.

Automated Tools

  • βœ… GitHub Actions: Runs tests, security checks (Bandit, Safety, Snyk), and deployments.
  • πŸ”’ Protected Branches: Direct pushes to main, develop, or release/* are blocked.
  • πŸ“¦ Poetry: Manages dependencies and environment isolation.

This workflow ensures continuous integration, reliable delivery, and a clean project history. For contributions, follow the guidelines in CONTRIBUTING.md.

πŸ“ Folder Structure and Code Organization

πŸ“ .
β”œβ”€β”€ βš™οΈ .cursorrules \<- LLM instructions for Cursor IDE
β”œβ”€β”€ πŸ’» .devcontainer \<- Devcontainer config
β”œβ”€β”€ βš™οΈ .gitattributes \<- GIT-LFS Setup Configuration
β”œβ”€β”€ πŸ§‘β€πŸ’» .github
β”‚ β”œβ”€β”€ ⚑️ actions
β”‚ β”‚ └── πŸ“ setup-python-env \<- Automated python setup w/ uv
β”‚ β”œβ”€β”€ πŸ’‘ ISSUE_TEMPLATE \<- Templates for Raising Issues on GH
β”‚ β”œβ”€β”€ πŸ’‘ pull_request_template.md \<- Template for making GitHub PR
β”‚ └── ⚑️ workflows
β”‚ β”œβ”€β”€ πŸš€ main.yml \<- Automated cross-platform testing w/ uv, precommit, deptry,
β”‚ └── πŸš€ on-release-main.yml \<- Automated mkdocs updates
β”œβ”€β”€ πŸ’» .vscode \<- Preconfigured extensions, debug profiles, workspaces, and tasks for VSCode/Cursor powerusers
β”‚ β”œβ”€β”€ πŸš€ launch.json
β”‚ β”œβ”€β”€ βš™οΈ settings.json
β”‚ β”œβ”€β”€ πŸ“‹ tasks.json
β”‚ └── βš™οΈ '{{ cookiecutter.repo_name }}.code-workspace'
β”œβ”€β”€ πŸ“ data
β”‚ β”œβ”€β”€ πŸ“ external \<- Data from third party sources
β”‚ β”œβ”€β”€ πŸ“ interim \<- Intermediate data that has been transformed
β”‚ β”œβ”€β”€ πŸ“ processed \<- The final, canonical data sets for modeling
β”‚ └── πŸ“ raw \<- The original, immutable data dump
β”œβ”€β”€ 🐳 docker \<- Docker configuration for reproducability
β”œβ”€β”€ πŸ“š docs \<- Project documentation (using mkdocs)
β”œβ”€β”€ πŸ‘©β€βš–οΈ LICENSE \<- Open-source license if one is chosen
β”œβ”€β”€ πŸ“‹ logs \<- Preconfigured logging directory for
β”œβ”€β”€ πŸ‘·β€β™‚οΈ Makefile \<- Makefile with convenience commands (PyPi publishing, formatting, testing, and more)
β”œβ”€β”€ πŸš€ Taskfile.yml \<- Modern alternative to Makefile w/ same functionality
β”œβ”€β”€ πŸ“ notebooks \<- Jupyter notebooks
β”‚ β”œβ”€β”€ πŸ““ 01_name_example.ipynb
β”‚ └── πŸ“° README.md
β”œβ”€β”€ πŸ—‘οΈ out
β”‚ β”œβ”€β”€ πŸ“ features \<- Extracted Features
β”‚ β”œβ”€β”€ πŸ“ models \<- Trained and serialized models
β”‚ └── πŸ“š reports \<- Generated analysis
β”‚ └── πŸ“Š figures \<- Generated graphics and figures
β”œβ”€β”€ πŸ”’ secrets \<- Ignored project-level secrets directory to keep API keys and SSH keys safe and separate from your system (no setting up a new SSH-key in ~/.ssh for every project)
β”‚ └── βš™οΈ schema \<- Clearly outline expected variables
β”‚ β”œβ”€β”€ βš™οΈ example.env
β”‚ └── πŸ”‘ ssh
β”‚ β”œβ”€β”€ βš™οΈ example.config.ssh
β”‚ β”œβ”€β”€ πŸ”‘ example.something.key
β”‚ └── πŸ”‘ example.something.pub
└── 🚰 '{{ cookiecutter.module_name }}' \<- Easily publishable source code
β”œβ”€β”€ βš™οΈ config.py \<- Store useful variables and configuration (Preset)
β”œβ”€β”€ 🐍 dataset.py \<- Scripts to download or generate data
β”œβ”€β”€ 🐍 features.py \<- Code to create features for modeling
β”œβ”€β”€ πŸ“ modeling
β”‚ β”œβ”€β”€ 🐍 __init__.py
β”‚ β”œβ”€β”€ 🐍 predict.py \<- Code to run model inference with trained models
β”‚ └── 🐍 train.py \<- Code to train models
└── 🐍 plots.py \<- Code to create visualizations
β”œβ”€β”€ βš™οΈ poetry.lock \<- Project configuration file w/ carefully selected dependency stacks
β”œβ”€β”€ βš™οΈ pyproject.toml \<- Project configuration file w/ carefully selected dependency stacks
β”œβ”€β”€ πŸ“° README.fr.md \<- The top-level README in french
└── πŸ“° README.md \<- The top-level README

Useful resources

Client types generation

Contributing

Contributions are always welcome! If you have any ideas, suggestions, fixes, feel free to contribute. You can do that by going through the following steps:

  1. Clone this repo
  2. Create a branch: git checkout -b your-feature
  3. Make some changes
  4. Test your changes
  5. Push your branch and open a Pull Request

License

MIT

About

Flask application boilerplate based on clean architecture, domain-driven design (DDD), SOLID principle, CQRS pattern, DTO pattern, test-driven development (TDD) for building production-grade applications πŸš€

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 3

  •  
  •  
  •