@api-client/domain-templates
v0.3.5
Published
A package that has the definition of the well-know API Now domains.
Downloads
859
Readme
Domain Templates
This repository contains reusable data domain templates for the Quick API platform. These templates follow Domain-Driven Design (DDD) principles and provide pre-built structures for various industry verticals.
Features
- Vertical Organization: Templates are categorized by industry verticals (e.g., E-commerce, Healthcare, Finance).
- Distributed Metadata: Template metadata is defined alongside the implementation, making it easy to manage.
- Automated Registry: The template registry is automatically generated from the source files.
- Robust Testing: Comprehensive unit tests ensure template integrity using
@japa/runner.
Usage
Using Templates in Code
You can import and instantiate templates directly in your application:
import { TEMPLATES, createDomain } from '@api-client/domain-templates'
// 1. Create a domain using its ID
const ecommerceDomain = createDomain('ecommerce-platform')
// 2. Or use the specific factory function
import createEcommerceDomain from '@api-client/domain-templates/verticals/business-services/ecommerce-domain.js'
const domain = createEcommerceDomain()
console.log(domain.info.name) // "E-Commerce Platform"Using Generated Metadata
The build process generates JSON metadata files in the src/meta directory. These files are useful for building UI catalogs or preview tools.
Example Metadata (@api-client/domain-templates/meta/ecommerce-platform.json):
{
"id": "ecommerce-platform",
"name": "E-Commerce Platform",
"description": "A comprehensive e-commerce platform...",
"category": "Business Services",
"structure": {
"domain": {
"totalEntities": 11,
"totalProperties": 73
},
"namespaces": [ ... ]
}
}You can consume these JSON files to display template details without importing the entire domain logic.
Organization by Industry Verticals
Templates are organized into the following verticals in src/verticals/:
- Business Services: E-commerce, Financial Services, Legal Services, Hospitality
- Healthcare & Life Sciences: Healthcare
- Education & Training: Education
- Real Estate & Construction: Real Estate
- Manufacturing & Logistics: Manufacturing
- Technology & Media: Gaming, IoT, Blog, Content Management
- Public Sector: Non-Profit
Developing a Template
1. Create the Template File
Create a new file in the appropriate vertical directory (e.g., src/verticals/my-vertical/my-domain.ts).
2. Implement the Template
Each template file must export a meta object and a default creation function.
import { DataDomain } from '@api-client/core/modeling/DataDomain.js'
import type { CreateTemplateOptions, DomainTemplateMetadata } from '../../types.js'
// 1. Define Metadata
export const meta: DomainTemplateMetadata = {
id: 'my-domain-platform',
name: 'My Domain Platform',
description: 'A comprehensive domain for...',
version: '1.0.0',
author: 'Your Name',
category: 'My Vertical',
subcategory: 'My Subcategory',
tags: ['tag1', 'tag2'],
createdAt: '2025-01-01T00:00:00.000Z',
updatedAt: '2025-01-01T00:00:00.000Z',
}
// 2. Define Creation Function
export default function createMyDomain(options: CreateTemplateOptions = {}): DataDomain {
const domain = options.domain ?? new DataDomain({
info: {
name: meta.name,
displayName: meta.name,
description: meta.description,
},
})
// ... implementation details ...
return domain
}3. Update the Registry
Run the registry generation script to include your new template:
npm run generate-metadataThis will update src/index.ts automatically.
Testing
Run the test suite to verify your changes:
npm testTests successfully validate:
- Registry integrity (all templates are loadable)
- Template structure (namespaces, entities, etc.)
building
To build the project and generate types:
npm run buildThe build process also triggers the metadata generation script. JSON metadata files for UI previews are generated in the src/meta directory.
