Skip to main content

Introduction

MicroCBM uses TypeScript to provide type safety across the entire application. This section documents all type definitions organized by domain, extracted directly from the source code.

Type Categories

Inventory Types

Asset, Sites, and related analytics types for equipment management

Sample Types

Oil sample analysis types including wear metals, contaminants, and measurements

Alarm Types

Alarm monitoring and acknowledgment types with analytics

Recommendation Types

Maintenance recommendation types with severity levels and attachments

RCA Types

Root Cause Analysis types including 5 Whys, Logic Tree, and Fishbone diagrams

Common Patterns

Timestamps

All entities include timestamp fields for tracking creation and updates:
created_at: number;           // Unix timestamp in milliseconds
created_at_datetime: string;  // ISO 8601 formatted string
updated_at: number;           // Unix timestamp in milliseconds
updated_at_datetime: string;  // ISO 8601 formatted string

Entity References

Related entities are embedded as nested objects with at minimum an id field:
site: {
  id: string;
  name?: string;
}
This pattern allows for optional hydration of related data while maintaining referential integrity.

Filter Types

Most collections have corresponding filter types for querying:
export interface SampleFilters {
  search?: string;
  site_id?: string;
  asset_id?: string;
  sampling_point_id?: string;
  lab_name?: string;
}
All filter fields are optional, enabling flexible query composition.

Analytics Types

Analytics types follow a consistent pattern with totals and trend data:
export interface AlarmAnalytics {
  total_alarms: number;
  alarm_trend: {
    growth: number;
    percentage: number;
  };
  forecast_alarms: number;
  open_overdue_alarms: number;
}

Type Safety Best Practices

All types are exported from @/types and can be imported directly:
import type { Asset, Sample, Alarm } from '@/types';

Using Discriminated Unions

Severity and status fields use literal types for type safety:
severity: "low" | "medium" | "high" | "critical";
status: "open" | "in_progress" | "completed" | "overdue";
This ensures compile-time validation and excellent IDE autocomplete.

Payload Types

Create and update operations have dedicated payload types that may differ from the full entity:
export interface AddRecommendationPayload {
  title: string;
  severity: "low" | "medium" | "high" | "critical";
  description: string;
  attachments?: RecommendationAttachment[];
  // ... references to related entities
}

Next Steps

Server Actions

Learn how to use these types with server actions

Hooks

Explore custom hooks that work with these types

Build docs developers (and LLMs) love