How kartikp36/gitagpt works
Project type and purpose
• This is a full-stack, React-based web application built with Next.js and TypeScript.
• It serves as an AI-powered chatbot (“Gita GPT”) that lets users converse with Lord Krishna, pulling in Bhagavad Gita content from Notion and generating responses via OpenAI’s ChatGPT.
• Key features: conversational UI, personalized Q&A, Notion-sourced content, user authentication via Supabase, and AI integration.
File structure
Top-level:
• pages/ – Next.js “pages” (route-based), including UI pages (index.tsx, about.tsx) and API routes (pages/api/generate.ts).
• components/ – React UI components (ChatBubble, ChatSection, Navbar, Header, Footer, Input & SuggestionBox, NotionPage viewer, SupaAuthModal).
• apiFunctions/ – shared front-end logic to invoke the generate endpoint.
• lib/ – server-side utility modules: config.ts (env & API keys), notion.ts (Notion API wrappers), preview-images.ts.
• utils/ – client utilities: request.tsx (HTTP helper), useTimeFormat.tsx.
• constants/ – sampleData.json for mock/testing.
• public/ – static assets (avatars).
• styles/ & tailwind.config.js – global CSS and Tailwind setup.
• next.config.js, tsconfig.json, .eslintrc.json – framework/config declarations.
README for insights
• Confirms core architecture: Next.js frontend + API routes, AI powered by OpenAI, content from Notion.
• Mentions user authentication (SupaAuthModal).
• No explicit persistence beyond Notion & potential Supabase.
Main components and interactions
a. Frontend (Next.js React):
• UI Pages (pages/*.tsx)
• Layout components (Header, Footer, Navbar)
• Chat UI (ChatSection → ChatBubble → UserDetails)
• Input components (Input, SuggestionBox)
• NotionPage renderer
b. Backend/API (Next.js API routes):
• /api/generate – accepts user prompt → calls OpenAI via utils/request → returns AI response
• (Potentially other API endpoints for auth, Notion)
c. External services:
• OpenAI API (for ChatGPT)
• Notion API (for Bhagavad Gita content)
• Supabase Auth (Supabase handles user login via SupaAuthModal)
d. Configuration & Utilities:
• lib/config.ts: centralizes environment variables (API keys, URLs)
• utils/request.tsx: abstract fetch requests to OpenAI and Notion
• lib/notion.ts: wraps Notion API calls
• preview-images.ts: generates image previews (used by NotionPage)
Architectural patterns and principles
• Monolithic full-stack app using Next.js’s hybrid routing (server-side & client-side).
• Layered structure:
1. Presentation Layer (React components in components/)
2. API Layer (Next.js API routes under pages/api/)
3. Integration Layer (lib/ + utils/ modules that call external services)
• Separation of concerns:
• UI vs. business logic vs. external integrations
• TypeScript for type safety across layers
• “Browser / Client” at left
• “Next.js Frontend” grouping: Pages, Components, Styles
• “Next.js Server” grouping: API Routes (/api/generate), lib modules
• “External Services”: OpenAI API, Notion API, Supabase Auth
1. User → Next.js Frontend (HTTP/React events)
2. Frontend → /api/generate (fetch)
3. /api/generate → OpenAI API (HTTPS)
4. API Route → lib/notion.ts → Notion API (HTTPS)
5. Frontend ↔ Supabase Auth (via SupaAuthModal)
6. Next.js Frontend → NotionPage component → lib/notion fetches content
c. Patterns:
• Data flow: user input → API → external AI engine → response → UI
• Shared config across server modules (lib/config)
• Reusable UI components vs. business logic modules
d. Technologies:
• Next.js (server & client)
• React + TypeScript + Tailwind CSS
• OpenAI, Notion, Supabase