cr-agent / docs /FRONTEND_SETUP.md
Sibi Krishnamoorthy
first commit
fd06b5a

🎨 Frontend Setup Guide

Overview

Beautiful React.js chat interface with gradient design, real-time updates, and full chat memory.

Prerequisites

  • Node.js 16+ and npm
  • Backend running on port 8000

Installation

Option 1: Using npm (Recommended)

# Navigate to frontend directory
cd frontend

# Install dependencies
npm install

# Start development server
npm start

The app will automatically open at http://localhost:3000

Option 2: Using yarn

cd frontend
yarn install
yarn start

Running Both Backend and Frontend

Terminal 1 - Backend:

cd D:\python_workspace\multi-agent
uv run uvicorn main:app --reload

Terminal 2 - Frontend:

cd D:\python_workspace\multi-agent\frontend
npm start

Features Showcase

1. Chat Interface

  • πŸ’¬ Modern gradient design
  • πŸ“œ Scrollable chat history
  • ⚑ Real-time typing indicators
  • 🎨 Different colors for user/assistant/error messages

2. File Upload

  • πŸ“ Click folder icon to upload
  • βœ… Supported: PDF, TXT, MD, DOCX
  • πŸ“Ž File badge shows current upload
  • πŸ” Ask questions about uploaded documents

3. Example Queries

  • 🌀️ "What's the weather in Chennai?"
  • πŸ“… "Schedule a team meeting tomorrow at 2pm"
  • πŸ’Ύ "Show all meetings scheduled tomorrow"
  • πŸ“„ "What is the remote work policy?"

4. Chat Memory

  • βœ… Full conversation history maintained
  • πŸ—‘οΈ Clear chat button to start fresh
  • πŸ“Œ System messages for file uploads

Screenshots

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ πŸ€– Multi-Agent AI Assistant             β”‚
β”‚ Weather β€’ Documents β€’ Meetings β€’ SQL    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚                                         β”‚
β”‚ πŸ€– Hello! I'm your Multi-Agent AI...   β”‚
β”‚                                         β”‚
β”‚            What's the weather? πŸ‘€        β”‚
β”‚                                         β”‚
β”‚ πŸ€– The weather in Chennai is...        β”‚
β”‚                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ 🌀️ Weather | πŸ“… Meetings | πŸ’Ύ SQL      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ Type your message...               πŸ“€  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

API Integration

The frontend uses axios to communicate with FastAPI:

Chat Endpoint

POST http://localhost:8000/chat
{
  "query": "user question",
  "file_path": "path/to/uploaded/file" // optional
}

Upload Endpoint

POST http://localhost:8000/upload
FormData: { file: File }

Customization

Change Theme Colors

Edit frontend/src/App.css:

.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* Change to your preferred gradient */
.chat-header {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

Add More Example Queries

Edit frontend/src/App.js:

const exampleQueries = [
  '🌀️ What\'s the weather in Chennai?',
  'πŸ“… Schedule a team meeting tomorrow at 2pm',
  // Add your custom queries here
  'πŸ” Search for AI trends',
];

Production Deployment

Build for Production

cd frontend
npm run build

Serve Static Build

# Using Python
cd build
python -m http.server 3000

# Or using serve package
npm install -g serve
serve -s build -p 3000

Deploy to Vercel (Free)

npm install -g vercel
cd frontend
vercel

Deploy to Netlify (Free)

  1. Push to GitHub
  2. Connect repo to Netlify
  3. Set build command: npm run build
  4. Set publish directory: build

Troubleshooting

"Cannot connect to backend"

Solution:

  1. Check backend is running: http://localhost:8000/docs
  2. Verify proxy setting in package.json: "proxy": "http://localhost:8000"

"File upload failed"

Reasons:

  • File too large (>10MB)
  • Unsupported file type
  • Backend not running

Solution: Check backend logs and file constraints

"npm install fails"

Solution:

# Clear npm cache
npm cache clean --force

# Delete node_modules and reinstall
rm -rf node_modules package-lock.json
npm install

Port 3000 already in use

Solution:

# Use different port
set PORT=3001 && npm start

# Or kill existing process
npx kill-port 3000

Development Tips

Hot Reload

Changes to React components automatically reload in browser

React DevTools

Install React Developer Tools for debugging

API Testing

Use the browser's Network tab to inspect API calls

Architecture

Frontend (React)
β”œβ”€β”€ public/
β”‚   └── index.html          # HTML template
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ App.js              # Main chat component
β”‚   β”œβ”€β”€ App.css             # Styling
β”‚   β”œβ”€β”€ index.js            # Entry point
β”‚   └── index.css           # Global styles
β”œβ”€β”€ package.json            # Dependencies
└── README.md               # Documentation

Next Steps

  1. Start both services:

    • Backend: uv run uvicorn main:app --reload
    • Frontend: cd frontend && npm start
  2. Test the interface:

    • Try weather queries
    • Upload a document
    • Schedule a meeting
    • Query the database
  3. Customize:

    • Change colors in CSS
    • Add new features
    • Deploy to production

Enjoy your beautiful AI chat interface! πŸš€