|
| 1 | +--- |
| 2 | +description: Guidelines for developing GitHub constructs and extending DotGitHub functionality |
| 3 | +--- |
| 4 | + |
| 5 | +# Construct Development Guidelines |
| 6 | + |
| 7 | +## Construct Architecture |
| 8 | + |
| 9 | +Constructs in DotGitHub follow a specific pattern for extending functionality: |
| 10 | + |
| 11 | +- Constructs (loadable modules) are located in `packages/core/src/plugins/` |
| 12 | +- Each construct should export a main class and any helper classes |
| 13 | +- Constructs receive configuration through the stack context |
| 14 | +- Use dependency injection for better testability |
| 15 | + |
| 16 | +## Construct Interface |
| 17 | + |
| 18 | +```typescript |
| 19 | +export abstract class GitHubConstruct { |
| 20 | + readonly name: string; |
| 21 | + readonly version?: string; |
| 22 | + |
| 23 | + validate?(stack: GitHubStack): void; |
| 24 | + synthesize(stack: GitHubStack): Promise<void> | void; |
| 25 | + describe?(): ConstructDescription | Promise<ConstructDescription>; |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +## Action Collection Constructs |
| 30 | + |
| 31 | +For constructs that provide actions, extend [ActionCollection](mdc:packages/core/src/plugins/action-collection.ts): |
| 32 | + |
| 33 | +- Use `invokeAction()` for type-safe action invocation |
| 34 | +- Use `createOutputs()` for output management |
| 35 | +- Access the stack via `this.stack` |
| 36 | +- Implement proper error handling |
| 37 | + |
| 38 | +## Construct Configuration |
| 39 | + |
| 40 | +- Constructs receive configuration through `stack.config` |
| 41 | +- Use Zod schemas for configuration validation |
| 42 | +- Provide sensible defaults for optional configuration |
| 43 | +- Document all configuration options |
| 44 | + |
| 45 | +## Construct Registration |
| 46 | + |
| 47 | +- Constructs are registered in the configuration file under `constructs` |
| 48 | +- Use the construct manager for loading and initialization |
| 49 | +- Support construct dependencies and ordering |
| 50 | +- Handle construct loading errors gracefully |
| 51 | + |
| 52 | +## Testing Constructs |
| 53 | + |
| 54 | +- Create comprehensive unit tests for construct logic |
| 55 | +- Test configuration validation |
| 56 | +- Test construct integration with the stack |
| 57 | +- Use mocks for external dependencies |
| 58 | +- Test error conditions and edge cases |
0 commit comments