# shubhsk88/realbnb-frontend architecture

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

- Interactive diagram: https://gitdiagram.com/shubhsk88/realbnb-frontend
- Repository: https://github.com/shubhsk88/realbnb-frontend

## Overview

##### Project type and purpose
- This is a front-end for a vacation-rental platform (“Realbnb”) built with Next.js (React + TypeScript).
- It communicates with a GraphQL backend (Express + Prisma) and integrates external services (Stripe for payments, Twilio for phone verification, Algolia for search, Google OAuth for login).

##### File structure
- Top-level:
- pages/ — Next.js routes (SSR/SSG entry points).
- components/ — React UI components (Auth, Algolia, Booking, common UI primitives).
- graphql/ — .graphql query/mutation files, organized by domain (user, room, reservation, list).
- generated/ — GraphQL Codegen output (typed hooks, schema).
- lib/ — Apollo Client setup, auth helpers, cache config.
- utils/ — shared utilities (date formatting, custom hooks).
- Configs: next.config.js, tsconfig.json, codegen.yml, .eslintrc, package.json.
- No server code here—this repo is purely the front-end that calls out to an external GraphQL API.

##### README for additional insights
- Confirms React/Next.js front-end talking to GraphQL + Prisma + Express backend.
- Lists external integrations: Stripe, Twilio, Algolia, Google Sign‐In.
- Highlights features (search, booking, payments, save listings).

a. Main components
- Client Browser (Next.js pages + React components)
- Next.js App Server (SSR/SSG, routing, rendering)
- Apollo Client (GraphQL queries/mutations)
- GraphQL API Server (Express + Apollo Server + Prisma)
- Database (PostgreSQL or similar)
- External Services:
– Stripe (payment processing)
– Twilio (phone verification)
– Algolia (search index)
– Google OAuth (social login)
b. Relationships & interactions
1. User’s browser requests a Next.js page → Next.js server renders or hydrates React.
2. React/Apollo issues GraphQL queries → GraphQL API server.
3. GraphQL resolvers use Prisma to read/write the database.
4. For payments, GraphQL server calls Stripe’s API.
5. For phone login, GraphQL server calls Twilio.
6. For full-text search/autocomplete, Next.js invokes Algolia client in browser.
c. Architectural patterns/principles
– Component-based UI (atomic common components under components/common).
– Domain-organized GraphQL queries (graphql/lists, graphql/room, graphql/user…).
– API client abstraction (lib/apolloClient, lib/auth, context providers).
– Codegen for type safety (generated/ folder via codegen.yml).
– SSR/SSG benefits for SEO and performance.
d. Key technologies/frameworks
– Next.js + React + TypeScript
– Chakra UI for styling
– Apollo Client for GraphQL
– GraphQL + Apollo Server + Prisma on backend
– Stripe, Twilio, Algolia, Google OAuth

