# shahadat-hossain99/trailnest-client architecture

> Architecture diagram of the GitHub repository shahadat-hossain99/trailnest-client, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shahadat-hossain99/trailnest-client
- Repository: https://github.com/shahadat-hossain99/trailnest-client

## Overview

#### Purpose and Runtime
TrailNest is the Next.js 16 frontend for an outdoor campsite and gear-rental marketplace. It renders public discovery content plus authenticated listing, booking, and account workflows. The separate Express/MongoDB API owns marketplace data and booking enforcement; this app also hosts BetterAuth route handling and session integration.

Key entry points: `src/app/layout.tsx`, `src/app/page.tsx`, `src/app/api/auth/[...all]/route.ts`.

#### Application Shell and Routing
The App Router organizes the product into public marketing/support route groups, discovery routes, and authenticated workspaces. Root loading, error, 404, and authorization-status routes provide application-level fallbacks.

Paths: `src/app/(informational)/about/page.tsx`, `src/app/(support)/help/page.tsx`, `src/app/error.tsx`.

#### Authentication Boundary
BetterAuth is configured for server and client contexts, with a catch-all Next route serving auth operations. Protected UI obtains a session token and sends it as a Bearer token to the external API; the backend independently validates it against shared BetterAuth/MongoDB session data.

Paths: `src/lib/auth.ts`, `src/lib/auth-client.ts`, `src/lib/core/auth-server.ts`.

#### Listing Discovery and Detail
`/explore` is the primary browsing surface: it retrieves filtered/paginated listings and presents grid and map views. Dynamic `/explore/[id]` resolves an individual listing and delegates interactive detail behavior to a client component. Listing domain contracts centralize API/UI shapes.

Paths: `src/app/explore/page.tsx`, `src/app/explore/[id]/page.tsx`, `src/types/listing.ts`.

#### Maps, Search, and Listing Presentation
Leaflet-backed components form the geographic boundary: a multi-pin map supports browse results, while a single-listing map displays location. Cards, skeletons, and debounce behavior support responsive filtered discovery while remote results are in flight.

Paths: `src/components/Listing/ListingsMap.tsx`, `src/components/Listing/ListingMap.tsx`, `src/components/Listing/ListingCard.tsx`.

#### Booking and Ownership Workflows
Booking starts from the listing detail modal, checks confirmed date ranges through the API, then submits protected reservations. Owners create listings, upload images directly to ImgBB, and manage their inventory through edit/delete controls. The API is the authority for date-conflict checks and owner-only mutations.

Paths: `src/components/Listing/BookingModal.tsx`, `src/app/add-listing/page.tsx`, `src/app/my-listings/MyListingsClient.tsx`.

#### Account Workspaces and External Services
Authenticated users manage reservations, profile analytics, and settings through client-facing dashboard components. The UI relies on the external Express API (`NEXT_PUBLIC_API_URL`), MongoDB-backed BetterAuth storage, ImgBB uploads, and Vercel deployment. Leaflet, Recharts, Sonner, and Tailwind provide maps, analytics, notifications, and styling.

Paths: `src/app/my-bookings/MyBookingsClient.tsx`, `src/app/profile/ProfileClient.tsx`, `src/app/settings/SettingsClient.tsx`.

