### Execute Automated Setup Scripts Source: https://github.com/shellicar/reference-enterprise/blob/main/README.md Run the platform-specific setup script to install necessary dependencies, Node.js, and Azure tooling. This is the recommended method for initializing the development environment. ```bash ./setup.sh ``` ```powershell .\setup.ps1 ``` -------------------------------- ### Repository Initialization and Build Source: https://github.com/shellicar/reference-enterprise/blob/main/README.md Clone the repository, install all project dependencies, and perform an initial build of the monorepo. ```bash git clone https://github.com/shellicar/reference-enterprise.git cd reference-enterprise pnpm install pnpm build ``` -------------------------------- ### Install Dependencies (Bash) Source: https://github.com/shellicar/reference-enterprise/blob/main/packages/ui/README.md Installs the necessary project dependencies using the pnpm package manager. This is a prerequisite for running the development server or building the project. ```bash pnpm install ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/shellicar/reference-enterprise/blob/main/apps/admin/README.md Installs all required project dependencies defined in the package.json file. Supports multiple package managers to ensure environment compatibility. ```bash npm install pnpm install yarn install bun install ``` -------------------------------- ### Manual Environment Configuration Source: https://github.com/shellicar/reference-enterprise/blob/main/README.md Manually enable Corepack and install the pnpm package manager. This is required if the automated setup script is not used. ```bash corepack enable corepack prepare pnpm@latest --activate ``` -------------------------------- ### Start Development Server (Bash) Source: https://github.com/shellicar/reference-enterprise/blob/main/packages/ui/README.md Starts the Nuxt development server, typically on http://localhost:3000. This command is used for local development and testing of the Nuxt layer. ```bash pnpm dev ``` -------------------------------- ### Preview Production Build Source: https://github.com/shellicar/reference-enterprise/blob/main/apps/admin/README.md Starts a local server to preview the production-ready build. Useful for verifying the application behavior before deploying to a live environment. ```bash npm run preview pnpm preview yarn preview bun run preview ``` -------------------------------- ### Start Development Server Source: https://github.com/shellicar/reference-enterprise/blob/main/apps/admin/README.md Launches the Nuxt development server with hot module replacement. The application will be accessible at http://localhost:3000. ```bash npm run dev pnpm dev yarn dev bun run dev ``` -------------------------------- ### Install Layer Dependency (Bash) Source: https://github.com/shellicar/reference-enterprise/blob/main/packages/ui/README.md Installs the published Nuxt layer as a dependency in another project using npm. This command should be run in the user's project where the layer will be extended. ```bash npm install --save your-layer ``` -------------------------------- ### Development Workflow Commands Source: https://github.com/shellicar/reference-enterprise/blob/main/README.md Common commands for starting specific services, building the entire monorepo, and executing the test suite. ```bash # Start the API pnpm --filter api dev # Start the web application pnpm --filter webapp dev # Build all packages pnpm build # Run tests pnpm test ``` -------------------------------- ### Publish Layer to NPM (Bash) Source: https://github.com/shellicar/reference-enterprise/blob/main/packages/ui/README.md Publishes the Nuxt layer to NPM, making it available for installation by other projects. Ensure the 'files' property in package.json is correctly configured before running this command. ```bash npm publish --access public ``` -------------------------------- ### GET /api/Version Source: https://context7.com/shellicar/reference-enterprise/llms.txt Retrieves build version information to assist with deployment verification and debugging. ```APIDOC ## GET /api/Version ### Description Returns build version information computed at build time, useful for verifying the currently deployed code version. ### Method GET ### Endpoint /api/Version ### Response #### Success Response (200) - **version** (string) - The semantic version of the build. - **commit** (string) - The git commit hash associated with the build. #### Response Example { "version": "1.0.0", "commit": "abc123" } ``` -------------------------------- ### Setup Service Collection for Dependency Injection with TypeScript Source: https://context7.com/shellicar/reference-enterprise/llms.txt Initializes a service collection using `@shellicar/core-di` and registers modules from a generated source. This collection is then used to build a provider for creating scoped service instances. ```typescript // apps/api/src/core/di/services.ts import { createServiceCollection } from '@shellicar/core-di'; import { modules } from '@shellicar-reference-enterprise/server-common/generated'; const services = createServiceCollection(); services.registerModules(...modules); export { services }; // apps/api/src/core/di/serviceProvider.ts import { services } from './services'; export const serviceProvider = services.buildProvider(); // apps/api/src/core/graphql/context.ts - Creates scoped DI container per request import type { v4 } from '@as-integrations/azure-functions'; import { serviceProvider } from '../di/serviceProvider'; export const context = async (_ctx: v4.AzureFunctionsContextFunctionArgument) => { const scope = serviceProvider.createScope(); return { scope }; }; ``` -------------------------------- ### Configure API Endpoint with TypeScript Source: https://context7.com/shellicar/reference-enterprise/llms.txt Sets up an HTTP endpoint for retrieving current configuration values. It uses a custom async handler and is configured for anonymous access with GET method. ```typescript // apps/api/src/functions/config.ts import { app } from '@azure/functions'; import { createAsyncHandler } from '@shellicar-reference-enterprise/server-common/core/createAsyncHandler'; const handler = await createAsyncHandler('Config', () => import('./handlers/config')); app.http('Config', { handler, methods: ['GET'], authLevel: 'anonymous', }); // curl example: // curl http://localhost:7071/api/Config // Response: {} ``` -------------------------------- ### GET /api/Health Source: https://context7.com/shellicar/reference-enterprise/llms.txt Endpoint used for monitoring and load balancer health checks to verify the status of the API application. ```APIDOC ## GET /api/Health ### Description Returns the overall health status of the API application and individual feature health indicators. ### Method GET ### Endpoint /api/Health ### Response #### Success Response (200) - **status** (object) - The health status object. #### Response Example { "status": "ok" } ``` -------------------------------- ### Widget Feature GraphQL Schema Source: https://context7.com/shellicar/reference-enterprise/llms.txt Defines the GraphQL schema for the Widget feature, including queries for retrieving and searching widgets, mutations for creating and starting widgets, and detailed types for widget data and payload results. ```graphql # apps/api/src/features/widget/Widget.graphql extend type Query { widget: WidgetQueries! } extend type Mutation { widget: WidgetMutations! } type WidgetQueries { get(input: WidgetGetInput!): Widget search(input: WidgetSearchInput!): WidgetFeed! } type WidgetMutations { create(input: WidgetCreateInput!): WidgetCreatePayload! start(input: WidgetStartInput!): WidgetStartPayload! } type Widget { id: UUID! name: String! description: String created: Instant! modified: Instant! } input WidgetGetInput { id: UUID! } input WidgetSearchInput { name: StringFilter description: StringFilter limit: Int = 10 @constraint(min: 1, max: 100) cursor: Cursor } input WidgetCreateInput { name: String! @constraint(minLength: 1, maxLength: 100, pattern: "^[\\x20-\\x7E]+$") description: String! @constraint(minLength: 1, maxLength: 100, pattern: "^[\\x20-\\x7E]+$") } union WidgetCreatePayload = WidgetCreatePayloadSuccess | WidgetCreatePayloadFailure type WidgetCreatePayloadSuccess { id: UUID! } type WidgetCreatePayloadFailure { status: WidgetCreatePayloadFailureStatus! errors: [WidgetCreatePayloadFailureError!]! } type WidgetFeed { items: [Widget!]! cursor: Cursor } ``` -------------------------------- ### Worker Application Main Execution Source: https://context7.com/shellicar/reference-enterprise/llms.txt The main entry point for the worker application. It sets up a dependency injection scope, resolves and starts all registered worker modules, and handles process signals (SIGINT, SIGTERM) for graceful shutdown. ```typescript // apps/worker/src/main.ts import { serviceProvider } from './core/di/serviceProvider'; import { IWorkerModule } from './interfaces'; const main = async () => { await using scope = serviceProvider.createScope(); const workers = scope.resolveAll(IWorkerModule); const abortController = new AbortController(); await Promise.all(workers.map((instance) => instance.start())); const termHandler = async (signal: string) => { console.log(`Received ${signal}, shutting down gracefully...`); for (const instance of workers) { try { await instance[Symbol.asyncDispose](); } catch (err) { console.error(`Error during shutdown of ${instance.constructor.name}:`, err); } } console.log('All modules shut down gracefully.'); abortController.abort(); }; process.on('SIGINT', termHandler); process.on('SIGTERM', termHandler); console.log('Worker modules started successfully.'); await new Promise((resolve) => { abortController.signal.addEventListener('abort', () => resolve(), { once: true }); }); }; await main(); ``` -------------------------------- ### Worker Module Interface Definition Source: https://context7.com/shellicar/reference-enterprise/llms.txt Defines an abstract base class for worker modules, enforcing the disposable pattern for graceful shutdown. It includes abstract methods for starting the module and for synchronous and asynchronous disposal. ```typescript // apps/worker/src/interfaces.ts export abstract class IWorkerModule implements AsyncDisposable, Disposable { public abstract start(): Promise; public abstract [Symbol.dispose](): void; public abstract [Symbol.asyncDispose](): Promise; } ``` -------------------------------- ### Build for Production Source: https://github.com/shellicar/reference-enterprise/blob/main/apps/admin/README.md Compiles the application into a production-ready bundle. This process optimizes assets and prepares the code for deployment. ```bash npm run build pnpm build yarn build bun run build ``` -------------------------------- ### Build for Production (Bash) Source: https://github.com/shellicar/reference-enterprise/blob/main/packages/ui/README.md Builds the Nuxt application for production deployment. This command optimizes the application for performance and size. ```bash pnpm build ``` -------------------------------- ### Generate Static Site (Bash) Source: https://github.com/shellicar/reference-enterprise/blob/main/packages/ui/README.md Statically generates the Nuxt application. This is useful for deploying static sites to hosting platforms that do not support server-side rendering. ```bash pnpm generate ``` -------------------------------- ### Preview Production Build (Bash) Source: https://github.com/shellicar/reference-enterprise/blob/main/packages/ui/README.md Locally previews the production build of the Nuxt application. This command allows you to test the production version before deploying it. ```bash pnpm preview ``` -------------------------------- ### Configure Nuxt Extends (TypeScript) Source: https://github.com/shellicar/reference-enterprise/blob/main/packages/ui/README.md Configures a Nuxt project to extend the functionality of a published layer. This is done by adding the layer's name to the 'extends' array in the nuxt.config file. ```typescript defineNuxtConfig({ extends: 'your-layer' }) ``` -------------------------------- ### Create Apollo Server Configuration Source: https://context7.com/shellicar/reference-enterprise/llms.txt Configures and creates an Apollo Server instance with various options including CSRF prevention, introspection, error formatting, and plugins. It utilizes environment variables and service provider configurations. ```typescript // packages/server-common/src/graphql/createApolloServer.ts import { env } from 'node:process'; import { ApolloServer } from '@apollo/server'; import { formatError } from './formatError'; import { isDevelopment } from './isDevelopment'; import { logger } from './logger'; import { persistedQueries } from './persistedQueries'; import { plugins } from './plugins'; import { schema } from './schema'; import type { CreateApolloServerOptions } from './types'; export function createApolloServer(options: CreateApolloServerOptions) { const { serviceProvider } = options; return new ApolloServer({ csrfPrevention: true, introspection: isDevelopment, hideSchemaDetailsFromClientErrors: !isDevelopment, schema, nodeEnv: env.NODE_ENV, includeStacktraceInErrorResponses: isDevelopment, formatError, plugins, logger, persistedQueries: persistedQueries(serviceProvider), }); } ``` -------------------------------- ### Implement GraphQL Resolvers with DI Delegation Source: https://context7.com/shellicar/reference-enterprise/llms.txt Demonstrates how GraphQL resolvers delegate business logic to services resolved from the DI container. This pattern separates the API schema definition from the underlying service implementation. ```typescript import type { Resolvers, WidgetMutations, WidgetQueries } from '../../generated/server'; import { IWidgetCreateResolver, IWidgetGetResolver, IWidgetSearchResolver, IWidgetStartResolver } from './interfaces'; export const WidgetResolver = { Query: { widget: () => ({}) as WidgetQueries, }, Mutation: { widget: () => ({}) as WidgetMutations, }, WidgetQueries: { search: (_, { input }, { scope }) => scope.resolve(IWidgetSearchResolver).query(input), get: (_, { input }, { scope }) => scope.resolve(IWidgetGetResolver).query(input), }, WidgetMutations: { create: (_, { input }, { scope }) => scope.resolve(IWidgetCreateResolver).mutate(input), start: (_, { input }, { scope }) => scope.resolve(IWidgetStartResolver).mutate(input), }, } satisfies Resolvers; export class WidgetCreateResolver implements IWidgetCreateResolver { public mutate(input: WidgetCreateInput): Promise { throw new Error('Method not implemented.'); } } ``` -------------------------------- ### Configure GraphQL Permission Rules Source: https://context7.com/shellicar/reference-enterprise/llms.txt Utilizes graphql-shield to define field-level authorization rules. It implements a default-deny strategy with explicit overrides for specific operations. ```typescript import { rules } from '@shellicar-reference-enterprise/server-common/graphql/permissions/rules'; import type { IRules } from 'graphql-shield'; export const WidgetRules = { Query: { widget: rules.allowed, }, WidgetQueries: { '*': rules.notAllowed, }, Mutation: { widget: rules.allowed, }, WidgetMutations: { '*': rules.notAllowed, create: rules.allowed, }, } satisfies IRules; import { GraphQLError } from 'graphql'; import { type IRule, rule } from 'graphql-shield'; export const allowed: IRule = rule({ cache: 'contextual' })(async (_parent, _args, _ctx, _info) => { return true; }); export const notAllowed: IRule = rule({ cache: 'contextual' })(async (_parent, _args, ctx, info) => { return new GraphQLError('Not Allowed', { extensions: { http: { status: 403 } }, }); }); ``` -------------------------------- ### Executable GraphQL Schema Definition Source: https://context7.com/shellicar/reference-enterprise/llms.txt Defines and builds an executable GraphQL schema using makeExecutableSchema from @graphql-tools/schema. It merges type definitions and resolvers, and applies middleware and constraint directives. ```typescript // packages/server-common/src/graphql/schema.ts import { resolvers, typeDefs } from '@graphql/generated'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { constraintDirectiveTypeDefs } from 'graphql-constraint-directive/apollo4'; import { middleware } from './middleware'; let schema = makeExecutableSchema({ typeDefs: [constraintDirectiveTypeDefs, ...typeDefs], resolvers, }); schema = middleware(schema); export { schema }; ``` -------------------------------- ### Nuxt Web Application Configuration (TypeScript) Source: https://context7.com/shellicar/reference-enterprise/llms.txt Configures Nuxt web applications, extending a shared UI package for consistent component libraries and configurations. This configuration sets up the Nuxt project with specific compatibility dates, disables auto-imports for clarity, enables devtools, and configures the development server port. It depends on 'nuxt/config'. ```typescript // apps/webapp/nuxt.config.ts import { defineNuxtConfig } from 'nuxt/config'; export default defineNuxtConfig({ compatibilityDate: '2025-05-15', imports: { autoImport: false, // Explicit imports for better code clarity }, devtools: { enabled: true }, devServer: { port: 3000, }, extends: ['@shellicar-reference-enterprise/ui'], // Shared UI components telemetry: { enabled: false, }, }); // Development commands: // pnpm --filter webapp dev # Start webapp on port 3000 // pnpm --filter dashboard dev # Start dashboard on port 3001 // pnpm --filter admin dev # Start admin on port 3002 ``` -------------------------------- ### POST /api/GraphQL Source: https://context7.com/shellicar/reference-enterprise/llms.txt The primary GraphQL endpoint for the application, supporting CRUD operations for widgets via queries and mutations. ```APIDOC ## POST /api/GraphQL ### Description Provides a type-safe GraphQL interface for frontend applications to interact with widget data, supporting cursor-based pagination and input validation. ### Method POST ### Endpoint /api/GraphQL ### Request Body - **query** (string) - Required - The GraphQL query or mutation string. - **variables** (object) - Optional - Variables for the GraphQL operation. ### Request Example { "query": "query { widget { search(input: { limit: 10 }) { items { id name } } } }" } ### Response #### Success Response (200) - **data** (object) - The result of the GraphQL operation. #### Response Example { "data": { "widget": { "search": { "items": [{"id": "1", "name": "Example Widget"}] } } } } ``` -------------------------------- ### Hono HTTP Server for Health and Version Endpoints (TypeScript) Source: https://context7.com/shellicar/reference-enterprise/llms.txt Implements a lightweight HTTP server using Hono for health checks and version endpoints on a worker application. It listens on localhost:7073 and exposes /health, /version, and /config endpoints. Dependencies include '@hono/node-server', '@shellicar/build-version/version', and 'hono'. ```typescript import { type ServerType, serve } from '@hono/node-server'; import version from '@shellicar/build-version/version'; import { Hono } from 'hono'; import type { IWorkerModule } from '../../interfaces'; export class HonoServer implements IWorkerModule { private readonly app: Hono; private readonly host = 'localhost'; private readonly port = 7073; private server: ServerType | null = null; public constructor() { this.app = new Hono({ strict: true }); this.app.get('/health', (c) => c.json({ status: 'ok' })); this.app.get('/version', (c) => c.json(version)); this.app.get('/config', (c) => c.json({ hello: 'world' })); } public async start(): Promise { const url = new URL(`http://${this.host}:${this.port}`); console.log(`Starting server on: ${url.href}`); this.server = serve({ fetch: this.app.fetch, port: this.port, hostname: this.host, }); } public [Symbol.dispose](): void { this.server?.close(); } public async [Symbol.asyncDispose](): Promise { this.server?.close(); } } // curl examples for worker endpoints: // curl http://localhost:7073/health // Response: {"status":"ok"} // curl http://localhost:7073/version // Response: {"version": "1.0.0", ...} ``` -------------------------------- ### Version Endpoint for Build Information (TypeScript) Source: https://context7.com/shellicar/reference-enterprise/llms.txt Exposes a version endpoint that returns build version information, including the git commit hash, computed at build time using `@shellicar/build-version`. This is useful for verifying deployed code and troubleshooting deployment issues. It leverages Azure Functions v4. ```typescript // apps/api/src/functions/version.ts import { app } from '@azure/functions'; import { createAsyncHandler } from '@shellicar-reference-enterprise/server-common/core/createAsyncHandler'; const handler = createAsyncHandler('Version', () => import('./handlers/version')); app.http('Version', { handler, methods: ['POST', 'GET'], authLevel: 'anonymous', }); // Handler implementation // apps/api/src/functions/handlers/version.ts import type { HttpHandler } from '@azure/functions'; import version from '@shellicar/build-version/version'; export const handler: HttpHandler = () => { return { status: 200, body: JSON.stringify(version), headers: { 'Content-Type': 'application/json' }, }; }; // curl example: // curl http://localhost:7071/api/Version // Response: {"version": "1.0.0", "commit": "abc123", ...} ``` -------------------------------- ### GraphQL API Endpoint for Widget Operations (TypeScript) Source: https://context7.com/shellicar/reference-enterprise/llms.txt Implements the main GraphQL endpoint for frontend applications, enabling CRUD operations for widgets. It uses Azure Functions v4 and Apollo Server, with type safety enforced by GraphQL code generation and schema validation. Supports cursor-based pagination and input validation. ```typescript // apps/api/src/functions/graphql.ts import { app } from '@azure/functions'; import { createAsyncHandler } from '@shellicar-reference-enterprise/server-common/core/createAsyncHandler'; const handler = createAsyncHandler('GraphQL', () => import('./handlers/graphql')); app.http('GraphQL', { handler, methods: ['POST', 'GET'], authLevel: 'anonymous', }); // Example GraphQL queries and mutations: // Query: Get a widget by ID const getWidgetQuery = " query GetWidget($id: UUID!) { widget { get(input: { id: $id }) { id name description created modified } } } "; // Query: Search widgets with pagination const searchWidgetsQuery = " query SearchWidgets($name: String, $limit: Int, $cursor: Cursor) { widget { search(input: { name: { contains: $name }, limit: $limit, cursor: $cursor }) { items { id name description } cursor } } } "; // Mutation: Create a new widget const createWidgetMutation = " mutation CreateWidget($name: String!, $description: String!) { widget { create(input: { name: $name, description: $description }) { ... on WidgetCreatePayloadSuccess { id } ... on WidgetCreatePayloadFailure { status errors { message details { key value } } } } } } "; // curl example: // curl -X POST http://localhost:7071/api/GraphQL \ // -H "Content-Type: application/json" \ // -d '{"query": "query { widget { search(input: { limit: 10 }) { items { id name } } } }"}' ``` -------------------------------- ### Deferred Promise and Async Handler for Azure Functions (TypeScript) Source: https://context7.com/shellicar/reference-enterprise/llms.txt Provides a Deferred class for lazy promise resolution and a createAsyncHandler utility for Azure Functions. This pattern enables lazy initialization of handlers with graceful fallback for service unavailability. It depends on '@azure/functions' and a local Deferred class. ```typescript export class Deferred { readonly promise: Promise; resolve!: (value: T) => void; reject!: (reason?: any) => void; constructor() { this.promise = new Promise((resolve, reject) => { this.resolve = resolve; this.reject = reject; }); } } // packages/server-common/src/core/createAsyncHandler.ts import type { HttpHandler, HttpRequest, InvocationContext } from '@azure/functions'; import { Deferred } from './Deferred'; type ImportHandler = () => Promise<{ handler: HttpHandler }>; const createErrorHandler = (): HttpHandler => () => ({ status: 503, body: JSON.stringify({ errors: [{ message: 'Service temporarily unavailable' }] }), headers: { 'Content-Type': 'application/json' }, }); export const createAsyncHandler = (name: string, importHandler: ImportHandler): HttpHandler => { const deferred = new Deferred(); // Start async initialization (async () => { try { const { handler } = await importHandler(); deferred.resolve(handler); } catch (error) { console.error(`Failed to initialise ${name} handler`, error); deferred.resolve(createErrorHandler()); } })(); // Return handler that waits for initialization return async (request: HttpRequest, context: InvocationContext) => { const handler = await deferred.promise; return handler(request, context); }; }; ``` -------------------------------- ### Core GraphQL Schema Definition Source: https://context7.com/shellicar/reference-enterprise/llms.txt Defines the fundamental GraphQL types, including common scalars (Cursor, UUID, Instant), interfaces for mutation results, and input types for filtering. This forms the base for all feature schemas. ```graphql # apps/api/src/core/graphql/graphql-core/GraphqlCore.graphql type Query type Mutation scalar Cursor scalar UUID scalar Instant interface MutationProblemDetails { key: String! value: String! } interface MutationProblem { message: String! details: [MutationProblemDetails!]! } type PageInfo { total: Int! count: Int! hasNextPage: Boolean! endCursor: Cursor } input StringFilter { eq: String ne: String contains: String startsWith: String endsWith: String } ``` -------------------------------- ### Register Feature Modules with Dependency Injection Source: https://context7.com/shellicar/reference-enterprise/llms.txt Defines abstract resolver interfaces and implements a module class to register concrete implementations into the DI container. This ensures loose coupling between feature logic and the application core. ```typescript import type { Widget, WidgetCreateInput, WidgetCreatePayload, WidgetFeed, WidgetGetInput, WidgetSearchInput, WidgetStartInput, WidgetStartPayload } from '../../generated/server'; export abstract class IWidgetGetResolver { public abstract query(input: WidgetGetInput): Promise; } export abstract class IWidgetSearchResolver { public abstract query(input: WidgetSearchInput): Promise; } export abstract class IWidgetCreateResolver { public abstract mutate(input: WidgetCreateInput): Promise; } export abstract class IWidgetStartResolver { public abstract mutate(input: WidgetStartInput): Promise; } import { type IServiceCollection, IServiceModule } from '@shellicar/core-di'; import { IWidgetCreateResolver, IWidgetGetResolver, IWidgetSearchResolver, IWidgetStartResolver } from './interfaces'; import { WidgetCreateResolver } from './WidgetCreateResolver'; import { WidgetGetResolver } from './WidgetGetResolver'; import { WidgetSearchResolver } from './WidgetSearchResolver'; import { WidgetStartResolver } from './WidgetStartResolver'; export class WidgetModule extends IServiceModule { public registerServices(services: IServiceCollection): void { services.register(IWidgetGetResolver).to(WidgetGetResolver); services.register(IWidgetSearchResolver).to(WidgetSearchResolver); services.register(IWidgetCreateResolver).to(WidgetCreateResolver); services.register(IWidgetStartResolver).to(WidgetStartResolver); } } ``` -------------------------------- ### Temporal Worker Implementation Source: https://context7.com/shellicar/reference-enterprise/llms.txt Implements the IWorkerModule interface to run a Temporal.io worker. It handles worker creation, execution, and graceful shutdown using Temporal's API. It logs worker status and errors during execution. ```typescript // apps/worker/src/core/temporal-worker/TemporalWorker.ts import { Worker, type WorkerOptions } from '@temporalio/worker'; import type { IWorkerModule } from '../../interfaces'; export class TemporalWorker implements IWorkerModule { private readonly options: WorkerOptions; private worker: Worker | null = null; private promise: Promise | null = null; public constructor() { this.options = { taskQueue: 'default' }; } public async start(): Promise { console.log('Starting Temporal worker with options:', this.options); this.worker = await Worker.create(this.options); this.promise = this.worker.run().catch((err) => { console.error('Error running Temporal worker:', err); }); } public async [Symbol.asyncDispose](): Promise { if (this.worker) { const state = this.worker.getStatus(); if (state.runState === 'RUNNING') { this.worker.shutdown(); } await this.promise; } } public [Symbol.dispose](): void { this[Symbol.asyncDispose]().catch(console.error); } } ``` -------------------------------- ### Health Check Endpoint for API Status (TypeScript) Source: https://context7.com/shellicar/reference-enterprise/llms.txt Provides a health check endpoint for the API application, returning overall status and individual feature health indicators. This is crucial for monitoring and load balancer health checks. It uses Azure Functions v4. ```typescript // apps/api/src/functions/health.ts import { app } from '@azure/functions'; import { createAsyncHandler } from '@shellicar-reference-enterprise/server-common/core/createAsyncHandler'; const handler = createAsyncHandler('Health', () => import('./handlers/health')); app.http('Health', { handler, methods: ['GET', 'HEAD'], authLevel: 'anonymous', }); // Handler implementation returns simple JSON status // apps/api/src/functions/handlers/health.ts import type { HttpHandler } from '@azure/functions'; export const handler: HttpHandler = () => { return { status: 200, body: JSON.stringify({}), headers: { 'Content-Type': 'application/json' }, }; }; // curl example: // curl http://localhost:7071/api/Health // Response: {} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.