# arpitgami/sessionhq architecture

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

- Interactive diagram: https://gitdiagram.com/arpitgami/sessionhq
- Repository: https://github.com/arpitgami/sessionhq

## Overview

##### Project Type and Purpose
- This is a full-stack Next.js application for booking and running live expert sessions.
- The “app” folder under src contains both the React pages (UI) and API routes (Next.js serverless functions).
- A custom Node server (server.js) and Socket.io + PeerJS hooks enable real-time video/audio chat.
- Stripe is used for payments; a database (configured in src/dbconfig and models in src/models) persists users, experts, meetings, availability, etc.

##### File Structure
- src/app – Next.js App Router pages and layouts.
– /(info-page) and its subfolders: marketing/info pages (landing, explore, expert profiles, meetings).
– /(after-payment): success/failed pages.
– post-sign-in, userform, room/[roomid] (live session UI).
- src/app/api – Next.js API routes (expert data, meeting control, user payment, Stripe webhook).
- src/component – Reusable UI components (ExpertCard, Navbar, modals, room chat controls).
- src/context & src/hooks – Socket connection, WebRTC (usePeer, useMediaStream), image upload, refund initiation, guard hooks.
- src/dbconfig + src/models – DB connector and ORM/ODM models for Users, Experts, Meetings, Requests, Availability, SessionData.
- server.js – Custom Next.js server entrypoint, attaches Socket.io and handles real-time signaling.
- Config files – next.config.ts, tsconfig.json, ESLint, PostCSS.

##### README
- Standard create-next-app boilerplate – no custom architecture doc.
- Emphasizes development server and deployment on Vercel.

a. Main Components
– Client (Browser): React pages under src/app, WebRTC/Socket.io client in context/hooks.
– Next.js Server:
- Server-Side Rendering and API routes (src/app/api).
- Custom Express/Next server + Socket.io (server.js).
– Database: Postgres/MongoDB (via dbconfig).
– External Services:
- Stripe (payment sessions + webhooks).
- PeerJS (signaling via Socket.io).
b. Relationships & Interactions
1. User navigates to Next.js pages → SSR or client-side render.
2. UI calls Next.js API endpoints for expert data, availability, meeting creation, payments.
3. Payment flow: Next API → Stripe Checkout → Stripe Webhook → Next API → DB.
4. Meeting flow: Next API schedules meeting → DB. User enters room → Socket.io signaling handshake → WebRTC media streams.
5. Real-time chat/control via Socket.io channels managed by server.js.
c. Architectural Patterns & Principles
– Full-stack “App Router” in Next.js: co-located UI + API folders.
– Layered separation: Presentation (app/pages + components), Business (API routes + hooks), Data (models + dbconfig).
– Event-driven for payments (webhooks) and real-time (Socket.io).
– Modular React components and context for reusability.
d. Key Technologies/Frameworks
– Next.js 13+, App Router
– React + TypeScript/JSX
– Express + Socket.io (custom server)
– WebRTC (PeerJS, custom hooks)
– Stripe API
– ORM/ODM (models in src/models) + dbconfig
– Vercel deployment (optional)

