Architecture — Category Master: Three-Level Hierarchy Administration

By Engineering Team•October 9, 2026•6 min read
Metadata Details
System product-catalog — Category Master
Document ID ARCH-2026-PCT-002
Author Engineering Team
Status Approved

Implements SR-024, per the hierarchy-representation decision in ADR-00038.


Components

Component Language/Runtime Role
CategoryPage.tsx / CategoryController.ts React (admin UI) Three-panel cascading tree + Inspector Panel
pages/CategoryRootLeafPage.tsx / CategoryRootLeafController.ts React (admin UI) Level-0 (root) sub-form, hosted in the Add/Edit Drawer
pages/CategorySubcatsLeafPage.tsx / CategorySubcatsLeafController.ts React (admin UI) Level-1 (sub-category) sub-form
pages/CategoryLeafNodesPage.tsx / CategoryLeafNodesController.ts React (admin UI) Level-2 (leaf) sub-form
CategoryRepository.ts React/Axios (admin UI) Sole apiClient consumer for this feature
transport/api/category/ Go (Echo REST) product-catalog’s category controller
service/category/ Go Validation, ancestors computation, children-existence delete guard
repository/category/ Go (MongoDB) categories collection persistence
transport/grpc/category/ Go (gRPC server) CategoryQueryService.GetCategoriesByIDs, read-only
shop-service (gRPC client) Go Resolves category details for storefront display
Product-setup wizard (REST client) React (admin UI) Separate consumer of GET /category/product-categories

End-to-end flow (A) — Create a root category (level 0)

  1. Admin selects “Add Root,” fills pages/CategoryRootLeafPage.tsx’s name/slug/specTemplate fields (SR-024 FR-04), and submits.
  2. CategoryRepository.ts calls POST /product/admin/api/v1/category with nodeLevel = 0, parentId = null.
  3. service/category/Create validates the payload against domain/category_validation.go’s level-0 rules, confirms slug uniqueness (SR-024 FR-07), sets ancestors = [] (a root has none), and inserts the document via repository/category/ (SR-024 FR-09).

End-to-end flow (B) — Create a sub-category (level 1) or leaf category (level 2)

  1. Admin selects the parent node in the panel above, then “Add Sub-Category” or “Add Leaf” — the Drawer hosts CategorySubcatsLeafPage.tsx or CategoryLeafNodesPage.tsx accordingly (SR-024 FR-05/FR-06).
  2. CategoryRepository.ts calls POST /product/admin/api/v1/category with parentId set to the selected parent’s ID and nodeLevel set accordingly (never client-chosen independently of the parent).
  3. service/category/Create reads the parent document, sets the new document’s ancestors = parent.ancestors + [parent.id] (SR-024 FR-09), sets mainDisplayCategory deterministically by level (SR-024 FR-05/FR-06), and inserts the document.

End-to-end flow (C) — Edit, delete, and the two downstream reads

  1. Edit: PUT /product/admin/api/v1/category/:id updates only name/slug/spec_template/display_order/main_display_category/variant_attributes — parentId/nodeLevel/ancestors are immutable after insert (SR-024 FR-08).
  2. Delete: DELETE /product/admin/api/v1/category/:id first checks repository/category/ for any document whose parentId equals the target’s ID; if any exist, the call is rejected rather than deleted (SR-024 FR-10).
  3. Product wizard’s category picker: GET /product/admin/api/v1/category/product-categories returns every leaf category joined with its parent’s variantAttributes — a separate, read-only consumer of this same collection (SR-024 FR-13).
  4. shop-service’s gRPC read: CategoryQueryService.GetCategoriesByIDs resolves category details for the storefront, entirely independent of this console’s REST surface (SR-024 FR-14).

Why this is simple, and what it does not yet guarantee

Computing ancestors once, at insert, and never allowing parentId/nodeLevel to change afterward (per ADR-00038) means no code path anywhere in product-catalog ever has to cascade an ancestor-array correction to a node’s descendants — the array is write-once and trusted thereafter.

This flow does not yet guarantee: (a) a way to move a category to a different parent or level once created — not supported at all, by design, not just unbuilt; (b) any staged-publish lifecycle the way Warehouse Master/Package Master have — active is always true; (c) that description/createdAt/updatedAt, though stored on every document, are ever returned to a caller. All three, plus the admin console’s absent search/filter/pagination and the feature’s missing DEV_MOCK_* fallback, are tracked in Technical Debt — TD-00018.