Skip to content

shreyansh232/planfirst

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

58 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Planfirst

A constraint-first travel planning agent powered by AI with real-time web search. Built for web and extensible for CLI.

Unlike typical travel planners that immediately generate generic itineraries, Planfirst thinks before planning by following a strict agentic workflow.

πŸš€ The Multi-Phase Workflow

  1. Clarification: Intelligently extracts trip details from your initial message and only asks for what's missing (season, duration, budget, interests, etc.)
  2. Feasibility Check: Uses real-time web search to evaluate travel advisories, weather, and conditions for the specific travel period
  3. Assumptions: Makes all planning assumptions explicit (e.g., transport modes, accommodation styles) and requires user confirmation
  4. Planning: Researches current prices and creates a detailed day-by-day itinerary with:
    • Activities with cost estimates and notes
    • Travel times and costs
    • Accommodation recommendations
    • Daily tips (money-saving hacks, hidden gems, fast routes, must-try food)
    • General trip tips (visa info, SIM cards, cultural etiquette, essential apps)
    • Complete budget breakdown
  5. Refinement: Allows adjustments for safety, speed, comfort, or location preferences

πŸ› οΈ Tech Stack

Backend

  • Framework: FastAPI (Python 3.12+)
  • Database: PostgreSQL with SQLAlchemy 2.0 (Async) & Alembic migrations
  • Auth:
    • JWT-based authentication with refresh tokens
    • Google OAuth 2.0 integration
    • Bcrypt password hashing
    • Multi-device session management
  • AI/LLM: OpenRouter API (supports multiple models including Gemini 3 Flash)
  • Web Search: DuckDuckGo Search (duckduckgo-search)
  • Package Manager: uv

Frontend

  • Framework: Next.js 15+ (App Router)
  • UI Library: React 19
  • Styling: Tailwind CSS 4
  • Package Manager: pnpm

Infrastructure

  • Container: Docker Compose (PostgreSQL)
  • Database: PostgreSQL 15+

πŸ“¦ Project Structure

planfirst/
β”œβ”€β”€ backend/                      # FastAPI application
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ agent/               # Travel planning agent logic
β”‚   β”‚   β”‚   β”œβ”€β”€ agent.py         # Main TravelAgent orchestrator
β”‚   β”‚   β”‚   β”œβ”€β”€ models.py        # Pydantic models for phases
β”‚   β”‚   β”‚   β”œβ”€β”€ prompts.py       # Phase-specific prompts
β”‚   β”‚   β”‚   β”œβ”€β”€ tools.py         # Web search & tool execution
β”‚   β”‚   β”‚   β”œβ”€β”€ sanitizer.py     # Input sanitization (prompt injection defense)
β”‚   β”‚   β”‚   └── openai_client.py # LLM client wrapper
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   └── v1/
β”‚   β”‚   β”‚       └── auth.py      # Auth endpoints (register, login, OAuth)
β”‚   β”‚   β”œβ”€β”€ db/
β”‚   β”‚   β”‚   β”œβ”€β”€ models.py        # SQLAlchemy models (User, Trip, TripVersion, etc.)
β”‚   β”‚   β”‚   β”œβ”€β”€ crud.py          # Database operations
β”‚   β”‚   β”‚   └── database.py      # DB connection setup
β”‚   β”‚   β”œβ”€β”€ schemas/             # Pydantic request/response models
β”‚   β”‚   β”œβ”€β”€ services/            # Business logic layer
β”‚   β”‚   β”œβ”€β”€ core/                # Security & config
β”‚   β”‚   β”œβ”€β”€ config.py            # App settings
β”‚   β”‚   └── main.py              # FastAPI app entry point
β”‚   β”œβ”€β”€ alembic/                 # Database migrations
β”‚   └── scripts/                 # Utility scripts
β”œβ”€β”€ frontend/                     # Next.js application
β”‚   └── src/
β”‚       β”œβ”€β”€ app/                 # App router pages
β”‚       β”œβ”€β”€ components/          # React components
β”‚       └── lib/                 # Utilities & API client
β”œβ”€β”€ docker-compose.yml           # PostgreSQL container
└── gemini.md                    # Project patterns & standards

