CMS Overview
The CMS (cms.myeasyguide.com) is a standalone Next.js 16 application for editorial content: blog posts, travel guides, destination pages, authors, media, redirects and Claude-powered batch generation. It has its own PostgreSQL database and no shared tables with the commerce API.
What it owns
| Domain | Models / tools |
|---|---|
| Posts | Post, PostCategory, SubCategory, Tag |
| Authors | Author, role and per-area permissions |
| Destinations | City, Country |
| Media | Media, upload, resize, blur, alt-text baking |
| URL management | Post.canonicalUrl, Post.urlHistory, Redirect |
| AI generation | GenerationBatch, prompt templates, Claude Batch API |
| Operations | JSONL audit log, OpenAPI spec |
It does not own activities, suppliers, bookings, payments, reviews or catalog data. Those stay in the Express API and the myeasyguide_prod database.
Admin UI
The editor app lives under /admin; login is at /login.
| Route | Purpose |
|---|---|
/admin/posts | Post list, status filters, trash |
/admin/posts/edit | Create a post |
/admin/posts/edit/[slug] | Edit a post |
/admin/posts/preview/[slug] | Preview rendered content |
/admin/post-categories | Top-level categories |
/admin/subcategories | Subcategories |
/admin/authors | Authors and permissions (super admin) |
/admin/manage-cities | Destination cities |
/admin/manage-countries | Countries |
/admin/media | Media library |
/admin/generate | Submit and inspect AI batches |
/admin/prompts | Prompt templates |
/admin/links | Internal link bank |
/admin/audit-logs | Audit trail (super admin) |
The editor is Tiptap 3.27 and stores sanitised HTML, not a JSON document. The server sanitises content on write, extracts a table of contents into Post.toc, strips absolute image URLs, and removes internal links that are not in the link bank.
Authentication and permissions
POST /api/auth/login verifies the author with bcrypt and sets an httpOnly token cookie for 7 days (SameSite=Lax). Tokens are JWTs signed with jose using JWT_SECRET and carry id, email, role, name and permissions.
Two roles exist:
| Role | Access |
|---|---|
super_admin | Everything, including authors, audit logs, and every post |
author | Only the permissions listed on their row, and only their own posts for edit/delete |
Permissions are area keys, not route strings:
posts, categories, subcategories, generate, prompts,
media, redirects, cities, countriesrequirePermission(key) returns the session for a super admin, or for an author whose permissions array contains the key. requireSuperAdmin() is used for author management and audit logs.
API surface
All admin routes live under /api/* and are protected by requirePermission; public reads are explicitly open.
Public reads
| Method | Endpoint | Purpose |
|---|---|---|
| GET | /api/posts/published | Paginated published posts with search/category/country/city filters |
| GET | /api/posts/public | Lighter public listing, max 50 per page |
| GET | /api/posts/category/:slug | Posts in a category |
| GET | /api/posts/author/:id | Posts by an author |
| GET | /api/posts/:slug | Single post by slug, path, country/category/city |
| GET | /api/posts/resolve/:slug | Resolve any historical or current path |
| GET | /api/redirects/resolve?source=... | Active redirect lookup |
| GET | /api/spec | OpenAPI JSON, CORS-enabled |
Admin content
| Method | Endpoint | Purpose |
|---|---|---|
| GET/POST | /api/posts | List or create |
| PATCH | /api/posts/:slug | Update (by slug, or by id in the body) |
| DELETE | /api/posts/delete/:postId | Trash, or permanent with ?permanent=true |
| PATCH | /api/posts/restore/:id | Restore from trash |
| GET/POST | /api/post-categories | List / create |
| GET/PATCH/DELETE | /api/post-categories/:id | Detail / update / delete |
| GET/POST | /api/subcategories | List / create |
| GET/PATCH/DELETE | /api/subcategories/:id | Detail / update / delete |
| GET/POST | /api/authors | List / create (super admin) |
| PATCH/DELETE | /api/authors/:id | Update / delete (super admin) |
| GET | /api/tags | Tag list |
| GET/POST | /api/cities | List / create |
| GET/PATCH/DELETE | /api/cities/:id | Detail / update / delete |
| GET/POST | /api/countries | List / create |
| GET/PATCH/DELETE | /api/countries/:id | Detail / update / delete |
| GET/POST | /api/redirects | List / create |
| PATCH/DELETE | /api/redirects/:id | Update / delete |
| GET | /api/audit-logs | Audit entries (super admin) |
Media and AI
| Method | Endpoint | Purpose |
|---|---|---|
| GET/POST | /api/media | Library list / register a file |
| GET/PATCH/DELETE | /api/media/:id | Detail / metadata / delete |
| POST | /api/media/upload | Upload a file |
| POST | /api/media/batch | Batch media operation |
| GET | /api/uploads/:filename | Serve with ?w= resize and ?blur |
| GET/POST | /api/generate | List batches / submit topics |
| GET | /api/generate/:id | Batch status |
| POST | /api/generate/:id/process | Turn a finished batch into drafts |
| GET/POST | /api/prompts | List / create prompt templates |
| PATCH/DELETE | /api/prompts/:name | Update / delete a template |
| GET | /api/links/bank | Internal link bank |
Post lifecycle
draft ──▶ scheduled ──(cron, every minute)──▶ published
│ │ │
└──────────────┴──────────────▶ trash ◀─────────┘
│
restore or delete permanentlystatus is a plain string with the values draft, scheduled, published and trash. Publishing sets publishedAt; moving out of published clears it. Scheduling stores scheduledAt.
A Node cron started from instrumentation.ts runs every minute, finds scheduled posts whose scheduledAt has passed, sets them to published, and calls revalidation for each.
URL model
A post's unique identity is its canonicalUrl, not its slug. The same slug may exist in different country/city/category namespaces, so every lookup that knows the full path resolves by canonicalUrl first.
Canonical URLs are assembled from the country handle, city handle, category slug and post slug, skipping the sentinel handle default:
/{countryHandle}/{cityHandle}/{categorySlug}/{slug}When an edit changes the canonical URL, the old value is pushed onto urlHistory[]. resolvePost tries the exact path, its normalised form, then urlHistory. Bare-slug lookup is a legacy fallback and returns no result when a slug is ambiguous.
normalizeCanonicalPath strips default segments and empty slashes. Public listings and sitemaps emit the normalised form, so lookups normalise before comparing.
Scheduled publishing and revalidation
The scheduler runs in the CMS process. On publish (manual or scheduled), triggerRevalidation(slug) posts to:
POST ${FRONTEND_URL}/api/revalidate
x-revalidation-secret: <REVALIDATION_SECRET>
Content-Type: application/json
{ "slug": "post-slug" }The frontend compares the secret with timingSafeEqual, validates the slug, and calls revalidateTag("post-<slug>"). The header is preferred over a query string so the secret stays out of access logs. If REVALIDATION_SECRET is unset, the CMS logs a warning and skips the call.
Media handling
Uploads are stored on disk under public/uploads and served through /api/uploads/:filename, which adds:
?w=800— resize to a maximum width, convert to WebP, cache underpublic/resized?blur— 20px-wide blurred placeholder, cached
Both variants are immutable and cached for a year. Alt text is saved on the media row and also baked into the WebP EXIF/IPTC metadata (skipped for SVG and GIF).
The frontend proxies CMS uploads through its own /uploads/cms/[...path] route and preloads post cover images with a srcset.
Audit log
Creates and updates append one JSON line to logs/audit.jsonl (outside the database). Each entry records the action, entity, post title/slug, changed fields, old/new status, IP, user agent and parsed device info. GET /api/audit-logs reads the file, filters, reverses it newest-first, and paginates in memory. Because it is a flat file, it is per-instance: a multi-instance deployment needs shared storage before the log is a reliable audit trail.
Deployment shape
The CMS is a normal Next.js app: next build then next start. It needs DATABASE_URL, JWT_SECRET, CLAUDE_API_KEY (or ANTHROPIC_API_KEY), CLAUDE_MODEL, FRONTEND_URL and REVALIDATION_SECRET. The scheduler only runs in a long-lived server process, not in a serverless deployment.