# kaialan/dhwani-frontend architecture

> Architecture diagram of the GitHub repository kaialan/dhwani-frontend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kaialan/dhwani-frontend
- Repository: https://github.com/kaialan/dhwani-frontend

## Overview

##### Project type and purpose
- This is a full-stack Next.js application serving as an educational platform where users can register/login, browse courses, view content, clear doubts, and purchase courses via Stripe.
- Key features gleaned from the file tree and README:
- Next.js 13 App Router under `app/` with server and client components
- Authentication flows (NextAuth + custom actions)
- Stripe checkout integration
- Static/data-driven course content (JSON in `data/`)
- UI component library under `components/ui/`

##### File structure
- Top-level directories:
- `app/` – Next.js App Router pages, layouts, protected and public routes
- `app/api/` – Next.js API Routes for auth, webhook, checkout
- `action/` – Server actions for business logic (auth, course queries, profile, payment)
- `components/` – Reusable React UI components (domain-specific + generic UI library)
- `data/` – Hard-coded constants and simple data-fetching utilities
- `lib/`, `utils/`, `hooks/`, `schema/` – Types, helpers, hooks, validation schemas
- `pages/` – Legacy Pages Router API for location lookup
- Config files (`next.config.mjs`, `tailwind.config.ts`, ESLint, TS)

