Spaces:
Build error
Domify Academy Super Bot - Frontend Setup Guide
Overview
The frontend is built with React 19 + TypeScript + Tailwind CSS 4 with a dark glassmorphism design (21dev theme). It features:
- Ask | Imagine mode switcher at the top (Grok-style)
- Advanced prompt input with Search Online and Think Longer toggles
- DeepSeek reasoning panel (collapsible with ^ icon)
- Rich response formatting with markdown, code highlighting, and tables
- File upload with OCR (Tesseract.js)
- Image gallery for Imagine mode with download and video conversion options
- Auto-scroll chat with smooth animations
- Dark glassmorphism UI with violet/indigo glows
Project Structure
client/
βββ src/
β βββ pages/
β β βββ Chat.tsx # Main chat interface (Ask/Imagine modes)
β β βββ Home.tsx # Landing page
β β βββ NotFound.tsx # 404 page
β βββ components/ # Reusable UI components
β βββ contexts/ # React contexts
β βββ lib/
β β βββ trpc.ts # tRPC client configuration
β βββ App.tsx # Routes and layout
β βββ main.tsx # React entry point
β βββ index.css # Global styles (glassmorphism theme)
βββ public/ # Static assets
βββ index.html # HTML template
Key Features
1. Ask Mode
Text-based conversation with AI:
- Send messages with optional search online
- Enable "Think Longer" for DeepSeek-style reasoning
- Upload files and images for context
- View reasoning process in collapsible panel
- Rich markdown rendering with syntax highlighting
Input Features:
- Auto-resizing textarea
- File upload with drag-and-drop support
- Toggle buttons for Search and Think modes
- Keyboard shortcuts (Shift+Enter for new line, Enter to send)
2. Imagine Mode
Image generation interface:
- Describe images you want to create
- View previously generated images in horizontal scrolling gallery
- Download generated images
- Optional: Convert images to videos (coming soon)
3. Dark Glassmorphism Theme
21dev Design System:
- Deep black background (
oklch(0.07 0.002 0)) - Violet primary color (
oklch(0.623 0.214 259.815)) - Indigo secondary color (
oklch(0.55 0.15 264)) - Glass panels with backdrop blur and transparency
- Smooth animations and transitions
- Glow effects on interactive elements
4. Reasoning Panel
DeepSeek-style internal thoughts:
- Collapsible panel showing bot's reasoning process
- Triggered when "Think Longer" is enabled
- Animated expansion/collapse with ^ icon
- Styled with glass effect and subtle colors
5. Rich Response Formatting
Professional output rendering:
- Bold text for key concepts (auto-highlighted)
- Code blocks with syntax highlighting and copy button
- Markdown tables for structured data
- Links with hover effects
- Blockquotes for citations
- Lists with proper indentation
Configuration
API Endpoint
Update the API endpoint in client/src/pages/Chat.tsx:
const API_BASE_URL = process.env.REACT_APP_API_URL || "http://localhost:3000";
For Hugging Face Spaces:
export REACT_APP_API_URL=https://YOUR_SPACE_URL
Environment Variables
Create a .env.local file:
# API Configuration
REACT_APP_API_URL=https://your-hugging-face-space-url
# Optional: Analytics
REACT_APP_ANALYTICS_ID=your-analytics-id
# Optional: Feature flags
REACT_APP_ENABLE_VIDEO_GENERATION=false
Installation & Development
Install Dependencies
cd client
pnpm install
Start Development Server
pnpm run dev
The app will be available at http://localhost:5173
Build for Production
pnpm run build
Output will be in dist/ directory.
Type Checking
pnpm run check
Component Architecture
Chat.tsx (Main Component)
State Management:
mode- Current mode (ask/imagine)messages- Chat message historyinput- Current input textisLoading- Loading stateenableSearch- Search online toggleenableThinking- Think longer toggleshowReasoning- Reasoning panel visibilityuploadedFiles- Uploaded filesgeneratedImages- Generated images in Imagine mode
Key Functions:
handleSendMessage()- Send chat message to backendhandleGenerateImage()- Generate image via Imagine modehandleFileUpload()- Handle file uploadsremoveFile()- Remove uploaded file
API Calls:
POST /api/trpc/chat.send- Send messagePOST /api/trpc/imagine.generate- Generate image
Styling
CSS Classes (from index.css):
.glass-panel- Glass effect container.glass-panel-lg- Larger glass panel.glow-primary- Primary color glow.glow-accent- Accent color glow.gradient-text- Gradient text effect.transition-smooth- Smooth transitions.btn-primary- Primary button.btn-ghost- Ghost button.input-glass- Glass input field.code-block- Code block styling.markdown- Markdown rendering
Animations:
animate-fade-in- Fade in animationanimate-slide-up- Slide up animationanimate-pulse-glow- Pulsing glow effect
Integration with Backend
tRPC Procedures
The frontend calls these backend procedures:
Chat:
POST /api/trpc/chat.send
{
prompt: string;
enableSearch: boolean;
enableThinking: boolean;
history: Array<{ role: string; content: string }>;
}
Response:
{
response: string;
reasoning: string;
model: string;
tokensUsed: number;
}
Image Generation:
POST /api/trpc/imagine.generate
{
prompt: string;
}
Response:
{
imageUrl: string;
prompt: string;
}
Search:
POST /api/trpc/search.online
{
query: string;
maxResults: number;
}
Response:
{
results: Array<{
title: string;
url: string;
snippet: string;
}>;
}
File Upload & OCR
Supported Formats
- Images: JPG, PNG, GIF, WebP
- Documents: PDF, TXT, DOC, DOCX
OCR Implementation
Uses Tesseract.js for client-side text extraction:
// Example (not yet implemented in Chat.tsx)
import Tesseract from 'tesseract.js';
const result = await Tesseract.recognize(imageFile);
const extractedText = result.data.text;
To enable OCR:
- Install Tesseract.js:
pnpm add tesseract.js - Add OCR handler in Chat.tsx
- Send extracted text with message
Customization
Change Colors
Edit client/src/index.css in the .dark section:
.dark {
--primary: oklch(0.623 0.214 259.815); /* Violet */
--secondary: oklch(0.55 0.15 264); /* Indigo */
--accent: oklch(0.65 0.18 280); /* Light indigo */
--background: oklch(0.07 0.002 0); /* Deep black */
--foreground: oklch(0.95 0.002 0); /* Near white */
}
Change Fonts
Edit client/index.html:
<link href="https://fonts.googleapis.com/css2?family=YOUR_FONT&display=swap" rel="stylesheet">
Then update client/src/index.css:
body {
font-family: 'YOUR_FONT', sans-serif;
}
Add New Pages
- Create component in
client/src/pages/NewPage.tsx - Add route in
client/src/App.tsx:
<Route path={"/new-page"} component={NewPage} />
Performance Optimization
Code Splitting
Routes are automatically code-split by React Router.
Image Optimization
- Generated images are cached in browser
- Use lazy loading for image gallery
Caching
- tRPC client caches responses automatically
- Clear cache on logout or mode switch
Accessibility
- Keyboard navigation: Tab through buttons and inputs
- Focus rings: Visible focus indicators on all interactive elements
- Color contrast: WCAG AA compliant (dark theme)
- ARIA labels: Added to interactive elements
- Semantic HTML: Proper heading hierarchy
Browser Support
- Chrome/Edge 90+
- Firefox 88+
- Safari 14+
- Mobile browsers (iOS Safari, Chrome Mobile)
Troubleshooting
API Connection Failed
Error: "Failed to connect to backend"
Solution:
- Verify
REACT_APP_API_URLis correct - Check backend is running
- Verify CORS is enabled on backend
- Check browser console for network errors
Styling Issues
Error: "Colors look wrong" or "Layout is broken"
Solution:
- Clear browser cache
- Rebuild CSS:
pnpm run build - Check theme is set to "dark" in App.tsx
- Verify index.css is imported in main.tsx
Image Upload Not Working
Error: "File upload fails"
Solution:
- Check file size (should be <10MB)
- Verify file format is supported
- Check browser console for errors
- Ensure backend file upload endpoint is working
Slow Performance
Error: "App feels sluggish"
Solution:
- Check network tab for slow API calls
- Reduce chat history size (archive old messages)
- Optimize images before upload
- Check for memory leaks in browser DevTools
Deployment
Build for Production
pnpm run build
Deploy to Hugging Face Spaces
The frontend is included in the main Dockerfile. It's built as part of the Docker image build process.
Deploy to Vercel/Netlify
# Build
pnpm run build
# Deploy dist/ folder
Next Steps
- Update API endpoint with your Hugging Face Space URL
- Test Ask mode - Send messages and verify responses
- Test Imagine mode - Generate images
- Test features - Search online, Think longer, file upload
- Customize colors - Match your brand
- Deploy - Push to production
Support
- Frontend issues: Check browser console for errors
- API issues: Check backend logs in Hugging Face Space
- Styling issues: Review
index.cssand Tailwind documentation - Component issues: Check React DevTools
License
MIT License - See LICENSE file for details