Main entry points: [`src/app/explore/page.tsx`](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/explore/page.tsx) (Explore listings), [`src/app/explore/[id]/page.tsx`](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/explore/%5Bid%5D/page.tsx) (Listing detail), [`src/app/layout.tsx`](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/layout.tsx) (Application shell), [`src/lib/auth.ts`](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/lib/auth.ts) (BetterAuth configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Next.js App Router"]
  node_shell["Application shell<br/>Next.js layout<br/>[layout.tsx]"]
  node_public["Marketing routes<br/>public pages<br/>[page.tsx]"]
  node_support["Support routes<br/>support pages<br/>[page.tsx]"]
  node_discovery["Explore listings<br/>discovery route<br/>[page.tsx]"]
  node_listing_detail["Listing detail<br/>dynamic route<br/>[page.tsx]"]
  node_listing_contracts["Listing contracts<br/>domain types<br/>[listing.ts]"]
  node_browse_map["Browse map<br/>Leaflet component<br/>[ListingsMap.tsx]"]
  node_listing_map["Listing location map<br/>Leaflet component<br/>[ListingMap.tsx]"]
  node_booking["Booking modal<br/>booking UI<br/>[BookingModal.tsx]"]
  node_create_listing["Create listing<br/>owner workspace<br/>[page.tsx]"]
  node_manage_listings["Manage listings<br/>owner workspace"]
  node_my_bookings["My bookings<br/>account workspace"]
  node_profile["Profile analytics<br/>account workspace<br/>[ProfileClient.tsx]"]
  node_settings["Settings<br/>account workspace<br/>[SettingsClient.tsx]"]
end

subgraph group_auth["Authentication"]
  node_auth_route{{"Auth catch-all route<br/>Next route handler<br/>[route.ts]"}}
  node_auth_server["Server auth integration<br/>auth server layer<br/>[auth-server.ts]"]
  node_auth_client["Auth client<br/>session client<br/>[auth-client.ts]"]
  node_betterauth["BetterAuth configuration<br/>[auth.ts]"]
end

subgraph group_external["External Services"]
  node_marketplace_api{{"Express marketplace API<br/>external API"}}
  node_auth_mongo[("MongoDB auth storage<br/>database")]
  node_imgbb["ImgBB<br/>image upload service"]
end

node_shell -->|"renders"| node_public
node_shell -->|"renders"| node_support
node_shell -->|"hosts"| node_discovery
node_discovery -->|"fetches filtered listings"| node_marketplace_api
node_discovery -->|"renders results on"| node_browse_map
node_discovery -->|"uses"| node_listing_contracts
node_discovery -->|"opens"| node_listing_detail
node_listing_detail -->|"fetches listing"| node_marketplace_api
node_listing_detail -->|"renders"| node_listing_map
node_listing_detail -->|"starts booking"| node_booking
node_booking -->|"checks dates and reserves"| node_marketplace_api
node_create_listing -->|"uploads images"| node_imgbb
node_create_listing -->|"creates listing"| node_marketplace_api
node_manage_listings -->|"edits and deletes"| node_marketplace_api
node_my_bookings -->|"manages reservations"| node_marketplace_api
node_profile -->|"loads analytics"| node_marketplace_api
node_settings -->|"updates account"| node_marketplace_api
node_auth_route -->|"handles via"| node_betterauth
node_betterauth -->|"stores sessions"| node_auth_mongo
node_auth_server -->|"integrates"| node_betterauth
node_auth_client -->|"uses session operations"| node_auth_route
node_auth_client -->|"sends bearer token"| node_marketplace_api
node_marketplace_api -.->|"validates shared sessions"| node_auth_mongo

click node_shell "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/layout.tsx"
click node_public "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/(informational)/about/page.tsx"
click node_support "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/(support)/help/page.tsx"
click node_discovery "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/explore/page.tsx"
click node_listing_detail "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/explore/%5Bid%5D/page.tsx"
click node_listing_contracts "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/types/listing.ts"
click node_browse_map "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/components/Listing/ListingsMap.tsx"
click node_listing_map "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/components/Listing/ListingMap.tsx"
click node_booking "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/components/Listing/BookingModal.tsx"
click node_create_listing "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/add-listing/page.tsx"
click node_manage_listings "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/my-listings/MyListingsClient.tsx"
click node_my_bookings "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/my-bookings/MyBookingsClient.tsx"
click node_profile "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/profile/ProfileClient.tsx"
click node_settings "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/settings/SettingsClient.tsx"
click node_auth_route "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/api/auth/%5B...all%5D/route.ts"
click node_auth_server "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/lib/core/auth-server.ts"
click node_auth_client "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/lib/auth-client.ts"
click node_betterauth "https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/lib/auth.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_shell,node_public,node_support,node_discovery,node_listing_detail,node_listing_contracts,node_browse_map,node_listing_map,node_booking,node_create_listing,node_manage_listings,node_my_bookings,node_profile,node_settings toneBlue
class node_auth_route,node_auth_server,node_auth_client,node_betterauth toneAmber
class node_marketplace_api,node_auth_mongo,node_imgbb toneMint
```

## Components

### Next.js App Router

Public, discovery, and authenticated product routes.

- [Application shell](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/layout.tsx): Next.js layout · `src/app/layout.tsx`
- [Marketing routes](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/(informational)/about/page.tsx): public pages · Informational pages and application fallbacks. · `src/app/(informational)/about/page.tsx`
- [Support routes](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/(support)/help/page.tsx): support pages · `src/app/(support)/help/page.tsx`
- [Explore listings](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/explore/page.tsx): discovery route · Filtered, paginated grid and map browsing. · `src/app/explore/page.tsx`
- [Listing detail](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/explore/%5Bid%5D/page.tsx): dynamic route · Loads a listing and hosts its interactive detail UI. · `src/app/explore/[id]/page.tsx`
- [Listing contracts](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/types/listing.ts): domain types · Shared listing API and UI shapes. · `src/types/listing.ts`
- [Browse map](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/components/Listing/ListingsMap.tsx): Leaflet component · Multi-pin map for search results. · `src/components/Listing/ListingsMap.tsx`
- [Listing location map](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/components/Listing/ListingMap.tsx): Leaflet component · Single-listing location display. · `src/components/Listing/ListingMap.tsx`
- [Booking modal](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/components/Listing/BookingModal.tsx): booking UI · Checks dates and submits reservations. · `src/components/Listing/BookingModal.tsx`
- [Create listing](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/add-listing/page.tsx): owner workspace · `src/app/add-listing/page.tsx`
- [Manage listings](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/my-listings/MyListingsClient.tsx): owner workspace · Owner inventory edit and delete controls. · `src/app/my-listings/MyListingsClient.tsx`
- [My bookings](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/my-bookings/MyBookingsClient.tsx): account workspace · `src/app/my-bookings/MyBookingsClient.tsx`
- [Profile analytics](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/profile/ProfileClient.tsx): account workspace · `src/app/profile/ProfileClient.tsx`
- [Settings](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/settings/SettingsClient.tsx): account workspace · `src/app/settings/SettingsClient.tsx`

### Authentication

BetterAuth route and session integration.

- [Auth catch-all route](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/app/api/auth/%5B...all%5D/route.ts): Next route handler · Serves BetterAuth operations. · `src/app/api/auth/[...all]/route.ts`
- [Server auth integration](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/lib/core/auth-server.ts): auth server layer · `src/lib/core/auth-server.ts`
- [Auth client](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/lib/auth-client.ts): session client · Obtains sessions and bearer tokens for protected UI. · `src/lib/auth-client.ts`
- [BetterAuth configuration](https://github.com/shahadat-hossain99/trailnest-client/blob/main/src/lib/auth.ts): auth configuration · `src/lib/auth.ts`

### External Services

Systems outside the frontend runtime.

- **Express marketplace API**: external API · Owns marketplace data, authorization, and booking conflict enforcement.
- **MongoDB auth storage**: database · Shared BetterAuth session storage.
- **ImgBB**: image upload service · Receives listing images directly from the client.

## Connections

- Application shell → Marketing routes: renders
- Application shell → Support routes: renders
- Application shell → Explore listings: hosts
- Explore listings → Express marketplace API: fetches filtered listings
- Explore listings → Browse map: renders results on
- Explore listings → Listing contracts: uses
- Explore listings → Listing detail: opens
- Listing detail → Express marketplace API: fetches listing
- Listing detail → Listing location map: renders
- Listing detail → Booking modal: starts booking
- Booking modal → Express marketplace API: checks dates and reserves
- Create listing → ImgBB: uploads images
- Create listing → Express marketplace API: creates listing
- Manage listings → Express marketplace API: edits and deletes
- My bookings → Express marketplace API: manages reservations
- Profile analytics → Express marketplace API: loads analytics
- Settings → Express marketplace API: updates account
- Auth catch-all route → BetterAuth configuration: handles via
- BetterAuth configuration → MongoDB auth storage: stores sessions
- Server auth integration → BetterAuth configuration: integrates
- Auth client → Auth catch-all route: uses session operations
- Auth client → Express marketplace API: sends bearer token
- Express marketplace API → MongoDB auth storage: validates shared sessions
