This project is a backend template for a FastAPI-based application that uses the repository pattern approach to provide an abstraction layer between the business logic and the data access layer. It aims to provide a scalable and maintainable architecture for building web applications.
You can check a working example of this architecture here with a simple todo-app
To use this template, you first need to have cookiecutter installed. If you don't have it already, you can install it with:
pip install cookiecutter
Once you have cookiecutter
installed, you can create a new project from this template by running:
cookiecutter https://github.com/agusmdev/fastapi-ddd-cookiecutter.git
This will prompt you for some information about your new project, such as the project name and the the main entity of your project. Then it will create a new project directory based on this template.
The generator (cookiecutter) will ask you for some data, you might want to have at hand before generating the project.
The input variables, with their default values (some auto generated) are:
project_name
: The name of the projectproject_slug
: The development friendly name of the project. By default, based on the project nameproject_description
: Short description of your projectauthor
: Your namefirst_entity
: Your project's first entity, start with a ready entity with CRUD operations. This value must be written using lowercase
To run the project locally, execute the following scripts:
# Activate the environment
$ source scripts/venv.sh
To run the service locally, execute the following script:
./scripts/run_app.sh
This command will start the service on port 8000.
This is the list of commands implemented to facilitate the development of this project:
clean.sh Remove temporary files
install.sh Install the repository in the current directory
lint.sh Run linting on the source code
run_app.sh Run the app
setup_dev.sh Set up for local development
tests.sh Run a specific test suite
venv.sh Activate the environment created with virtualenv
To run the project tests, execute the following command:
# run unit tests
$ ./scripts/tests.sh unit
# run system tests
$ ./scripts/tests.sh system
By default, all unit tests defined in the project will be run.
If you're interested in contributing to the project, we welcome pull requests and issue submissions!
I would also like to extend a big thank you to Leandro Acosta and Leandro Ferrado for their invaluable contributions to the initial development of this template.