Skip to content

About

SWEN-566 AI-powered Intelligence Project

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Movie Master

Movie Master is a full-stack movie exploration app.

You can:

  • Search movies
  • View details and generated summaries
  • Chat with a movie assistant
  • Translate content
  • Rate movies and get recommendations

The project has:

  • A FastAPI backend in backend/
  • A React + Vite frontend in frontend/

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • pnpm 9+ preferred for manual frontend work
  • npm 9+ if you want to use scripts/dev-setup.ps1
  • Docker and Docker Compose (for PostgreSQL)

Quick checks:

python --version
node --version
pnpm --version
docker --version
docker-compose --version

If python is not recognized on Windows, try:

py --version

PostgreSQL Setup (Optional)

The backend uses SQLite by default for local development. For production or advanced development with PostgreSQL:

1. Start PostgreSQL with Docker Compose

docker-compose up -d

This starts a PostgreSQL 15 container with:

  • Database: userdb
  • User: postgres
  • Password: postgres
  • Port: 5432

2. Connect to PostgreSQL

docker exec -it movie-master psql -U postgres -d userdb

3. View Database Contents

Once connected to psql, you can:

-- List all tables
\dt

-- View users table
SELECT * FROM users;

-- View ratings table
SELECT * FROM ratings;

-- Exit psql
\q

4. Configure Backend for PostgreSQL

Create or update backend/.env:

DATABASE_URL=postgresql://postgres:postgres@localhost:5432/userDB
USE_POSTGRESQL=true

5. Stop PostgreSQL

docker-compose down

To also remove the data volume:

docker-compose down -v

Run Latest Version (Recommended)

The quickest way to run the app with the latest code and dependencies:

Windows (PowerShell):

.\scripts\run-latest.ps1

macOS / Linux (Bash):

chmod +x scripts/run-latest.sh
./scripts/run-latest.sh

This script will:

  • Pull the latest code from git
  • Create/update the backend virtual environment
  • Install/update all dependencies
  • Start both backend and frontend

The apps will open automatically:

  • Backend: http://localhost:8000/docs
  • Frontend: http://localhost:5173

Optional flags:

  • PowerShell: -NoGitUpdate, -BackendPort 8001, -FrontendPort 5174
  • Bash: --no-git-update, --backend-port 8001, --frontend-port 5174

Example:

.\scripts\run-latest.ps1 -BackendPort 8001 -FrontendPort 5174

Quick Start (Two Terminals)

From the repository root:

  1. Start backend in terminal 1
  2. Start frontend in terminal 2
  3. Open http://localhost:5173

Detailed commands are below.

One-Command Setup (Windows)

If you are on Windows PowerShell, use the bootstrap script:

.\scripts\dev-setup.ps1

What it does:

  • Creates backend virtual environment (backend/.venv) if missing
  • Installs backend dependencies (requirements.txt and requirements-dev.txt)
  • Installs frontend dependencies (npm install)

To set up and launch backend + frontend automatically in separate terminal windows:

.\scripts\dev-setup.ps1 -Run

If PowerShell blocks scripts in your session, run:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Backend Setup (FastAPI + Virtual Environment)

1. Move into backend folder

cd backend

2. Create a virtual environment

python -m venv .venv

If needed on Windows:

py -3.11 -m venv .venv

3. Activate the virtual environment

PowerShell:

.\.venv\Scripts\Activate.ps1

Command Prompt:

.venv\Scripts\activate.bat

macOS/Linux:

source .venv/bin/activate

You should now see (.venv) in your terminal prompt.

4. Install backend dependencies

pip install -r requirements.txt

For PostgreSQL support, also install:

pip install psycopg2-binary

Optional dev/test extras:

pip install -r requirements-dev.txt

5. Configure environment variables (optional but recommended)

Create backend/.env.

The app runs without API keys using built-in fallback behavior, but real providers require keys.

For the current template, start from backend/.env.example.

Example backend/.env:

# App
APP_NAME=Movie Master API
API_PREFIX=/api/v1
DEBUG=false

# Database (SQLite is default, PostgreSQL optional)
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/userDB
USE_POSTGRESQL=false
DATABASE_PATH=./data/ratings.db

# Auth / JWT
JWT_SECRET_KEY=change-this-for-any-non-local-environment
JWT_ACCESS_TOKEN_EXPIRE_MINUTES=60

# Movie providers
TMDB_API_KEY=
OMDB_API_KEY=

# Azure AI Foundry (chat)
AZURE_FOUNDRY_ENDPOINT=
AZURE_FOUNDRY_AGENT_NAME=
AZURE_FOUNDRY_AGENT_VERSION=
AZURE_FOUNDRY_MODEL_DEPLOYMENT=

