Skip to content

Commit e94d997

Browse files
committed
docs: add architecture guide for vscode-dbt-power-user extension
1 parent f96cd20 commit e94d997

File tree

1 file changed

+271
-0
lines changed

1 file changed

+271
-0
lines changed

CLAUDE.md

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
# Claude Code - dbt Power User VSCode Extension Architecture Guide
2+
3+
## Project Overview
4+
5+
**vscode-dbt-power-user** is a comprehensive VSCode extension that makes VSCode seamlessly work with dbt (data build tool). It's an open-source project published by Altimate AI that extends VSCode with advanced dbt features including auto-completion, query preview, lineage visualization, documentation generation, and AI-powered features.
6+
7+
### Key Statistics
8+
- **Version**: 0.57.3
9+
- **Project Type**: VSCode Extension (TypeScript/React)
10+
- **License**: MIT
11+
- **Architecture**: Multi-layered with webview panels, Python integrations, and MCP server
12+
13+
## High-Level Architecture
14+
15+
### 1. Core Extension Architecture
16+
17+
The extension follows a **dependency injection pattern** using Inversify container:
18+
19+
- **Entry Point**: `src/extension.ts``DBTPowerUserExtension`
20+
- **DI Container**: `src/inversify.config.ts` manages all service dependencies
21+
- **Main Extension Class**: `DBTPowerUserExtension` orchestrates all components
22+
23+
### 2. Multi-Process Architecture
24+
25+
The extension operates across multiple processes:
26+
27+
1. **Main Extension Process** (Node.js/TypeScript)
28+
- VSCode API integration
29+
- File system operations
30+
- dbt CLI interactions
31+
32+
2. **Webview Panels** (React/TypeScript)
33+
- Modern React-based UI components
34+
- Located in `webview_panels/` directory
35+
- Built with Vite, uses Antd for UI components
36+
37+
3. **Python Bridge Integration**
38+
- dbt core/cloud integration via Python scripts
39+
- Key files: `dbt_core_integration.py`, `dbt_cloud_integration.py`
40+
- Jupyter kernel for notebook functionality
41+
42+
4. **MCP Server** (Model Context Protocol)
43+
- AI integration and tool calling functionality
44+
- Located in `src/mcp/`
45+
46+
### 3. Key Module Organization
47+
48+
```
49+
src/
50+
├── manifest/ # dbt project parsing and management
51+
├── dbt_client/ # dbt integration (core, cloud, fusion)
52+
├── webview_provider/ # Webview panel management
53+
├── autocompletion_provider/ # Language server features
54+
├── services/ # Business logic services
55+
├── commands/ # VSCode command implementations
56+
├── mcp/ # Model Context Protocol server
57+
└── telemetry/ # Analytics and tracking
58+
```
59+
60+
## Core Functionality Areas
61+
62+
### 1. dbt Integration Support
63+
64+
**Multiple Integration Types**:
65+
- **dbt Core**: Direct Python integration
66+
- **dbt Cloud**: API-based integration
67+
- **dbt Fusion**: Command-line integration
68+
- **Core Command**: CLI wrapper integration
69+
70+
**Key Integration Files**:
71+
- `src/dbt_client/dbtCoreIntegration.ts`
72+
- `src/dbt_client/dbtCloudIntegration.ts`
73+
- `dbt_core_integration.py` (Python bridge)
74+
75+
### 2. Language Server Features
76+
77+
**Provider Architecture**: Each feature implemented as a separate provider:
78+
- `autocompletion_provider/` - IntelliSense for dbt models, macros, sources
79+
- `definition_provider/` - Go-to-definition functionality
80+
- `hover_provider/` - Hover information
81+
- `code_lens_provider/` - Inline actions
82+
- `validation_provider/` - SQL validation
83+
84+
### 3. Webview Panel System
85+
86+
**Modern React Architecture** (`webview_panels/`):
87+
- **Build System**: Vite + TypeScript + React 18
88+
- **State Management**: Redux Toolkit
89+
- **UI Framework**: Antd + custom components
90+
- **Data Visualization**: Perspective.js, Plotly.js
91+
92+
**Key Panels**:
93+
- `modules/dataPilot/` - AI chat interface
94+
- `modules/queryPanel/` - Query results and analysis
95+
- `modules/lineage/` - Data lineage visualization
96+
- `modules/documentationEditor/` - Documentation management
97+
- `modules/insights/` - Project insights and actions
98+
99+
### 4. AI and Advanced Features
100+
101+
**DataPilot AI Integration**:
102+
- Chat-based interface for dbt assistance
103+
- Query explanation and optimization
104+
- Documentation generation
105+
- Test suggestions
106+
107+
**MCP Server Integration**:
108+
- Tool calling for dbt operations
109+
- Integration with Claude and other AI models
110+
- Located in `src/mcp/server.ts`
111+
112+
## Build System and Tooling
113+
114+
### 1. Multi-Stage Build Process
115+
116+
**Main Extension Build** (Webpack):
117+
```bash
118+
npm run webpack # Development build
119+
npm run vscode:prepublish # Production build
120+
```
121+
122+
**Webview Panels Build** (Vite):
123+
```bash
124+
npm run panel:webviews # Build React components
125+
```
126+
127+
### 2. Development Workflow
128+
129+
**Key Scripts**:
130+
- `npm run watch` - Development with hot reload
131+
- `npm run test` - Jest-based testing
132+
- `npm run lint` - ESLint + Prettier
133+
- `npm run build-vsix` - Package extension
134+
135+
**Development Environment**:
136+
- Uses VSCode's built-in debugger ("Launch Extension")
137+
- Hot reload for webview panels
138+
- Python environment auto-detection
139+
140+
### 3. Testing Strategy
141+
142+
**Test Configuration** (`jest.config.js`):
143+
- **Unit Tests**: Jest + ts-jest
144+
- **Mock System**: Custom VSCode API mocks
145+
- **Coverage**: Istanbul-based coverage reporting
146+
- **Test Location**: `src/test/` with mock infrastructure
147+
148+
## Key Dependencies and Integrations
149+
150+
### 1. VSCode Extension Dependencies
151+
152+
**Required Extensions**:
153+
- `samuelcolvin.jinjahtml` - Jinja templating support
154+
- `ms-python.python` - Python environment integration
155+
- `altimateai.vscode-altimate-mcp-server` - MCP server
156+
157+
### 2. Major Technical Dependencies
158+
159+
**Backend (Node.js)**:
160+
- `inversify` - Dependency injection
161+
- `python-bridge` - Python process communication
162+
- `zeromq` - Jupyter kernel communication
163+
- `@modelcontextprotocol/sdk` - MCP protocol
164+
165+
**Frontend (React)**:
166+
- `react` 18 + `react-dom`
167+
- `@reduxjs/toolkit` - State management
168+
- `antd` - UI component library
169+
- `@finos/perspective` - Data grid and visualization
170+
171+
### 3. Python Integration
172+
173+
**Python Scripts**:
174+
- `dbt_core_integration.py` - Core dbt operations
175+
- `dbt_cloud_integration.py` - Cloud API operations
176+
- `dbt_healthcheck.py` - Project health analysis
177+
- `altimate_notebook_kernel.py` - Jupyter integration
178+
179+
## Configuration and Extensibility
180+
181+
### 1. Extension Configuration
182+
183+
**Comprehensive Settings** (190+ configuration options):
184+
- dbt integration mode selection
185+
- Query limits and templates
186+
- AI features and endpoints
187+
- Lineage visualization options
188+
- Defer-to-production configuration
189+
190+
### 2. Language Support
191+
192+
**File Type Associations**:
193+
- `jinja-sql` - Primary dbt model files
194+
- `jinja-yaml` - dbt configuration files
195+
- `jinja-md` - Documentation files
196+
- Custom notebook format (`.notebook`)
197+
198+
### 3. Command System
199+
200+
**80+ Commands Available**:
201+
- Model execution (`dbtPowerUser.runCurrentModel`)
202+
- Documentation generation (`dbtPowerUser.generateSchemaYML`)
203+
- Query analysis (`dbtPowerUser.sqlLineage`)
204+
- AI assistance (`dbtPowerUser.openDatapilotWithQuery`)
205+
206+
## Deployment and Distribution
207+
208+
### 1. Multi-Platform Distribution
209+
210+
**CI/CD Pipeline** (`.github/workflows/ci.yml`):
211+
- **Build Matrix**: macOS, Ubuntu, Windows
212+
- **Visual Studio Marketplace**: Primary distribution
213+
- **OpenVSX Registry**: Open-source alternative
214+
- **Platform-specific builds**: Architecture-aware packaging
215+
216+
### 2. Release Process
217+
218+
**Automated Release**:
219+
- Git tag triggers release pipeline
220+
- Pre-release and stable channel support
221+
- Slack notifications for release status
222+
- VSIX package generation
223+
224+
## Development Guidelines
225+
226+
### 1. Code Organization Principles
227+
228+
- **Dependency Injection**: All services use Inversify DI
229+
- **Provider Pattern**: Language features as modular providers
230+
- **Event-Driven**: Manifest changes trigger updates across components
231+
- **Separation of Concerns**: Clear boundaries between UI, business logic, and dbt integration
232+
233+
### 2. Adding New Features
234+
235+
**For Language Features**:
236+
1. Create provider in appropriate `*_provider/` directory
237+
2. Register in `inversify.config.ts`
238+
3. Wire up in `DBTPowerUserExtension`
239+
240+
**For UI Features**:
241+
1. Add React component in `webview_panels/src/modules/`
242+
2. Update routing in `AppRoutes.tsx`
243+
3. Add state management slice if needed
244+
245+
**For dbt Integration**:
246+
1. Extend appropriate dbt client (`dbtCoreIntegration.ts` etc.)
247+
2. Add Python bridge function if needed
248+
3. Update MCP server tools if AI-accessible
249+
250+
### 3. Testing Approach
251+
252+
- **Unit Tests**: Mock VSCode APIs and dependencies
253+
- **Integration Tests**: Test with real dbt projects
254+
- **Manual Testing**: Use "Launch Extension" debug configuration
255+
- **Webview Testing**: Storybook for component development
256+
257+
## Common Development Patterns
258+
259+
### 1. Manifest-Driven Architecture
260+
The extension heavily relies on dbt's `manifest.json` for understanding project structure. Most features key off manifest parsing events.
261+
262+
### 2. Multi-Integration Support
263+
Always consider how features work across dbt core, cloud, and other integration types. Use strategy pattern for integration-specific behavior.
264+
265+
### 3. Webview Communication
266+
Uses VSCode's webview messaging system with typed message contracts. State is synchronized between extension and webview contexts.
267+
268+
### 4. Python Bridge Pattern
269+
For dbt operations requiring Python, use the established bridge pattern with JSON serialization and error handling.
270+
271+
This architecture enables the extension to provide comprehensive dbt development support while maintaining modularity and extensibility for future enhancements.

0 commit comments

Comments
 (0)