Skip to content

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 ​

DomainModels / tools
PostsPost, PostCategory, SubCategory, Tag
AuthorsAuthor, role and per-area permissions
DestinationsCity, Country
MediaMedia, upload, resize, blur, alt-text baking
URL managementPost.canonicalUrl, Post.urlHistory, Redirect
AI generationGenerationBatch, prompt templates, Claude Batch API
OperationsJSONL 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.

RoutePurpose
/admin/postsPost list, status filters, trash
/admin/posts/editCreate a post
/admin/posts/edit/[slug]Edit a post
/admin/posts/preview/[slug]Preview rendered content
/admin/post-categoriesTop-level categories
/admin/subcategoriesSubcategories
/admin/authorsAuthors and permissions (super admin)
/admin/manage-citiesDestination cities
/admin/manage-countriesCountries
/admin/mediaMedia library
/admin/generateSubmit and inspect AI batches
/admin/promptsPrompt templates
/admin/linksInternal link bank
/admin/audit-logsAudit 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:

RoleAccess
super_adminEverything, including authors, audit logs, and every post
authorOnly the permissions listed on their row, and only their own posts for edit/delete

Permissions are area keys, not route strings:

ts
posts, categories, subcategories, generate, prompts,
media, redirects, cities, countries

requirePermission(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 ​

MethodEndpointPurpose
GET/api/posts/publishedPaginated published posts with search/category/country/city filters
GET/api/posts/publicLighter public listing, max 50 per page
GET/api/posts/category/:slugPosts in a category
GET/api/posts/author/:idPosts by an author
GET/api/posts/:slugSingle post by slug, path, country/category/city
GET/api/posts/resolve/:slugResolve any historical or current path
GET/api/redirects/resolve?source=...Active redirect lookup
GET/api/specOpenAPI JSON, CORS-enabled

Admin content ​

MethodEndpointPurpose
GET/POST/api/postsList or create
PATCH/api/posts/:slugUpdate (by slug, or by id in the body)
DELETE/api/posts/delete/:postIdTrash, or permanent with ?permanent=true
PATCH/api/posts/restore/:idRestore from trash
GET/POST/api/post-categoriesList / create
GET/PATCH/DELETE/api/post-categories/:idDetail / update / delete
GET/POST/api/subcategoriesList / create
GET/PATCH/DELETE/api/subcategories/:idDetail / update / delete
GET/POST/api/authorsList / create (super admin)
PATCH/DELETE/api/authors/:idUpdate / delete (super admin)
GET/api/tagsTag list
GET/POST/api/citiesList / create
GET/PATCH/DELETE/api/cities/:idDetail / update / delete
GET/POST/api/countriesList / create
GET/PATCH/DELETE/api/countries/:idDetail / update / delete
GET/POST/api/redirectsList / create
PATCH/DELETE/api/redirects/:idUpdate / delete
GET/api/audit-logsAudit entries (super admin)

Media and AI ​

MethodEndpointPurpose
GET/POST/api/mediaLibrary list / register a file
GET/PATCH/DELETE/api/media/:idDetail / metadata / delete
POST/api/media/uploadUpload a file
POST/api/media/batchBatch media operation
GET/api/uploads/:filenameServe with ?w= resize and ?blur
GET/POST/api/generateList batches / submit topics
GET/api/generate/:idBatch status
POST/api/generate/:id/processTurn a finished batch into drafts
GET/POST/api/promptsList / create prompt templates
PATCH/DELETE/api/prompts/:nameUpdate / delete a template
GET/api/links/bankInternal link bank

Post lifecycle ​

text
draft ──▶ scheduled ──(cron, every minute)──▶ published
  │              │                                │
  └──────────────┴──────────────▶ trash ◀─────────┘
                                    │
                              restore or delete permanently

status 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:

text
/{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:

http
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 under public/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.

Built with VitePress