This project is a FastAPI based API to solve the buzz api tech test. The project is structured with modular components for easy maintenance and scaling.
.
├── Dockerfile
├── app
│ ├── api
│ │ ├── endpoints
│ │ │ ├── __init__.py
│ │ │ └── machine.py
│ │ └── shared
│ │ ├── __init__.py
│ │ └── responses.py
│ ├── database
│ │ ├── base.py
│ │ ├── engine.py
│ │ ├── models.py
│ │ └── schemas.py
│ └── services
│ ├── __init__.py
│ ├── machine_service.py
│ ├── shared
│ │ ├── __init__.py
│ │ └── errors.py
│ └── site_service.py
├── docker-compose.yml
├── entrypoint.sh
├── main.py
└── requirements.txt
Dockerfile
: Dockerfile for building the container image.app
: Main application folder containing the API, database, and service modules.app/api
: API endpoints and shared responses.app/api/endpoints
: Individual endpoint modules.app/api/shared
: Shared response schemas.app/database
: Database-related modules, including models, schemas, and engine.app/services
: Service modules that handle the business logic.app/services/shared
: Shared service-related modules, including error handling.docker-compose.yml
: Docker Compose configuration file.entrypoint.sh
: Shell script for running the application in a Docker container.main.py
: Entry point of the FastAPI application.requirements.txt
: Python package dependencies for the project.
- Install the required packages:
pip install -r requirements.txt
- Run the application:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
You can now access the API at http://localhost:8000
.
-
Set the env vars on .env file, if is the first time you are running the project or you just want to rebuild the database just set RUN_INIT_DB=1 otherwise you can leave 0.
-
Build the Docker image:
docker build -t my-fastapi-project .
- Run the Docker container:
docker run -d --name my-fastapi-project -p 8000:8000 my-fastapi-project
Alternatively, use Docker Compose to run the container:
docker-compose up -d
If you want you can up only the db image with:
docker-compose up -d db
The API should be accessible at http://localhost:8000
.
Run the following command:
python3 -m pytest
You can access the API documentation at http://localhost:8000/docs
and the ReDoc documentation at http://localhost:8000/redoc
.