How jaiteshg/codeflex works
1. This repo is a Next.js App Router application with three major boundaries: the UI layer in src/app and src/components, the realtime backend in convex, and external auth/AI services (Clerk, Vapi, Gemini) wired in through environment variables and small integration modules.
2. The presentation layer is split between public/marketing pages and authenticated app pages. The root route (src/app/page.tsx) is the entry point, while src/app/(auth)/sign-in and src/app/(auth)/sign-up host Clerk’s auth UI, src/app/generate-program/page.tsx drives the assistant-based program creation flow, and src/app/profile/page.tsx shows a user’s saved fitness plans.
3. Shared UI chrome lives in reusable components such as Navbar, Footer, CornerElements, TerminalOverlay, ProfileHeader, UserPrograms, and NoFitnessPlan. This suggests the app is designed around a branded shell plus a few feature-specific panels rather than a large page hierarchy.
4. Authentication is a first-class subsystem. Clerk handles sign-in/sign-up and user identity, while src/middleware.ts likely protects authenticated routes and redirects unauthenticated users. The ConvexClerkProvider in src/providers bridges Clerk session state into Convex so backend queries/mutations know who the user is.
5. The fitness-plan generation flow is voice-driven. src/lib/vapi.ts encapsulates the Vapi client integration, and the generate-program screen likely uses TerminalOverlay plus Vapi’s workflow id/API key to start a conversational AI session that collects fitness goals, injuries, preferences, and dietary constraints.
6. Vapi is acting as the conversation orchestration layer, while Gemini is the LLM used behind that workflow to produce the actual personalized workout and diet output. From an architecture standpoint, the app itself does not appear to call the model directly; it initiates a workflow and receives results back through the assistant pipeline.
7. Convex is the application database and realtime state layer. convex/schema.ts defines the collections, convex/users.ts and convex/plans.ts hold domain operations, and the generated client in convex/_generated is consumed from the Next.js app for typed reads/writes. This is the primary persistence boundary for users and fitness programs.
8. The data model appears centered on users and plans, with the business rule that a user can have multiple programs but only the latest one is active. That behavior is reflected in the README and the presence of dedicated plans and users modules, plus the profile UI that likely lists historical programs.
9. convex/http.ts indicates there is at least one HTTP-facing backend surface in addition to direct Convex queries/mutations. In this kind of architecture, that file usually serves webhook-style traffic or external callbacks from services like Vapi, keeping third-party integration logic out of the React app.
10. Styling and UI primitives are handled with Tailwind and shadcn/ui. The src/components/ui folder contains low-level building blocks like button, card, accordion, and tabs, while src/app/globals.css and public/globals.css provide the global theme layer.
11. The overall runtime flow is: user lands on the Next.js frontend, authenticates through Clerk, uses the voice assistant to describe a desired fitness profile, Vapi/Gemini generates the plan, Convex persists the user and plan records, and the profile page reads back the stored plans in realtime.
12. In diagram terms, the important external services are Clerk for identity, Vapi for conversational AI orchestration, Gemini for generation, Convex for persistence/realtime sync, and Next.js/Vercel as the application host. The architecture is mostly frontend-driven, with Convex providing the backend domain boundary rather than a separate custom API server.
Main entry points: api.js Generated Client · layout.tsx App Shell · profile/page.tsx Profile · generate-program/page.tsx Generate Plan
Components 23
Next.js Frontend
App Router pages, shared chrome, and client-side flow entrypoints.
- Home · Public landing page and primary entry into the app.
src/app/page.tsx - App Shell · Top-level application layout and shared providers.
src/app/layout.tsx - Sign In · Clerk sign-in route mounted under the App Router.
src/app/(auth)/sign-in/[[...sign-in]]/page.tsx - Sign Up · Clerk sign-up route mounted under the App Router.
src/app/(auth)/sign-up/[[...sign-up]]/page.tsx - Generate Plan · Voice-driven fitness program creation screen.
src/app/generate-program/page.tsx - Profile · Shows the user's saved fitness plans and latest program.
src/app/profile/page.tsx - Navbar · Shared top-level navigation component.
src/components/Navbar.tsx - Footer · Shared footer used across the public-facing shell.
src/components/Footer.tsx - Terminal UI · Branded overlay used during the voice/program generation experience.
src/components/TerminalOverlay.tsx - Profile Header · Header block for the profile and plan history view.
src/components/ProfileHeader.tsx - User Programs · Renders a user's saved fitness plans.
src/components/UserPrograms.tsx - No Plan · Fallback view when the user has no saved fitness plan.
src/components/NoFitnessPlan.tsx - Corner Elements · Decorative layout accents for branded presentation.
src/components/CornerElements.tsx - Clerk Bridge · Connects Clerk session state into Convex for authenticated data access.
src/providers/ConvexClerkProvider.tsx - Middleware · Protects authenticated routes and handles redirects.
src/middleware.ts
Convex Backend
Realtime persistence, domain logic, and external callback surface.
- Schema · Defines users and plans collections.
convex/schema.ts - Users · User-related Convex queries and mutations.
convex/users.ts - Plans · Fitness plan persistence and retrieval logic.
convex/plans.ts - HTTP Surface · External callback or webhook entrypoint for integrations.
convex/http.ts - Generated Client · Generated Convex API bindings consumed by the app.
convex/_generated/api.js
External Services
Identity and AI services used by the application.
- Vapi Client · Encapsulates the conversational AI workflow client.
src/lib/vapi.ts - Clerk · Authentication and user identity provider.
- Gemini · Model used to generate personalized workout and diet plans.
Connections 26
- App Shell → Navbar: renders · Shared shell composes navigation.
- App Shell → Footer: renders · Shared shell composes footer.
- App Shell → Corner Elements: renders · Shared branded presentation layer.
- App Shell → Clerk Bridge: wraps · Provides authenticated Convex access to the app.
- Home → Navbar: uses · Landing page uses shared navigation.
- Home → Footer: uses · Landing page uses shared footer.
- Generate Plan → Terminal UI: uses · Assistant flow is presented through the terminal-style overlay.
- Profile → Profile Header: uses · Profile view starts with a summary header.
- Profile → User Programs: uses · Profile view lists saved plans.
- Profile → No Plan: fallback · Empty state when no plans exist.
- Middleware → Sign In: redirects · Unauthenticated users are sent to sign-in.
- Middleware → Sign Up: redirects · Unauthenticated users can reach sign-up.
- Clerk Bridge → Clerk: bridges · Session identity is forwarded from Clerk into Convex.
- Sign In → Clerk: delegates · Sign-in UI is handled by Clerk.
- Sign Up → Clerk: delegates · Sign-up UI is handled by Clerk.
- Generate Plan → Vapi Client: starts · Program creation launches the voice assistant workflow.
- Vapi Client → Gemini: orchestrates · Vapi coordinates generation using Gemini behind the scenes.
- Vapi Client → HTTP Surface: callbacks · Workflow results can arrive through backend HTTP callbacks.
- HTTP Surface → Plans: writes · External events are persisted as fitness plans.
- Users → Schema: implements · User operations follow the shared schema.
- Plans → Schema: implements · Plan operations follow the shared schema.
- Generated Client → Users: types · Generated client exposes user operations.
- Generated Client → Plans: types · Generated client exposes plan operations.
- Profile → Generated Client: reads · Profile page loads user plans through typed Convex bindings.
- Generate Plan → Generated Client: writes · Generated plan data is persisted through Convex.
- Clerk Bridge → Generated Client: enables · Provider makes typed Convex access available in the UI.