# yossri21/airbnb-build architecture

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

- Interactive diagram: https://gitdiagram.com/yossri21/airbnb-build
- Repository: https://github.com/yossri21/airbnb-build

## Overview

##### Main Components
- API Layer & Server Components: The project leverages Next.js Route Handlers (“app/api/…”), as well as the older /pages/api directory (which mainly seems to support NextAuth authentication). Represent this as the “API Layer” handling RESTful (or route-based) endpoints for resources like listings, favorites, reservations, register, and auth.
- Business Logic & Actions: The /app/actions folder houses several action files (like getCurrentUser, getFavoriteListings, etc.) which encapsulate core business logic. Include these as a service/logic layer between API endpoints and database operations.
- Third-party Services: External integrations are a significant part:
- Cloudinary (for image upload and CDN).
- NextAuth integrated with Google and Facebook login.
- External location lookup API for location selection and country autocomplete.
As external services linking into the authentication and file-upload parts of your architecture.

##### Components’ Relationships and Data Flow
- The Client (browser) interacts with the Next.js frontend which renders pages using Server Components and standard React components.
- Requests from the Client are routed to the API Layer. For example, listing data is fetched via endpoints in “app/api/listings” or reservation endpoints in “app/api/reservations”.
- The API Layer delegates calls to business logic in the actions folder, and then uses the Prisma client (via lib/prismadb.ts) to interact with MongoDB.
- Authentication requests flow through the “pages/api/auth” endpoint, which is handled by NextAuth.
- Image uploads and cloud storage interactions pass through Cloudinary integrations.
- Third-party APIs (Google, Facebook, IP lookup, etc.) are invoked during the authentication flow and location selection.

##### Architectural Patterns & Design Principles
- The project follows a modern full-stack pattern where the presentation layer (Next.js frontend) is closely tied to an integrated API backend.
- It leverages the new “app” directory of Next.js 13, using Server Components and App Routing (note the layout.tsx, loading.tsx, etc.).
- Separation of concerns is evident in the clear organization: UI components (/components and subfolders), business logic (/app/actions), API routes (/app/api and /pages/api), and persistence (/prisma schema, lib folder).

##### Technologies & Frameworks
- Next.js 13 with the new App Router for both client-side rendering and server-side rendering.
- Typescript for type-safety.
- Tailwind CSS for styling.
- Prisma as the ORM connecting to MongoDB.
- NextAuth for authentication with Google and Facebook.
- Other libraries such as Framer-motion for animations, Cloudinary for image hosting, etc.

##### Putting It All Together
- Below that, represent the API layer:
- Two API sources: one modern Next.js “app/api” for resource handling and the “pages/api” directory for authentication.
- From the API layer, show a connection to the “Business Logic” (the actions inside /app/actions).
- Business Logic to the Database component (MongoDB / Prisma, referenced in /prisma/schema.prisma and /lib/prismadb.ts).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Layer
    subgraph "Client Layer"
        FE["Next.js Frontend"]:::frontend
        UI["UI Components"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        API1["Modern API Endpoints"]:::backend
        API2["Authentication API"]:::backend
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        BL["Business Logic Actions"]:::logic
    end

    %% Data Layer
    subgraph "Data Layer"
        DB1["Database Schema"]:::database
        DB2["Database Client"]:::database
    end

    %% External Integrations
    subgraph "External Integrations"
        EXT1["Auth Providers (Google,Facebook)"]:::external
        EXT2["Cloudinary Service"]:::external
    end

    %% Connections
    FE -->|"fetchesData"| API1
    API1 -->|"delegatesTo"| BL
    API2 -->|"processesAuth"| BL
    BL -->|"performsCRUD"| DB1
    BL -->|"performsCRUD"| DB2
    API1 -->|"handlesImageUpload"| EXT2
    API2 -->|"invokesAuthProvider"| EXT1
    UI -->|"triggersUIInteraction"| FE

    %% Click Events
    click FE "https://github.com/yossri21/airbnb-build/tree/master//app"
    click UI "https://github.com/yossri21/airbnb-build/tree/master//components"
    click API1 "https://github.com/yossri21/airbnb-build/tree/master//app/api"
    click API2 "https://github.com/yossri21/airbnb-build/blob/master//pages/api/auth/[...nextauth].ts"
    click BL "https://github.com/yossri21/airbnb-build/tree/master//app/actions"
    click DB1 "https://github.com/yossri21/airbnb-build/blob/master//prisma/schema.prisma"
    click DB2 "https://github.com/yossri21/airbnb-build/blob/master//lib/prismadb.ts"
    click EXT1 "https://github.com/yossri21/airbnb-build/blob/master//pages/api/auth/[...nextauth].ts"
    click EXT2 "https://github.com/yossri21/airbnb-build/blob/master//components/inputs/ImageUpload.tsx"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,stroke-width:2px;
    classDef backend fill:#E1BEE7,stroke:#4A148C,stroke-width:2px;
    classDef logic fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
    classDef database fill:#FFF9C4,stroke:#F57F17,stroke-width:2px;
    classDef external fill:#FFCCBC,stroke:#BF360C,stroke-width:2px;
```
