Skip to content
wardacoderPublic

About

Full-stack AI comparison system built with FastAPI, React.js, LangChain, and GPT-4o, enhanced with Brave Search grounding for accurate, real-time context. Supports personalized, category-aware comparisons, schema-validated outputs, caching, and PostgreSQL-backed history with follow-up reasoning and shareable comparison links.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

27 Commits

Folders and files

Repository files navigation

COMPAIR

Intelligent decision-making through structured AI comparisons

A full-stack web application that transforms decision paralysis into clarity. Built with React.js and FastAPI, and fully containerized with Docker, COMPAIR uses GPT-4o, LangChain, Brave Search, structured JSON validation, and an MCP (Model Context Protocol) layer to deliver grounded, personalized comparisons across any category, including gadgets, cars, technologies, destinations, and more.


🎯 The Problem

Choosing between multiple options usually means:

  • Sifting through scattered reviews
  • Opening too many tabs
  • Manually comparing specifications
  • Struggling to weigh trade-offs

COMPAIR solves this by generating structured, validated, context-aware comparisons that adapt to your needs, priorities, and budget.


✨ Core Features

πŸ€– Intelligent Comparison Engine

  • Uses OpenAI GPT-4o through LangChain for structured AI reasoning
  • Generates comparison tables, pros and cons, summaries, and recommendations
  • Understands category context such as Gadgets, Cars, Technologies, Destinations, Shows, and more
  • Validates items with category-specific rules to prevent incorrect comparisons
  • Produces consistent structured JSON outputs through Pydantic parsing

πŸ‘€ Personalization

  • Users can provide priorities, a budget range, and a detailed use case
  • COMPAIR produces a personalized winner based on user needs
  • When preferences are not provided, COMPAIR provides neutral and balanced comparisons

πŸ” Real-Time Search Integration

  • Integrates Brave Search API to fetch real and current data for each item
  • Reduces hallucinations by grounding the model using factual search snippets
  • Search snippets are injected into prompts before LLM processing for accuracy

πŸ’¬ Context-Aware Follow-Up

  • Users can ask follow-up questions after receiving results
  • COMPAIR maintains conversation memory for each comparison
  • Follow-up answers stay relevant without restarting any session

πŸ“Š Analytics Dashboard

  • Built for Product Managers to monitor platform performance and user behaviour at a glance
  • Time-range filtering (7, 30, 90 days) across total comparisons, category breakdowns, popular pairs, and decision confidence metrics
  • Tracks user feedback statistics including ratings and improvement comments
  • Integrated AI chat lets Product Managers ask natural-language questions about comparison trends

⭐ User Feedback System

  • Collects star ratings for accuracy and winner match quality after each comparison
  • Separate feedback paths for personalized and neutral comparisons
  • Stores user comments (what worked, what could improve) in PostgreSQL for analytics

πŸ”Œ MCP (Model Context Protocol) Layer

  • A dedicated FastAPI MCP server runs alongside the main backend (port 8001)
  • Exposes 9 structured tools covering dashboard metrics, feedback summaries, category insights, activity trends, and AI-generated reports
  • Any MCP-compatible AI assistant (Grok, ChatGPT, Claude) can connect and query COMPAIR data programmatically

πŸ“š Comparison History and Sharing

  • Stores all comparisons in PostgreSQL using JSONB
  • Generates public shareable links for quick access and collaboration

🎨 Modern User Experience

  • Built with React 18 and TailwindCSS
  • Smooth interactions using Framer Motion
  • Fully responsive design
  • Clean and intuitive form controls, tabs, and results display
  • Light and dark mode support
  • Optional PDF exporting capability

πŸ› οΈ Technical Architecture

COMPAIR is designed as a modular, scalable, and grounded full-stack system that connects frontend interaction, backend logic, AI reasoning, real-time search, and persistent data storage.

Frontend

  • React.js 18
  • TailwindCSS
  • Framer Motion
  • Component-based structure
  • Fetch API for backend communication
  • Local storage for theme persistence

Backend

  • FastAPI with async support
  • Category validation and prompt construction
  • Brave Search integration
  • LangChain for GPT-4o orchestration and output parsing
  • Conversation memory for follow-up interactions
  • MCP server (separate FastAPI service on port 8001) exposing dashboard data as AI-callable tools
  • Comprehensive error handling and logging

AI Reasoning Layer

  • GPT-4o for structured and grounded comparisons
  • Groq LLM for analytics chat responses via the MCP layer
  • MCP flow: user query β†’ Groq LLM β†’ MCP tool call β†’ PostgreSQL β†’ structured AI response
  • Real-time data from Brave Search
  • Dynamic prompt construction using system and human messages
  • Strict schema enforcement with PydanticOutputParser

πŸŽ₯ Project Demo

