|
1 | | -# [PROJECT_NAME] Constitution |
2 | | -<!-- Example: Spec Constitution, TaskFlow Constitution, etc. --> |
| 1 | +<!-- |
| 2 | + SYNC IMPACT REPORT |
| 3 | + ================== |
| 4 | + Version Change: NONE → 1.0.0 |
| 5 | + Constitution Type: New (Initial Ratification) |
| 6 | + |
| 7 | + Principles Defined: |
| 8 | + 1. Security First |
| 9 | + 2. Deterministic & Production-Grade |
| 10 | + 3. Bundled Dependencies |
| 11 | + 4. Grafana Plugin Standards |
| 12 | + 5. React-Based UI |
| 13 | + 6. Clear Architecture |
| 14 | + 7. Type Safety |
| 15 | + 8. PEV2 Integration |
| 16 | + 9. Error Handling |
| 17 | + 10. Performance |
| 18 | + |
| 19 | + Additional Sections: |
| 20 | + - Quality Standards |
| 21 | + - Development Workflow |
| 22 | + - Governance |
| 23 | + |
| 24 | + Templates Status: |
| 25 | + ✅ plan-template.md - Reviewed, no updates needed (generic template structure compatible) |
| 26 | + ✅ spec-template.md - Reviewed, no updates needed (generic template structure compatible) |
| 27 | + ✅ tasks-template.md - Reviewed, no updates needed (generic template structure compatible) |
| 28 | + ✅ agent-file-template.md - Reviewed, no updates needed (generic template) |
| 29 | + ✅ checklist-template.md - Reviewed, no updates needed (generic template) |
| 30 | + |
| 31 | + Follow-up TODOs: None |
| 32 | + |
| 33 | + Generated: 2025-11-24 |
| 34 | +--> |
| 35 | + |
| 36 | +# Grafana Panel Plugin for PostgreSQL EXPLAIN Visualization Constitution |
| 37 | + |
| 38 | +**Project**: cybertec-pev-panel |
| 39 | +**Domain**: Grafana plugin development, TypeScript, React, PostgreSQL query analysis |
| 40 | +**Expert Role**: Grafana plugin engineer and TypeScript architect |
3 | 41 |
|
4 | 42 | ## Core Principles |
5 | 43 |
|
6 | | -### [PRINCIPLE_1_NAME] |
7 | | -<!-- Example: I. Library-First --> |
8 | | -[PRINCIPLE_1_DESCRIPTION] |
9 | | -<!-- Example: Every feature starts as a standalone library; Libraries must be self-contained, independently testable, documented; Clear purpose required - no organizational-only libraries --> |
| 44 | +### I. Security First |
| 45 | + |
| 46 | +All code MUST prioritize security above convenience. Never use unsafe HTML rendering (dangerouslySetInnerHTML), external CDN resources, iframes, or eval-based patterns. All user-provided content and PostgreSQL EXPLAIN output MUST be sanitized and validated before display. Grafana plugin sandboxing rules MUST be respected. No bypass of Content Security Policy. External scripts or resources are strictly prohibited. |
| 47 | + |
| 48 | +**Rationale**: Grafana runs in enterprise environments with sensitive data. Security vulnerabilities in plugins can compromise entire Grafana installations and expose production databases. |
| 49 | + |
| 50 | +### II. Deterministic & Production-Grade |
| 51 | + |
| 52 | +All code MUST compile without modification and be production-ready on first delivery. TypeScript strict mode MUST be enabled with zero compilation errors. No experimental features, unstable APIs, or "it works on my machine" patterns. Code MUST be fully typed, documented, and tested before delivery. No placeholder implementations or TODOs in production code. |
| 53 | + |
| 54 | +**Rationale**: Plugin failures in production can impact monitoring and observability. Deterministic behavior ensures reliability and reduces operational risk. |
| 55 | + |
| 56 | +### III. Bundled Dependencies |
| 57 | + |
| 58 | +All dependencies MUST be bundled within the plugin distribution. Zero external CDN usage. Zero runtime fetching of libraries, fonts, or resources. Plugin MUST work in air-gapped environments, VPNs, and restricted networks. PEV2 library and all its dependencies MUST be fully bundled using webpack or the Grafana build toolchain. |
| 59 | + |
| 60 | +**Rationale**: Enterprise Grafana installations often run in isolated networks. External dependencies create failure points and security risks. |
| 61 | + |
| 62 | +### IV. Grafana Plugin Standards |
| 63 | + |
| 64 | +Strictly follow Grafana plugin guidelines, conventions, and best practices. Use official Grafana APIs, lifecycle hooks, and data models. Adhere to plugin.json schema requirements. Follow Grafana's theming system and design patterns. Use @grafana/data for data transformation, @grafana/runtime for runtime services, and @grafana/ui for all UI components. |
| 65 | + |
| 66 | +**Rationale**: Grafana provides battle-tested patterns. Deviating from standards creates maintenance burden and compatibility issues across Grafana versions. |
| 67 | + |
| 68 | +### V. React-Based UI |
| 69 | + |
| 70 | +All UI components MUST be React-based using @grafana/ui components. No vanilla JavaScript DOM manipulation, jQuery, or imperative DOM updates. Leverage Grafana's theme-aware components for consistency. Use React hooks and functional components as the primary pattern. No class components unless required by third-party integration. |
| 71 | + |
| 72 | +**Rationale**: React provides predictable UI updates and integrates seamlessly with Grafana's rendering pipeline. @grafana/ui ensures visual consistency and theme compatibility. |
| 73 | + |
| 74 | +### VI. Clear Architecture |
| 75 | + |
| 76 | +Favor explicitness over magic. Clear separation of concerns between data fetching, transformation, and presentation. Self-documenting code structure with intuitive file organization. Avoid overly clever abstractions or hidden dependencies. Each module should have a single, clear responsibility. |
| 77 | + |
| 78 | +**Rationale**: Plugins may be maintained by teams unfamiliar with the original implementation. Clear architecture reduces onboarding time and maintenance cost. |
| 79 | + |
| 80 | +### VII. Type Safety |
10 | 81 |
|
11 | | -### [PRINCIPLE_2_NAME] |
12 | | -<!-- Example: II. CLI Interface --> |
13 | | -[PRINCIPLE_2_DESCRIPTION] |
14 | | -<!-- Example: Every library exposes functionality via CLI; Text in/out protocol: stdin/args → stdout, errors → stderr; Support JSON + human-readable formats --> |
| 82 | +Leverage TypeScript fully. No 'any' types unless absolutely necessary (document justification). Comprehensive interfaces for all data structures. Use strict TypeScript compiler options. Type all props, state, events, and API responses. Define explicit types for PostgreSQL EXPLAIN JSON structures. |
15 | 83 |
|
16 | | -### [PRINCIPLE_3_NAME] |
17 | | -<!-- Example: III. Test-First (NON-NEGOTIABLE) --> |
18 | | -[PRINCIPLE_3_DESCRIPTION] |
19 | | -<!-- Example: TDD mandatory: Tests written → User approved → Tests fail → Then implement; Red-Green-Refactor cycle strictly enforced --> |
| 84 | +**Rationale**: Type safety catches bugs at compile time, provides IDE autocompletion, and serves as living documentation of data contracts. |
20 | 85 |
|
21 | | -### [PRINCIPLE_4_NAME] |
22 | | -<!-- Example: IV. Integration Testing --> |
23 | | -[PRINCIPLE_4_DESCRIPTION] |
24 | | -<!-- Example: Focus areas requiring integration tests: New library contract tests, Contract changes, Inter-service communication, Shared schemas --> |
| 86 | +### VIII. PEV2 Integration |
25 | 87 |
|
26 | | -### [PRINCIPLE_5_NAME] |
27 | | -<!-- Example: V. Observability, VI. Versioning & Breaking Changes, VII. Simplicity --> |
28 | | -[PRINCIPLE_5_DESCRIPTION] |
29 | | -<!-- Example: Text I/O ensures debuggability; Structured logging required; Or: MAJOR.MINOR.BUILD format; Or: Start simple, YAGNI principles --> |
| 88 | +Integrate the PEV2 (Postgres EXPLAIN Visualizer 2) library for EXPLAIN visualization while maintaining security and bundling requirements. PEV2 MUST be bundled, not loaded from CDN. Any required modifications to PEV2 MUST preserve its core visualization logic. Encapsulate PEV2 within a React component wrapper that handles Grafana-specific concerns (theming, data transformation, error handling). |
30 | 89 |
|
31 | | -## [SECTION_2_NAME] |
32 | | -<!-- Example: Additional Constraints, Security Requirements, Performance Standards, etc. --> |
| 90 | +**Rationale**: PEV2 is the proven standard for PostgreSQL EXPLAIN visualization. Proper integration ensures users get expert-level query analysis while maintaining plugin security and reliability standards. |
33 | 91 |
|
34 | | -[SECTION_2_CONTENT] |
35 | | -<!-- Example: Technology stack requirements, compliance standards, deployment policies, etc. --> |
| 92 | +### IX. Error Handling |
36 | 93 |
|
37 | | -## [SECTION_3_NAME] |
38 | | -<!-- Example: Development Workflow, Review Process, Quality Gates, etc. --> |
| 94 | +Robust error boundaries at component boundaries. Graceful degradation when EXPLAIN data is malformed or incomplete. User-friendly error messages that guide users to resolution (e.g., "Invalid EXPLAIN JSON format. Ensure query returns EXPLAIN (FORMAT JSON) output"). All errors logged with sufficient context for debugging. No silent failures or generic error messages. |
39 | 95 |
|
40 | | -[SECTION_3_CONTENT] |
41 | | -<!-- Example: Code review requirements, testing gates, deployment approval process, etc. --> |
| 96 | +**Rationale**: Query analysis involves parsing complex JSON from diverse PostgreSQL versions. Clear error messages reduce support burden and improve user experience. |
| 97 | + |
| 98 | +### X. Performance |
| 99 | + |
| 100 | +Efficient rendering for large EXPLAIN plans (1000+ nodes). Proper React optimization (memoization, virtualization for large trees). Minimal bundle size where possible without sacrificing functionality or bundling requirements. Lazy loading of PEV2 visualization logic if beneficial. Avoid unnecessary re-renders or computation. |
| 101 | + |
| 102 | +**Rationale**: PostgreSQL EXPLAIN plans can be very large. Poor performance degrades the user experience and can make the plugin unusable for complex queries. |
| 103 | + |
| 104 | +## Quality Standards |
| 105 | + |
| 106 | +All code MUST meet the following quality gates before delivery: |
| 107 | + |
| 108 | +- **Compilation**: Zero TypeScript errors with strict mode enabled |
| 109 | +- **Runtime**: No console errors or warnings in browser developer tools |
| 110 | +- **UI**: Responsive design supporting Grafana's responsive breakpoints |
| 111 | +- **Accessibility**: Keyboard navigation support, ARIA labels where appropriate |
| 112 | +- **Compatibility**: Works with Grafana 10.4.0+ and modern browsers (Chrome, Firefox, Safari, Edge) |
| 113 | +- **Documentation**: Clear README with setup instructions, usage examples, and troubleshooting guide |
| 114 | + |
| 115 | +## Development Workflow |
| 116 | + |
| 117 | +### Constitution Check Gates |
| 118 | + |
| 119 | +Before any feature implementation: |
| 120 | + |
| 121 | +1. **Security Review**: Verify no unsafe patterns (innerHTML, external resources, eval) |
| 122 | +2. **Dependency Audit**: Confirm all dependencies are bundled, no CDN usage |
| 123 | +3. **Type Safety Check**: Ensure strict TypeScript, no 'any' types without justification |
| 124 | +4. **Grafana Standards**: Verify use of official Grafana APIs and @grafana/ui components |
| 125 | +5. **Error Handling**: Confirm error boundaries and user-friendly error messages |
| 126 | +6. **Performance**: Validate rendering performance with sample large EXPLAIN plans |
| 127 | + |
| 128 | +Re-check after design phase before implementation begins. |
| 129 | + |
| 130 | +### Code Review Requirements |
| 131 | + |
| 132 | +- All PRs MUST pass constitution compliance checks |
| 133 | +- Type safety verified (no 'any' escapes without documentation) |
| 134 | +- Security patterns validated (no unsafe HTML, external resources) |
| 135 | +- Error handling coverage confirmed |
| 136 | +- Performance impact assessed for large EXPLAIN plans |
42 | 137 |
|
43 | 138 | ## Governance |
44 | | -<!-- Example: Constitution supersedes all other practices; Amendments require documentation, approval, migration plan --> |
45 | 139 |
|
46 | | -[GOVERNANCE_RULES] |
47 | | -<!-- Example: All PRs/reviews must verify compliance; Complexity must be justified; Use [GUIDANCE_FILE] for runtime development guidance --> |
| 140 | +This constitution supersedes all other development practices. Any deviation MUST be explicitly documented and justified with rationale. |
| 141 | + |
| 142 | +### Amendment Process |
| 143 | + |
| 144 | +- Constitution amendments require version bump and documentation update |
| 145 | +- Breaking changes to principles require major version increment |
| 146 | +- New principles or expanded guidance require minor version increment |
| 147 | +- Clarifications and wording improvements require patch version increment |
| 148 | +- All amendments MUST include Sync Impact Report at top of file |
| 149 | + |
| 150 | +### Versioning Policy |
| 151 | + |
| 152 | +Constitution follows semantic versioning (MAJOR.MINOR.PATCH): |
| 153 | + |
| 154 | +- **MAJOR**: Backward incompatible governance changes or principle removals/redefinitions |
| 155 | +- **MINOR**: New principles added or materially expanded guidance |
| 156 | +- **PATCH**: Clarifications, wording improvements, non-semantic refinements |
| 157 | + |
| 158 | +### Compliance Review |
| 159 | + |
| 160 | +All feature specifications, implementation plans, and task lists MUST reference constitution principles. Violations MUST be tracked in Complexity Tracking section with explicit justification. |
48 | 161 |
|
49 | | -**Version**: [CONSTITUTION_VERSION] | **Ratified**: [RATIFICATION_DATE] | **Last Amended**: [LAST_AMENDED_DATE] |
50 | | -<!-- Example: Version: 2.1.1 | Ratified: 2025-06-13 | Last Amended: 2025-07-16 --> |
| 162 | +**Version**: 1.0.0 | **Ratified**: 2025-11-24 | **Last Amended**: 2025-11-24 |
0 commit comments