This is a FastAPI-based notifications application that uses PostgreSQL as its database backend. The application is containerized using Docker for easy deployment and development.
- Docker
- Docker Compose
The project consists of a FastAPI application and a PostgreSQL database, both running in separate Docker containers.
- Clone this repository:
git clone <repository-url> cd <repository-directory>
- To load seeds, go to docker-compose.yml and uncomment
#- SEED=True
line in serviceweb
,environment
's variables.
- Start the application using Docker Compose:
docker-compose up -d
This command will build the FastAPI app image and start both the app and the database containers.
- SEED=True
line in service web
, environment
's variables.
- The API will be available at
http://localhost:8000
In order to make the project plug-n-play, the following environment variables are explicitly written in compose file:
POSTGRES_DB
: The name of the PostgreSQL database (default:notifications
)POSTGRES_USER
: The PostgreSQL user (default:challenge
)POSTGRES_PASSWORD
: The PostgreSQL password (default:rNmRZ6DJwvxqdQP2h7yk8z
)DATABASE_URL
: The URL for connecting to the PostgreSQL database
You can modify these variables in the docker-compose.yml
file if needed.
In order to handle secrets it can always be set as .secret
or OS environment variables.
The PostgreSQL database runs on port 5433 of the host machine to avoid conflicts with any existing PostgreSQL instances.
To develop the application:
- Make changes to the FastAPI application code in the
src
directory. - Rebuild and restart the containers:
docker-compose down docker-compose up -d --build
This project uses Alembic for database migrations. Migrations are automatically applied when the container starts up.
To create a new migration:
- Make changes to your SQLAlchemy models
- Run the following command:
docker-compose exec web alembic revision --autogenerate -m "Description of changes"
ℹ️ You don't need to apply migrations in order to run this tests.
FastAPI provides automatic API documentation. Once the application is running, you can access:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
To run tests, use the following command:
docker-compose exec web pytest
If you encounter any issues, try the following steps:
-
Ensure all containers are running:
docker-compose ps
-
Check the logs of the containers:
docker-compose logs
-
If there are database connection issues, ensure the
db
service is fully up before theweb
service starts.
- Removing containers, networks and volumes
docker-compose down --volumes
- Removing elements of item 1 + Images
docker-compose down --rmi all --volumes