# DreamChat Frontend Guide ## Overview This document outlines the frontend architecture, component structure, and development guidelines for the DreamChat React application. ## Tech Stack | Category | Technology | Purpose | |----------|------------|---------| | Framework | React 18+ | UI library | | Build Tool | Vite | Fast development and building | | Language | TypeScript | Type safety | | Styling | Tailwind CSS | Utility-first CSS | | State Management | Zustand | Global state | | Server State | TanStack Query | API data caching | | Routing | React Router v6 | Navigation | | WebSocket | Socket.io-client | Real-time communication | | Shared Types | `@dreamchat/shared` | Monorepo shared package | | API Client | OpenAPI Generator | Auto-generated API client | | Forms | React Hook Form + Zod | Form handling and validation | | UI Components | Radix UI + shadcn/ui | Accessible primitives | | Icons | Lucide React | Icon library | | Testing | Vitest + React Testing Library | Unit/component tests | ## Project Structure ``` apps/frontend/ ├── src/ │ ├── api/ │ │ ├── generated/ # Auto-generated from OpenAPI │ │ │ ├── models/ # DTO types │ │ │ └── apis/ # API client classes │ │ └── client.ts # Axios/fetch configuration │ │ │ ├── websocket/ │ │ ├── socket.ts # Socket.io client setup │ │ └── hooks.ts # WebSocket hooks (uses @dreamchat/shared) │ │ │ ├── components/ │ │ ├── ui/ # Reusable UI components │ │ │ ├── button.tsx │ │ │ ├── input.tsx │ │ │ ├── card.tsx │ │ │ ├── dialog.tsx │ │ │ └── ... │ │ ├── layout/ │ │ │ ├── sidebar.tsx │ │ │ ├── header.tsx │ │ │ └── main-layout.tsx │ │ ├── character/ │ │ │ ├── character-card.tsx │ │ │ ├── character-form.tsx │ │ │ ├── attribute-editor.tsx │ │ │ └── personality-editor.tsx │ │ ├── chat/ │ │ │ ├── chat-container.tsx │ │ │ ├── message-list.tsx │ │ │ ├── message-bubble.tsx │ │ │ ├── chat-input.tsx │ │ │ └── typing-indicator.tsx │ │ └── import/ │ │ ├── file-dropzone.tsx │ │ ├── url-input.tsx │ │ └── import-progress.tsx │ │ │ ├── pages/ │ │ ├── login-page.tsx │ │ ├── register-page.tsx │ │ ├── character-list-page.tsx │ │ ├── character-detail-page.tsx │ │ ├── chat-page.tsx │ │ ├── story-page.tsx │ │ └── import-page.tsx │ │ │ ├── hooks/ │ │ ├── use-auth.ts │ │ ├── use-chat.ts │ │ ├── use-characters.ts │ │ └── use-import.ts │ │ │ ├── stores/ │ │ ├── auth-store.ts │ │ ├── chat-store.ts │ │ └── ui-store.ts │ │ │ ├── lib/ │ │ ├── utils.ts # Utility functions │ │ └── constants.ts # App constants │ │ │ ├── types/ │ │ └── index.ts # App-specific types │ │ │ ├── styles/ │ │ └── globals.css │ │ │ ├── main.tsx │ └── App.tsx │ ├── public/ │ └── assets/ │ ├── index.html ├── vite.config.ts ├── tailwind.config.ts ├── tsconfig.json └── package.json ``` ## Component Architecture ### UI Components (shadcn/ui pattern) Base components built on Radix UI primitives: ```typescript // components/ui/button.tsx import * as React from "react"; import { cva, type VariantProps } from "class-variance-authority"; import { cn } from "@/lib/utils"; const buttonVariants = cva( "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors", { variants: { variant: { default: "bg-primary text-primary-foreground hover:bg-primary/90", destructive: "bg-destructive text-destructive-foreground", outline: "border border-input bg-background hover:bg-accent", secondary: "bg-secondary text-secondary-foreground", ghost: "hover:bg-accent hover:text-accent-foreground", link: "underline-offset-4 hover:underline text-primary", }, size: { default: "h-10 px-4 py-2", sm: "h-9 rounded-md px-3", lg: "h-11 rounded-md px-8", icon: "h-10 w-10", }, }, defaultVariants: { variant: "default", size: "default", }, } ); export interface ButtonProps extends React.ButtonHTMLAttributes, VariantProps {} const Button = React.forwardRef( ({ className, variant, size, ...props }, ref) => { return (