##### README for additional insights
- Standard Next.js starter README with hints that this is server-rendered, uses `next/font`, and is deployable to Vercel.

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Frontend Layer
  subgraph "Frontend (Browser)" 
    direction TB
    Browser["Browser"]:::frontend
    subgraph "Auth Flow"
      direction TB
      AuthLayout["Auth Layout"]:::frontend
      LoginPage["Login Page"]:::frontend
      RegisterPage["Register Page"]:::frontend
    end
    subgraph "Protected Routes"
      direction TB
      ProtectedLayout["Protected Layout"]:::frontend
      WithSidebarLayout["With-Sidebar Layout"]:::frontend
      DoubtPage["Doubt Clearing Page"]:::frontend
      ProfilePage["Profile Page"]:::frontend
      BuyCoursePage["Buy Course Page"]:::frontend
      SuccessPage["Buy Success Page"]:::frontend
      CancelPage["Buy Cancel Page"]:::frontend
      YearCoursePage["Year Course Page"]:::frontend
    end
    subgraph "UI Component Library"
      direction TB
      UIComponents["components/ui/*"]:::ui
    end
    subgraph "Domain Components"
      direction TB
      DomainComponents["components/*.tsx"]:::frontend
    end
  end

  %% Backend Layer
  subgraph "Backend (Next.js Server)" 
    direction TB
    subgraph "API Routes"
      direction TB
      AuthRoute["/api/auth/[...nextauth]"]:::api
      CheckoutRoute["/api/create-checkout-session"]:::api
      WebhookRoute["/api/webhook"]:::api
      LocationRoute["/api/location"]:::api
    end
    subgraph "Server Actions"
      direction TB
      LoginAction["action/auth/login.ts"]:::action
      RegisterAction["action/auth/register.ts"]:::action
      LogoutAction["action/auth/logout.ts"]:::action
      RefreshAction["action/auth/refresh.ts"]:::action
      GetAllCourses["action/course/getAllCourses.ts"]:::action
      GetCourse["action/course/getCourse.ts"]:::action
      GetProfile["action/profile/getProfile.ts"]:::action
      StripeCheckoutAct["action/stripe-checkout.ts"]:::action
      GetLocation["action/get-user-location.ts"]:::action
    end
    subgraph "Data Store"
      direction TB
      DataStore["Static JSON Data"]:::data
    end
  end

  %% External Services
  subgraph "External Services"
    direction TB
    NextAuthSvc["NextAuth Service"]:::external
    StripeSvc["Stripe API"]:::external
    VimeoSvc["Vimeo Embed"]:::external
    LocationSvc["Location API"]:::external
  end

  %% Interactions
  Browser -->|"navigate/auth"| AuthLayout
  AuthLayout --> LoginPage
  AuthLayout --> RegisterPage
  Browser -->|"access/protected"| ProtectedLayout
  ProtectedLayout --> WithSidebarLayout
  WithSidebarLayout --> DoubtPage
  WithSidebarLayout --> ProfilePage
  ProtectedLayout --> BuyCoursePage
  BuyCoursePage --> SuccessPage
  BuyCoursePage --> CancelPage
  ProtectedLayout --> YearCoursePage
  Browser --> UIComponents
  Browser --> DomainComponents

  %% Frontend calls backend
  LoginPage -->|"POST /api/auth/login"| AuthRoute
  RegisterPage -->|"POST /api/auth/register"| AuthRoute
  ProtectedLayout -->|"GET courses"| GetAllCourses
  YearCoursePage -->|"GET course details"| GetCourse
  ProfilePage -->|"GET profile"| GetProfile
  BuyCoursePage -->|"createCheckoutSession()"| CheckoutRoute
  WebhookRoute --> StripeCheckoutAct

  %% Backend flows
  AuthRoute -->|calls| NextAuthSvc
  AuthRoute -->|uses| LoginAction
  AuthRoute -->|uses| RegisterAction
  AuthRoute -->|uses| RefreshAction
  AuthRoute -->|uses| LogoutAction

  CheckoutRoute -->|uses| StripeCheckoutAct
  StripeCheckoutAct -->|POST create session| StripeSvc
  WebhookRoute -->|handles| StripeSvc

  GetAllCourses -->|read| DataStore
  GetCourse -->|read| DataStore
  GetProfile -->|read| DataStore
  GetLocation -->|calls| LocationSvc

  DomainComponents -->|embeds| VimeoSvc

  %% Click events
  click AuthLayout "https://github.com/kaialan/dhwani-frontend/blob/main/app/auth/layout.tsx"
  click LoginPage "https://github.com/kaialan/dhwani-frontend/blob/main/app/auth/login/page.tsx"
  click RegisterPage "https://github.com/kaialan/dhwani-frontend/blob/main/app/auth/register/page.tsx"
  click ProtectedLayout "https://github.com/kaialan/dhwani-frontend/blob/main/app/(protected)/layout.tsx"
  click WithSidebarLayout "https://github.com/kaialan/dhwani-frontend/blob/main/app/(protected)/(with-sidebar)/layout.tsx"
  click DoubtPage "https://github.com/kaialan/dhwani-frontend/blob/main/app/(protected)/(with-sidebar)/doubt-clearing/page.tsx"
  click ProfilePage "https://github.com/kaialan/dhwani-frontend/blob/main/app/(protected)/(with-sidebar)/profile/page.tsx"
  click BuyCoursePage "https://github.com/kaialan/dhwani-frontend/blob/main/app/(protected)/buy-course/page.tsx"
  click SuccessPage "https://github.com/kaialan/dhwani-frontend/blob/main/app/(protected)/buy-course/success/page.tsx"
  click CancelPage "https://github.com/kaialan/dhwani-frontend/blob/main/app/(protected)/buy-course/cancel/page.tsx"
  click YearCoursePage "https://github.com/kaialan/dhwani-frontend/blob/main/app/(protected)/courses/year/[yearId]/page.tsx"
  click AuthRoute "https://github.com/kaialan/dhwani-frontend/blob/main/app/api/auth/[...nextauth]/route.ts"
  click CheckoutRoute "https://github.com/kaialan/dhwani-frontend/blob/main/app/api/create-checkout-session/route.ts"
  click WebhookRoute "https://github.com/kaialan/dhwani-frontend/blob/main/app/api/webhook/route.ts"
  click LocationRoute "https://github.com/kaialan/dhwani-frontend/blob/main/pages/api/location.ts"
  click LoginAction "https://github.com/kaialan/dhwani-frontend/blob/main/action/auth/login.ts"
  click RegisterAction "https://github.com/kaialan/dhwani-frontend/blob/main/action/auth/register.ts"
  click LogoutAction "https://github.com/kaialan/dhwani-frontend/blob/main/action/auth/logout.ts"
  click RefreshAction "https://github.com/kaialan/dhwani-frontend/blob/main/action/auth/refresh.ts"
  click GetAllCourses "https://github.com/kaialan/dhwani-frontend/blob/main/action/course/getAllCourses.ts"
  click GetCourse "https://github.com/kaialan/dhwani-frontend/blob/main/action/course/getCourse.ts"
  click GetProfile "https://github.com/kaialan/dhwani-frontend/blob/main/action/profile/getProfile.ts"
  click StripeCheckoutAct "https://github.com/kaialan/dhwani-frontend/blob/main/action/stripe-checkout.ts"
  click GetLocation "https://github.com/kaialan/dhwani-frontend/blob/main/action/get-user-location.ts"
  click UIComponents "https://github.com/kaialan/dhwani-frontend/tree/main/components/ui/"
  click DataStore "https://github.com/kaialan/dhwani-frontend/blob/main/data/constants/courses.ts"

  %% Styles
  classDef frontend fill:#b2f5ea,stroke:#2c7a7b,color:#1a202c
  classDef backend fill:#bee3f8,stroke:#2b6cb0,color:#1a202c
  classDef api fill:#bee3f8,stroke:#2b6cb0,color:#1a202c
  classDef action fill:#bee3f8,stroke:#2b6cb0,color:#1a202c
  classDef data fill:#e2e8f0,stroke:#4a5568,color:#1a202c
  classDef external fill:#fbd38d,stroke:#dd6b20,color:#1a202c
  classDef ui fill:#f0fff4,stroke:#38a169,color:#1a202c

  class Browser,AuthLayout,LoginPage,RegisterPage,ProtectedLayout,WithSidebarLayout,DoubtPage,ProfilePage,BuyCoursePage,SuccessPage,CancelPage,YearCoursePage,DomainComponents frontend
  class AuthRoute,CheckoutRoute,WebhookRoute,LocationRoute backend
  class LoginAction,RegisterAction,LogoutAction,RefreshAction,GetAllCourses,GetCourse,GetProfile,StripeCheckoutAct,GetLocation backend
  class DataStore data
  class NextAuthSvc,StripeSvc,VimeoSvc,LocationSvc external
  class UIComponents ui
```
