/fastapi-boilerplate

This repository is a FastAPI boilerplate to be used as a fast starter point

Primary LanguagePython

FastAPI Boilerplate status

  • This repository is meant to be used as a fast starter point.
  • The Python version is the 3.12.
  • The project has configured a Github Action which runs on every push to the main branch.
  • The project has a Dockerfile ready to use to deploy the app in production.

Requirements

  • You only need to have Poetry installed.

Folder structure

  • There is a tests folder with the tests files.
    • The unit folder contains the unit tests, also know as F.I.R.S.T.
    • The integration folder contains the tests that will validate the connection between our app and the external services.
    • The acceptance folder contains the tests that validate the app behavior from the outside.
  • The production code goes inside the src folder.
    • The delivery folder contains the API logic.
    • The domain folder contains the domain classes of the app.
    • The infrastructure folder contains the classes that interact with the external services.
    • The use_cases folder contains the business logic.
    • The common folder contains the shared logic.
  • Inside the scripts folder you can find the git hooks files.

Project commands

The project uses Makefiles to run the most common tasks:

  • add-package package=XXX: Installs the package XXX in the app, ex: make install package=requests.
  • build : Builds the app using the Dockerfile.
  • check-typing: Runs a static analyzer over the code in order to find issues.
  • check-format: Checks the code format.
  • coverage : Generates the coverage report.
  • dev: Runs the app in development mode.
  • format: Formats the code.
  • help : Shows this help.
  • install: Installs the app packages.
  • local-setup: Sets up the local environment (e.g. install git hooks).
  • run: Runs the app in production mode.
  • test: Run all the tests.
  • update: Updates the app packages.
  • watch: Run all the tests in watch mode.

Important: Please run the make local-setup command before starting with the code.

In order to create a commit you have to pass the pre-commit phase which runs the check and test commands.

Packages

This project uses Poetry as the package manager.

Testing

  • pytest: Testing runner.
  • pytest-xdist: Pytest plugin to run the tests in parallel.
  • expects: An expressive and extensible TDD/BDD assertion library for Python..
  • doublex: A powerful test doubles framework for Python.

Code style

  • mypy: A static type checker.
  • ruff: A Python linter and formatter.