How rajnishtheone/weather-insight-by-swara works
Project Type & Purpose
• SwaRaWeather is a full-stack web application built on Next.js 13 (App Router) with:
• A React-based frontend (UI components, Tailwind CSS, PWA support, dark mode).
• A serverless backend (Next.js API routes under app/api/*).
• External integrations: OpenAI (chatbot intelligence) and RapidAPI (weather data).
• Client-side features (world clock, timer, voice input, offline caching).
File Structure
• app/ directory:
• page.tsx, layout.tsx, loading.tsx, not-found.tsx — React server/client components and routing.
• app/api/chatbot/route.ts — REST endpoint for AI chat interactions.
• app/api/weather/route.ts — Weather data endpoint.
• app/api/search-cities/route.ts — City‐search/autocomplete endpoint.
• components/ and components/ui/:
• Shared UI primitives (buttons, dialogs, forms) and higher-level widgets (Chatbot, ThemeToggle).
• hooks/: Reusable client hooks (use-toast, use-mobile).
• lib/utils.ts: Shared utility functions (e.g., date formatting, fetch wrappers).
• public/, styles/, tailwind.config.ts: Static assets, global CSS, Tailwind configuration.
• next.config.mjs, tsconfig.json, package.json: Build/deploy configuration.
README Insights
• Confirms features: PWA, dark/light, voice, mobile-first, offline support.
• Emphasizes secure API usage (keys never leak to frontend).
• Mentions deployment on Vercel.
Main Components & Their Relationships
a. Frontend (Client Browser)
• UI Layer: React components (app/pages + components/ui).
• PWA/Service Worker: Offline caching, installable manifest.
• Local Storage or IndexedDB: Persist chat history, user settings (dark mode, last searches).
b. Next.js Serverless Backend
• API Routes:
• /api/chatbot → Proxies to OpenAI API, handles chat context.
• /api/weather → Fetches current & 7-day forecast from RapidAPI.
• /api/search-cities → Autocomplete cities (could use a geocoding API).
• Shared Utils: lib/utils.ts for consistent request handling, error formatting.
c. External Services
• OpenAI API (ChatGPT endpoints)
• RapidAPI (weather data)
• (Optional) Geocoding/autocomplete API if distinct from weather provider.
d. Deployment Environment
• Vercel (build & serverless functions)
• Environment Variables: OPENAI_API_KEY, RAPIDAPI_KEY stored securely in Vercel dashboard.
Data Flow & Interactions:
1. User interacts with UI → React calls client hooks → invokes fetch() on /api/* routes.
2. Next.js API route receives request → uses serverless function → calls external API → transforms response → returns JSON.
3. Frontend receives JSON → updates UI (chat messages, weather cards).
4. PWA service worker caches static assets & API responses (weather, UI bundles) for offline use.
5. Client persists chat history/settings locally for session restoration.
Important Architectural Patterns & Principles
• Separation of Concerns: UI vs. API logic vs. utilities.
• Serverless Micro-Endpoints: Each API route is a narrowly scoped Lambda (chatbot, weather, search).
• Component-Driven Design: Reusable UI primitives in components/ui, theming via theme-provider.
• PWA Best Practices: Manifest, service worker, offline caching strategies.
• Security by Design: All secret keys reside server-side; frontend never sees raw credentials.
Diagramming Tools & Export
• Export as SVG/PNG for documentation.
• Embed in your README/docs or Confluence page.