##### Essential Architectural Elements
– Do not oversimplify: include API subdomains (expert, meeting, stripe, user).
– Explicitly show the real-time signaling (Socket.io) vs media streams (WebRTC).
– Illustrate payment flow separately from booking flow.
– Reflect the folder structure: map “src/app/experts/*” to “Expert Dashboard UI”, map “src/models” to “Database Schema”.

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Frontend Zone
  subgraph "Frontend (Browser)"
    direction TB
    subgraph "Pages" 
      direction TB
      Landing["Landing & Marketing Pages"]:::frontend
      Explore["Explore Experts"]:::frontend
      Profile["Expert Profile Page"]:::frontend
      Become["Become an Expert"]:::frontend
      MeetingsOV["Meetings Overview"]:::frontend
      Success["After-Payment Success"]:::frontend
      Failure["After-Payment Failure"]:::frontend
      PostSignIn["Post Sign-In Flow"]:::frontend
      Onboarding["User Onboarding Form"]:::frontend
      RoomLayout["Room Layout"]:::frontend
      RoomPage["Live Session Room Page"]:::frontend
      Calendar["Expert Calendar"]:::frontend
      RequestsUI["Incoming Requests UI"]:::frontend
      Upcoming["Upcoming Meetings UI"]:::frontend
      Feedback["General Feedback Page"]:::frontend
    end

    subgraph "Components"
      direction TB
      ExpertCard["ExpertCard"]:::frontend
      MeetingCard["MeetingCard"]:::frontend
      Navbar["Navbar"]:::frontend
      Notification["Notification"]:::frontend
      UserRequest["UserRequestDetails"]:::frontend
      Step1["Expert Form Step1"]:::frontend
      Step2["Expert Form Step2"]:::frontend
      Step3["Expert Form Step3"]:::frontend
      FormInputs["Expert Form Inputs"]:::frontend
      ModalAbout["Modal: AboutYou"]:::frontend
      ModalLock["Modal: LockYourSlot"]:::frontend
      ModalIntent["Modal: SessionIntent"]:::frontend
      ModalSlot["Modal: Slot"]:::frontend
      ControlPanel["Room Control Panel"]:::frontend
      ChatSection["Chat Section"]:::frontend
      ChatMessage["Chat Message"]:::frontend
      StreamPlayer["Stream Player"]:::frontend
      LeaveMeeting["Leave Meeting"]:::frontend
    end

    subgraph "Hooks & Context"
      direction TB
      SocketClient["Socket.io Client Context"]:::realtime
      PeerHook["usePeer Hook"]:::realtime
      MediaHook["useMediaStream Hook"]:::realtime
      UploadImage["Upload Image Hook"]:::frontend
      Refund["Initiate Refund Hook"]:::frontend
      AuthGuard["Auth Guard Hook"]:::frontend
    end
  end

  %% Backend Zone
  subgraph "Backend (Server)"
    direction TB
    SSR["Next.js SSR"]:::backend
    API["Next.js API Routes"]:::backend
    Server["Custom Server + Socket.io"]:::realtime
  end

  %% Data & External
  DB["Database (Users, Experts, Meetings, ...)"]:::database
  Stripe["Stripe API"]:::external

  %% Interactions
  Landing -->|"HTTP"| API
  Explore -->|"HTTP"| API
  Profile -->|"HTTP"| API
  Become -->|"HTTP"| API
  MeetingsOV -->|"HTTP"| API
  PostSignIn -->|"HTTP"| API
  Onboarding -->|"HTTP"| API
  RoomPage -->|"HTTP"| API
  RoomPage -->|"WS"| Server
  Server -->|"WebRTC Signaling"| RoomPage
  API -->|"Read/Write"| DB
  API -->|"REST"| Stripe
  Stripe -->|"Webhook"| API

  ExpertCard --> Landing
  MeetingCard --> MeetingsOV
  Navbar --> Landing
  Notification --> Landing
  UserRequest --> RequestsUI
  ControlPanel --> RoomPage
  ChatSection --> RoomPage

  SocketClient --> RoomPage
  PeerHook --> RoomPage
  MediaHook --> RoomPage

  %% Click Events
  click Landing "https://github.com/arpitgami/sessionhq/blob/main/src/app/(info-page)/landing/page.tsx"
  click Explore "https://github.com/arpitgami/sessionhq/blob/main/src/app/(info-page)/explore/page.tsx"
  click Profile "https://github.com/arpitgami/sessionhq/blob/main/src/app/(info-page)/expert/[expertid]/page.tsx"
  click Become "https://github.com/arpitgami/sessionhq/blob/main/src/app/(info-page)/become_an_expert/page.jsx"
  click MeetingsOV "https://github.com/arpitgami/sessionhq/blob/main/src/app/(info-page)/meetings/page.tsx"
  click Success "https://github.com/arpitgami/sessionhq/blob/main/src/app/(after-payement)/success/page.tsx"
  click Failure "https://github.com/arpitgami/sessionhq/blob/main/src/app/(after-payement)/failed/page.tsx"
  click PostSignIn "https://github.com/arpitgami/sessionhq/blob/main/src/app/post-sign-in/page.tsx"
  click Onboarding "https://github.com/arpitgami/sessionhq/blob/main/src/app/userform/page.jsx"
  click RoomLayout "https://github.com/arpitgami/sessionhq/blob/main/src/app/room/layout.jsx"
  click RoomPage "https://github.com/arpitgami/sessionhq/blob/main/src/app/room/[roomid]/page.jsx"
  click Calendar "https://github.com/arpitgami/sessionhq/blob/main/src/app/experts/calendar/page.tsx"
  click RequestsUI "https://github.com/arpitgami/sessionhq/blob/main/src/app/experts/requests/page.tsx"
  click Upcoming "https://github.com/arpitgami/sessionhq/blob/main/src/app/experts/upcomingmeetings/page.tsx"
  click Feedback "https://github.com/arpitgami/sessionhq/blob/main/src/app/feedback/page.tsx"

  click ExpertCard "https://github.com/arpitgami/sessionhq/blob/main/src/component/ExpertCard.tsx"
  click MeetingCard "https://github.com/arpitgami/sessionhq/blob/main/src/component/MeetingCard.tsx"
  click Navbar "https://github.com/arpitgami/sessionhq/blob/main/src/component/Navbar.tsx"
  click Notification "https://github.com/arpitgami/sessionhq/blob/main/src/component/Notification.tsx"
  click UserRequest "https://github.com/arpitgami/sessionhq/blob/main/src/component/UserRequestDetails.tsx"
  click Step1 "https://github.com/arpitgami/sessionhq/blob/main/src/component/expertform/step1.jsx"
  click Step2 "https://github.com/arpitgami/sessionhq/blob/main/src/component/expertform/step2.jsx"
  click Step3 "https://github.com/arpitgami/sessionhq/blob/main/src/component/expertform/step3.jsx"
  click FormInputs "https://github.com/arpitgami/sessionhq/blob/main/src/component/expertform/forminputs.jsx"
  click ModalAbout "https://github.com/arpitgami/sessionhq/blob/main/src/component/modal/AboutYou.jsx"
  click ModalLock "https://github.com/arpitgami/sessionhq/blob/main/src/component/modal/LockYourSlot.jsx"
  click ModalIntent "https://github.com/arpitgami/sessionhq/blob/main/src/component/modal/SessionIntent.jsx"
  click ModalSlot "https://github.com/arpitgami/sessionhq/blob/main/src/component/modal/Slot.jsx"
  click ControlPanel "https://github.com/arpitgami/sessionhq/blob/main/src/component/room/ControlPannel.jsx"
  click ChatSection "https://github.com/arpitgami/sessionhq/blob/main/src/component/room/ChatSection.jsx"
  click ChatMessage "https://github.com/arpitgami/sessionhq/blob/main/src/component/room/ChatMessage.jsx"
  click StreamPlayer "https://github.com/arpitgami/sessionhq/blob/main/src/component/room/StreamPlayer.jsx"
  click LeaveMeeting "https://github.com/arpitgami/sessionhq/blob/main/src/component/room/LeaveMeeting.tsx"

  click SocketClient "https://github.com/arpitgami/sessionhq/blob/main/src/context/socket.js"
  click PeerHook "https://github.com/arpitgami/sessionhq/blob/main/src/hooks/usePeer.js"
  click MediaHook "https://github.com/arpitgami/sessionhq/blob/main/src/hooks/useMediaStream.js"
  click UploadImage "https://github.com/arpitgami/sessionhq/blob/main/src/hooks/uploadImage.js"
  click Refund "https://github.com/arpitgami/sessionhq/blob/main/src/hooks/initiateRefund.ts"
  click AuthGuard "https://github.com/arpitgami/sessionhq/blob/main/src/hooks/useUserGuard.ts"

  click API "https://github.com/arpitgami/sessionhq/tree/main/src/app/api"
  click Server "https://github.com/arpitgami/sessionhq/blob/main/server.js"
  click DB "https://github.com/arpitgami/sessionhq/blob/main/src/dbconfig/dbconfig.js"
  click Stripe "https://github.com/arpitgami/sessionhq/tree/main/n/a"

  click SSR "https://github.com/arpitgami/sessionhq/blob/main/next.config.ts"

  %% Styles
  classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6
  classDef backend fill:#E6FFFA,stroke:#00A37F,color:#006644
  classDef realtime fill:#FFE8A1,stroke:#D97706,color:#B45309
  classDef database fill:#F0F0F0,stroke:#999999,color:#333333
  classDef external fill:#F5E0FF,stroke:#A259FF,color:#702BEF
```
