Skip to content

Architecture ​

System Diagram ​

┌─────────────────────────────────────────────────────────────────────────┐
│                          myeasyguide.com                                │
│                    Next.js 15.5 — Public Frontend                       │
│                                                                          │
│   Serves: Visitors, Travelers, Suppliers, Authors, Admins                │
│   Port (dev): 3001                                                       │
└──────────────┬──────────────────────────────┬───────────────────────────┘
               │                              │
               │  NEXT_PUBLIC_API_BASE_URL     │  NEXT_PUBLIC_POST_URL
               │  (API calls + /api/v1         │  (direct CMS reads)
               │   rewrites, proxied)          │
               ▼                              ▼
┌──────────────────────────────┐  ┌──────────────────────────────────────┐
│   api.myeasyguide.com        │  │   cms.myeasyguide.com                │
│   Express 5 — REST API       │  │   Next.js 16 — CMS                  │
│                              │  │                                      │
│   DB: myeasyguide_prod       │  │   DB: cms_myeasyguide                │
│   (PostgreSQL + Prisma 7)    │  │   (PostgreSQL + Prisma 7)            │
│                              │  │                                      │
│   ■ Activities/departures    │  │   ■ Posts / categories               │
│   ■ Catalog (locations,      │  │   ■ Authors / permissions            │
│     categories, keywords,    │  │   ■ AI generation (Claude)           │
│     food, transport, etc.)   │  │   ■ Media library / uploads          │
│   ■ Users / suppliers / auth │  │   ■ Cities / countries / tags        │
│   ■ Bookings / payments      │  │   ■ Redirects / audit log            │
│   ■ Reviews / wishlists      │  │   ■ OpenAPI spec                     │
│   ■ Newsletter / inquiries   │  │                                      │
│   ■ Payouts / revenue        │  │                                      │
│   ■ Legal pages / media      │  │                                      │
│   ■ Recombee / popularity    │  │                                      │
└──────────────────────────────┘  └──────────────────────────────────────┘

Data Flow ​

Guest-facing content ​

  1. Activities, suppliers, bookings, payments, reviews — The frontend fetches commerce data from api.myeasyguide.com via NEXT_PUBLIC_API_BASE_URL. Next.js rewrites() in next.config.ts proxy /api/v1/:path* to the Express backend and normalise duplicate /api//api/v1 suffixes.

  2. Blog posts, travel guides, locations/countries — The frontend fetches content directly from cms.myeasyguide.com via NEXT_PUBLIC_POST_URL (default https://cms.myeasyguide.com). The CMS runs independently with its own database.

  3. Search — The search page queries both backends in parallel: CMS posts and Express activities.

  4. Images — CMS uploads are served by the CMS, with resize (?w=), LQIP (?blur) and a disk cache. The frontend proxies them through /uploads/cms/[...path]. Activity images use Cloudflare Images (and the frontend imageLoader).

  5. Sitemap — next-sitemap + custom scripts fetch CMS posts/locations to build sitemaps.

  6. Revalidation — When CMS publishes/updates a post, it calls the frontend POST /api/revalidate with x-revalidation-secret to refresh cached pages.

Admin content ​

  • Platform admin — The frontend has admin routes under app/admin/ for activities, suppliers, users, bookings, revenue, payouts, legal pages, etc. via the Express API.
  • Content admin — The CMS has its own admin at app/admin/ for posts/categories/authors/media/redirects/AI generation.

URL Routing ​

The frontend uses a catch-all route [...slug]. Resolution order:

Request: /nepal/pokhara/trekking/everest-base-camp-trek-abc123

1. Exact CMS lookup by canonicalUrl (getPostByPath) → render post
2. Exact activity lookup by canonicalPath (getActivityByPath) → render activity
3. Category / country / city / location landing page
4. Trip-category page
5. 404

Examples:

URLResolves to
/travel-guide/best-time-to-visitCMS post (canonicalUrl)
/nepal/pokhara/trekking/everest-base-camp-trek-123Activity (canonicalPath)
/nepalCountry/location page
/pokharaCity/location page
/nepal/trekkingCategory page
/pokhara/trekkingTrip-category page

The frontend's middleware applies the CMS Redirect table (301/302 via /api/redirects/resolve). Post-level canonical and urlHistory redirects are resolved by the catch-all route by full canonical path before rendering, so they are not guessed from bare slugs.

Database Independence ​

The API and CMS use completely separate PostgreSQL databases:

PropertyAPICMS
Database namemyeasyguide_prodcms_myeasyguide
Hostlocalhostlocalhost
Port54325432

There are no cross-database foreign keys or direct database-level communication. They share the same Postgres instance but operate on separate databases.

Key Architectural Decisions ​

Normalised catalog instead of flat activity columns ​

The API used to store location/category/type as flat fields on Activity. It now uses a normalised catalog:

  • Location tree (LocationType, parent/child, locationAncestors denormalised for filtering)
  • Category, Keyword
  • FoodType / FoodFormat / DietaryRestriction
  • TransportType, SuitabilityConcern, ActivityRestriction, MandatoryItem

This supports faceted filtering, reusable catalog management, and location hierarchies without duplicating text.

Why split the CMS from the API? ​

Blog management originally lived inside the Express API. As content needs grew:

  • Blog CRUD competed with commerce endpoints for resources
  • Editors needed rich text, scheduling, AI generation, media tools
  • Content deployments were tied to API restarts
  • Editors authenticated through the same system as suppliers

The CMS was extracted as a standalone Next.js app with its own database, admin UI, API layer, permissions, and scheduler.

Payments are fulfilled idempotently ​

Stripe webhooks and the frontend status poll can both confirm a booking. The confirm transaction uses a conditional updateMany on PENDING_PAYMENT so only one path wins and emails are sent once. Expired/cancelled sessions release the held departure spots.

Why not a monolith? ​

The project started as a monolith. The editorial extraction is part of splitting concerns. Future migrations may move more admin domains out of the Express API.

Built with VitePress