This is the backend service for the LMU App. It provides the necessary API endpoints and data processing for the LMU application.
- FastAPI - Modern Python web framework
- PostgreSQL - Primary database
- Docker Compose - Container orchestration
- Nginx Proxy Manager - Reverse proxy and SSL management
- Metabase - Data analytics and visualization
- PgAdmin - Database management interface
Before you begin, ensure you have met the following requirements:
- You have installed the latest version of Python (3.12 recommended)
- You have installed Docker and Docker Compose
- You have a Windows/Linux/Mac machine
-
Clone the repository:
git clone https://github.com/lmu-devs/lmu_app_backend.git cd lmu_app_backend
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On macOS and Linux:
source venv/bin/activate
- On Windows:
-
Install the required dependencies:
pip install -r requirements.txt
-
Copy the environment template (Ask a developer for the .env file):
cp .env.template .env
-
Run docker compose:
docker compose up db api_dev data_fetcher_dev -d
The application supports three environments:
The development environment is used for local development and testing.
- Run the application using Docker Compose with development services:
docker compose up api_dev data_fetcher_dev db db_mb pgadmin metabase nginx --build
This setup uses the api_dev
and data_fetcher_dev
services which mount the local codebase as a volume, enabling:
- Hot-reload: Code changes are reflected immediately without rebuilding containers
- Live debugging: Changes to the codebase are immediately available in the containers
- Development workflow: Edit code locally while running services in containers
The staging environment is hosted on a Digital Ocean droplet.
- URL:
{service}-staging.lmu-dev.org
- IP:
157.230.114.51
- DNS: Managed through Cloudflare
- Deployment: Automatic when code is pushed to the
staging
branch
The production environment is hosted on a Digital Ocean droplet.
Available services:
api.lmu-dev.org metabase.lmu-dev.org pgadmin.lmu-dev.org nginx.lmu-dev.org
- URL:
{service}.lmu-dev.org
- IP:
64.226.106.247
- DNS: Managed through Cloudflare
- Deployment: Automatic when code is pushed to the
main
branch
The application consists of several Docker services:
-
API (
api
):- Main FastAPI application
- Exposed on port 8001 (localhost)
- Development mode available with hot-reload (
api_dev
)
-
Data Fetcher (
data_fetcher
):- Background data processing service
- Development mode available (
data_fetcher_dev
)
-
Database (
db
):- PostgreSQL 16.4
- Centralized database for all services
-
PgAdmin (
pgadmin
):- Database management interface
- Configurable port through environment variables
-
Metabase (
metabase
):- Data analytics platform
- Exposed on port 3000
- Separate PostgreSQL instance (
db_mb
) on port 5433
-
Nginx Proxy Manager (
nginx
):- Reverse proxy and SSL management
- Ports 80 and 443
We follow a trunk-based development strategy:
main
- Production branch, represents live codestaging
- Integration branch for testing- Feature branches - Created from
staging
Workflow:
- Create feature branch from
staging
- Develop and test
- Create PR to merge into
staging
- After testing, merge
staging
intomain
GitHub Actions automation:
-
Continuous Integration:
- Runs on all pull requests
- Formats code
- Executes test suite (TODO)
- Performs code quality checks (TODO)
-
Staging Deployment:
- Triggered on
staging
branch updates - Builds and tags Docker images
- Deploys to staging environment
- Triggered on
-
Production Deployment:
- Triggered on
main
branch updates - Uses staging-verified images
- Deploys to production environment
- Triggered on
-
Development:
docker compose up
-
Staging:
- Automatic deployment from
staging
branch - Manual:
docker compose up db api data_fetcher --build
- Automatic deployment from
-
Production:
- Automatic deployment from
main
branch - Manual:
docker compose up db api data_fetcher --build
- Automatic deployment from
The directus cms is used to manage the content for the application.
The graphql api is used to query the data from the database.
To setup a nice developer experience for the graphql api, we recommend installing the GraphQL: Language Feature Support extension for VSCode.
Setup:
- Copy the .graphqlconfig.example file to .graphqlconfig
- Replace the
<DIRECTUS_ACCESS_TOKEN FROM .env>
with your directus access token - Press
Ctrl+Shift+P
and selectVSCode GraphQL: Manual Restart
- Autocomplete should work now
After deployment, the following services are available:
- API Documentation:
http://localhost:8001/docs
- REST API:
http://localhost:8001/v1
- PgAdmin:
http://localhost:5050
- Metabase:
http://localhost:3000