Skip to content
GenerateNUPublic

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

Foresight

AI revenue intelligence platform for boutique hotels. Combines the hotel's booking history with events to recommend optimal room rates.

Prerequisites

  • uv — Python package manager
  • Docker — for PostgreSQL (and optional containerized backend)
  • just — command runner

Quick Start

# Build the backend image
just build

# Start everything (db + backend with hot reload)
just dev

# Run migrations
just migrate

# View logs
just logs

# Stop everything
just destroy

Frontend

just frontend-install     # once, and after package.json changes
just frontend             # http://localhost:5173, calls the API from `just dev`
just frontend --mocks     # fake data, no backend needed

Settings and conventions are in frontend/README.md. just lint checks the backend and the frontend.

Local vs Neon database

Recipes that touch the database take an optional --neon flag. Without it they use the local Docker Postgres; with it, the Neon production branch (URLs from .env).

just dev                  # local Docker Postgres
just dev --neon           # same stack, pointed at Neon (local db container not started)
just migrate --neon       # migrations against Neon (direct, non-pooled URL)
just run --neon           # API on the host, outside Docker

--neon works on dev, destroy, run, migrate, migrate-create, migrate-down and test. Re-run just dev / just dev --neon to switch; Compose recreates the backend. Neon URLs come from neon env pull. See docs/decisions/0027-neon-postgres.md.

The API will be available at http://localhost:8000
API docs at http://localhost:8000/docs

Re-run just build whenever you change backend dependencies or the Dockerfile — source code changes hot-reload automatically while just dev is running.

Database Migrations

# Create a new migration after changing models
just migrate-create "add_hotels_table"

# Run pending migrations
just migrate

# Rollback last migration
just migrate-down

Google sign-in

  1. In the Google Cloud console, create an OAuth client of type Web application with the redirect URI http://localhost:8000/auth/google/callback. While the consent screen is in Testing, add your Google account as a test user.
  2. Set these in .env:
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
SESSION_SECRET=   # openssl rand -hex 32
  1. Open http://localhost:8000/auth/google/login, then check http://localhost:8000/auth/me. Every other route needs this login, and you only see hotels you're linked to: create one with POST /hotels (you're linked automatically), and add a colleague with POST /hotels/{id}/users.

For production, register https://<api-domain>/auth/google/callback too and set GOOGLE_REDIRECT_URI, FRONTEND_URL and the SESSION_* settings (see .env.example). The frontend must call the API with credentials: "include".

Deploying to Render

render.yaml declares the API on Render's free plan, with Neon as the database. See docs/decisions/0054-hosted-on-render.md for why.

  1. Check the Neon production host says us-east-1. For another region, change region in render.yaml first, because Render can't change it afterwards.
  2. In Render, choose New > Blueprint and pick this repo. Enter the values it asks for:
    • DATABASE_URL: the pooled (-pooler) Neon URL
    • DATABASE_URL_UNPOOLED: the direct Neon URL
    • PREDICTHQ_TOKEN, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET
    • GOOGLE_REDIRECT_URI: https://<service>.onrender.com/auth/google/callback. The service's URL appears once it exists, so correct this afterwards if the name was taken.
  3. Add the same redirect URI to the Google OAuth client.
  4. Check it:
    • https://<service>.onrender.com/health returns {"status":"ok"}.
    • Open /auth/google/login and sign in. You land on FRONTEND_URL, which is a dead page until a frontend is hosted. Then /auth/me shows your user.

Each deploy applies migrations before the server starts, and a failed migration fails the deploy. The service sleeps after 15 minutes without requests, so the first request after that is slow, and any job still running is killed.

Code Quality

# Lint
just lint

# Format
just format

# Fix lint issues + format
just fix

Pre-commit Hooks

# Install hooks (ruff formatting/linting + conventional commits)
just hooks

Commit messages must follow Conventional Commits:

  • feat: add pricing endpoint
  • fix: correct rate calculation
  • docs: update README

Project Structure

foresight/
├── backend/
│   ├── foresight/          # Installable package (see pyproject.toml)
│   │   ├── main.py         # FastAPI app (foresight.main:app)
│   │   ├── config.py       # Settings (pydantic-settings)
│   │   ├── worker.py       # Runs background jobs
│   │   ├── routes/         # HTTP: routers and their schemas
│   │   ├── services/       # Business logic: domain, ingest, adapters, ml
│   │   ├── repository/     # Data access
│   │   └── database/       # Models, enums, session, Alembic migrations
│   ├── tests/
│   ├── pyproject.toml
│   └── Dockerfile
├── docs/
│   ├── system-design.md    # How the backend fits together
│   └── decisions/          # One design decision per file
├── frontend/               # React app; see frontend/README.md
├── docker-compose.yml
├── justfile
└── .env.example

See docs/system-design.md for the layers, data model, jobs and API.

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages