Skip to content

Repository files navigation

πŸ•·οΈ Marvel Oracle - RAG-Powered Marvel Universe Chat

A full-stack RAG (Retrieval-Augmented Generation) application that lets you chat with the Marvel Universe using AI. Ask questions about Marvel characters, storylines, and lore with context-aware responses powered by vector search and GPT-4.

Marvel Oracle Demo Vercel Next.js Python

πŸš€ Live Demo

🌐 Try Marvel Oracle

✨ Features

🧠 Intelligent RAG System

  • Context-Aware Conversations: Remembers chat history for follow-up questions
  • Query Rewriting: Automatically enhances ambiguous questions using conversation context
  • Vector Search: Uses Pinecone for semantic similarity search across Marvel content
  • GPT-4 Integration: Powered by OpenAI's most advanced language model

πŸ’¬ Chat Experience

  • Multiple Timelines: Create and manage separate conversation threads
  • Real-time Responses: Streaming responses with loading indicators
  • Chat History: Persistent conversation storage with Appwrite
  • Context Menu: Edit chat names, delete conversations
  • Auto-scroll: Automatically scrolls to latest messages

πŸ” Authentication & Security

  • Secure Login/Signup: Email-password authentication via Appwrite
  • Password Reset: Email-based password recovery system
  • HTTP-only Cookies: Secure session management
  • Route Protection: Middleware-based authentication guards

🎨 Modern UI/UX

  • Dark Theme: Marvel-inspired red and gray color scheme
  • Responsive Design: Works seamlessly on desktop and mobile
  • Smooth Animations: Polished loading states and transitions
  • Intuitive Navigation: Clean sidebar with chat history

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Next.js       β”‚    β”‚   Vercel         β”‚    β”‚   External      β”‚
β”‚   Frontend      │◄──►│   Serverless     │◄──►│   Services      β”‚
β”‚                 β”‚    β”‚   Functions      β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚                      β”‚                      β”‚
β”‚ β€’ React Components   β”‚ β€’ Python API        β”‚ β€’ Appwrite DB
β”‚ β€’ Zustand Store      β”‚ β€’ LangChain RAG      β”‚ β€’ Pinecone Vector
β”‚ β€’ TailwindCSS        β”‚ β€’ Query Processing   β”‚ β€’ OpenAI GPT-4
β”‚ β€’ TypeScript         β”‚ β€’ Chat History       β”‚ β€’ Email Service

πŸ› οΈ Tech Stack

Frontend

Backend

AI & Data

Database & Auth

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • Python 3.9+
  • npm or yarn

Environment Variables

Create these environment variable files:

Client (.env.local)

NEXT_PUBLIC_APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
NEXT_PUBLIC_APPWRITE_PROJECT_ID=your_project_id
NEXT_PUBLIC_APPWRITE_DATABASE_ID=your_database_id
NEXT_PUBLIC_APPWRITE_COLLECTION_ID=your_collection_id
NEXT_PUBLIC_API_URL=http://localhost:3000/api

Server Environment Variables

OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key

Local Development

  1. Clone the repository
git clone https://github.com/yourusername/marvel-oracle.git
cd marvel-oracle
  1. Install dependencies
# Install client dependencies
cd client
npm install

# Install server dependencies (for local development)
cd ../server
pip install -r requirements.txt
  1. Set up external services

    Appwrite Setup:

    • Create account at Appwrite Cloud
    • Create new project
    • Set up database and collection for chat storage
    • Configure authentication settings

    Pinecone Setup:

    • Create account at Pinecone
    • Create index named marvel-embeddings
    • Upload your Marvel content embeddings

    OpenAI Setup:

  2. Run development servers

# Start Next.js frontend (from project root)
npm run dev:client

# Start Python backend (from project root) 
npm run dev:server
  1. Open the application

πŸš€ Deployment

The application is configured for one-click deployment to Vercel:

Deploy to Vercel

  1. Using Vercel CLI
