Shop It Docs
Developer ResourcesContent

Content Module Backend Documentation

Data model, validation architecture, and cache behavior for IT Mart CMS pages.

Content Module - Backend Documentation

Scope and Boundaries

The Content module owns:

  • CMS page metadata: pageKey, title, optional seoId
  • CMS section payload CRUD
  • page-to-section compatibility checks
  • page-aware payload validation
  • public read projection with enabled sections only
  • Redis read caching and write-triggered cache invalidation

The Content module does not own listing data for products, categories, brands, reviews, care packages, FAQs, or articles. Those remain in their existing feature modules and are composed by the frontend.

Module Composition

ContentModule composes:

  • ContentAdminModule
  • ContentCustomerModule

ContentSharedModule provides and exports ContentService.

Route ownership:

  • Admin routes live under admin/content/pages
  • Public routes live under content/pages
  • Mobile routes are composed by MobileModule under mobile/content/pages

Database Model

No schema migration is needed for the IT Mart key update. Both key columns are varchar values, not database enums.

content_page

ColumnPurpose
idserial primary key
page_keyunique CMS page key
titleadmin-facing page title
seo_idoptional FK to seo.id, ON DELETE SET NULL
created_at, updated_attimestamps

content_section

ColumnPurpose
idserial primary key
page_idFK to content_page.id, ON DELETE CASCADE
section_keyCMS section key
positionlayout order
is_enabledpublic visibility flag
payload_jsonvalidated JSON payload
created_at, updated_attimestamps

Important constraints:

  • content_page.page_key is unique.
  • (content_section.page_id, content_section.section_key) is unique.
  • Sections sort by position ASC, then id ASC.

Page Registry

Valid IT Mart page keys:

  • home
  • about
  • faq
  • privacy_policy
  • terms_of_service
  • global_footer
  • digital_products
  • repair
  • itmartcare
  • itmartcare_claim
  • itmartcare_detail
  • categories
  • brands
  • articles

Retired copied keys are not valid API params anymore:

  • products_thangkas
  • products_singing_bowls
  • products_statues
  • products_jewellery

Section Registry

CONTENT_SECTIONS_BY_PAGE is the authority for compatibility. Invalid pairs fail before database access with 400 CONTENT_SECTION_KEY_INVALID.

The registry is page-aware because shared section keys can have different contracts:

  • about.hero requires label, heading, subtitle, description, and a main image.
  • digital_products.hero, repair.hero, categories.hero, and brands.hero require heading and description only.
  • itmartcare.hero requires logo, description, and shield image.
  • articles.hero requires heading only.

This avoids weakening validation to a single universal hero shape.

Validation Architecture

Validation happens in two stages:

  1. Param DTO validation:
    • pageKey must be in CONTENT_PAGE_KEYS
    • sectionKey must be in CONTENT_SECTION_KEYS
  2. Service/registry validation:
    • selected section must be allowed for the selected page
    • payloadJson must match the page-specific Zod schema

Shared validators:

  • Tiptap doc fields require type: "doc" and non-empty content[].
  • URL fields allow HTTP(S) URLs or site-relative paths beginning with /.
  • Payload schemas are strict and reject unknown fields.
  • Repeater arrays have bounded min/max sizes.

Privacy policy, terms of service, and FAQ retain their live-compatible payload contracts.

Service Behavior

ContentService owns all business behavior:

MethodBehavior
getPageForAdmincache-aside read; auto-creates missing page
getPageForPubliccache-aside read; missing page returns CONTENT_NOT_FOUND
updatePageMetavalidates non-null seoId, updates page, purges caches, triggers revalidation
upsertSectionvalidates pair and payload, upserts by (pageId, sectionKey), purges caches, triggers revalidation
deleteSectiondeletes existing section, purges caches, triggers revalidation

Controllers stay thin and only unwrap params/body, call the service, and return ResponseDto.

Cache Invalidation

Read cache prefixes:

  • content:page:public:
  • content:page:admin:

Write invalidation happens in two layers:

  1. ContentService.invalidatePageCache(pageKey) directly invalidates the admin and public Redis cache keys for that page.
  2. CacheInvalidationService.triggerForContentWrite(...) invalidates the same content Redis patterns through the centralized purge flow and triggers Next revalidation tags.

New IT Mart shared tags include:

Page keyShared tag
homepage:home
aboutpage:about
faqpage:faq
privacy_policypage:privacy-policy
terms_of_servicepage:terms-of-service
global_footerlayout:footer
digital_productspage:digital-products
repairpage:repair
itmartcarepage:itmartcare
itmartcare_claimpage:itmartcare:claim
itmartcare_detailpage:itmartcare:detail
categoriespage:categories
brandspage:brands
articlespage:articles

Cache failures are fail-open. The module logs warnings and does not roll back successful content writes because Redis/Next purge is recoverable through manual purge or retry.

Error Handling

ScenarioHTTPerrorCode
Missing public page404CONTENT_NOT_FOUND
Missing page or section on delete404CONTENT_NOT_FOUND
Invalid page/section pair400CONTENT_SECTION_KEY_INVALID
Invalid section payload400CONTENT_SECTION_PAYLOAD_INVALID
Unknown non-null SEO id400CONTENT_SEO_NOT_FOUND

Test Coverage

The module has focused coverage for:

  • invalid page/section pairs
  • invalid page-aware payloads
  • representative IT Mart section payloads
  • public/admin cache key generation
  • write-triggered invalidation of public and admin caches
  • centralized content revalidation tags and Redis purge patterns
  • admin and public controller forwarding

Operational Notes

  • Existing database rows with retired copied keys are not deleted by this code change.
  • Those rows are no longer reachable through validated API params.
  • If data cleanup is needed, handle it as a separate explicit data migration or SQL maintenance task.
  • The admin API still auto-creates newly requested valid pages with default IT Mart titles.

See Also