# Azure Language (summaries)
AZURE_LANGUAGE_ENDPOINT=
AZURE_LANGUAGE_KEY=

# Azure Translator
AZURE_TRANSLATOR_ENDPOINT=
AZURE_TRANSLATOR_KEY=
AZURE_TRANSLATOR_REGION=

Notes:

  • Database: Set USE_POSTGRESQL=true and DATABASE_URL for PostgreSQL, or leave as false for SQLite
  • AZURE_FOUNDRY_AGENT_VERSION is optional. Leave it blank to use the latest active prompt-agent version.
  • AZURE_FOUNDRY_MODEL_DEPLOYMENT is used by the manual Foundry publishing flow and by the direct model fallback path.
  • Ratings, recommendations, and authenticated user CRUD now use bearer JWT auth instead of trusting client-supplied user_id values.
  • The frontend stores the access token locally and sends it automatically on protected requests.
  • Set JWT_SECRET_KEY explicitly anywhere beyond local development.

6. Run the backend API

From backend/:

uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Or use the helper script from backend/scripts/:

./start_backend.sh

Useful endpoints:

  • Health: http://localhost:8000/health
  • OpenAPI docs: http://localhost:8000/docs

Terraform + Azure Setup (Optional)

If you want the Azure-backed chat, summary, and translation integrations, use the Terraform stack in terraform/.

What Terraform provisions:

  • Azure AI Foundry account
  • Azure AI Foundry project
  • Azure AI Model deployment
  • Azure AI Language resource
  • Azure AI Translator resource

What Terraform does not provision automatically:

  • The Foundry chat agent definition itself

Typical flow:

  1. Apply Terraform in terraform/
  2. Copy the generated backend env block into backend/.env
  3. Create or update the Foundry prompt agent manually
  4. Start the backend and frontend

Useful Terraform commands:

cd terraform
terraform output -raw backend_env_file
terraform output -json backend_env_values

backend_env_file gives you a ready-to-paste env block for backend/.env.

Terraform does not generate your JWT signing secret. Set JWT_SECRET_KEY separately in backend/.env or your deployment secret store.

After Terraform, you still need a Foundry agent name in:

AZURE_FOUNDRY_AGENT_NAME=movie-master-agent

Optional for version pinning:

AZURE_FOUNDRY_AGENT_VERSION=1

If you want more detail on the Azure mapping, see terraform/README.md and backend/README.md.

Manual Foundry Agent Publishing

This repo includes a manual helper script for prompt-agent publishing:

cd backend
python scripts/provision_foundry_agent.py

The script:

  • auto-loads backend/.env
  • reads backend/prompts/foundry_agent_instructions.txt
  • creates or versions the prompt agent in Foundry
  • prints the env values you should keep in backend/.env

Frontend Setup (React + Vite)

In a second terminal, from repo root:

cd frontend
npm install
npm run dev

Open:

  • App: http://localhost:5173

The frontend proxies /api/* requests to http://localhost:8000, so keep the backend running.

Account creation and login now persist a short-lived bearer token locally, so backend and frontend should be running from the same current branch when testing ratings, recommendations, or authenticated account actions.

Helpful Scripts

  • scripts/run-latest.ps1 (PowerShell) Recommended. Pulls latest code, updates dependencies, and launches both apps. Windows only.
  • scripts/run-latest.sh (Bash) Recommended. Pulls latest code, updates dependencies, and launches both apps. macOS / Linux.
  • scripts/dev-setup.ps1 (PowerShell) Creates the backend virtual environment, installs backend/frontend dependencies, and can optionally launch both apps with -Run. Windows only.
  • backend/scripts/start_backend.sh (Bash) Starts the FastAPI backend with the repo's standard Uvicorn command.
  • backend/scripts/provision_foundry_agent.py Manually creates or versions the Foundry prompt agent after Terraform provisioning.

Running Tests

Backend (from backend/ with venv activated):

pytest

Backend (from backend/):

pytest tests/test_full_integration_flow.py -v

Frontend (from frontend/):

npm test

for end to end tests

npm test -- tests/e2e

Watch mode:

npm run test:watch

Run all tests (Windows):

.\scripts\run-e2e-tests.ps1 --all

Common Problems

PowerShell blocks activation scripts

If activation fails with an execution policy error, run:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Then activate again:

.\.venv\Scripts\Activate.ps1

Port already in use

Use a different port:

uvicorn app.main:app --reload --port 8001

If you change backend port, update frontend proxy config in frontend/vite.config.js.

Installed packages go to global Python

Make sure (.venv) appears in your prompt before running pip install or pytest.

Deactivate Virtual Environment

When done:

deactivate

About

SWEN-566 AI-powered Intelligence Project

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages