Shop It Docs
Developer ResourcescatalogCategory

Category Module Feature List

Category feature contract for admin and customer/mobile catalog surfaces.

Category Module - Feature List

1. Feature Overview

The category submodule manages hierarchical product grouping, storefront visibility, and slug continuity. It supports admin CRUD/reorder and public category browse/detail reads.

2. Route Ownership and Surfaces

  • Admin controller: apps/api/src/modules/catalog/admin/category/category-admin.controller.ts
    • Base path: /api/admin/categories
  • Customer controller: apps/api/src/modules/catalog/customer/category/category-customer.controller.ts
    • Base path: /api/categories
  • Mobile composition: apps/api/src/modules/mobile/mobile.module.ts
    • Same customer controller additionally exposed as /api/mobile/categories

3. Admin Feature Matrix

FeatureBehavior
List categoriesFilter/search/sort/paginate
Get categoryNumeric :id lookup
Create categoryValidates parent depth and slug generation
Update categorySupports slug updates with history capture
Delete categoryBlocked when child categories exist
Reorder categoriesBatch reorder via POST /admin/categories/reorder

4. Customer/Mobile Feature Matrix

FeatureBehavior
Visible category listDefaults isVisible=true
Category by slugResolves current slug first, then category_slug_history
Optional filteringparentId, search, sorting, pagination
Public accessEndpoint marked @Public()

5. Key Business Rules

  • A category cannot be its own parent.
  • Category trees cannot exceed depth 3.
  • Moving a category into its descendant is rejected.
  • Delete is blocked when child categories exist.
  • Slug changes write previous slug to category_slug_history.

6. State Models

Category tree model

  • Root category: parentId = null
  • Child category: parentId = <category.id>
  • Depth cap: 3 levels

Visibility model

  • isVisible=true: included in storefront browse
  • isVisible=false: excluded by default customer query behavior

7. Caching Strategy

Key PrefixUsed For
catalog:categories:list:Customer list cache
catalog:category:slug:Detail-by-slug cache

TTL resolution in customer service:

  • CATALOG_CATEGORY_CACHE_TTL_SECONDS
  • fallback CATALOG_CACHE_TTL_SECONDS
  • fallback REDIS_CACHE_TTL_SECONDS

Admin invalidates:

  • catalog:categories:visible*
  • catalog:categories:list:*
  • catalog:category:slug:*

8. Rate Limiting

No explicit per-endpoint rate limiter is implemented in category controllers in this subphase.

9. Queue/Worker Features

No BullMQ queue or background worker flow is implemented for categories in this scope.

10. Error UX Mapping

errorCodeTypical UX Handling
CATEGORY_NOT_FOUNDShow not-found state for detail/edit pages
CATEGORY_SELF_PARENTInline parent-field validation error
CATEGORY_MOVE_TO_DESCENDANTBlock parent change and prompt valid parent
CATEGORY_MISSING_PARENTPrompt admin to select existing parent
CATEGORY_DEPTH_EXCEEDEDExplain max depth (3) in form validation
CATEGORY_HAS_CHILDRENShow conflict modal before delete
CATEGORY_DUPLICATE_IDSPrompt reorder payload correction
CATEGORY_INVALID_SORTReset to default sort in client

11. Integration Flows

11.1 Category Tree Creation Flow

An admin creates a hierarchical category structure with depth validation.

  1. Admin calls POST /api/admin/categories to create root category (no parent).
  2. System generates slug and writes to category_slug_history.
  3. Admin calls POST /api/admin/categories to create child category with valid parentId.
  4. System validates parent depth < 3 and rejects if depth would exceed limit.
  5. Admin calls POST /api/admin/categories/reorder to adjust display order within same level.

11.2 Customer Category Browse Flow

A customer browses categories on the storefront for product discovery.

  1. Customer calls GET /api/categories to list visible categories (isVisible=true).
  2. Customer calls GET /api/categories?parentId=X to browse child categories.
  3. Customer calls GET /api/categories/:slug to view category detail.
  4. System resolves current slug first, then falls back to category_slug_history for legacy URLs.
  5. Customer can filter products by category ID on product list endpoint.

11.3 Category Restructuring Flow

An admin moves a category to a new parent with validation.

  1. Admin calls PATCH /api/admin/categories/:id with new parentId.
  2. System validates: category cannot be its own parent.
  3. System validates: moving to new parent does not create a cycle (category cannot become descendant of itself).
  4. System validates: resulting depth < 3.
  5. On slug change, system writes previous slug to category_slug_history.

12. Release/QA Checklist

  • Verify admin CRUD + reorder under Categories_* permissions.
  • Verify depth/cycle guards for create and update.
  • Verify slug-history resolution for old category URLs.
  • Verify visibility defaults on customer/mobile list.
  • Verify cache invalidation after create/update/delete/reorder.

See Also