This project uses a modern stack for building and testing a robust backend application. I use FastAPI for fast, asynchronous web API development, with SQLAlchemy for database interactions, and PostgreSQL as the database. File storage is managed with MinIO, an S3-compatible storage service. The application is containerized using Docker and managed with Docker Compose. For development and testing, I employ pytest for testing with pytest-cov for coverage reports. Code quality tools like black and isort ensure code formatting and organization, while ruff helps with linting. Asynchronous programming is leveraged to handle multiple tasks concurrently, improving performance.
-
Clone the repo https://github.com/nhesusrz/am_crm_service.git
-
Install and configure Poetry: https://python-poetry.org/docs/basic-usage/
-
cd am_crm_service
-
Activate the virtual environment:
poetry shell
-
Install app dependencies from
pyproject.toml
file:poetry install
-
Run
uvicorn app.main:app --reload
to run the application locally.
Navigate to http://localhost:8000/docs find documentation and resources to test the application locally.
Pre-commit hooks help ensure code quality by running checks and formatting tools before commits. Follow these steps to set up pre-commit hooks in your repository:
Install the hooks defined in the .pre-commit-config.yaml
file:
pre-commit install
To run all configured hooks on all files, use:
pre-commit run --all-files
To update the hooks to their latest versions, use:
pre-commit autoupdate
- Run
alembic revision --autogenerate -m "migration message"
to auto generate migrations. - Run
alembic upgrade head
to apply migrations. - Run
alembic downgrade -1
to downgrade migrations. - NOTE: Do not modify the imports from
alembic/env.py
file.
This project uses poetry
for dependency management.
cd am_crm_service
poetry install
poetry shell
poetry run pytest
Before deploying the application, make sure you have Docker and Docker Compose installed.
Follow the instructions on the official Docker website to install Docker engine in your operating system.
Starting from Docker version 1.13, Docker Compose is included as part of Docker installations.
To install Docker Compose from the official repository:
- Download Docker Compose: Find the latest release version from the Docker Compose GitHub releases page.
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- Apply Executable Permissions: Make the Docker Compose binary executable.
sudo chmod +x /usr/local/bin/docker-compose
- Verify Installation: Check that Docker Compose is installed correctly. You should see the version of Docker Compose that you installed.
docker-compose --version
- Clone the repo https://github.com/nhesusrz/am_crm_service.git
-
cd am_crm_service
-
cp .env.example .env
- Run Docker Compose to build and start the services. This command will build the Docker images and start the containers of the application, PostgreSQL, and MinIO:
Or for earlier versions
docker compose up -d --build
docker-compose up -d --build
The FastAPI application will be available at http://localhost:8000. Use this URL to interact with the API.
To view and manage your buckets and their contents, you can access the MinIO WebUI: Open your web browser and go to http://127.0.0.1:9001.
Log in using the credentials specified in your .env file:
- Access Key:
<your-minio-access-key>
- Secret Key:
<your-minio-secret-key>
This interface allows you to view, create, and manage buckets and their contents.
- Container Status: Check the status of your containers:
docker compose ps
- Logs: To view the logs for debugging, use:
docker compose logs
To test the API, you can use Postman. Import the provided Postman collection file into Postman: Download Postman Collection
To clean up everything related to the containers, including volumes and images, follow these steps:
- Stop and remove containers:
docker stop app_container minio_container postgres_container
docker rm app_container minio_container postgres_container
- The volumes defined in your docker-compose.yml file are postgres_data and minio_data. To remove these volumes, use:
docker volume rm postgres_data minio_data
- To remove the images postgres:latest and minio/minio use:
docker rmi postgres:latest minio/minio