How hmz865/fitguy works
Step 1: Identify the project type and purpose
• This is a full-stack, single-page web application built in React/TypeScript (via Vite) for a fitness and wellness platform (BMI calculators, AI chat coach, nutrition/workout plans, subscription management, admin dashboards).
• The README confirms the tech stack (Vite, React, TypeScript, Tailwind CSS, shadcn-ui) and that the app is backed by Supabase (database, auth, edge functions).
Step 2: Analyze the file structure
• Top-level folders:
• public/ (static assets, robots.txt, index.html)
• src/ (all front-end code, subdivided into components, pages, contexts, hooks, integrations, utils)
• supabase/ (backend-as-a-service config & edge functions)
• Under src/components you see UI slices, feature components (BMI, AIChat, NutritionPlan), admin panel components, dashboard sections, and a UI library scaffold (ui/*).
• src/contexts holds React context providers (AuthContext, SubscriptionContext, ThemeContext).
• src/hooks implements data-fetching and business hooks (useSavedWorkouts, useFeatureAccess, etc.).
• supabase/functions defines serverless edge functions for checkout, subscription checks, AI chat, nutrition recommendations, newsletters.
Step 3: Examine the README for additional insights
• Confirms a Lovable dashboard project, with Git-backed and Lovable-managed workflows.
a. Main components
1. Client (Browser): React SPA served as static assets.
2. Front-end layers:
– UI Components & Pages (src/pages, src/components)
– React Router (ProtectedRoute, PremiumRoute)
– Context Providers & Hooks (AuthContext, SubscriptionContext, custom data hooks)
3. BaaS Back-end: Supabase
– Authentication Service
– PostgreSQL Database
– Edge Functions (check-subscription, create-checkout, AI Chat, nutrition recommendations, send newsletters)
4. External Services
– Stripe (checkout, billing portal)
– OpenAI (fitness-AI chat)
– Email service (newsletter delivery)
b. Relationships and interactions
• Browser loads the SPA and interacts with UI.
• UI uses AuthContext & SubscriptionContext to manage user state.
• Data hooks call the Supabase client (via integrations/supabase/client.ts) for CRUD and auth.
• For specialized tasks (AI chat, nutrition logic, billing), front end invokes Supabase Edge Functions which in turn integrate with external APIs (Stripe, OpenAI, Email).
• Supabase edge functions read/write to the Postgres database.
c. Architectural patterns and design principles
• Single-page application with client-side routing.
• Container/presenter split: pages orchestrate, components render UI.
• Context for global state, custom hooks for data logic.
• BaaS pattern: minimize custom back-end by leveraging Supabase edge functions.
• Feature gating (PremiumRoute, PremiumFeatureGate).
d. Key technologies, frameworks, or libraries
• Vite & TypeScript for build & typing.
• React & shadcn-ui (Tailwind CSS) for UI.
• Supabase for auth, database, and serverless logic.
• Stripe, OpenAI, email service for payments, AI, and mailing.
• Clearly separate the Front-end SPA layer from the Supabase BaaS layer.
• API boundary: Supabase client SDK calls vs. Edge Function HTTP endpoints.
• How context and hooks mediate between UI components and data services.
• Labels for each component (e.g., “React SPA”, “AuthContext”, “Supabase Edge Function: fitness-ai-chat”).
• Front-end (blue rectangles)
• External services (orange clouds)
Step 7: Final guidelines
• Be very detailed: break the front end into UI components, contexts, hooks, and routing layers.
• On the backend side, separate the database, auth, and individual edge functions.
• Don’t overthink it—capture every major directory or module as its own node so the engineer can see how traffic flows through the system from UI to data to external APIs.
• Use a consistent layout: top row for UI, middle for BaaS, bottom for external services.