Skip to main content

Open Mercato patterns & execution roadmap

Part of the Architecture Specification. Patterns adopted from Open Mercato (§13) and the high-level execution roadmap that sequences the 7-module build (§14).

13. Patterns Adopted from Open Mercato

Context

The team also develops Open Mercato, an AI-supportive CRM/ERP foundation framework (Next.js, MikroORM, PostgreSQL, Redis, 14 shared packages, 20+ modules). A formal analysis evaluated 15 Open Mercato patterns for applicability to Constellation's enterprise commerce context.

See: Open_Mercato_Pattern_Analysis_v1.md for the full evaluation.

Adopted Patterns (8 of 15)

PatternAdaptation for Constellation
Event-Driven DecouplingTyped events with as const, domain-verb naming, transactional outbox (PostgreSQL), audit-critical events are synchronous
Module Setup Lifecyclesetup.ts per module with onTenantCreated, seedDefaults, defaultRoleFeatures. seedExamples hard-gated from production
No Cross-Module ORM RelationsFK IDs only across modules. Typed service contracts in packages/contracts. Prisma schema lint in CI
Spec-Driven Development.kiro/specs/ directory. Tasks with 3+ file changes require a spec before implementation
Field-Level EncryptionTenant-scoped DEKs, Prisma $extends for transparent encrypt/decrypt. HSM in production, local in dev. No deterministic hashing in regulated environments
CLAUDE.md Task RoutingRoot CLAUDE.md with task routing table. Per-module CLAUDE.md with domain context + import tables + known pitfalls
Module-Decoupling TestCI check: each module builds independently. Import boundary lint. Prisma schema cross-reference check
Import Pattern TablesEach module CLAUDE.md maps "need X → import from Y → NOT from Z"

Adapted Patterns (2 of 15)

PatternWhat Changed
CRUD Factory → Tool-Oriented CompositionEnterprise entities are too varied for a single factory. Use explicit services, tools, and workflows with composable policy/audit helpers instead
Dual Queue → Postgres-First RuntimePostgreSQL outbox + jobs are canonical. BullMQ is optional for high-throughput. In-memory adapter for unit tests

Skipped Patterns (5 of 15)

PatternWhy Skipped
Module Auto-DiscoveryNext.js App Router already provides conventions. 7 modules can be listed explicitly.
Awilix DI ContainerRuntime opacity hinders compliance auditing. React cache() + factory functions suffice.
Widget InjectionClassification boundaries could be violated. Use explicit imports + parallel routes.
Custom Entities / EAVRegulated schemas are compliance-driven and rigid. Use metadata Json? for narrow cases only.
Overlay/Override SystemEnterprise deployments need deterministic, auditable builds. Use feature flags instead.

14. Execution Roadmap

Phase 0: Monorepo Setup (1 week)

TaskDeliverable
Initialise Turborepo workspaceturbo.json, root package.json
Move project-tracker into apps/Working project-tracker in monorepo
Create packages/tsconfig and packages/eslint-configShared configs
Set up Docker Compose for local PostgreSQLdocker/docker-compose.yml
Create root CLAUDE.md with task routing table + universal rulesAI agent governance (Open Mercato pattern)
Create .kiro/specs/ directory with templateSpec-driven development (Open Mercato pattern)
Set up module-decoupling CI checkIsolation guardrail (Open Mercato pattern)
Set up GitHub Actions CI for monorepoLint, type-check, test across all apps

Phase 1: Directory Module + Platform Packages (6-8 weeks) — API Only

TaskDeliverable
Design Directory data model (Users, Orgs, Roles, Permissions, Tenants)Prisma schema for identity + tenancy schemas
Build @constellation-platform/auth-core and auth-nextAuth packages with permission evaluation engine
Build @constellation-platform/db with RLS + audit helpersDB package with tenant-aware Prisma client
Build Directory API (CRUD for users, orgs, roles, credentials)REST API with auth middleware
Build @constellation-platform/events with pg LISTEN/NOTIFYEvent bus with typed contracts
Build @constellation-platform/jobsPostgres-first job abstraction
Write Directory CLAUDE.mdAI agent context for the module

Note: Directory UI is deferred to Phase 3a (UI Layer). Phase 1 delivers the complete backend API and platform packages. packages/ui is built as part of Phase 3a when all core module backends are available.

Phase 2: Extract and Stabilise (2 weeks)

