- Python 3.11
- Docker
- FastAPI
- Firebase Storage (GCS)
- SQLAlchemy
- Install poetry
curl -sSL https://install.python-poetry.org | python3 - - Install uv package manager
curl -LsSf https://astral.sh/uv/install.sh | sh - RUN
poetry install --only-rootto create a new poetry environment - RUN
uv pip install -r pyproject.toml - Install pre-commit and ruff linter
uv pip install pre-commit ruff - RUN
pre-commit install - RUN
pre-commit run
Install Docker Engine
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-pluginVerify that Docker Engine is installed correctly by running the hello-world image.
sudo docker run hello-worldCompile Images
After you have installed docker-engine and docker-compose,
cp .env.example .env
sudo docker compose buildNote: make sure to tweak .env file according to your preferences
After you have compiled the images successfully do the following:
- Add service account JSON file to resources folder and make sure to exclude the file from git, you just have to include
firebase-adminsdkin file name. - Update
GOOGLE_APPLICATION_CREDENTIALSenvironment variable and point it to service account JSON filepath. - Run the following commands
sudo docker compose up -d sudo docker compose exec web alembic upgrade head
Now you can access the API documentation in your browser.
- An error related to
*.shscript not found- Change line endings for the related script in
dockerdirectory to LF(Unix) - Rebuild the image
- Change line endings for the related script in
sudo docker compose up -d
sudo docker compose exec web pytest- Repository pattern: A simplifying abstraction over data storage that hide the complexity of DB operations from the client.
- UoW pattern: It’s a nice place to put all your repositories so client code can access them. It helps to enforce the consistency of our domain model, and improves performance, by letting us perform a single flush operation at the end of an operation
- Inverting the Dependency: ORM Depends on Model not the other way around i.e. high-level modules (the domain) should not depend on low-level ones (the infrastructure)
- Dependency Injection: It adds flexibility as the components are loosely coupled and can be easily swapped with mocks or fakes. Also, enhances code maintainability by clearly defining where dependencies are used and making it easier to identify and update them when needed.
- Factory pattern: Use factory method to abstract filesystems behaviour and let the client rely on a single interface
AbstractFileSystem. Hence, we can easily migrate tos3orlocalsimply by changing the injected factory