From 08796f688a780bcf7edfa56556994962eac2fc30 Mon Sep 17 00:00:00 2001 From: Nipuna Perera Date: Sun, 26 Oct 2025 16:39:33 +0000 Subject: [PATCH 01/50] feat: Complete Phase 1 - Core Features + Monitoring MVP Features Implemented: - Core UI: Tree view, Query Editor, Process List, Variables viewer - Monitoring: Metrics Dashboard with Chart.js, EXPLAIN D3.js visualization - Performance: Queries Without Indexes detection, Slow Queries panel - Query Analysis: EXPLAIN viewer with table and tree views - Connection Management: Save/load connections, SSL/TLS support - Security: Input validation, SQL injection prevention, data anonymization Technical Highlights: - Service Container architecture with dependency injection - Event-driven architecture using Event Bus - MySQL/MariaDB 8.0+ support with Performance Schema integration - Performance Schema configuration with user consent flow - Webview panels with CSP, error boundaries, and refresh mechanisms - Real-time metrics collection and visualization - Query profiling via MySQL Performance Schema Bug Fixes: - Fixed SQL validation false positives for system queries - Fixed logger string interpolation issues with % characters - Fixed Chart.js canvas reuse and date adapter issues - Added explicit DOCTYPE to all webviews to prevent Quirks Mode - Improved system query detection for Performance Schema queries Documentation: - Comprehensive PRD with implementation status tracking - Product roadmap with phase-by-phase breakdown - Architecture documents (ARDs) covering all major components - Privacy and anonymization strategy documentation - Contributing guidelines and security policy Testing: - Unit tests for InputValidator - Integration test setup with Jest - Docker compose for MySQL test environment --- .eslintrc.js | 32 + .gitignore | 25 + .vscodeignore | 44 + CONTRIBUTING.md | 669 + LICENSE | 2 +- QUICKSTART.md | 233 + README.md | 284 + SECURITY.md | 503 + docker-compose.test.yml | 50 + docs/ANONYMIZATION_STRATEGY.md | 574 + docs/PRD.md | 2911 ++++ docs/PRIVACY.md | 517 + docs/PRODUCT_ROADMAP.md | 356 + docs/ards/00-ARCHITECTURE_REVIEW.md | 239 + docs/ards/01-SYSTEM_ARCHITECTURE.md | 1046 ++ docs/ards/02-DATABASE_ADAPTER.md | 687 + docs/ards/03-AI_INTEGRATION.md | 525 + docs/ards/04-SECURITY_ARCHITECTURE.md | 129 + docs/ards/05-WEBVIEW_ARCHITECTURE.md | 158 + docs/ards/06-PERFORMANCE_SCALABILITY.md | 135 + jest.config.js | 17 + jest.integration.config.js | 21 + media/connectionDialogView.css | 211 + media/connectionDialogView.js | 246 + media/explainViewerView.css | 535 + media/explainViewerView.js | 432 + media/metricsDashboardView.css | 213 + media/metricsDashboardView.js | 600 + media/processListView.css | 229 + media/processListView.js | 257 + media/queriesWithoutIndexesView.css | 286 + media/queriesWithoutIndexesView.js | 216 + media/queryEditorView.css | 352 + media/queryEditorView.js | 402 + media/queryProfilingView.css | 8 + media/queryProfilingView.js | 57 + media/slowQueriesView.css | 16 + media/slowQueriesView.js | 133 + media/variablesView.css | 150 + media/variablesView.js | 219 + package-lock.json | 14475 ++++++++++++++++ package.json | 360 + resources/mydba-icon.png | Bin 0 -> 8319 bytes resources/mydba-icon.svg | 19 + resources/mydba.png | Bin 0 -> 748733 bytes resources/mydba.svg | 47 + src/adapters/adapter-registry.ts | 46 + src/adapters/database-adapter.ts | 189 + src/adapters/mysql-adapter.ts | 474 + src/commands/command-registry.ts | 383 + src/core/service-container.ts | 211 + src/extension.ts | 123 + src/providers/tree-view-provider.ts | 288 + src/services/ai-service-coordinator.ts | 72 + src/services/ai-service.ts | 343 + src/services/configuration-service.ts | 20 + src/services/connection-manager.ts | 365 + src/services/event-bus.ts | 112 + src/services/metrics-collector.ts | 72 + .../queries-without-indexes-service.ts | 357 + src/services/query-profiling-service.ts | 225 + src/services/query-service.ts | 29 + src/services/secret-storage-service.ts | 84 + src/services/slow-queries-service.ts | 71 + src/types/index.ts | 311 + src/utils/__tests__/input-validator.test.ts | 30 + src/utils/data-sanitizer.ts | 237 + src/utils/input-validator.ts | 265 + src/utils/logger.ts | 82 + src/webviews/base-webview-provider.ts | 51 + src/webviews/connection-dialog-panel.ts | 408 + src/webviews/explain-viewer-panel.ts | 626 + src/webviews/explain-viewer-provider.ts | 415 + src/webviews/metrics-dashboard-panel.ts | 550 + src/webviews/process-list-panel.ts | 296 + src/webviews/profiling-viewer-provider.ts | 490 + src/webviews/queries-without-indexes-panel.ts | 399 + src/webviews/query-editor-panel.ts | 603 + src/webviews/query-profiling-panel.ts | 146 + src/webviews/slow-queries-panel.ts | 211 + src/webviews/variables-panel.ts | 203 + src/webviews/webview-manager.ts | 155 + test/sql/sample-data.sql | 58 + test/test-extension.sh | 55 + tsconfig.json | 21 + 85 files changed, 37695 insertions(+), 1 deletion(-) create mode 100644 .eslintrc.js create mode 100644 .gitignore create mode 100644 .vscodeignore create mode 100644 CONTRIBUTING.md create mode 100644 QUICKSTART.md create mode 100644 README.md create mode 100644 SECURITY.md create mode 100644 docker-compose.test.yml create mode 100644 docs/ANONYMIZATION_STRATEGY.md create mode 100644 docs/PRD.md create mode 100644 docs/PRIVACY.md create mode 100644 docs/PRODUCT_ROADMAP.md create mode 100644 docs/ards/00-ARCHITECTURE_REVIEW.md create mode 100644 docs/ards/01-SYSTEM_ARCHITECTURE.md create mode 100644 docs/ards/02-DATABASE_ADAPTER.md create mode 100644 docs/ards/03-AI_INTEGRATION.md create mode 100644 docs/ards/04-SECURITY_ARCHITECTURE.md create mode 100644 docs/ards/05-WEBVIEW_ARCHITECTURE.md create mode 100644 docs/ards/06-PERFORMANCE_SCALABILITY.md create mode 100644 jest.config.js create mode 100644 jest.integration.config.js create mode 100644 media/connectionDialogView.css create mode 100644 media/connectionDialogView.js create mode 100644 media/explainViewerView.css create mode 100644 media/explainViewerView.js create mode 100644 media/metricsDashboardView.css create mode 100644 media/metricsDashboardView.js create mode 100644 media/processListView.css create mode 100644 media/processListView.js create mode 100644 media/queriesWithoutIndexesView.css create mode 100644 media/queriesWithoutIndexesView.js create mode 100644 media/queryEditorView.css create mode 100644 media/queryEditorView.js create mode 100644 media/queryProfilingView.css create mode 100644 media/queryProfilingView.js create mode 100644 media/slowQueriesView.css create mode 100644 media/slowQueriesView.js create mode 100644 media/variablesView.css create mode 100644 media/variablesView.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 resources/mydba-icon.png create mode 100644 resources/mydba-icon.svg create mode 100644 resources/mydba.png create mode 100644 resources/mydba.svg create mode 100644 src/adapters/adapter-registry.ts create mode 100644 src/adapters/database-adapter.ts create mode 100644 src/adapters/mysql-adapter.ts create mode 100644 src/commands/command-registry.ts create mode 100644 src/core/service-container.ts create mode 100644 src/extension.ts create mode 100644 src/providers/tree-view-provider.ts create mode 100644 src/services/ai-service-coordinator.ts create mode 100644 src/services/ai-service.ts create mode 100644 src/services/configuration-service.ts create mode 100644 src/services/connection-manager.ts create mode 100644 src/services/event-bus.ts create mode 100644 src/services/metrics-collector.ts create mode 100644 src/services/queries-without-indexes-service.ts create mode 100644 src/services/query-profiling-service.ts create mode 100644 src/services/query-service.ts create mode 100644 src/services/secret-storage-service.ts create mode 100644 src/services/slow-queries-service.ts create mode 100644 src/types/index.ts create mode 100644 src/utils/__tests__/input-validator.test.ts create mode 100644 src/utils/data-sanitizer.ts create mode 100644 src/utils/input-validator.ts create mode 100644 src/utils/logger.ts create mode 100644 src/webviews/base-webview-provider.ts create mode 100644 src/webviews/connection-dialog-panel.ts create mode 100644 src/webviews/explain-viewer-panel.ts create mode 100644 src/webviews/explain-viewer-provider.ts create mode 100644 src/webviews/metrics-dashboard-panel.ts create mode 100644 src/webviews/process-list-panel.ts create mode 100644 src/webviews/profiling-viewer-provider.ts create mode 100644 src/webviews/queries-without-indexes-panel.ts create mode 100644 src/webviews/query-editor-panel.ts create mode 100644 src/webviews/query-profiling-panel.ts create mode 100644 src/webviews/slow-queries-panel.ts create mode 100644 src/webviews/variables-panel.ts create mode 100644 src/webviews/webview-manager.ts create mode 100644 test/sql/sample-data.sql create mode 100755 test/test-extension.sh create mode 100644 tsconfig.json diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..748da6e --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,32 @@ +module.exports = { + root: true, + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 6, + sourceType: 'module', + }, + plugins: [ + '@typescript-eslint' + ], + rules: { + '@typescript-eslint/naming-convention': [ + 'warn', + { + 'selector': 'import', + 'format': ['camelCase', 'PascalCase'] + } + ], + '@typescript-eslint/semi': 'warn', + 'curly': 'warn', + 'eqeqeq': 'warn', + 'no-throw-literal': 'warn', + 'semi': 'off' + }, + ignorePatterns: [ + 'out', + 'dist', + '**/*.d.ts', + 'node_modules', + 'coverage' + ] +}; diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d1da0b --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +out +dist +node_modules +*.vsix +coverage +.nyc_output +.vscode-test/ +.vscode/ +*.log +.DS_Store +.env +.env.local +.env.development.local +.env.test.local +.env.production.local +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Temporary files and scripts +docs/tmp/ +temp/ +*.tmp diff --git a/.vscodeignore b/.vscodeignore new file mode 100644 index 0000000..7c87c22 --- /dev/null +++ b/.vscodeignore @@ -0,0 +1,44 @@ +.vscode/** +.vscode-test/** +src/** +.gitignore +.yarnrc +vsc-extension-quickstart.md +**/tsconfig.json +**/.eslintrc.json +**/*.map +**/*.ts +test/** +jest.config.js +jest.integration.config.js +docker-compose.test.yml +test/** +*.test.js +*.test.ts +coverage/** +.nyc_output/** +node_modules/** +*.log +.DS_Store +.env +.env.local +.env.development.local +.env.test.local +.env.production.local +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* +docs/** +!docs/PRD.md +!docs/PRIVACY.md +!docs/ANONYMIZATION_STRATEGY.md +!docs/ards/** +*.md +LICENSE +CONTRIBUTING.md +SECURITY.md +QUICKSTART.md +# Keep icon +!resources/mydba-icon.png diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e01e614 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,669 @@ +# Contributing to MyDBA + +Thank you for your interest in contributing to MyDBA! This document provides guidelines and instructions for contributing to the project. + +--- + +## 📋 Table of Contents + +- [Code of Conduct](#code-of-conduct) +- [Getting Started](#getting-started) +- [Development Setup](#development-setup) +- [Project Structure](#project-structure) +- [Development Workflow](#development-workflow) +- [Coding Standards](#coding-standards) +- [Testing Guidelines](#testing-guidelines) +- [Submitting Changes](#submitting-changes) +- [Pull Request Process](#pull-request-process) +- [Documentation](#documentation) +- [Community](#community) + +--- + +## Code of Conduct + +This project adheres to a Code of Conduct that all contributors are expected to follow. Please be respectful, inclusive, and considerate in all interactions. + +### Our Standards + +- **Be Respectful**: Treat all contributors with respect and kindness +- **Be Inclusive**: Welcome contributors of all backgrounds and skill levels +- **Be Collaborative**: Work together to improve the project +- **Be Professional**: Keep discussions focused and constructive +- **Be Patient**: Remember that everyone was a beginner once + +### Unacceptable Behavior + +- Harassment, discrimination, or offensive comments +- Personal attacks or trolling +- Spam or self-promotion +- Sharing private information without consent +- Any behavior that would be inappropriate in a professional setting + +### Reporting + +If you experience or witness unacceptable behavior, please report it to the project maintainers at conduct@mydba.dev. + +--- + +## Getting Started + +### Prerequisites + +Before you begin, ensure you have the following installed: + +- **Node.js**: v18.x or v20.x LTS ([Download](https://nodejs.org/)) +- **npm**: v9.x or higher (comes with Node.js) +- **VSCode**: v1.85.0 or higher ([Download](https://code.visualstudio.com/)) +- **Git**: v2.30 or higher ([Download](https://git-scm.com/)) +- **Docker**: For running test databases (optional but recommended) + +### Fork and Clone + +1. **Fork the repository** on GitHub (click "Fork" button) + +2. **Clone your fork**: + ```bash + git clone https://github.com/YOUR_USERNAME/mydba.git + cd mydba + ``` + +3. **Add upstream remote**: + ```bash + git remote add upstream https://github.com/original/mydba.git + ``` + +4. **Verify remotes**: + ```bash + git remote -v + # origin https://github.com/YOUR_USERNAME/mydba.git (fetch) + # origin https://github.com/YOUR_USERNAME/mydba.git (push) + # upstream https://github.com/original/mydba.git (fetch) + # upstream https://github.com/original/mydba.git (push) + ``` + +--- + +## Development Setup + +### Install Dependencies + +```bash +npm install +``` + +### Build the Extension + +```bash +npm run compile +``` + +### Watch Mode (Auto-rebuild) + +```bash +npm run watch +``` + +### Run in VSCode + +1. Open the project in VSCode +2. Press `F5` to launch the Extension Development Host +3. A new VSCode window will open with MyDBA installed +4. Test your changes in this window + +### Set Up Test Databases (Optional) + +```bash +# Start MySQL 8.0 and MariaDB 10.11 containers +docker-compose up -d + +# Verify containers are running +docker ps +``` + +Default test database credentials (from `docker-compose.yml`): +- **MySQL 8.0**: `localhost:3306`, user: `root`, password: `test_password` +- **MariaDB 10.11**: `localhost:3307`, user: `root`, password: `test_password` + +For profiling and EXPLAIN features, ensure Performance Schema is enabled for MySQL 8.0+. + +--- + +## Project Structure + +``` +mydba/ +├── src/ # Source code +│ ├── extension.ts # Extension entry point +│ ├── connection/ # Database connection management +│ ├── views/ # Tree view providers +│ ├── webviews/ # Webview panels and content +│ ├── ai/ # AI integration (LM API, RAG, chat) +│ ├── queries/ # SQL query builders +│ ├── metrics/ # Performance metrics collection +│ └── utils/ # Utility functions +├── test/ # Tests +│ ├── unit/ # Unit tests +│ ├── integration/ # Integration tests +│ └── e2e/ # End-to-end tests +├── docs/ # Documentation +│ ├── PRD.md # Product Requirements Document +│ ├── PRIVACY.md # Privacy Policy +│ └── ANONYMIZATION_STRATEGY.md # Query templating spec +├── resources/ # Icons, images, CSS +├── package.json # Extension manifest and dependencies +├── tsconfig.json # TypeScript configuration +├── .eslintrc.json # ESLint configuration +├── .prettierrc # Prettier configuration +└── docker-compose.yml # Test database setup +``` + +--- + +## Development Workflow + +### 1. Create a Branch + +Always create a new branch for your work: + +```bash +git checkout -b feature/your-feature-name +# or +git checkout -b fix/issue-number-description +``` + +**Branch Naming Conventions**: +- `feature/` - New features +- `fix/` - Bug fixes +- `docs/` - Documentation changes +- `refactor/` - Code refactoring +- `test/` - Test additions/improvements +- `chore/` - Build, CI, or maintenance tasks + +### 2. Make Your Changes + +- Write clean, readable code +- Follow the [Coding Standards](#coding-standards) +- Add tests for new features or bug fixes +- Update documentation if needed + +### 3. Test Your Changes + +```bash +# Run unit tests +npm test + +# Run with coverage +npm run test:coverage + +# Run integration tests +npm run test:integration + +# Run E2E tests (requires VSCode) +npm run test:e2e + +# Lint code +npm run lint + +# Format code +npm run format +``` + +### 4. Commit Your Changes + +We use [Conventional Commits](https://www.conventionalcommits.org/) format: + +```bash +git add . +git commit -m "feat: add support for custom system views" +``` + +**Commit Message Format**: +``` +(): + + + +