2:I[7012,["4765","static/chunks/4765-f5afdf8061f456f3.js","9856","static/chunks/9856-3b185291364d9bef.js","6687","static/chunks/app/docs/%5B...slug%5D/page-e07536548216bee4.js"],"MarkdownRenderer"] 4:I[9856,["4765","static/chunks/4765-f5afdf8061f456f3.js","9856","static/chunks/9856-3b185291364d9bef.js","6687","static/chunks/app/docs/%5B...slug%5D/page-e07536548216bee4.js"],""] 5:I[4126,[],""] 7:I[9630,[],""] 8:I[4278,["9856","static/chunks/9856-3b185291364d9bef.js","8172","static/chunks/8172-b3a2d6fe4ae10d40.js","3185","static/chunks/app/layout-2814fa5d15b84fe4.js"],"HeadingProvider"] 9:I[1476,["9856","static/chunks/9856-3b185291364d9bef.js","8172","static/chunks/8172-b3a2d6fe4ae10d40.js","3185","static/chunks/app/layout-2814fa5d15b84fe4.js"],"Header"] a:I[3167,["9856","static/chunks/9856-3b185291364d9bef.js","8172","static/chunks/8172-b3a2d6fe4ae10d40.js","3185","static/chunks/app/layout-2814fa5d15b84fe4.js"],"Sidebar"] b:I[7409,["9856","static/chunks/9856-3b185291364d9bef.js","8172","static/chunks/8172-b3a2d6fe4ae10d40.js","3185","static/chunks/app/layout-2814fa5d15b84fe4.js"],"PageFrame"] 3:T7aec, # VoiceAssist Client Applications - Technical Architecture **Version:** 1.0 **Date:** 2025-11-21 **Status:** Draft - Awaiting Team Review --- ## πŸ“‹ Table of Contents 1. [Architecture Overview](#architecture-overview) 2. [Monorepo Structure](#monorepo-structure) 3. [Shared Packages](#shared-packages) 4. [State Management](#state-management) 5. [API Communication](#api-communication) 6. [Real-time Communication](#real-time-communication) 7. [Authentication & Authorization](#authentication--authorization) 8. [Routing & Navigation](#routing--navigation) 9. [Performance Optimization](#performance-optimization) 10. [Security Architecture](#security-architecture) 11. [Testing Architecture](#testing-architecture) 12. [Build & Deployment](#build--deployment) --- ## 1. Architecture Overview ### High-Level Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ User Devices β”‚ β”‚ (Desktop, Tablet, Mobile - Chrome, Firefox, Safari, Edge) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ CDN / Edge Cache β”‚ β”‚ (CloudFlare / AWS CloudFront) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Web App β”‚ β”‚ Admin β”‚ β”‚ Docs β”‚ β”‚ (SPA) β”‚ β”‚ Panel β”‚ β”‚ Site β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Load Balancer / β”‚ β”‚ API Gateway β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ HTTP β”‚ β”‚WebSocket β”‚ β”‚ Auth β”‚ β”‚ REST API β”‚ β”‚ Server β”‚ β”‚ Service β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚PostgreSQLβ”‚ β”‚ Redis β”‚ β”‚ Qdrant β”‚ β”‚ (pgvector)β”‚ β”‚ Cache β”‚ β”‚ Vector β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Design Principles 1. **Monorepo First** - Single repository for all client applications 2. **Shared Core** - Maximum code reuse through shared packages 3. **Type Safety** - End-to-end TypeScript with strict mode 4. **Performance** - Code splitting, lazy loading, optimized bundles 5. **Accessibility** - WCAG 2.1 AA compliance across all apps 6. **Security** - Defense in depth, secure by default 7. **Testability** - High test coverage with automated testing 8. **Maintainability** - Clean code, clear patterns, good documentation --- ## 2. Monorepo Structure ### Directory Layout ``` VoiceAssist/ β”œβ”€β”€ apps/ β”‚ β”œβ”€β”€ web-app/ # Main user-facing application β”‚ β”‚ β”œβ”€β”€ public/ # Static assets β”‚ β”‚ β”œβ”€β”€ src/ β”‚ β”‚ β”‚ β”œβ”€β”€ components/ # React components β”‚ β”‚ β”‚ β”œβ”€β”€ pages/ # Page components β”‚ β”‚ β”‚ β”œβ”€β”€ hooks/ # Custom hooks β”‚ β”‚ β”‚ β”œβ”€β”€ stores/ # Zustand stores β”‚ β”‚ β”‚ β”œβ”€β”€ utils/ # App-specific utilities β”‚ β”‚ β”‚ β”œβ”€β”€ types/ # App-specific types β”‚ β”‚ β”‚ β”œβ”€β”€ App.tsx # Root component β”‚ β”‚ β”‚ └── main.tsx # Entry point β”‚ β”‚ β”œβ”€β”€ index.html β”‚ β”‚ β”œβ”€β”€ package.json β”‚ β”‚ β”œβ”€β”€ tsconfig.json β”‚ β”‚ β”œβ”€β”€ vite.config.ts β”‚ β”‚ └── tailwind.config.js β”‚ β”‚ β”‚ β”œβ”€β”€ admin-panel/ # Admin/management application β”‚ β”‚ β”œβ”€β”€ public/ β”‚ β”‚ β”œβ”€β”€ src/ β”‚ β”‚ β”‚ β”œβ”€β”€ components/ β”‚ β”‚ β”‚ β”œβ”€β”€ pages/ β”‚ β”‚ β”‚ β”œβ”€β”€ hooks/ β”‚ β”‚ β”‚ β”œβ”€β”€ stores/ β”‚ β”‚ β”‚ β”œβ”€β”€ utils/ β”‚ β”‚ β”‚ β”œβ”€β”€ types/ β”‚ β”‚ β”‚ β”œβ”€β”€ App.tsx β”‚ β”‚ β”‚ └── main.tsx β”‚ β”‚ β”œβ”€β”€ index.html β”‚ β”‚ β”œβ”€β”€ package.json β”‚ β”‚ β”œβ”€β”€ tsconfig.json β”‚ β”‚ β”œβ”€β”€ vite.config.ts β”‚ β”‚ └── tailwind.config.js β”‚ β”‚ β”‚ └── docs-site/ # Documentation site β”‚ β”œβ”€β”€ app/ # Next.js app directory β”‚ β”œβ”€β”€ content/ # MDX content β”‚ β”œβ”€β”€ components/ β”‚ β”œβ”€β”€ public/ β”‚ β”œβ”€β”€ package.json β”‚ β”œβ”€β”€ tsconfig.json β”‚ β”œβ”€β”€ next.config.js β”‚ └── tailwind.config.js β”‚ β”œβ”€β”€ packages/ β”‚ β”œβ”€β”€ ui/ # Shared UI component library β”‚ β”‚ β”œβ”€β”€ src/ β”‚ β”‚ β”‚ β”œβ”€β”€ components/ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ Button/ β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ Button.tsx β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ Button.test.tsx β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ Button.stories.tsx β”‚ β”‚ β”‚ β”‚ β”‚ └── index.ts β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ Input/ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ Card/ β”‚ β”‚ β”‚ β”‚ └── ... β”‚ β”‚ β”‚ β”œβ”€β”€ hooks/ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ useMediaQuery.ts β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ useDebounce.ts β”‚ β”‚ β”‚ β”‚ └── ... β”‚ β”‚ β”‚ └── index.ts β”‚ β”‚ β”œβ”€β”€ package.json β”‚ β”‚ └── tsconfig.json β”‚ β”‚ β”‚ β”œβ”€β”€ types/ # Shared TypeScript types β”‚ β”‚ β”œβ”€β”€ src/ β”‚ β”‚ β”‚ β”œβ”€β”€ api/ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ auth.ts β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ chat.ts β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ admin.ts β”‚ β”‚ β”‚ β”‚ └── ... β”‚ β”‚ β”‚ β”œβ”€β”€ models/ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ user.ts β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ message.ts β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ conversation.ts β”‚ β”‚ β”‚ β”‚ └── ... β”‚ β”‚ β”‚ β”œβ”€β”€ events/ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ websocket.ts β”‚ β”‚ β”‚ β”‚ └── ... β”‚ β”‚ β”‚ └── index.ts β”‚ β”‚ β”œβ”€β”€ package.json β”‚ β”‚ └── tsconfig.json β”‚ β”‚ β”‚ β”œβ”€β”€ api-client/ # Shared API client β”‚ β”‚ β”œβ”€β”€ src/ β”‚ β”‚ β”‚ β”œβ”€β”€ client.ts # Axios instance β”‚ β”‚ β”‚ β”œβ”€β”€ auth.ts # Auth endpoints β”‚ β”‚ β”‚ β”œβ”€β”€ chat.ts # Chat endpoints β”‚ β”‚ β”‚ β”œβ”€β”€ admin.ts # Admin endpoints β”‚ β”‚ β”‚ β”œβ”€β”€ websocket.ts # WebSocket manager β”‚ β”‚ β”‚ └── index.ts β”‚ β”‚ β”œβ”€β”€ package.json β”‚ β”‚ └── tsconfig.json β”‚ β”‚ β”‚ β”œβ”€β”€ utils/ # Shared utilities β”‚ β”‚ β”œβ”€β”€ src/ β”‚ β”‚ β”‚ β”œβ”€β”€ formatting/ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ date.ts β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ currency.ts β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ number.ts β”‚ β”‚ β”‚ β”‚ └── ... β”‚ β”‚ β”‚ β”œβ”€β”€ validation/ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ schemas.ts # Zod schemas β”‚ β”‚ β”‚ β”‚ └── ... β”‚ β”‚ β”‚ β”œβ”€β”€ constants/ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ specialties.ts β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ countries.ts β”‚ β”‚ β”‚ β”‚ └── ... β”‚ β”‚ β”‚ └── index.ts β”‚ β”‚ β”œβ”€β”€ package.json β”‚ β”‚ └── tsconfig.json β”‚ β”‚ β”‚ └── config/ # Shared configurations β”‚ β”œβ”€β”€ eslint/ β”‚ β”‚ └── index.js β”‚ β”œβ”€β”€ typescript/ β”‚ β”‚ β”œβ”€β”€ base.json β”‚ β”‚ β”œβ”€β”€ react.json β”‚ β”‚ └── nextjs.json β”‚ └── tailwind/ β”‚ └── base.js β”‚ β”œβ”€β”€ server/ # Backend (existing) β”‚ β”œβ”€β”€ docs/ # Project documentation β”‚ └── client-implementation/ β”‚ β”œβ”€β”€ .github/ β”‚ └── workflows/ β”‚ β”œβ”€β”€ ci.yml β”‚ β”œβ”€β”€ deploy-web-app.yml β”‚ β”œβ”€β”€ deploy-admin.yml β”‚ └── deploy-docs.yml β”‚ β”œβ”€β”€ pnpm-workspace.yaml β”œβ”€β”€ turbo.json β”œβ”€β”€ package.json └── README.md ``` ### Package Manager: pnpm with Workspaces **Why pnpm?** - Faster than npm/yarn (symlinked node_modules) - Disk space efficient (global store) - Strict dependency resolution - Built-in monorepo support **Configuration:** ```yaml # pnpm-workspace.yaml packages: - "apps/*" - "packages/*" ``` ```json // package.json (root) { "name": "voiceassist-monorepo", "private": true, "scripts": { "dev": "turbo run dev", "build": "turbo run build", "test": "turbo run test", "lint": "turbo run lint", "type-check": "turbo run type-check", "clean": "turbo run clean && rm -rf node_modules" }, "devDependencies": { "turbo": "^1.11.0", "typescript": "^5.3.0" }, "engines": { "node": ">=18.0.0", "pnpm": ">=8.0.0" } } ``` ### Build Orchestration: Turborepo **Why Turborepo?** - Intelligent task caching - Parallel execution - Remote caching support - Dependency-aware scheduling **Configuration:** ```json // turbo.json { "$schema": "https://turbo.build/schema.json", "globalDependencies": [".env", "tsconfig.json"], "pipeline": { "build": { "dependsOn": ["^build"], "outputs": ["dist/**", ".next/**", "out/**"] }, "dev": { "cache": false, "persistent": true }, "test": { "dependsOn": ["build"], "outputs": ["coverage/**"] }, "lint": { "outputs": [] }, "type-check": { "dependsOn": ["^build"], "outputs": [] }, "clean": { "cache": false } } } ``` --- ## 3. Shared Packages ### 3.1 UI Component Library (@voiceassist/ui) **Purpose:** Shared, reusable UI components across all applications **Key Components:** ```tsx // packages/ui/src/components/Button/Button.tsx import { forwardRef } from "react"; import { cva, type VariantProps } from "class-variance-authority"; import { cn } from "../../utils/cn"; const buttonVariants = cva( "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none", { variants: { variant: { primary: "bg-blue-600 text-white hover:bg-blue-700 focus-visible:ring-blue-600", secondary: "bg-gray-200 text-gray-900 hover:bg-gray-300 focus-visible:ring-gray-500", outline: "border border-gray-300 bg-transparent hover:bg-gray-100 focus-visible:ring-gray-500", ghost: "hover:bg-gray-100 hover:text-gray-900", danger: "bg-red-600 text-white hover:bg-red-700 focus-visible:ring-red-600", }, size: { sm: "h-9 px-3", md: "h-10 px-4", lg: "h-11 px-8", icon: "h-10 w-10", }, }, defaultVariants: { variant: "primary", size: "md", }, }, ); export interface ButtonProps extends React.ButtonHTMLAttributes, VariantProps { asChild?: boolean; } export const Button = forwardRef( ({ className, variant, size, asChild = false, ...props }, ref) => { return