How abrar-husain-870/sahayak-ai works
Project Type and Purpose
• Sahayak-AI is a full-stack Next.js (v13+) application that serves as an AI-powered teaching assistant.
• It delivers a React-based dashboard UI, runs serverless API routes for auth, registration, history, and orchestrates AI flows (via OpenAI) to generate lesson content, visual aids, differentiated materials, etc.
File Structure Analysis
• src/app: Next.js “app” directory containing server-rendered and client components, layouts, and pages (dashboard, login, register).
• src/components: Shared UI primitives (buttons, cards, dialogs) and feature-specific result viewers.
• src/app/api: Next.js serverless routes for authentication (NextAuth), user registration, and history retrieval/storage.
• src/ai: Core AI orchestration module (genkit.ts) and individual flow definitions (e.g., week-plan, visual aids) that call out to OpenAI.
• src/lib: Firebase configuration (likely Firestore as the data store), utility functions, constants.
• Configuration: next.config.ts, tailwind.config.ts, postcss.config.mjs, apphosting.yaml (deployment), dev.nix (.idx/dev.nix)
• Middleware: src/middleware.ts for auth checks or routing guards.
Key Components
a. Client (Browser)
• React components under src/app and src/components.
• UI state managed via hooks (use-mobile, use-toast), theme/provider wrappers, global CSS.
b. Next.js Server
• Route handlers (server-rendered pages) and API endpoints (src/app/api).
• Middleware for auth gating.
c. Authentication Layer
• NextAuth engine ([...nextauth] route), sessions, OAuth providers.
• Firebase integration (src/lib/firebase.ts) for persisting user profiles or session data.
d. AI Engine
• AI genkit (src/ai/genkit.ts) orchestrates calls to OpenAI API.
• Per-flow modules under src/ai/flows define prompts and response parsing.
e. Data Layer
• Firestore (Firebase) storing: user data, history of generated content.
f. External Services
• OpenAI API for content generation.
• Firebase Auth/Firestore as managed services.
• Hosting provider (Vercel/GCP via apphosting.yaml).
Relationships & Interactions
• User → Frontend UI: HTTP(S) GET/POST for SSR or client navigation.
• UI → API Route (e.g., /api/history): fetch or mutate history records.
• UI → AI Endpoint (internal server function): triggers genkit → OpenAI → returns generated content.
• API Route (NextAuth) ↔ Firebase Auth: validate credentials, issue session.
• Data Persistance: successful AI runs or user actions → Firestore.
Architectural Patterns
• Serverless functions (API routes) for backend logic.
• Separation of concerns: UI layer vs. AI orchestration vs. data persistence.
• Component-driven design (reusable UI primitives).
• Middleware for cross-cutting concerns (auth).
• Flows-as-plugins: each AI feature is a distinct module implementing a common interface.