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.
- Dependency and package management: Poetry
- Hooks: Pre-commit
- Framework: Flask
- ORM: SQLAlchemy
- Format and Style: Ruff + MyPy
- Tests: Pytest
- Security: Snyk + Bandit
- Documentation: Sphinx
- Getting Started
- Principles
- Git Flow Workflow
- Folder Structure and Code Organization
- Useful resources
- Client types generation
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.poetry install- Installation with poetrypoetry install --extras "web cli"- Installation with extraspoetry install --with dev- Installation for developmentpoetry install --with docs- Installation for documentationpoetry run ruff .- Format the codepoetry run mypy .- Check typespoetry run pre-commit run --all-files- Run pre-commitpoetry run pytest- Run testspoetry run flask-boilerplate- Start applicationpoetry add requests- Add a dependencypoetry add --group dev pytest- Add a dev dependencypoetry remove requests- Remove a dependency
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
-
Development:
feature/*branches are created fromdevelopand merged via PR after passing tests (pytest,pre-commit).hotfix/*branches address critical issues inmainand require an urgent PR.
-
Release Preparation:
- A
release/*branch is created fromdevelopfor final testing and staging deployment. - After validation, a PR merges the release into
main.
- A
-
Production Deployment:
- Merging into
maintriggers an automated production deployment (Docker) and a semantic tag (v1.2.3). - Hotfixes deployed to production generate a new tag.
- Merging into
- β
GitHub Actions: Runs tests, security checks (
Bandit,Safety,Snyk), and deployments. - π Protected Branches: Direct pushes to
main,develop, orrelease/*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.
π .
βββ βοΈ .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
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:
- Clone this repo
- Create a branch:
git checkout -b your-feature - Make some changes
- Test your changes
- Push your branch and open a Pull Request