How yuchenmao-nus/cs5260_project works
1. Repository shape
- SmartFlight is a two-tier app: a React + Vite frontend in frontend/ and a FastAPI backend in backend/.
- The backend is the real system boundary for sensitive work: NLU, flight search, ranking, formatting, and any external API keys.
2. User-facing client
- The frontend is a single-page chat-style UI.
- Key UI pieces are App.tsx, ChatMessage, FlightCard, and FlightFilters, which suggest the UX combines conversation with structured flight results and filter controls.
- Frontend code also contains airline metadata generation (src/generated/airlines.ts) and route/airline utilities, so it likely renders normalized flight data rather than raw API payloads.
3. Backend API entry point
- backend/src/smartflight/main.py is the FastAPI application entry point.
- routers/chat.py is the main public API surface, so the primary interaction pattern is likely a chat request/response flow rather than a broad REST surface.
- The frontend talks to this API through frontend/src/api.ts.
4. Core backend layering
- The backend is organized into three main layers:
- routers/ for HTTP endpoints
- services/ for business logic and integration orchestration
- agent/ for the AI-driven flight discovery pipeline
- This separation matters: the router should stay thin, while services and agent modules do the work.
5. Agent orchestration
- smartflight/agent/agent.py appears to be the orchestrator for the conversational flight-discovery workflow.
- Supporting modules like extract_query.py, extract_preference.py, search_flights.py, filter_flights.py, and guardrail.py indicate a pipeline that:
1. interprets user intent,
2. extracts structured search criteria,
3. retrieves flight options,
4. filters/ranks them,
5. applies safety or validity checks before responding.
6. Flight search subsystem
- agent/fast_flights/ is a distinct subsystem for flight retrieval.
- It includes:
- fetcher.py for data acquisition,
- querying.py for building searches,
- parser.py for turning raw results into structured objects,
- model.py and types.py for internal representations.
- The presence of browser_capture.py suggests the backend may capture or interact with browser-rendered content when direct structured APIs are insufficient.
7. External integration boundary
- agent/fast_flights/integrations/bright_data.py shows at least one external data source/infrastructure dependency: Bright Data.
- integrations/base.py implies an abstraction over providers, so the system can swap or extend search backends without changing the agent logic.
- This is the main outbound integration boundary for obtaining flight inventory.
8. Internal data contract
- agent/fast_flights/pb/flights.proto and generated protobuf files indicate a strongly typed internal schema for flight results.
- That suggests the system normalizes heterogeneous search results into a stable intermediate contract before presentation.
- The UI and higher-level services likely consume simplified models derived from this schema.
9. Services layer responsibilities
- services/flight_search.py appears to wrap the agent/search pipeline for application use.
- services/nlu.py likely handles model-backed or heuristic language understanding, probably using OpenAI when enabled.
- services/chat_formatting.py, recommendation_text.py, and progress.py suggest the backend generates:
- user-facing conversational text,
- recommendation summaries,
- progress/status updates during longer searches.
- services/booking.py exists as a separate boundary, implying booking is modeled as a downstream capability distinct from discovery.
10. State, safety, and control flow
- agent/state.py implies the agent maintains conversation/search state across turns.
- guardrail.py suggests the system validates outputs or constrains unsafe/invalid requests before acting on them.
- search_result_sample.txt is probably a fixture/reference for expected search output shape.
11. Runtime, tooling, and deployment
- Backend runtime: Python 3.11+, FastAPI, with uvicorn for local serving.
- Frontend runtime: Node 20+, React, TypeScript, Vite.
- The repo includes a .devcontainer/ and Dockerfile, so development and deployment are container-friendly.
- backend/.env.example and the README make it clear that secrets such as OPENAI_API_KEY must stay server-side.
12. Testing and verification
- Backend tests live in backend/tests/, including test_chat.py and test_fast_flights_querying.py.
- This indicates two important test seams: the chat/API contract and the flight-querying engine.
- There are no obvious frontend tests in the tree, so validation appears backend-heavy.
13. High-level data flow
- The typical flow is:
- user chats in the frontend,
- frontend sends the message to the backend chat endpoint,
- backend agent extracts intent/preferences,
- flight search service queries external sources,
- results are normalized, filtered, and formatted,
- backend returns both conversational text and structured flight cards for the UI.
14. What to show in an architecture diagram
- Draw a clear boundary between browser UI and FastAPI backend.
- Inside the backend, separate router, services, and agent/search/integration layers.
- Show Bright Data and any LLM/OpenAI dependency as external services behind backend-only secrets.
- Represent protobuf/normalized flight models as the internal contract between search and presentation layers.
Main entry points: agent.py Agent · chat.py Chat Router · App.tsx App · flight_search.py Flight Search
Components 24
Frontend
React/Vite chat UI and presentation layer
- App · Top-level chat experience and UI composition
frontend/src/App.tsx - Chat Message · Renders conversational messages
frontend/src/components/ChatMessage.tsx - Flight Card · Displays structured flight offers
frontend/src/components/FlightCard.tsx - Flight Filters · Filter controls for narrowing results
frontend/src/components/FlightFilters.tsx - API Client · Frontend entry point for backend chat requests
frontend/src/api.ts - UI Models · Frontend flight normalization helpers and airline metadata
frontend/src/types.ts
Backend
FastAPI API, services, and agent pipeline
- FastAPI App · Backend startup and app wiring
backend/src/smartflight/main.py - Chat Router · Primary public API surface for chat interactions
backend/src/smartflight/routers/chat.py - NLU · Interprets user intent and preferences
backend/src/smartflight/services/nlu.py - Flight Search · Application wrapper around flight discovery pipeline
backend/src/smartflight/services/flight_search.py - Chat Formatting · Builds user-facing responses and summaries
backend/src/smartflight/services/chat_formatting.py - Progress · Produces status updates during longer searches
backend/src/smartflight/services/progress.py - Recommendations · Generates recommendation text and ranking summaries
backend/src/smartflight/services/recommendation_text.py - Booking · Downstream booking capability separate from discovery
backend/src/smartflight/services/booking.py - Agent · Coordinates the conversational flight-discovery workflow
backend/src/smartflight/agent/agent.py - State · Tracks search and conversation context across turns
backend/src/smartflight/agent/state.py - Query Parsing · Extracts search query and preferences from user input
backend/src/smartflight/agent/extract_query.py - Guardrail · Constrains invalid or unsafe requests and outputs
backend/src/smartflight/agent/guardrail.py - Filter Flights · Applies filtering and ranking to candidate flights
backend/src/smartflight/agent/filter_flights.py
Search Core
Flight discovery, normalization, and external retrieval
- Query Builder · Constructs flight search requests
backend/src/smartflight/agent/fast_flights/querying.py - Fetcher · Acquires flight data from providers
backend/src/smartflight/agent/fast_flights/fetcher.py - Parser · Turns raw results into structured flights
backend/src/smartflight/agent/fast_flights/parser.py - Flight Proto · Stable protobuf schema for normalized flight results
backend/src/smartflight/agent/fast_flights/pb/flights.proto - Bright Data · Outbound flight inventory and retrieval dependency
backend/src/smartflight/agent/fast_flights/integrations/bright_data.py
Connections 26
- App → Chat Message: renders · Chat UI composes message timeline
- App → Flight Card: renders · Displays flight results as cards
- App → Flight Filters: includes · Provides result filtering controls
- App → API Client: calls · Sends chat requests to backend
- Flight Card → UI Models: uses · Renders normalized flight data
- Flight Filters → UI Models: uses · Operates on structured flight fields
- API Client → Chat Router: HTTP · Frontend talks to chat endpoint
- FastAPI App → Chat Router: mounts · Registers chat router on app startup
- Chat Router → NLU: delegates · Parses and understands user intent
- Chat Router → Flight Search: delegates · Triggers flight discovery workflow
- Chat Router → Chat Formatting: formats · Builds conversational response payloads
- Chat Router → Progress: reports · Streams or emits progress updates
- Flight Search → Agent: orchestrates · Wraps the agent pipeline for app use
- NLU → Query Parsing: feeds · Provides structured intent and preferences
- Agent → State: maintains · Keeps conversation context across turns
- Agent → Guardrail: checks · Validates requests and outputs
- Agent → Query Builder: builds · Creates search queries from parsed intent
- Agent → Fetcher: retrieves · Fetches flight inventory
- Agent → Filter Flights: filters · Ranks and prunes candidate flights
- Agent → Flight Proto: normalizes to · Uses stable internal flight schema
- Query Builder → Bright Data: requests · Sends provider-specific search requests
- Fetcher → Bright Data: calls · Outbound integration for inventory access
- Fetcher → Parser: parses · Converts raw provider responses
- Parser → Flight Proto: emits · Produces normalized protobuf-backed flights
- Chat Formatting → Recommendations: summarizes · Generates recommendation text from results
- Flight Search → Booking: handoff · Keeps booking separate from discovery