Knowledge Sprint SeriesMT24 Learning

Phase 1 · Sprint 3/90 · Engineering Foundations

Project Structure & Quality Gates

In short. A src/ layout with pyproject.toml and tests, and quality gates that run in order (format, lint, types, tests) with CI blocking the merge; pre-commit hooks, and why CI repeats them.

Sprint 3 of 90 infographic: Project Structure & Quality Gates. The full text of the image is on this page.
Full resolution2160 × 2700 PNGPhase summary

The part of the image you are reading lights up. Tap a part to jump to its text.

Project Layout

my-project/
├── pyproject.toml
├── README.md
├── src/
│   └── mypkg/
└── tests/

Why a src/ Layout

  • Tests run the installed package
  • No stray imports from the project root
  • Missing files fail early, not after release
  • Install once: pip install -e .

Try It Yourself

sprint03_project_structure_quality_gates.sh

#!/bin/sh
# Sprint 3 · the Try It commands printed on the image, run on the layout
# shown on the image (my-project/ with pyproject.toml, README.md, src/mypkg/
# and tests/). Needs pip, ruff, mypy and pytest on the PATH.
# Run: sh sprint03_project_structure_quality_gates.sh  (it works in a new folder, sprint03-run/)
set -e                          # not on the image: stop at the first error
mkdir sprint03-run                                              # setup (not on the image)
cd sprint03-run                                                 # setup (not on the image)
mkdir -p my-project/src/mypkg my-project/tests                  # setup (not on the image)
cd my-project                                                   # setup (not on the image)
# setup (not on the image): the small project of the image's Project Layout box
cat > pyproject.toml <<'TOML'
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "mypkg"
version = "0.1.0"
requires-python = ">=3.10"
TOML
echo "# mypkg" > README.md
printf 'def add(a: int, b: int) -> int:\n    return a + b\n' > src/mypkg/__init__.py
printf 'from mypkg import add\n\n\ndef test_add() -> None:\n    assert add(2, 3) == 5\n' > tests/test_add.py
# the image's commands start here
pip install -e .
ruff format --check .
ruff check .
mypy src
pytest

Run it. sprint03_project_structure_quality_gates.sh · versions, data and steps

Quality Gates

  • 1. Format — ruff format
  • 2. Lint — ruff check
  • 3. Types — mypy
  • 4. Tests — pytest
  • 5. CI blocks the merge if one fails

Gate Discipline

  • One pyproject.toml for all settings
  • pre-commit runs checks on every commit
  • Hooks can be skipped, so CI repeats them
  • Fix the cause, don't mute the check

Mini Project

  • Restructure into src/ + tests/
  • Watch a test fail, then pass
  • Wire ruff into pre-commit
  • Make CI a required check

R Trusted Sources

  1. Python Packaging User Guide — src layout vs flat layout
  2. pytest docs — Good Integration Practices
  3. pre-commit.com — official documentation
  4. GitHub Docs — About protected branches

Cite this phase

Tahri, M. (2026). MT24 Learning — Knowledge Sprint Series, Phase 1: Engineering Foundations (Version 1.0) [Educational resource]. Zenodo. https://doi.org/10.5281/zenodo.22979790

Version DOI 10.5281/zenodo.22979790 · all versions 10.5281/zenodo.22979789 · first published 19 September 2026