##### Essential elements
- Search: browser directly to Algolia vs. GraphQL-mediated data.
- SSR/SSG roles of Next.js and where Apollo cache is used.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Front-End Layer
    subgraph "Front-End" 
        direction TB
        Browser["User's Browser"]:::frontend
        NextServer["Next.js App Server"]:::frontend
        ApolloClient["Apollo Client"]:::frontend
        Pages["Next.js Pages"]:::frontend
        Components["React UI Components"]:::frontend
        AuthHelpers["Auth Helpers"]:::frontend
        CacheConfig["Apollo Cache Config"]:::frontend
        GraphqlFiles["GraphQL Files"]:::frontend
        Generated["Codegen Output"]:::frontend
        ComponentsAlgolia["Algolia Search UI"]:::frontend
        StripeWrapper["Stripe Payment Wrapper"]:::frontend
        BookingCard["BookingCard"]:::frontend
        BookingDetails["BookingDetails"]:::frontend
        CheckoutPage["Checkout Page"]:::frontend
        PaymentCard["PaymentCard"]:::frontend
        CreatePaymentGQL["createPayment.graphql"]:::frontend
        GoogleSignIn["GoogleSignIn UI"]:::frontend
        GoogleLoginGQL["googleLogin.graphql"]:::frontend
        StartPhoneGQL["startPhoneVerification.graphql"]:::frontend
        CompletePhoneGQL["completePhoneVerification.graphql"]:::frontend
        LoginUI["Login UI"]:::frontend
        SignUpUI["SignUp UI"]:::frontend
        CreateUserEmailGQL["createUserViaEmail.graphql"]:::frontend
        CreateUserPhoneGQL["createUserViaPhone.graphql"]:::frontend
        EmailLoginGQL["emailLogin.graphql"]:::frontend
        GetRoomsGQL["getRooms.graphql"]:::frontend
        GetRoomGQL["getRoom.graphql"]:::frontend
    end

    %% Back-End Layer
    subgraph "Back-End API" 
        direction TB
        GraphQLServer["GraphQL API Server"]:::backend
        Prisma["Prisma ORM"]:::backend
    end

    %% Database
    Database[(Database)]:::db

    %% External Services
    subgraph "External Services"
        direction TB
        Stripe["Stripe"]:::external
        Twilio["Twilio"]:::external
        Algolia["Algolia"]:::external
        GoogleOAuth["Google OAuth"]:::external
    end

    %% Relationships
    Browser -->|"SSR Request"| NextServer
    NextServer -->|"serves pages"| Browser
    NextServer -->|"uses"| Pages
    NextServer -->|"hydrates UI"| Components
    Pages -->|calls| ApolloClient
    Components -->|queries/mutations| ApolloClient
    ApolloClient -->|GraphQL requests| GraphQLServer
    ApolloClient -->|caches data| CacheConfig
    ApolloClient -->|auth logic| AuthHelpers
    GraphQLServer -->|resolves with| Prisma
    Prisma -->|reads/writes| Database
    GraphQLServer -->|calls API| Stripe
    GraphQLServer -->|calls API| Twilio
    Browser -->|client search| Algolia
    Browser -->|login redirect| GoogleOAuth

    %% Detailed UI Flows
    ComponentsAlgolia -->|uses| ApolloClient
    StripeWrapper -->|wraps| PaymentCard
    BookingCard -->|links to| BookingDetails
    BookingDetails -->|navigates to| CheckoutPage
    CheckoutPage -->|executes| CreatePaymentGQL
    CreatePaymentGQL -->|through| ApolloClient
    PaymentCard -->|calls| CreatePaymentGQL
    GoogleSignIn -->|executes| GoogleLoginGQL
    GoogleLoginGQL -->|through| ApolloClient
    StartPhoneGQL -->|through| ApolloClient
    CompletePhoneGQL -->|through| ApolloClient
    LoginUI -->|executes| EmailLoginGQL
    SignUpUI -->|executes| CreateUserEmailGQL
    SignUpUI -->|executes| CreateUserPhoneGQL
    GetRoomsGQL -->|through| ApolloClient
    GetRoomGQL -->|through| ApolloClient

    %% Click Events
    click Pages "https://github.com/shubhsk88/realbnb-frontend/tree/main/pages/"
    click Components "https://github.com/shubhsk88/realbnb-frontend/tree/main/components/"
    click ApolloClient "https://github.com/shubhsk88/realbnb-frontend/blob/main/lib/apolloClient.ts"
    click AuthHelpers "https://github.com/shubhsk88/realbnb-frontend/blob/main/lib/auth.tsx"
    click CacheConfig "https://github.com/shubhsk88/realbnb-frontend/blob/main/lib/cache.ts"
    click GraphqlFiles "https://github.com/shubhsk88/realbnb-frontend/tree/main/graphql/"
    click Generated "https://github.com/shubhsk88/realbnb-frontend/tree/main/generated/"
    click ComponentsAlgolia "https://github.com/shubhsk88/realbnb-frontend/tree/main/components/Algolia/"
    click StripeWrapper "https://github.com/shubhsk88/realbnb-frontend/blob/main/components/common/StripeWrapper.tsx"
    click BookingCard "https://github.com/shubhsk88/realbnb-frontend/blob/main/components/BookingCard.tsx"
    click BookingDetails "https://github.com/shubhsk88/realbnb-frontend/blob/main/components/BookingDetails.tsx"
    click CheckoutPage "https://github.com/shubhsk88/realbnb-frontend/blob/main/pages/rooms/[roomId]/checkout.tsx"
    click PaymentCard "https://github.com/shubhsk88/realbnb-frontend/blob/main/components/PaymentCard.tsx"
    click CreatePaymentGQL "https://github.com/shubhsk88/realbnb-frontend/blob/main/graphql/reservation/createPayment.graphql"
    click GoogleSignIn "https://github.com/shubhsk88/realbnb-frontend/blob/main/components/Auth/GoogleSignIn.tsx"
    click GoogleLoginGQL "https://github.com/shubhsk88/realbnb-frontend/blob/main/graphql/user/googleLogin.graphql"
    click StartPhoneGQL "https://github.com/shubhsk88/realbnb-frontend/blob/main/graphql/user/startPhoneVerification.graphql"
    click CompletePhoneGQL "https://github.com/shubhsk88/realbnb-frontend/blob/main/graphql/user/completePhoneVerification.graphql"
    click LoginUI "https://github.com/shubhsk88/realbnb-frontend/blob/main/components/Auth/Login.tsx"
    click SignUpUI "https://github.com/shubhsk88/realbnb-frontend/blob/main/components/Auth/SignUp.tsx"
    click CreateUserEmailGQL "https://github.com/shubhsk88/realbnb-frontend/blob/main/graphql/user/createUserViaEmail.graphql"
    click CreateUserPhoneGQL "https://github.com/shubhsk88/realbnb-frontend/blob/main/graphql/user/createUserViaPhone.graphql"
    click EmailLoginGQL "https://github.com/shubhsk88/realbnb-frontend/blob/main/graphql/user/emailLogin.graphql"
    click GetRoomsGQL "https://github.com/shubhsk88/realbnb-frontend/blob/main/graphql/room/getRooms.graphql"
    click GetRoomGQL "https://github.com/shubhsk88/realbnb-frontend/blob/main/graphql/room/getRoom.graphql"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#3399ff,stroke-width:1px;
    classDef backend fill:#ccffcc,stroke:#33cc33,stroke-width:1px;
    classDef external fill:#ffe0b3,stroke:#ff9933,stroke-width:1px;
    classDef db fill:#dddddd,stroke:#888888,stroke-width:1px;
```
