Skip to main content

API Reference

DEJA.js organizes its shared code into workspace packages under the @repo/ scope. This page documents the public API for each package -- the composables, components, types, and utilities that apps import and use.

@repo/modules -- Core Business Logic

The central package for domain-specific composables and types. Organized by feature domain.

import { useLocos, useTurnouts, useEfx, useSignals, useLayout, useRoutes } from '@repo/modules'

Composables

useLocos()

Locomotive management. Returns functions for reading and managing the locomotive roster.

  • getThrottles() -- Returns reactive throttle data from Firestore.

useFunctions()

Locomotive function management (headlights, horns, bells, etc.).

useFunctionIcon()

Maps DCC function numbers to Material Design icon names for UI rendering.

useTurnouts()

Turnout state management.

  • getTurnouts() -- Returns reactive turnout collection from Firestore.

useEfx()

Effect management for lights, sounds, animations, and relays.

  • getEffects() -- Returns reactive effects collection from Firestore.
  • getGuestEffects() -- Returns only guest-accessible effects (used by the Tour app).

useSignals()

Signal state management.

  • getSignals() -- Returns reactive signal collection from Firestore.

useLayout()

Layout configuration and device management.

  • getLayout() -- Returns reactive layout document from Firestore.
  • getDevices() -- Returns reactive devices collection from Firestore.

useRoutes()

Route preset management for saved turnout configurations.

useLayoutRoutes()

Layout-specific route management that ties routes to the current layout.

Exported Types

Each domain exports its TypeScript types and interfaces:

  • effects/types -- Effect interfaces and enums.
  • effects/constants -- Effect category constants.
  • layouts/types -- Layout, device, and configuration interfaces.
  • layouts/constants -- Layout-related constants.
  • locos/types -- Locomotive, throttle, and function interfaces.
  • locos/constants -- Loco-related constants.
  • turnouts/types -- Turnout state interfaces.
  • signals/types -- Signal state interfaces.
  • routes/types -- Route and route step interfaces.
  • routes/constants -- Route-related constants.

@repo/dccex -- DCC-EX Integration

Provides the composable for sending DCC-EX commands from frontend apps to the server via Firebase RTDB.

import { useDcc } from '@repo/dccex'

useDcc()

The primary interface for sending DCC commands. Commands are written to dccCommands/{layoutId} in Firebase Realtime Database, where the server picks them up and dispatches them to the CommandStation over serial.

Returned functions:

FunctionSignatureDescription
setFunction(address: number, func: number, state: boolean) => Promise<void>Toggle a locomotive function (headlight, horn, bell, etc.)
setPower(payload: object) => Promise<void>Send a power command (on/off, main/prog track)
sendOutput(pin: number, state: boolean) => Promise<void>Control an accessory output pin
sendDccCommand({ action, payload }: DccCommand) => Promise<void>Send an arbitrary DCC command
send(action: string, payload?: object) => Promise<void>General-purpose command sender that routes through cloud, serial, or emulator based on mode

The composable reads the layout ID from local storage (@DEJA/layoutId) and supports three modes:

  • Cloud mode (default) -- Writes commands to Firebase RTDB.
  • Emulated mode -- Logs commands without sending them (for development).
  • Serial mode -- Direct serial communication (when available).

defaultCommands

An array of predefined DCC-EX command objects for common operations (power on/off, reset, status query, save EEPROM, etc.). Exported from @repo/dccex/constants.


@repo/deja -- DEJA Core

The core composable for writing DEJA system commands to Firebase.

import { useDejaJS } from '@repo/deja'

useDejaJS()

Writes commands to the dejaCommands/{layoutId} queue in Firebase RTDB. These commands handle system-level operations that do not go to the DCC serial port:

  • Device connection and disconnection.
  • Serial port listing.
  • Server status queries.

@repo/ui -- Shared Vue Components

A library of reusable Vue 3 components shared across all frontend apps.

import { LocoAvatar, TurnoutList, TrackPower } from '@repo/ui'

Components

ComponentDescription
AppHeaderApplication header bar
LocoAvatarLocomotive image/icon display
ConsistMulti-locomotive consist display
EditConsistEditable consist configuration
MiniConsistCompact consist display
FunctionsLocomotive function button grid
FunctionListFunction list display
FunctionsSpeedDialSpeed dial for quick function access
TurnoutListList of turnouts with state indicators
TurnoutItemSingle turnout list item
TurnoutSwitchToggle switch for turnout control
TurnoutCardCard-style turnout display
TurnoutButtonButton for throwing/closing turnouts
TurnoutRawRaw turnout data display
TurnoutTableTable view of turnouts
TurnoutLabelsPrintable turnout label generator
EffectListList of effects with state indicators
EffectItemSingle effect list item
EffectSwitchToggle switch for effect control
EffectCardCard-style effect display
EffectButtonButton for activating/deactivating effects
EffectRawRaw effect data display
EffectTableTable view of effects
GuestEffectCardGuest-friendly effect card (used in Tour app)
TrackPowerTrack power on/off control
SignalListSignal state display list
SelectLayoutLayout selection dropdown
LayoutChipCompact layout identifier chip
UserProfileUser profile display
SignOutSign out button
ViewJsonJSON data viewer for debugging
ListMenuGeneric list menu component
DeviceStatusItemSingle device connection status
DeviceStatusListList of device statuses
EmptyStateEmpty state placeholder
ModuleListGeneric module list
LocoListLocomotive roster list
MenuApplication navigation menu
StatStatistics display card
BackgroundDecorDecorative background element
BackgroundFallingStarsAnimated falling stars background
NotificationContainerToast notification container

Animation Utilities

The @repo/ui package also exports animation utilities from @repo/ui/animations:

  • DURATION, EASING, SPRING, GLOW -- Animation timing constants.
  • presets -- Named animation presets.
  • useReducedMotion -- Composable that respects the user's reduced motion preference.
  • StatusPulse, TransitionFade, TransitionSlide, TransitionExpand, TransitionList -- Transition wrapper components.

Composables

  • useColors() -- Returns color utilities for consistent theming.
  • useNotification() / provideNotifications() -- Toast notification system.

@repo/auth -- Authentication

Firebase Auth integration with Vue Router guards and authentication UI components.

import { requireAuth, requireLayout, Login } from '@repo/auth'

Route Guards

GuardDescription
requireAuthRedirects to login if the user is not authenticated
requireDccExEnsures a DCC-EX connection is available
requireLayoutRequires a layout to be selected
requireApprovalChecks that the user's account is approved
requireOnboardingRedirects to onboarding if not completed
redirectIfAuthenticatedRedirects away from login if already authenticated

Components

ComponentDescription
LoginFirebase authentication login form
SignupAccount registration form
ForgotPasswordPassword reset form
SignoutSign out button

@repo/firebase-config -- Firebase Initialization

Exports configured Firebase instances for both browser and server use.

// Browser client
import { db, rtdb } from '@repo/firebase-config'

// Server (Node.js with Admin SDK)
import { db, rtdb } from '@repo/firebase-config/firebase-admin-node'
  • db -- Firestore database instance.
  • rtdb -- Realtime Database instance.

@repo/utils -- Common Utilities

Shared utility functions used across multiple packages.

import { createLogger, slugify } from '@repo/utils'
  • createLogger(namespace) -- Creates a namespaced logger instance for consistent debug output.
  • slugify(text) -- Converts text to a URL-friendly slug.