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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# 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`:

```typescript
const API_BASE_URL = process.env.REACT_APP_API_URL || "http://localhost:3000";
```

**For Hugging Face Spaces:**

```bash
export REACT_APP_API_URL=https://YOUR_SPACE_URL
```

### Environment Variables

Create a `.env.local` file:

```env
# 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

```bash
cd client
pnpm install
```

### Start Development Server

```bash
pnpm run dev
```

The app will be available at `http://localhost:5173`

### Build for Production

```bash
pnpm run build
```

Output will be in `dist/` directory.

### Type Checking

```bash
pnpm run check
```

---

## Component Architecture

### Chat.tsx (Main Component)

**State Management:**
- `mode` - Current mode (ask/imagine)
- `messages` - Chat message history
- `input` - Current input text
- `isLoading` - Loading state
- `enableSearch` - Search online toggle
- `enableThinking` - Think longer toggle
- `showReasoning` - Reasoning panel visibility
- `uploadedFiles` - Uploaded files
- `generatedImages` - Generated images in Imagine mode

**Key Functions:**
- `handleSendMessage()` - Send chat message to backend
- `handleGenerateImage()` - Generate image via Imagine mode
- `handleFileUpload()` - Handle file uploads
- `removeFile()` - Remove uploaded file

**API Calls:**
- `POST /api/trpc/chat.send` - Send message
- `POST /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 animation
- `animate-slide-up` - Slide up animation
- `animate-pulse-glow` - Pulsing glow effect

---

## Integration with Backend

### tRPC Procedures

The frontend calls these backend procedures:

**Chat:**
```typescript
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:**
```typescript
POST /api/trpc/imagine.generate
{
  prompt: string;
}

Response:
{
  imageUrl: string;
  prompt: string;
}
```

**Search:**
```typescript
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:

```typescript
// 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:

1. Install Tesseract.js: `pnpm add tesseract.js`
2. Add OCR handler in Chat.tsx
3. Send extracted text with message

---

## Customization

### Change Colors

Edit `client/src/index.css` in the `.dark` section:

```css
.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`:

```html
<link href="https://fonts.googleapis.com/css2?family=YOUR_FONT&display=swap" rel="stylesheet">
```

Then update `client/src/index.css`:

```css
body {
  font-family: 'YOUR_FONT', sans-serif;
}
```

### Add New Pages

1. Create component in `client/src/pages/NewPage.tsx`
2. Add route in `client/src/App.tsx`:

```typescript
<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:**
1. Verify `REACT_APP_API_URL` is correct
2. Check backend is running
3. Verify CORS is enabled on backend
4. Check browser console for network errors

### Styling Issues

**Error**: "Colors look wrong" or "Layout is broken"

**Solution:**
1. Clear browser cache
2. Rebuild CSS: `pnpm run build`
3. Check theme is set to "dark" in App.tsx
4. Verify index.css is imported in main.tsx

### Image Upload Not Working

**Error**: "File upload fails"

**Solution:**
1. Check file size (should be <10MB)
2. Verify file format is supported
3. Check browser console for errors
4. Ensure backend file upload endpoint is working

### Slow Performance

**Error**: "App feels sluggish"

**Solution:**
1. Check network tab for slow API calls
2. Reduce chat history size (archive old messages)
3. Optimize images before upload
4. Check for memory leaks in browser DevTools

---

## Deployment

### Build for Production

```bash
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

```bash
# Build
pnpm run build

# Deploy dist/ folder
```

---

## Next Steps

1. **Update API endpoint** with your Hugging Face Space URL
2. **Test Ask mode** - Send messages and verify responses
3. **Test Imagine mode** - Generate images
4. **Test features** - Search online, Think longer, file upload
5. **Customize colors** - Match your brand
6. **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.css` and Tailwind documentation
- **Component issues**: Check React DevTools

---

## License

MIT License - See LICENSE file for details