TaskDeliverable
Extract patterns from Directory into packagesStabilised shared packages
Build tools/create-module scaffold generatorCLI tool for new modules
Document shared package APIsPackage-level documentation
Validate shared packages by building a minimal Catalog skeletonProof that packages work for a second module

Phase 3: Catalog + Procurement (8-12 weeks)

TaskDeliverable
Build Catalog module (products, taxonomy, search, shortlisting)Full catalog application
Build Procurement module (RFQ, CPQ, scoring, orders)Full procurement application
Integrate Catalog → Procurement flow (shortlists become RFQs)End-to-end procurement workflow
Integrate Procurement → Projects (orders trigger project creation)Event-driven integration

Phase 3a: UI Layer (4-6 weeks)

Build the user-facing frontend for the core modules. This phase delivers the first end-to-end user experience and coincides with the Business Plan Phase 2 "Commercial Pilot Release" milestone.

TaskDeliverable
Build packages/ui — shared component library (shadcn, Tailwind, layouts)Design system package consumed by all module apps
Build apps/auth/ — login, registration, MFA, password reset, session mgmtStandalone auth app wrapping Supabase (or Keycloak)
Build Directory UI — org profiles, user management, role admin, certsFrontend in apps/directory/ consuming Directory API
Build Catalog UI — catalog entry creation, search, filter, shortlistingFrontend in apps/catalog/ consuming Catalog API
Build Procurement UI — RFQ creation from shortlists, offer submissionFrontend in apps/procurement/ consuming Procurement API
Implement shared navigation component across module appsCross-module nav via URL links (no micro-frontend)

Dependencies: Phase 1 (Directory API), Phase 3 (Catalog + Procurement APIs). This phase produces packages/ui/ as a deliverable.

Key decisions:

  • apps/auth/ is the central entry point for all authentication flows. Other modules redirect to apps/auth/ for login and rely on a shared auth cookie for session continuity.
  • Each module app owns its own UI routes. Shared components (nav, layouts, form primitives) live in packages/ui/.
  • Supplier self-service (org profile, catalog management, RFQ response) is a frontend route group within the existing module apps, not a separate application.

Phase 4: Project-Tracker Migration (2-3 weeks)

TaskDeliverable
Replace project-tracker auth with @constellation-platform/auth-core and auth-nextShared auth in project-tracker
Add tenant_id to project-tracker schemaTenant isolation
Complete project-tracker Phases 3-5 using shared packagesProduction-ready project coordination

Phase 5: Remaining Modules (8-13 weeks, parallel AI agents)

ModuleEstimated DurationDependencies
Documents4-5 weeksDirectory (auth), Security (classification)
Supply Chain3-4 weeksDirectory (auth), Catalog (product references)
Compliance3-4 weeksDirectory (auth), Procurement (screening integration)

Phase 6: Enterprise Readiness (Ongoing, parallel)

TaskTrigger
Keycloak auth provider implementationFirst customer requiring SAML/OIDC federation
MinIO storage providerFirst customer requiring on-prem file storage
Docker/K8s deployment manifestsFirst dedicated/on-prem deployment
HSM key management integrationFirst customer requiring FIPS 140-2
Full RLS audit and penetration testingBefore any regulated or classified data enters platform

Phase Crosswalk: Architecture vs Business Plan

The architecture roadmap and business plan use independent phase numbering. This table maps between them to avoid confusion.

Architecture PhaseBusiness Plan PhaseKey Deliverables
Phase 0: Platform BootstrapPhase 1 (Foundation) — infrastructureMonorepo, platform packages, scaffold generator
Phase 1: Directory ModulePhase 1 (Foundation) — first moduleIdentity, orgs, roles, tenancy backend API
Phase 2: Extract & StabilisePhase 1 (Foundation) — hardeningContracts package, package docs, Catalog skeleton
Phase 3: Catalog + ProcurementPhase 2 (Commercial Pilot) — backendsFull Catalog and Procurement backend APIs
Phase 3a: UI LayerPhase 2 (Commercial Pilot) — frontendspackages/ui, apps/auth/, module UIs, end-to-end UX
Phase 4: Project-Tracker MigrationPhase 2 (Commercial Pilot) — migrationProject-tracker on shared platform
Phase 5: Remaining ModulesPhase 3 (Operational Delivery)Documents, Supply Chain, Compliance
Phase 6: Enterprise ReadinessOngoingKeycloak, MinIO, K8s, HSM, penetration testing

Rule of thumb: Architecture phases are sequenced by technical dependency. Business plan phases are grouped by commercial milestone. When in doubt, the architecture spec governs build order; the business plan governs release scope.