|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## important-instruction-reminders |
| 6 | + |
| 7 | +- Do what has been asked; nothing more, nothing less. |
| 8 | +- NEVER create files unless they're absolutely necessary for achieving your goal. |
| 9 | +- ALWAYS prefer editing an existing file to creating a new one. |
| 10 | + |
| 11 | +## Project Overview |
| 12 | + |
| 13 | +Pandino is an OSGi-style framework for TypeScript that provides modular architecture, service registry, and dynamic dependency injection. The project follows a monorepo structure with multiple packages managed by pnpm workspaces. |
| 14 | + |
| 15 | +## Common Development Commands |
| 16 | + |
| 17 | +### Build Commands |
| 18 | +- `pnpm build` - Build all packages recursively |
| 19 | +- `pnpm build:dev` - Build all packages in development mode |
| 20 | +- `pnpm build:pandino` - Build only the core pandino package |
| 21 | +- `pnpm build:react-hooks` - Build only the React hooks package |
| 22 | + |
| 23 | +### Testing Commands |
| 24 | +- `pnpm test` - Run all tests using Vitest |
| 25 | +- `pnpm test:watch` - Run tests in watch mode |
| 26 | +- `pnpm test:coverage` - Run tests with coverage report |
| 27 | +- `vitest run --reporter=verbose` - Run tests with detailed output |
| 28 | +- Individual package tests: `cd packages/<package-name> && pnpm test` |
| 29 | + |
| 30 | +### Development Commands |
| 31 | +- `pnpm dev:example` - Start the example application |
| 32 | +- `pnpm lint` - Run oxlint for code linting |
| 33 | +- `pnpm format:write` - Format code using Biome |
| 34 | + |
| 35 | +### Package Management |
| 36 | +- Uses pnpm workspaces with packages in `packages/` directory |
| 37 | +- Node.js >=22 and pnpm >=10 required |
| 38 | +- Workspace dependencies use `workspace:*` protocol |
| 39 | + |
| 40 | +## Project Architecture |
| 41 | + |
| 42 | +### Core Packages Structure |
| 43 | +- `packages/pandino/` - Core framework (service registry, bundles, lifecycle management) |
| 44 | +- `packages/react-hooks/` - React integration with hooks and components |
| 45 | +- `packages/decorators/` - Decorators for Service Component Runtime (SCR) |
| 46 | +- `packages/rollup-bundle-plugin/` - Rollup plugin for bundle automation |
| 47 | +- `packages/example/` - Example application demonstrating usage |
| 48 | + |
| 49 | +### Key Architectural Concepts |
| 50 | + |
| 51 | +**Service Registry Pattern**: Central registry where services are registered by interface and discovered dynamically using LDAP-style filters. |
| 52 | + |
| 53 | +**Bundle System**: Self-contained modules with independent lifecycles. Each bundle has an activator that manages service registration/cleanup. |
| 54 | + |
| 55 | +**Service Component Runtime (SCR)**: Declarative service management using decorators (`@Component`, `@Service`, `@Reference`, `@Activate`). |
| 56 | + |
| 57 | +**Dynamic Dependencies**: Services can start in any order - dependencies are resolved automatically when services become available. |
| 58 | + |
| 59 | +### Core Framework Structure (`packages/pandino/src/`) |
| 60 | +- `framework/` - Core framework implementation and bootstrap |
| 61 | +- `services/` - Built-in services (service registry, event admin, etc.) |
| 62 | +- `bundle/` - Bundle management and lifecycle |
| 63 | +- `types/` - TypeScript interfaces and type definitions |
| 64 | +- `test/` - Test utilities and setup |
| 65 | + |
| 66 | +## Development Patterns |
| 67 | + |
| 68 | +### Service Definition Pattern |
| 69 | +```typescript |
| 70 | +// 1. Define interface |
| 71 | +interface MyService { |
| 72 | + doSomething(): void; |
| 73 | +} |
| 74 | + |
| 75 | +// 2. Implement with SCR decorators |
| 76 | +@Component({ name: 'my.service', immediate: true }) |
| 77 | +@Service({ interfaces: ['MyService'] }) |
| 78 | +class MyServiceImpl implements MyService { |
| 79 | + @Reference({ interface: 'DependencyService' }) |
| 80 | + private dependency?: DependencyService; |
| 81 | + |
| 82 | + @Activate |
| 83 | + activate(context: ComponentContext): void { |
| 84 | + // Initialization logic |
| 85 | + } |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### Bundle Activator Pattern |
| 90 | +```typescript |
| 91 | +export class BundleActivator { |
| 92 | + async start(context: BundleContext): Promise<void> { |
| 93 | + // Register services, event listeners |
| 94 | + } |
| 95 | + |
| 96 | + async stop(context: BundleContext): Promise<void> { |
| 97 | + // Cleanup |
| 98 | + } |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +## Testing Configuration |
| 103 | + |
| 104 | +- Vitest configuration in root and individual packages |
| 105 | +- Uses jsdom environment for DOM-related tests |
| 106 | +- Coverage reports with @vitest/coverage-v8 |
| 107 | +- Test files follow `*.test.ts` pattern |
| 108 | + |
| 109 | +## Code Quality Tools |
| 110 | + |
| 111 | +### Formatting & Linting |
| 112 | +- **Biome**: Code formatting with 2-space indentation, 120 character line width |
| 113 | +- **oxlint**: Fast linting (Biome linter disabled in favor of oxlint) |
| 114 | +- **TypeScript**: Strict type checking with multiple tsconfig files |
| 115 | + |
| 116 | +### Import Organization |
| 117 | +- Biome automatically organizes imports |
| 118 | +- Use `reflect-metadata` for decorator support |
| 119 | +- Peer dependency on `@pandino/decorators` |
| 120 | + |
| 121 | +## Build System |
| 122 | + |
| 123 | +- **Vite**: Module bundling with TypeScript support |
| 124 | +- **vite-plugin-dts**: Automatic TypeScript declaration generation |
| 125 | +- **Dual Format**: Generates both ESM and CJS outputs |
| 126 | +- **Type Exports**: Proper TypeScript module resolution support |
| 127 | + |
| 128 | +## Key Files for Understanding |
| 129 | +- `packages/pandino/src/framework/framework.ts` - Core framework implementation |
| 130 | +- `packages/pandino/src/services/` - Built-in service implementations |
| 131 | +- `packages/pandino/src/types/` - Type definitions for the entire system |
| 132 | +- Root `package.json` - Workspace configuration and scripts |
0 commit comments