πŸš₯ Getting Started

1. Prerequisites

  • Python: 3.12+
  • Node.js: 20+
  • Docker & Docker Compose: For PostgreSQL
  • uv: Python package manager (Install uv)
  • pnpm: Node.js package manager

2. Environment Setup

Create a .env file in the project root:

# Database
DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5433/planfirst

# Security
SECRET_KEY=your-super-secret-key-here-change-in-production
ALGORITHM=HS256

# OpenRouter API (for LLM)
OPENROUTER_API_KEY=sk-or-v1-your-key-here

# Google OAuth (optional)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_REDIRECT_URI=http://localhost:8000/api/auth/google/callback

# Frontend
FRONTEND_URL=http://localhost:3000

3. Infrastructure Setup

Start PostgreSQL:

docker-compose up -d

4. Backend Setup

cd backend

# Install dependencies
uv sync

# Run database migrations
uv run alembic upgrade head

# Start the API server
uv run uvicorn app.main:app --reload --port 8000

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

5. Frontend Setup

cd frontend

# Install dependencies
pnpm install

# Start the dev server
pnpm dev

The frontend will be available at http://localhost:3000

πŸ§ͺ Testing the Agent

You can test the agent directly via a script:

cd backend
uv run python scripts/test_agent.py

πŸ” Authentication

Planfirst supports two authentication methods:

  1. Email/Password: Traditional registration and login with JWT tokens
  2. Google OAuth: Sign in with Google account

Both methods issue:

  • Access Token: Short-lived (15 minutes), used for API requests
  • Refresh Token: Long-lived (30 days), used to obtain new access tokens

Refresh tokens support:

  • Multi-device sessions
  • Device tracking (user agent, IP)
  • Individual or bulk revocation (logout from one device or all)

πŸ—οΈ Key Features

Agent Capabilities

  • βœ… Smart clarification (extracts info from initial prompt, asks only what's missing)
  • βœ… Real-time web search for current prices, events, advisories
  • βœ… Risk assessment for weather, accessibility, health, infrastructure
  • βœ… Explicit assumption generation with user confirmation
  • βœ… Day-by-day itinerary with activities, costs, tips
  • βœ… Budget breakdown (flights, accommodation, transport, meals, activities)
  • βœ… Plan refinement (adjust for safety, speed, comfort, location)
  • βœ… Prompt injection protection (input sanitization)

Database Design

  • βœ… User Management: Users, preferences, refresh tokens
  • βœ… Trip Versioning: Separate trip identity from planning iterations
  • βœ… JSONB Storage: Fast iteration with phase-specific data (constraints, risk, assumptions, plan, budget, days)
  • βœ… 5-Phase Workflow: Tracks clarification β†’ feasibility β†’ assumptions β†’ planning β†’ refinement

Security

  • βœ… JWT-based auth with refresh tokens
  • βœ… Google OAuth 2.0
  • βœ… Password hashing (bcrypt)
  • βœ… CORS configuration
  • βœ… Session middleware for OAuth state
  • βœ… Input sanitization (anti-injection)

πŸ”§ Common Commands

Backend

Command Description
uv sync Install/update dependencies
uv run alembic revision --autogenerate -m "message" Create new migration
uv run alembic upgrade head Apply all migrations
uv run alembic downgrade -1 Rollback last migration
uv run uvicorn app.main:app --reload Start dev server
uv run python scripts/test_agent.py Test agent directly

Frontend

Command Description
pnpm install Install dependencies
pnpm dev Start dev server
pnpm build Build for production
pnpm lint Run ESLint

Infrastructure

Command Description
docker-compose up -d Start PostgreSQL
docker-compose down Stop PostgreSQL
docker-compose logs -f postgres View PostgreSQL logs
docker-compose ps Check container status

πŸ“š Documentation

πŸ—ΊοΈ Roadmap

  • Frontend UI for chat-based planning
  • Trip history and saved plans
  • User preferences integration
  • Export itineraries (PDF, calendar)
  • Collaborative trip planning
  • Mobile app

πŸ“„ License

MIT

About

AI-powered travel planning agent that builds realistic itineraries by checking feasibility, weather, and live data before planning

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors