Skip to content

Commit be4085d

Browse files
committed
chore: add CLAUDE.md and pnpm workspace config, update README
Introduces CLAUDE.md with guidance for Claude Code, adds pnpm-workspace.yaml for workspace dependency management, and updates README with installation, usage, and development instructions. Also documents new FileStore interface methods and improves code examples.
1 parent 73447f4 commit be4085d

3 files changed

Lines changed: 84 additions & 2 deletions

File tree

CLAUDE.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Common Development Commands
6+
7+
- **Build**: `pnpm run build` - Cleans dist and compiles TypeScript
8+
- **Test**: `pnpm test` - Runs Jest test suite
9+
- **Test with coverage**: `pnpm run test:coverage` - Runs tests with coverage report
10+
- **Format code**: `pnpm run pretty` - Formats code with Prettier
11+
- **Clean**: `pnpm run clean` - Removes dist directory
12+
- **Transpile**: `pnpm run transpile` - TypeScript compilation only
13+
14+
## Project Architecture
15+
16+
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:
17+
18+
### Core Structure
19+
- **Main exports** (`src/index.ts`): Exposes `Plugins.EventBus` and `Plugins.FileStore`
20+
- **Event Bus Plugin** (`src/event-bus/`): Message broker abstraction supporting RabbitMQ, GCP Pub/Sub, Azure Service Bus, and local in-process messaging
21+
- **File Store Plugin** (`src/file-store.ts`): Cloud storage abstraction supporting AWS S3, GCS, Azure Blob Storage, MinIO, and local filesystem
22+
23+
### Event Bus System
24+
- Uses a factory pattern to instantiate different message brokers based on `busType` configuration
25+
- Provides event consumer functionality for external event processing
26+
- Includes built-in `/event-bus/publish/:event` endpoint (can be disabled)
27+
- Supports delayed event processing and retry mechanisms with exponential backoff
28+
29+
### File Store System
30+
- Implements a common `FileStore` interface across all storage providers
31+
- Supports both streaming and buffer-based file operations
32+
- Uses environment variables for provider-specific configuration
33+
- Handles authentication through provider-specific credential chains (AWS IAM, GCP ADC, Azure Managed Identity)
34+
35+
### Plugin Registration
36+
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`).
37+
38+
## Testing
39+
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.
40+
41+
## Build Configuration
42+
- TypeScript configuration uses `tsconfig.build.json` for production builds
43+
- Excludes test files (`**/*.spec.ts`) from production builds
44+
- Outputs to `dist/` directory with type definitions

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Fastify plugins for Stackbox applications.
55
## Installation
66

77
```bash
8+
pnpm install @stackbox/fp-plugins
9+
# or
810
npm install @stackbox/fp-plugins
911
```
1012

@@ -100,7 +102,7 @@ app.register(Plugins.EventBus, {
100102
#### Usage Example
101103

102104
```typescript
103-
import { EventBus, Plugins } from "@stackbox/fp-plugins";
105+
import { EventBus, Plugins, EventBusOptions, EventMessage } from "@stackbox/fp-plugins";
104106

105107
const app = fastify();
106108

@@ -251,6 +253,7 @@ The plugin provides a `FileStore` interface with the following methods:
251253
```typescript
252254
interface FileStore {
253255
exists(filepath: string): Promise<boolean>;
256+
getInfo(filepath: string): Promise<FileInfo | null>;
254257
save(
255258
filepath: string,
256259
contentType: string,
@@ -269,12 +272,18 @@ interface FileStore {
269272
localFilepath: string,
270273
): Promise<void>;
271274
}
275+
276+
interface FileInfo {
277+
size: number;
278+
contentType: string;
279+
lastModified: Date;
280+
}
272281
```
273282

274283
#### Usage Example
275284

276285
```typescript
277-
import { Plugins } from "@stackbox/fp-plugins";
286+
import { Plugins, FileStore } from "@stackbox/fp-plugins";
278287
import { fastify } from "fastify";
279288

280289
const app = fastify();
@@ -291,6 +300,12 @@ app.post("/upload", async (request, reply) => {
291300
// Check if file exists
292301
const exists = await request.server.FileStore.exists(filepath);
293302

303+
// Get file info (returns null if file doesn't exist)
304+
const fileInfo = await request.server.FileStore.getInfo(filepath);
305+
if (fileInfo) {
306+
console.log(`File size: ${fileInfo.size}, Content type: ${fileInfo.contentType}`);
307+
}
308+
294309
// Save file
295310
await request.server.FileStore.save(filepath, contentType, data);
296311

@@ -318,6 +333,26 @@ app.post("/upload", async (request, reply) => {
318333
});
319334
```
320335

336+
## Development
337+
338+
### Prerequisites
339+
- Node.js 18+
340+
- pnpm
341+
342+
### Setup
343+
```bash
344+
pnpm install
345+
```
346+
347+
### Common Commands
348+
- `pnpm test` - Run tests
349+
- `pnpm run test:coverage` - Run tests with coverage
350+
- `pnpm run build` - Build the project
351+
- `pnpm run pretty` - Format code
352+
353+
### Testing
354+
Tests are written using Jest and located alongside source files with `.spec.ts` extension.
355+
321356
## Contributing
322357

323358
Contributions are welcome! Please feel free to submit a Pull Request.

pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
onlyBuiltDependencies:
2+
- protobufjs
3+
- unrs-resolver

0 commit comments

Comments
 (0)