How tanjim-islam/homiestay works
1. This repository is an Airbnb-style marketplace built on Next.js App Router. The core domain is centered on users, listings, favorites, reservations, and user-owned properties/trips.
2. The app is split into three main layers: route-level pages under app/, reusable UI components under app/components/, and data-access/server logic under app/actions/, app/api/, and app/libs/.
3. The primary UI shell is app/layout.tsx, which wires global styling, providers, and site-wide chrome like the navbar. Most pages are composed from small, reusable components rather than page-specific markup.
4. Client-side interaction is concentrated in modal and hook systems. Hooks such as useLoginModal, useRegisterModal, useRentModal, useSearchModal, and useFavorite manage shared UI state, while modal components trigger auth, search, and listing-creation flows.
5. Data access is split between server actions and API routes. The app/actions/* files fetch current user, listings, reservations, and favorites for server-rendered pages, while app/api/* exposes CRUD endpoints for listings, reservations, favorites, and registration.
6. The persistent data boundary is Prisma. app/libs/prismadb.ts is the database client, backed by the Prisma schema in prisma/schema.prisma, and all listing/reservation/favorite persistence flows ultimately go through this layer.
7. Authentication is handled separately through NextAuth in pages/api/auth/[...nextauth].ts. Session-aware UI and protected operations rely on this auth layer, and middleware.ts likely enforces access control or redirects for authenticated routes.
8. The main user journeys map cleanly to route groups:
- / for browsing listings
- /listings/[listingId] for a listing detail and reservation view
- /favorites for saved listings
- /trips for guest reservations
- /properties for host-owned listings
- /reservations for host reservation management
9. Listing creation and management are host-centric. The RentModal plus inputs like CategoryInput, CountrySelect, ImageUpload, Counter, and Calendar feed listing metadata into the listings API and Prisma-backed store.
10. Reservation and favorites flows are user-centric. HeartButton and useFavorite toggle saved listings through the favorites endpoints, while ListingReservation and the reservations routes manage date-based booking records.
11. Several browser-only integrations are isolated behind ClientOnly and provider wrappers. Map handles geospatial display, crisp-chat.tsx and crisp-provider.tsx integrate live chat, and ToasterProvider handles user feedback notifications.
12. The component structure is intentionally domain-oriented: navbar, listing, inputs, and modal folders each represent a boundary in the architecture. That makes the diagram easy to draw as a UI shell feeding into feature components, which then call shared hooks and server-backed APIs.
13. Overall data flow: user interaction in client components → shared modal/hook state → server actions or API routes → Prisma/database → updated server-rendered pages or client refreshes. The app is therefore a hybrid server/client Next.js application with a clearly defined auth, persistence, and feature-routing layer.
Main entry points: useSearchModal.ts Hooks · layout.tsx Layout · Modal.tsx Modals · route.ts Listings API
Components 21
App shell
Global layout, shared UI, modals, hooks, and client-only integrations.
- Layout · Global app layout that wires providers, chrome, and shared page structure.
app/layout.tsx - Navbar · Top-level navigation and search entry point.
app/components/navbar/Navbar.tsx - Modals · Shared modal system for login, register, search, and rent flows.
app/components/modals/Modal.tsx - Hooks · Shared UI state for auth, search, rent, favorites, and country selection.
app/hooks/useSearchModal.ts - Client helpers · Client-only wrappers and integrations such as maps, chat, and toasts.
app/components/ClientOnly.tsx
User journeys
Main route-level experiences for browsing, hosting, and reservations.
- Browse · Home route for browsing available listings.
app/page.tsx - Listing detail · Single-listing page with details, map, and booking flow.
app/listings/[listingId]/page.tsx - Favorites · Saved listings experience for the current user.
app/favorites/page.tsx - Trips · Guest-facing reservation history and upcoming stays.
app/trips/page.tsx - Properties · Host-owned listings management view.
app/properties/page.tsx - Reservations · Host reservation management view.
app/reservations/page.tsx
Data layer
Server actions, API routes, and database access.
- Listing actions · Server-side listing fetchers used by rendered pages.
app/actions/getListings.ts - Reservation actions · Server-side reservation fetchers for trips and host reservations.
app/actions/getReservations.ts - Favorite actions · Server-side favorite fetchers used by saved-listing views.
app/actions/getFavoriteListings.ts - Listings API · Create, update, and fetch listing records through route handlers.
app/api/listings/route.ts - Reservations API · Create, update, and delete reservation records through route handlers.
app/api/reservations/route.ts - Favorites API · Favorite add/remove endpoints for a specific listing.
app/api/favorites/[listingId]/route.ts - Register API · User registration endpoint used by the auth modal flow.
app/api/register/route.ts - Prisma DB · Database client boundary for persistence.
app/libs/prismadb.ts
Auth & state
Session handling and access control boundaries.
- NextAuth · Authentication and session handling for protected routes and user-aware UI.
pages/api/auth/[...nextauth].ts - Middleware · Access-control and redirect layer around authenticated routes.
middleware.ts
Connections 22
- Layout → Navbar: renders · The global layout includes the top navigation shell.
- Layout → Modals: mounts · Shared modal overlays are available across the app.
- Layout → Client helpers: wraps · Client-only providers and integrations are initialized here.
- Modals → Hooks: uses · Modal visibility and interaction state are managed by hooks.
- Navbar → Hooks: opens · Navbar actions trigger search and auth modals.
- Browse → Listing actions: loads · Browse page uses server data for listings.
- Listing detail → Listing actions: loads · Listing detail page fetches the selected listing.
- Listing detail → Reservation actions: checks · Reservation info is used to compute booking state.
- Favorites → Favorite actions: loads · Saved listings page fetches favorite items.
- Trips → Reservation actions: loads · Trips page fetches user reservation history.
- Properties → Listing actions: loads · Host properties page is driven by listing data.
- Reservations → Reservation actions: loads · Host reservations page is driven by reservation data.
- Hooks → Listings API: creates · Rent flow submits new listings through the API.
- Hooks → Register API: registers · Auth modal can register new users through the API.
- Hooks → Favorites API: toggles · Favorite hook drives listing favorite state changes.
- Modals → Listings API: submits · Rent modal sends listing metadata to persistence.
- Listings API → Prisma DB: persists · Listings are stored through Prisma.
- Reservations API → Prisma DB: persists · Reservations are stored through Prisma.
- Favorites API → Prisma DB: persists · Favorite relationships are stored through Prisma.
- Register API → NextAuth: authenticates · Registration works alongside the session auth layer.
- Middleware → NextAuth: protects · Route protection is based on authentication state.
- Client helpers → NextAuth: reads session · Client-only UI adapts to authenticated state.