npm install -g vercel
vercel --prod
  1. Using GitHub Integration
    • Push code to GitHub
    • Import repository in Vercel dashboard
    • Configure environment variables
    • Deploy automatically

Environment Variables in Production

Set these in your Vercel dashboard:

OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key
NEXT_PUBLIC_APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
NEXT_PUBLIC_APPWRITE_PROJECT_ID=your_project_id
NEXT_PUBLIC_APPWRITE_DATABASE_ID=your_database_id
NEXT_PUBLIC_APPWRITE_COLLECTION_ID=your_collection_id

πŸ“ Project Structure

marvel-oracle/
β”œβ”€β”€ client/                  # Next.js frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/            # App Router pages
β”‚   β”‚   β”‚   β”œβ”€β”€ login/      # Authentication pages
β”‚   β”‚   β”‚   β”œβ”€β”€ signup/
β”‚   β”‚   β”‚   └── reset-password/
β”‚   β”‚   β”œβ”€β”€ components/     # React components
β”‚   β”‚   β”‚   β”œβ”€β”€ Chatbot.tsx # Main chat interface
β”‚   β”‚   β”‚   β”œβ”€β”€ Chatbar.tsx # Message input
β”‚   β”‚   β”‚   β”œβ”€β”€ History.tsx # Chat sidebar
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”œβ”€β”€ store/          # Zustand state management
β”‚   β”‚   β”œβ”€β”€ types/          # TypeScript type definitions
β”‚   β”‚   └── utils.ts        # API utilities
β”‚   β”œβ”€β”€ middleware.ts       # Route protection
β”‚   └── package.json
β”œβ”€β”€ api/                    # Vercel serverless functions
β”‚   β”œβ”€β”€ index.py           # Health check endpoint
β”‚   └── query.py           # RAG query processing
β”œβ”€β”€ server/                 # Local development server
β”‚   └── server.py          # FastAPI development server
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ vercel.json            # Vercel configuration
└── README.md

🎯 Key Features Explained

RAG Pipeline

The core RAG (Retrieval-Augmented Generation) system works as follows:

  1. Query Processing: User questions are analyzed for context dependency
  2. Query Rewriting: Ambiguous questions are rewritten using chat history
  3. Vector Search: Enhanced queries retrieve relevant Marvel content from Pinecone
  4. Response Generation: GPT-4 generates responses using retrieved context and chat history

Context-Aware Conversations

User: "Who is the boss of Peter Parker's newspaper?"
AI: "J. Jonah Jameson is the editor-in-chief of the Daily Bugle..."

User: "Who is that?" ← Ambiguous question
AI: βœ… Understands "that" refers to J. Jonah Jameson from context

Chat Management

  • Multiple Timelines: Each chat maintains separate conversation history
  • Persistent Storage: All conversations saved to Appwrite database
  • Real-time Updates: UI updates immediately with new messages
  • Context Isolation: Each chat has its own context window

πŸ”§ API Documentation

Query Endpoint

GET /api/query
Headers:
  Query: "Who is Spider-Man?"
  Session-Id: "unique_chat_id"

Response:
{
  "query": "Who is Spider-Man?",
  "response": "Spider-Man is Peter Parker, a young man who gained spider-like abilities...",
  "session_id": "unique_chat_id"
}

Health Check

GET /api/
Response:
{
  "message": "Marvel RAG API is running!",
  "status": "healthy",
  "env_check": {
    "openai_key_set": true,
    "pinecone_key_set": true
  }
}

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Marvel Comics - For the incredible universe and characters
  • OpenAI - For GPT-4 and embedding models
  • LangChain - For RAG framework and tools
  • Vercel - For seamless deployment platform
  • Appwrite - For authentication and database services

πŸ“ž Support


πŸ•·οΈ Built with ❀️ for Marvel fans by Marvel fans πŸ•·οΈ Live Demo

Releases

Packages

Contributors

Languages