COMPAIR Demo

β–Ά Click here to watch the full COMPAIR demo on YouTube

Static screenshots are available in
πŸ“‚ COMPAIR/images


πŸ—„οΈ Database Overview

COMPAIR uses PostgreSQL with JSONB for fast and flexible structured storage.

Supports:

  • Comparison history
  • Public shareable comparisons
  • Conversation memory
  • A 24-hour caching layer for reducing repeated LLM calls
  • Item analytics and frequency tracking

Why JSONB

  • Faster than plain JSON
  • Ideal for storing AI-generated tables, pros and cons, and structured results
  • Works seamlessly with PostgreSQL indexing and filtering

πŸ“‚ Repository Structure

COMPAIR/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py                    # Core API (port 8000)
β”‚   β”œβ”€β”€ mcp_server.py              # MCP server β€” AI tool layer (port 8001)
β”‚   β”œβ”€β”€ grok_mcp_client.py         # MCP client for AI assistant integration
β”‚   β”œβ”€β”€ analytics_chat_endpoint.py # Analytics chat API endpoint
β”‚   β”œβ”€β”€ prompt/
β”‚   β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ utilities/
β”‚   └── database/
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/            # Includes AnalyticsChat, FeedbackSection
β”‚   β”‚   └── pages/                 # Compare, Dashboard, Home
β”‚   └── package.json
β”‚
β”œβ”€β”€ docs/                          # Technical deep-dives and implementation notes
β”œβ”€β”€ docker-compose.yml             # 4-service orchestration
β”œβ”€β”€ mcp_config.json                # AI assistant MCP configuration
β”œβ”€β”€ .env.example                   # Environment template
β”œβ”€β”€ images/
└── README.md

🐳 Docker Deployment

COMPAIR includes a complete, ready-to-run Docker setup.

Containers

  • Backend (FastAPI with GPT-4o integration) β€” port 8000
  • MCP Server (AI tool layer) β€” port 8001
  • Frontend (React served with Nginx) β€” port 3000
  • PostgreSQL (JSONB optimized)

Quick Start

cp .env.example .env   # fill in your API keys
docker-compose up --build

Access


πŸ§ͺ Testing Overview

Backend

  • Endpoint stability
  • Prompt construction logic
  • Brave Search integration
  • Schema validation
  • Error handling

AI Layer

  • Structured responses
  • Category consistency
  • Correct personalization
  • Hallucination reduction

Frontend

  • Form validation
  • Responsive UI
  • Flow stability
  • Animation performance

Integration

  • Context retention
  • End-to-end API reliability
  • History and sharing workflows

🧠 Learning Outcomes

Developing COMPAIR strengthened my full-stack and AI engineering capabilities across all layers of system design.
This project evolved from a simple comparison tool into a grounded, database-backed, cache-aware, multi-service AI system.

Full-Stack Architecture

Designed and delivered a complete React and FastAPI system with clean API contracts and structured data flows between frontend, backend, AI reasoning, and storage layers.

Backend Engineering

Built a production-ready backend with Brave Search grounding, a 24-hour PostgreSQL-backed caching layer, dynamic prompt templates, conversation memory, category filtering, a dedicated MCP server exposing structured AI tools, and the repository pattern for clean data access.

AI Integration and Prompt Engineering

Developed a reliable prompt-engineering workflow using GPT-4o, LangChain, PydanticOutputParser, system and human messages, real-time grounding, anti-hallucination strategies, and dynamic prompt construction. Extended the AI layer with Groq for analytics chat and MCP tool-calling for structured data queries.

Database Design and Data Engineering

Implemented PostgreSQL with JSONB storage, optimized indexing, TTL caches, history management, public sharing, item analytics, and stable data flows.

Frontend Development

Built a modern, responsive UI with React, TailwindCSS, Framer Motion, and clean state management patterns to present structured AI outputs effectively.

DevOps and Deployment

Containerized all services with Docker, configured Nginx for production frontend hosting, and set up environment-based configuration for portability.

System Thinking

Learned how to combine human preferences, AI reasoning, real-time grounding, backend orchestration, structured validation, and clean UI into one cohesive product.


✨ Author

Warda Ul Hasan
Computer Engineering Graduate, American University of Sharjah
LinkedIn: https://www.linkedin.com/in/wardaulhasan
GitHub: https://github.com/wardacoder

COMPAIR reflects my goal to build systems where intelligence meets structure, practical purpose, and thoughtful design.

About

Full-stack AI comparison system built with FastAPI, React.js, LangChain, and GPT-4o, enhanced with Brave Search grounding for accurate, real-time context. Supports personalized, category-aware comparisons, schema-validated outputs, caching, and PostgreSQL-backed history with follow-up reasoning and shareable comparison links.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages