Skip to content

Deployment

The Analytics Dashboard is deployed to an AWS EC2 instance running the FastAPI backend as a systemd service and the Streamlit frontend. Updates are deployed using the deploy.ps1 script in the analytics/ directory.

Architecture

Client Browser
     │
     ▼
EC2: Streamlit (Streamlit server, port 8501)
     │  reads from
     ▼
EC2: FastAPI backend (systemd service, port 8000)
     │  reads/writes
     ▼
EC2: PostgreSQL database

The Streamlit frontend hot-reloads when its Python files are updated (no restart needed). The FastAPI backend requires a service restart when main.py or database.py changes.

Deploying an update

From the via_onboard project root on your local machine, run the deploy script:

.\analytics\deploy.ps1

The script: 1. SCPs the updated Python files (main.py, auth.py, dashboard.py, demo_data.py, and Streamlit pages) to the EC2 instance at ~/via-dashboard-api/. 2. Restarts the FastAPI backend service (sudo systemctl restart via-dashboard-api). 3. Streamlit picks up the new page files automatically via hot-reload.

deploy.ps1 running in terminal

Screenshot: PowerShell terminal showing deploy.ps1 output — SCP file transfer lines and the "Restarting API service..." message

Server configuration

EC2 instance: ubuntu@ec2-3-15-145-180.us-east-2.compute.amazonaws.com
SSH key: %USERPROFILE%\.ssh\via-key-pair-v2.pem
Remote path: ~/via-dashboard-api/
Systemd service: via-dashboard-api

Starting services manually (first deploy or after reboot)

SSH into the EC2 instance:

ssh -i ~/.ssh/via-key-pair-v2.pem ubuntu@ec2-3-15-145-180.us-east-2.compute.amazonaws.com

Start the FastAPI backend:

sudo systemctl start via-dashboard-api
sudo systemctl status via-dashboard-api

Start Streamlit (if it's not managed by systemd):

cd ~/via-dashboard-api
streamlit run dashboard.py --server.port 8501

Checking logs on EC2

FastAPI backend logs:

journalctl -u via-dashboard-api -f

Streamlit logs:

# If running in the foreground
# Check the terminal where Streamlit was started

# If running under systemd
journalctl -u via-streamlit -f

Adding a new Streamlit page

  1. Create the new .py file in analytics/pages/.
  2. Run deploy.ps1 — the new page is uploaded and Streamlit picks it up automatically.
  3. If the page needs a new backend API endpoint, add it to main.py and redeploy. The systemd restart in deploy.ps1 covers this.

Environment variables

The backend reads database credentials and configuration from a .env file on the server at ~/via-dashboard-api/.env. This file is not deployed by deploy.ps1 — it must be set up manually on the server and never committed to the repository.

Required environment variables:

DATABASE_URL=postgresql://user:password@host:5432/via_analytics
DASHBOARD_API_KEY=your-api-key    # optional, enables API key auth