How shahadat-hossain99/trailnest-client works
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: explore/page.tsx Explore listings · [id]/page.tsx Listing detail · layout.tsx Application shell · auth.ts BetterAuth configuration
Components 21
Next.js App Router
Public, discovery, and authenticated product routes.
- Application shell
src/app/layout.tsx - Marketing routes · Informational pages and application fallbacks.
src/app/(informational)/about/page.tsx - Support routes
src/app/(support)/help/page.tsx - Explore listings · Filtered, paginated grid and map browsing.
src/app/explore/page.tsx - Listing detail · Loads a listing and hosts its interactive detail UI.
src/app/explore/[id]/page.tsx - Listing contracts · Shared listing API and UI shapes.
src/types/listing.ts - Browse map · Multi-pin map for search results.
src/components/Listing/ListingsMap.tsx - Listing location map · Single-listing location display.
src/components/Listing/ListingMap.tsx - Booking modal · Checks dates and submits reservations.
src/components/Listing/BookingModal.tsx - Create listing
src/app/add-listing/page.tsx - Manage listings · Owner inventory edit and delete controls.
src/app/my-listings/MyListingsClient.tsx - My bookings
src/app/my-bookings/MyBookingsClient.tsx - Profile analytics
src/app/profile/ProfileClient.tsx - Settings
src/app/settings/SettingsClient.tsx
Authentication
BetterAuth route and session integration.
- Auth catch-all route · Serves BetterAuth operations.
src/app/api/auth/[...all]/route.ts - Server auth integration
src/lib/core/auth-server.ts - Auth client · Obtains sessions and bearer tokens for protected UI.
src/lib/auth-client.ts - BetterAuth configuration
src/lib/auth.ts
External Services
Systems outside the frontend runtime.
- Express marketplace API · Owns marketplace data, authorization, and booking conflict enforcement.
- MongoDB auth storage · Shared BetterAuth session storage.
- ImgBB · Receives listing images directly from the client.
Connections 23
- 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