Skip to content

Repository files navigation

Fastapi Clean Architecture

Fastapi Clean Architecture boilerplate.

Requirements

Docs

Docs url will be put in here in advance

Development

Copy .env.example to .env then install requirements:

pipenv install
# or
pip install -r requirements.txt

Start development server

pipenv run uvicorn app.main:app --reload
# or
uvicorn app.main:app --reload

Migrations

We use alembic to manage database migrations.

Generating migrations

pipenv run alembic revision -m "{your migration message}"
# or
alembic revision -m "{your migration message}"

Then the migration file will be generated at ./migrations/versions/{timestamp}_create_todos_table.py directory

Migrate

pipenv run alembic upgrade head
# or
alembic upgrade head

Rollback

pipenv run alembic downgrade -1
# or
alembic downgrade -1

Testing

Test files will be placed on ./tests directory. All controllers test should be placed on ./tests/api directory.

Prepare database

Create database called my_test_db on your local machine.

Running test

To run test you can use pytest command to do the job

# run all tests
pipenv run pytest
# or
pytest

# run specific test file
pipenv run pytest ./tests/path_to_your_test_file.py
# or
pytest ./tests/path_to_your_test_file.py

# run with verbose
pipenv run pytest -v
# or
pytest -v

# run with complete log
pipenv run pytest --capture=no
# or
pytest --capture=no

Production

Build docker image

docker build -t fastapi-clean-architecture .

Run docker container

docker run -d -p 8000:8000 fastapi-clean-architecture --env-file .env

About

Company standard Fastapi clean architecture boilerplate

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages