Worklog for task "Add web page mechanics"

10 июл. 2026 г., 17:34:10

Custom URL Routing System (SiteRoute)

Task

Implement a flexible routing system that allows assigning arbitrary URLs to content. Instead of technical paths like /concepts/clxyz123abc β€” human-readable /articles/my-first-post.

Architectural Decision

A fallback routing approach at the Next.js level was chosen. All requests to non-existent pages are intercepted by a single entry point, which resolves the path via the database.

Why this way:

  • Does not require static regeneration when adding new routes
  • Hierarchical structure via parentId β€” allows building nested paths of any depth
  • 1:1 relation with content eliminates duplicates and canonicalization issues

Implementation

Database β€” a new SiteRoute model:

  • path β€” full path (unique index)
  • slug β€” path segment
  • parentId β€” reference to the parent for hierarchy
  • kBConceptId β€” link to the knowledge base concept
  • Compound index parentId + slug ensures slug uniqueness within a parent

Next.js β€” fallback rewrite in next.config.js redirects /:path* to /_fallback/[...path].tsx.

Handler β€” receives the current path, queries SiteRoute via GraphQL, renders the corresponding page or returns a 404.

Virtual uri field β€” added to KBConcept at the GraphQL schema level. Returns a custom path if a SiteRoute exists, otherwise the standard /concepts/{id}. All link components automatically use this field.

Technical Details

  • GraphQL resolvers: siteRoute, siteRoutes, createSiteRoute
  • Components: ConceptLink, PostLink, TaskLink, WorkLogLink
  • SEO headers: canonical URL is generated from uri
  • Server-side data preload for SSR

Result

The haih-agent engine has received a full-fledged SEF (search-engine-friendly) URL system with hierarchy support, no URL structure limitations, and automatic integration into all existing components.

10.07.2026