Righting Sentences - React Frontend Migration
Appearance
Purpose
Replace the single-file ui.html with a React application for better state management, markdown rendering, file uploads, and maintainability.
Current Backend Status (Complete)
- FastAPI app running on port 8080
- 4 models working:
gpt-4o,gpt-5.2-pro,claude-sonnet-4-5-20250929,gemini-3-flash-preview - Honeypot logging to GCS
- Google OAuth authentication
- Firestore for conversations/messages
React Frontend Requirements
Core Features
- Chat Interface
- Message input with send button
- Streaming responses displayed in real-time
- User messages on right, assistant on left
- Markdown Rendering
*→ bullets,#→ headings, code blocks, and so forth- Use
react-markdownwithremark-gfm
- Output
- Copy button on each assistant message
- Copy entire conversation option
- Model Selection
- Dropdown integrated with "New Chat" button
- Model locked once conversation has messages
- Show current model in header
- Conversation Management
- Sidebar with 10 most recent conversations
- Auto-generated titles from first message
- Delete button for each conversation
- Clear/New Chat button
- File Upload (Phase 2)
- Drag-and-drop or click to upload
- Support: PDF, TXT, DOCX, images
- Parse and include in message context
Technical Stack
frontend/ ├── package.json ├── vite.config.js ├── index.html ├── src/ │ ├── main.jsx │ ├── App.jsx │ ├── api.js # API calls to backend │ ├── components/ │ │ ├── ChatView.jsx # Main chat area │ │ ├── MessageBubble.jsx # Single message with markdown │ │ ├── MessageInput.jsx # Input + send button │ │ ├── Sidebar.jsx # Conversation list │ │ ├── ModelSelector.jsx # Model dropdown │ │ └── Header.jsx # Top bar with model info │ └── styles/ │ └── index.css # Tailwind or plain CSS
Dependencies:
react,react-domreact-markdown,remark-gfm(markdown)react-icons(copy icon, delete icon)- Vite for build
Development Phases
Phase 1: Basic Chat (Replace ui.html)
- Create Vite React project in
frontend/directory - Set API layer (
api.js) to match existing endpoints - Build components: Sidebar, ChatView, MessageBubble, MessageInput
- Add markdown rendering
- Add copy button
- Style with system-aware theming (respects OS light/dark mode via
prefers-color-scheme)
Phase 2: Model & Conversation Improvements
- ModelSelector integrated with New Chat
- Lock model dropdown when conversation has messages
- Delete conversation button
- Auto-title generation (already works on backend)
Phase 3: File Upload
- File upload feature with drag and drop
- Backend endpoint for file parsing
- Parsed content included in message context
Backend Updates
- CORS configuration
For File Upload (Phase 3)
<syntaxhighlight lang="python">
- New endpoint in messaging.py
@router.post("/upload") async def upload_file(file: UploadFile):
# Parse PDF, DOCX, TXT, images (OCR) # Return extracted text
</syntaxhighlight>
Files to Create/Modify
| Action | Path |
|---|---|
| CREATE | frontend/, the entire React app
|
| MODIFY | app/main.py to include the React app endpoints
|
| DELETE | app/ui.html after React is working
|
| MODIFY | app/api_routes/messaging.py - add file upload endpoint (Phase 3)
|
Development Workflow
- Run backend:
uvicorn app.main:app --reload --port 8080 - Run frontend dev:
cd frontend && npm run dev(port 5173) - Vite proxies API calls to backend
- For production:
npm run build→ serve from FastAPI
Next Steps
- Create React project structure
- Add API layer
- Build core components
- Test with backend
- Deploy to Cloud Run