A backend built with python to serve information to yurb.dev
This backend is also the core hearth for all the features of yurb.dev and a proxy-like backend for future projects.
You can see a detailed documentations about the APIs available here
Yurback uses PDM to manage its dependencies. Use the following command to install all the projects's dependencies without altering the lock file.
pdm syncYurback needs certain env variables to be able to run. In order to run the project locally, define all the env variables needed based on the .env.template file into a new .env file. Below is an example.
PORT=1234
ENVIRONMENT="dev" # accepts dev | prod
JWT_SECRET="my-super-confidencial-secret"
# DB
DATABASE_URI="postgresql://{user}:{password}@{host}/{database}"
...It is worth noting that certain env variables such as
AWS_*are not needed in production since the backend is built to run in AWS using IAM Roles. This allows the project to access all the AWS services required to work seamlessly.
All commands are run from the root of the project, from a terminal and using PDM:
| Command | Arguments | Action | Examples |
|---|---|---|---|
pdm sync |
Installs dependencies | ||
pdm run dev |
--port |
Starts local dev server at localhost:8910 |
pdm run dev --port 8080 |
pdm run tests |
Run all tests using pytest | ||
pdm run tests_cov |
Run all tests and generate a coverage report | ||
pdm run start |
Starts prod-like server at localhost:8910 |
||
pdm run db_revision |
Create a new alembic revision | ||
pdm run db_upgrade |
Upgrade the DB to the latest revision | ||
pdm run db_downgrade |
Downgrade the DB to the previous revision |
PDM allows running installed packages through the run command. This means that every installed package, especially dev-related packages such as pytest, can be run without activating the virtual environment.
# Generates a report based on the latest test run
pdm run coverage report -mThis project is built using [Python v3.11.x] or later. and uses the following stack.
- PDM - For package and dependency management.
- FastAPI - For web server provisioning.
- Pydantic - For IO validation
- SQLAlchemy - For models, querying and connection management.
- PostgreSQL - For SQL engine.
- Alembic - For migrations management.
- Boto3 - For AWS integration.
- Pytest - For unit testing.
- Redocly - For OpenAPI documentation.
- Docker - For containerization.
Terraform is used to provision the infrastructure needed to run this service/backend at api.yurb.dev. At the time, yurback is running in AWS using ECS, ALB, ASG, RDS and CloudFront as core services and Route53 as DNS resolution. You can find all the resources/services used by yurback within AWS in the terraform/ directory.
The infrastructure configured uses certain variables to properly deploy the infrastructure with hardcoded names and without exposing compromising information about the infrastructure configuration. Go to terraform/variables.tf to have a look to all the variables used by the infrastructure.
Before applying the infrastructure for the first time, there are certain requirements that the target AWS account needs to have configured.
Make sure to have the following AWS Roles before applying the terraform infrastructure.
- ecsInstanceRole
- AWSServiceRoleForECS
Note: In the future, I'm planning to migrate the IaC to pulumi, an open source alternative to Terraform. With this migration I expect to use a CDK rather than a specific configuration language.