How ramadan-elgamal/codespark works
Project Type and Purpose
• Full-stack web application built with Next.js (App Router) and TypeScript.
• Purpose: Let users input a topic/phase, invoke AI (Google AI via Genkit) to generate and display a programming course, and persist/share the result client-side.
File Structure
• src/app/… : Next.js application routes and layouts (login, signup, dashboard, share, pricing, etc.).
• src/ai/… : AI orchestration code (Genkit config + generate-course flow).
• src/components/… : Reusable UI (Radix UI + Tailwind CSS) and dashboard/landing components.
• src/lib/utils.ts & src/hooks/… : Utility functions and custom React hooks (mobile detection, toasts).
• Config: next.config.ts, tailwind.config.ts, apphosting.yaml for static hosting.
README for Additional Insights
• No backend database—persistence uses browser localStorage.
• AI calls via Genkit to Google AI; fallbacks use mock generator.
• UI uses React Hook Form + Zod for validation; theme switcher via Context.
Main Components & Their Relationships
a. Frontend (Browser)
• Next.js React pages & layouts
• Components (UI primitives, forms, dashboard, share page)
• React Hook Form + Zod for input
• LocalStorage for persistence & activity logs
b. Server-Side Logic (Next.js server actions)
• actions.ts: Exposes server actions to client
• src/ai/flows/generate-course.ts: Orchestrates AI prompt, handles fallback
c. AI Integration
• Genkit (src/ai/genkit.ts): Configures connection to Google AI LLM APIs
• Google AI service (external)
d. Fallback System
• Mock generation logic inside generate-course.ts if external AI fails
e. Static Hosting & Shareable URLs
• App deployed on Netlify (apphosting.yaml)
• “Share” route encodes course data in URL for read-only access
Data Flow & Interactions
1. User fills form on client → validated by React Hook Form/Zod.
2. Client calls a Next.js server action (actions.ts) → invoke generate-course flow.
3. generate-course → calls Genkit → Google AI → returns structured course JSON.
4. If AI errors → fallback mock generator.
5. Server action returns course JSON to client.
6. Client stores JSON in localStorage → updates dashboard UI.
7. On “Share,” serializes JSON into URL → shareable page deserializes and renders.
Architectural Patterns & Design Principles
• Separation of concerns:
• Presentation layer in src/app & src/components/ui
• Business logic in src/ai & server actions
• Persistence in localStorage (client-side data store)
• Componentization: Reusable UI primitives (Radix + Tailwind)
• Schema-driven design: Zod for input/output validation
• Resilience: Fallback logic for AI unavailability
• Static hosting: No dedicated backend server or database