How ayazsa/zerocode-fe-assignment works
Project Type and Purpose
• This is a full-stack, serverless web application (“AI Chatbot Interface”) built with Next.js (React + TypeScript) on the front end, Next.js API Routes on the back end, and Firebase Authentication as an external identity provider. It provides user authentication, an interactive chat UI, persistent chat history (via localStorage), and simple bot-reply logic in a serverless function.
Main Architectural Components
a. Client Browser
• Next.js pages and React components (ChatContainer, ChatInput, Header, Message, ConfirmModal)
• Global providers and hooks (AuthContext for user state, useTheme for UI theme)
• LocalStorage for storing/fetching chat history
b. Next.js Server (Serverless Runtime)
• API Routes under pages/api:
• chat.ts – receives user message, applies business logic (typing delay, conditional replies), returns bot response
• hello.ts – simple “hello” endpoint (often used for health checks or sample data)
• _app.tsx & _document.tsx – custom app wrapper, global CSS and meta tags
c. Firebase Authentication (External Service)
• Handled in lib/firebase.ts and lib/firebaseAuth.ts
• Provides sign-up, login, logout, current user verification
• Integrated into AuthContext for React-wide access
d. Styling and Static Assets
• Tailwind CSS config (tailwind.config.js, postcss.config.js) for design system
• Global and component-level CSS under styles/
Component Interactions & Data Flow
• On page load:
• Browser requests a Next.js page (index/login/register/dashboard) → Next.js server returns SSR/CSR HTML + JS.
• AuthContext initializes by checking Firebase Auth SDK for current user token.
• User logs in/registers:
• React form → Firebase Auth SDK (lib/firebaseAuth.ts) → Firebase backend → returns user tokens → stored in AuthContext.
• Chat interaction (dashboard):
• User types message in ChatInput → ChatContainer captures it → updates localStorage and UI.
• Front-end sends POST /api/chat with message and user token.
• Next.js API Route (chat.ts) verifies token via Firebase Admin (optional) → applies reply logic → returns JSON reply.
• Front-end appends bot reply to UI and localStorage.
• Auxiliary flows:
• Clear Chat → ConfirmModal triggers localStorage.clear() and UI reset.
• Export Chat → front-end serializes chat array → triggers browser download of .txt file.
• Theme Toggle → useTheme hook updates CSS variable or Tailwind class on <html>.
Architectural Patterns & Design Principles
• Separation of Concerns: UI (React components) vs. Business Logic (API routes) vs. Auth (Firebase SDK).
• Serverless Functions: stateless APIs under pages/api for chat logic, enabling horizontal scaling.
• Context & Hooks: centralized AuthContext and custom useTheme for cross-component state.
• Client-side Persistence: localStorage for chat history avoids a full database.
Final Advice
• Be thorough but focused: include all components listed above.
• Serverless nature of the API layer.
• Both UI state flow (chat history, theme) and backend flows (authentication, chat logic).