This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
- Build:
pnpm run build- Cleans dist and compiles TypeScript - Test:
pnpm test- Runs Jest test suite - Test with coverage:
pnpm run test:coverage- Runs tests with coverage report - Test RabbitMQ:
pnpm run test:rabbitmq- RabbitMQ integration tests (requires Docker, 2min timeout) - Test integration:
pnpm run test:integration- Event bus integration tests with testcontainers (3min timeout) - Test all:
pnpm run test:all- All tests including integration (3min timeout) - Format code:
pnpm run pretty- Formats code with Prettier - Clean:
pnpm run clean- Removes dist directory - Transpile:
pnpm run transpile- TypeScript compilation only
This is a Fastify plugin library (@stackbox-dev/fp-plugins) that provides reusable plugins for Stackbox applications. The architecture follows a modular plugin-based design:
- Main exports (
src/index.ts): ExposesPlugins.EventBusandPlugins.FileStore - Event Bus Plugin (
src/event-bus/): Message broker abstraction supporting RabbitMQ, GCP Pub/Sub, Azure Service Bus, NATS JetStream, and local in-process messaging - File Store Plugin (
src/file-store.ts): Cloud storage abstraction supporting AWS S3, GCS, Azure Blob Storage, MinIO, and local filesystem
- Uses a factory pattern to instantiate different message brokers based on
busTypeconfiguration - Provides event consumer functionality for external event processing
- Includes built-in
/event-bus/publish/:eventendpoint (can be disabled) - Supports delayed event processing and retry mechanisms with exponential backoff
- Optional Prometheus metrics via
prom-client(pass aRegistryin options)
- Implements a common
FileStoreinterface across all storage providers - Supports both streaming and buffer-based file operations
- Uses environment variables for provider-specific configuration
- Handles authentication through provider-specific credential chains (AWS IAM, GCP ADC, Azure Managed Identity)
- Standalone consumer module (
src/event-bus/event-consumer/) for processing events outside of Fastify - Per-provider implementations: RabbitMQ, GCP Pub/Sub, Azure Service Bus, NATS JetStream
- Uses
EventConsumerBuilderfactory pattern — takes aFastifyInstance, returns anEventConsumerwithclose() - Includes shared retry utilities with exponential backoff in
utils.ts
Both plugins are registered as Fastify plugins using fastify-plugin and follow the standard Fastify plugin lifecycle. They decorate the Fastify instance with their respective interfaces (EventBus and FileStore).
Tests are configured with Jest and ts-jest, located in the src/ directory with .spec.ts extension. Coverage reports are generated in the coverage/ directory.
- TypeScript configuration uses
tsconfig.build.jsonfor production builds - Excludes test files (
**/*.spec.ts) from production builds - Outputs to
dist/directory with type definitions
- Pre-commit hooks: Husky + lint-staged auto-runs Prettier on staged
.js/.ts/.json/.mdfiles at commit time - Lazy require in event-bus factory: Provider modules are loaded via
require()(not static imports) so only the selected provider's dependencies are needed at runtime - Fastify augmentation:
src/types.tsaugmentsFastifyRequestwithEventBus— this is imported as a side-effect tsconfig.build.jsonskipLibCheck: Set totrueas a workaround for@nats-io/jetstreamsubpath import.d.tsfiles requiringmoduleResolution: "node16"+- Default test command excludes integration tests:
pnpm testskipsrabbitmq.spec.tsandevent-bus.integration.spec.ts— usepnpm run test:allto include them