How deepanshu1531/friday-ai works
Project Type and Purpose
• The “Friday AI” project is a full-stack web application built on Next.js that serves as a 3D-avatar chat assistant.
• It offers user authentication (JWT), chat sessions saved in MongoDB, AI model integration (via Ollama, Huggingface, etc.), and voice bi-directional interaction using the Web Speech API.
High-Level Architecture
• Client (Browser)
• Next.js React app under src/app & src/components
• Three.js + @react-three/fiber for 3D avatar rendering
• Tailwind CSS + Framer Motion for UI/UX
• Web Speech API for speech-to-text and text-to-speech
• Server (Next.js API Routes)
• Located in src/pages/api
• Routes: /auth/login, /auth/register, /chat, /chat-history, /health-check
• Middleware for JWT auth (src/middleware/authMiddleware.ts)
• Service Layer
• Business logic in src/services (AuthService, ChatService, OllamaService, UtilsService)
• Data Layer
• MongoDB accessed via Mongoose models in src/models (User, ChatSession, FridayModel)
• DB connection abstraction in src/lib/dbConnect.ts
• External AI Providers
• Ollama (local or remote LLM inference)
• Potential endpoints for Huggingface or Replicate
Key Architectural Patterns
• Layered Architecture:
• Presentation Layer (React UI + Avatar + Voice)
• API Layer (Next.js serverless routes + middleware)
• Business Logic Layer (Services)
• Data Access Layer (Mongoose models)
• Separation of Concerns: Each folder (components, services, models, lib, middleware) has a distinct responsibility.
• Serverless / Function-as-a-Service: API routes deploy as isolated endpoints.
a. Main Components
• Browser Client
• Next.js Frontend (UI + 3D Avatar + Voice)
• Next.js API Routes (Auth, Chat, History, Health)
• Service Layer (AuthService, ChatService, OllamaService)
• MongoDB Database
• External AI Engines (Ollama, optional Huggingface)
b. Data Flows & Relationships
1. User loads Next.js app → UI + Avatar render
2. User speaks/types → Web Speech API → Frontend → POST /api/chat
3. /api/chat → ChatService → OllamaService (or other AI) → AI response
4. ChatService saves session via ChatSession model → MongoDB
5. Frontend polls or GET /api/chat-history to load past sessions
6. /api/auth routes manage JWT issuance and verification via authMiddleware
c. Architectural Highlights
• Stateless API endpoints with JWT for auth
• 3D rendering decoupled from chat logic
• Services abstract external API calls and business rules
d. Key Technologies
• Next.js (SSR/SSG + API Routes)
• React + Three.js (@react-three/fiber)
• MongoDB + Mongoose
• JWT for auth
• Web Speech API for TTS/STT