ServerDynamic Objects
Overview
Runtime-defined entities that allow tenants to create custom data structures without code deployments.
Dynamic Objects (also known as Custom Objects) enable Selegic CRM tenants to define their own data structures at runtime without requiring code deployments or Prisma migrations.
Core Philosophy
- Multi-Tenancy: Data is strictly isolated per tenant using
TenantPrismatransaction client - Runtime Validation: Entity definitions are converted to JSON Schemas for real-time request validation
- Schema Discovery: Metadata service tracks fields, relationships, and types for every dynamic entity
- Unified Pipeline: Dynamic operations share the same pipeline logic as standard CRUD
Key Components
| Component | File | Purpose |
|---|---|---|
DynamicRepository | services/dynamic-repository.service.ts | Executes dynamic SQL/Prisma calls against tenant DB |
ValidationService | services/validation.service.ts | Generates and caches JSON schemas |
EntityMetadataService | services/entity-metadata.service.ts | Source of truth for entity structures |
OperationHandlerService | services/operation-handler.service.ts | Orchestrates validation, hooks, flows, execution |
FlowIntegrationService | services/flow-integration.service.ts | Runs pre/post flows for automation |
File Structure
features/dynamic-objects/
├── dynamic.routes.ts # Hono routes for dynamic objects
├── factory.ts # Dynamic service factory
├── hooks.ts # Dynamic hook registry
├── layers.ts # Request-scoped layer composition
├── services/
│ ├── dynamic-repository.service.ts
│ ├── validation.service.ts
│ ├── entity-metadata.service.ts
│ ├── operation-handler.service.ts
│ ├── flow-integration.service.ts
│ ├── dynamic-hook.service.ts
│ └── audit-field.service.ts
├── types/
│ └── index.ts
└── tests/Quick Navigation
- Architecture — Request flow and service relationships
- Storage Strategy — Multi-tenant column-based storage
- Schema Runtime — Entity discovery and validation caching
- Hooks & Flows — Pre-flows, post-hooks, relationship hooks
- Runbook — Troubleshooting and maintenance
How It Works
- Request arrives with tenant context (
x-tenant-id) - Entity lookup — Is this a static or dynamic model?
- Field metadata fetch — Get field definitions from
Entity/Fieldtables - Validation — Validate request body against cached JSON schema
- Execute — Run pre-flows, database operation, post-flows
- Response — Return result with computed formula fields