Commerce Platform Blueprint¶
This folder turns the high-level "how Zomato / Zepto / Flipkart-style systems work" idea into a buildable backend blueprint for AIERP.
The current repository is a frontend POS application, so the right implementation here is:
- target service architecture
- POS / ERP integration model
- event contracts
- API contracts for the UI
- phased rollout plan
If you later split backend services into their own repos, these docs can become the source of truth for those repos.
Repo-Specific Blueprint¶
For the current multi-repo workspace, use this alongside the higher-level docs:
repo-refactor-blueprint.mdfor exact ownership, schema, events, and migration steps acrosscatalog-service,store-hub,api-gateway,sync-service, andretail-agent
What We Are Building¶
We want a platform that can support:
- restaurant menu sync from POS systems
- dark-store inventory sync from ERP / warehouse systems
- fast catalog serving for the POS and commerce apps
- real-time price and stock updates
- search and recommendations
- LLM-powered enrichment on top of raw supplier / seller data
Core Principles¶
- Source systems remain authoritative.
- Updates should be push-first, not polling-first.
- All writes should become events.
- Serving APIs should read from optimized views, not transactional raw tables.
- Search, pricing, inventory, and enrichment should be independently deployable.
- The UI should never wait on slow source systems directly.
Logical Architecture¶
flowchart LR
POS[Restaurant POS / Merchant POS]
ERP[ERP / WMS / Dark Store Systems]
SELLER[Seller APIs / Brand Feeds]
WEBHOOK[Webhook Gateway]
ADAPTERS[Connector Adapters]
NORMALIZER[Normalization Service]
CATALOG[(Catalog Core DB)]
EVENTS[(Kafka / Event Bus)]
INVENTORY[Inventory Service]
PRICING[Pricing Service]
SEARCH[Search Indexer]
CACHE[(Redis Cache)]
API[Serving API / BFF]
LLM[LLM Enrichment Pipeline]
INDEX[(OpenSearch / Elasticsearch)]
POS --> WEBHOOK
ERP --> WEBHOOK
SELLER --> ADAPTERS
WEBHOOK --> NORMALIZER
ADAPTERS --> NORMALIZER
NORMALIZER --> CATALOG
NORMALIZER --> EVENTS
EVENTS --> INVENTORY
EVENTS --> PRICING
EVENTS --> SEARCH
EVENTS --> LLM
SEARCH --> INDEX
INVENTORY --> CACHE
PRICING --> CACHE
INDEX --> API
CACHE --> API
CATALOG --> API
Service Boundaries¶
1. Webhook Gateway¶
Responsibilities:
- receive POS / ERP / seller callbacks
- authenticate source systems
- validate signatures
- deduplicate inbound events
- write raw payloads for replay / audit
This service should be extremely small and stable.
2. Connector Adapters¶
Responsibilities:
- convert source-specific formats into canonical commands
- hide vendor differences like PetPooja vs UrbanPiper vs Unicommerce
- map location / merchant / SKU / item identifiers
Examples:
petpooja-menu-adapterurbanpiper-store-adapterunicommerce-inventory-adapterseller-feed-bulk-importer
3. Catalog Normalization Service¶
Responsibilities:
- canonicalize product/menu/store structures
- validate required attributes
- version item payloads
- emit canonical catalog events
This is the heart of ingestion.
4. Catalog Core DB¶
Recommended storage:
- PostgreSQL for normalized canonical data and history
Store:
- merchants
- locations / stores / dark stores
- products
- variants
- addon groups
- price books
- assortment mappings
- source mappings
- version history
5. Inventory Service¶
Responsibilities:
- maintain per-location stock state
- compute orderability
- reserve / release stock
- publish availability changes
Recommended storage:
- PostgreSQL for durable state
- Redis for hot availability
6. Pricing Service¶
Responsibilities:
- store base price
- apply tax / promotion / store overrides
- publish effective price changes
7. Search Service¶
Responsibilities:
- maintain search documents
- power keyword, category, and filter queries
- expose ranking-ready attributes
Recommended storage:
- OpenSearch / Elasticsearch
8. Recommendation Service¶
Responsibilities:
- co-purchase signals
- substitutes / complements
- location-aware trending items
- business-rule recommendations
Start simple with rules and event aggregates before ML.
9. LLM Enrichment Pipeline¶
Responsibilities:
- clean titles
- normalize units
- infer missing attributes
- generate tags and synonyms
- deduplicate near-identical supplier items
This should be asynchronous and never block critical catalog serving.
Primary Data Flows¶
Restaurant Menu Sync¶
- Merchant updates item in POS.
- POS sends webhook to Webhook Gateway.
- Adapter maps vendor payload into canonical commands.
- Normalizer upserts menu / variant / addon entities.
- Event emitted:
catalog.menu_item.updatedpricing.price.updatedinventory.item_availability.updated- Search index refreshes.
- Redis cache invalidates.
- App sees updated menu.
Dark Store Inventory Sync¶
- ERP or store OMS publishes stock delta.
- Webhook Gateway accepts update.
- Adapter resolves source SKU to canonical SKU.
- Inventory service applies delta to store-level stock ledger.
- Event emitted:
inventory.stock.changedinventory.orderability.changed- Serving cache refreshes.
- App shows out-of-stock or available state.
Seller Feed / Bulk Catalog Sync¶
- Seller uploads CSV / API feed.
- Bulk importer stores raw payload in object storage.
- Normalizer transforms and validates rows.
- Good rows upsert canonical entities.
- Bad rows go to review queue.
- Search and enrichment pipelines run asynchronously.
Suggested Technology Choices¶
MVP¶
- Webhook/API: FastAPI or NestJS
- Catalog DB: PostgreSQL
- Event bus: Kafka or Redpanda
- Cache: Redis
- Search: OpenSearch
- Async workers: Celery / Dramatiq / BullMQ / Temporal
Scale-Up¶
- Inventory hot path: Redis + PostgreSQL
- Heavy search/reco workloads: dedicated search and feature stores
- Replay / lineage: S3 + compacted event topics
Serving API Shape¶
The frontend should not call many backend systems directly. Expose one API layer or BFF with fast read models:
GET /v1/catalogGET /v1/catalog/:itemIdGET /v1/stores/:storeId/inventoryGET /v1/stores/:storeId/search?q=milkGET /v1/stores/:storeId/recommendations?itemId=...
SLO Targets¶
Reasonable starting targets:
- webhook ack: < 300 ms
- catalog read: < 150 ms p95
- inventory update propagation: < 5 sec p95
- price update propagation: < 5 sec p95
- store search: < 200 ms p95
What To Build First¶
If you want working business value quickly, build in this order:
- Webhook Gateway
- Connector Adapter pattern
- Canonical catalog schema
- Inventory service
- Redis-backed serving API
- Search indexing
- Recommendation rules
- LLM enrichment
Files In This Folder¶
README.md: architecture overviewpos-integration-microservice.md: ingestion and sync designcontracts.md: canonical entities, events, and APIsroadmap.md: phased rollout plan