jit-architecture-deep-dive.mdā¢8.36 kB
# JIT Architecture Deep Dive - Code Structure Analysis
**Date**: January 12, 2025
**Version**: v5.1.0 JIT Analysis
**Purpose**: Comprehensive understanding of JIT implementation architecture for future development
---
## šļø JIT File Structure Discovery
### Key Finding: Hybrid Architecture ā”
The JIT implementation uses a **hybrid architecture** combining:
- **Standalone MCP Server**: `/dist/browser-automation-api-jit-v5.1.0.js`
- **Modular Tool Imports**: Imports from `/src/tools/` directory
- **Delegated Execution**: MCP handlers delegate to imported tool classes
### Architecture Components
#### 1. Main JIT Server (`/dist/browser-automation-api-jit-v5.1.0.js`)
```javascript
// File Location: /dist/browser-automation-api-jit-v5.1.0.js
// Last Modified: July 11 01:25 (Pre-fixes)
// Size: 20,633 bytes
// Type: Standalone MCP Server with imports
// Key Imports (Lines 22-30):
import { createSmartGuidanceTool } from '../src/tools/get-smart-guidance.js';
import { createContentWidgetAnalyzer } from '../src/tools/analyze-content-for-widgets.js';
import { createWidgetRequirementsTool } from '../src/tools/get-widget-requirements.js';
import { createLessonDataValidator } from '../src/tools/validate-lesson-data.js';
import { createComposerFormatter } from '../src/tools/format-for-composer.js';
import { createCompositionAPISaver } from '../src/tools/save-composition-api.js';
import { createCompositionEditorOpener } from '../src/tools/open-composition-editor.js';
```
#### 2. Tool Registration Pattern
```javascript
// 7 JIT Tools Registered (Lines 82-191):
{
name: 'get_smart_guidance', // STEP 1: Lightweight guidance
name: 'analyze_content_for_widgets', // STEP 2: Content analysis
name: 'get_widget_requirements', // STEP 3: JIT requirements
name: 'validate_lesson_data', // STEP 4: Auto-fix validation
name: 'format_for_composer', // STEP 5: Minimal transformation
name: 'save_composition_api', // STEP 6: API save
name: 'open_composition_editor' // STEP 7: Navigation
}
```
#### 3. Handler Delegation Pattern
```javascript
// Handler Pattern (Lines 194-240):
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
switch (request.params.name) {
case 'validate_lesson_data':
return this.validateLessonData(request.params.arguments); // Delegates to method
case 'open_composition_editor':
return this.openCompositionEditor(request.params.arguments); // Delegates to method
}
});
// Method Implementation Pattern:
async validateLessonData(args) {
// ... MCP wrapper logic ...
const validationResult = await this.lessonDataValidator.validateLessonData(lessonData);
// ā Delegates to imported tool class
}
async openCompositionEditor(args) {
// ... MCP wrapper + browser setup ...
const openResult = await this.compositionEditorOpener.openCompositionEditor(compositionUid, page);
// ā Delegates to imported tool class
}
```
### š Change Propagation Flow
```
1. Source Change: /src/tools/validate-lesson-data.js (Modified ā
)
ā
2. Import: JIT file imports from ../src/tools/ (Active ā
)
ā
3. Class Creation: this.lessonDataValidator = createLessonDataValidator() (Active ā
)
ā
4. Delegation: validateLessonData() ā this.lessonDataValidator.validateLessonData() (Active ā
)
ā
5. Execution: Should include fixes... (ā Investigation needed)
```
---
## š§ Implementation Patterns for Future Development
### 1. Adding New JIT Tools
**Pattern**: Hybrid registration approach
```javascript
// Step 1: Create tool in /src/tools/new-tool.js
export class NewTool {
async execute(args) { /* implementation */ }
}
export function createNewTool() {
return new NewTool();
}
// Step 2: Import in JIT file
import { createNewTool } from '../src/tools/new-tool.js';
// Step 3: Initialize in constructor
this.newTool = createNewTool();
// Step 4: Register in tool list
{
name: 'new_tool',
description: 'Tool description',
inputSchema: { /* schema */ }
}
// Step 5: Add handler case
case 'new_tool':
return this.newToolMethod(request.params.arguments);
// Step 6: Implement delegation method
async newToolMethod(args) {
const result = await this.newTool.execute(args);
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
}
```
### 2. Modifying Existing Tools
**Pattern**: Direct source modification (should propagate automatically)
```javascript
// Modify: /src/tools/existing-tool.js
// Effect: Changes propagate through import ā class creation ā delegation
// Restart: Required for changes to take effect
```
### 3. JIT Server Configuration
**Pattern**: Centralized initialization
```javascript
// Constructor pattern (Lines 34-65):
constructor() {
this.server = new Server(/* config */);
// Initialize all tools
this.toolName = createTool();
// Load external dependencies
this.loadJwtToken();
this.setupHandlers();
}
```
---
## šÆ Critical Insights for Development
### 1. **Change Deployment Strategy**
- ā
**Source Changes**: Modify `/src/tools/` files directly
- ā ļø **Restart Required**: Changes need server restart to take effect
- ā **No Build Step**: No compilation needed (ES modules)
- š **Hot Reload**: Not implemented - manual restart required
### 2. **Debugging Strategy**
- **Log Source**: Check MCP server console output
- **Error Isolation**: Each tool has individual error handling
- **Debug Mode**: Enable via environment variables
- **Testing**: Modify source ā restart ā test
### 3. **Architecture Benefits**
- ā
**Modularity**: Tools can be developed independently
- ā
**Maintainability**: Clear separation of concerns
- ā
**Testability**: Individual tools can be unit tested
- ā
**Extensibility**: Easy to add new tools following patterns
### 4. **Architecture Limitations**
- ā ļø **Restart Required**: No hot reload for changes
- ā ļø **Import Dependencies**: Relative path dependencies
- ā ļø **Single Distribution**: All tools bundled in one server
- ā ļø **Version Sync**: Source and dist versions must align
---
## š Change Impact Analysis
### Current Bug Fix Status
**Problem Identified**: Changes to `/src/tools/` should be active but aren't taking effect
**Possible Causes**:
1. **Caching Issue**: Node.js module cache preventing reload
2. **File System Issue**: Changes not properly saved
3. **Import Path Issue**: Incorrect relative path resolution
4. **Runtime Issue**: Error in modified code preventing execution
**Investigation Required**:
- ā
Verify file timestamps and content
- ā
Test import resolution
- ā
Check for runtime errors
- ā
Force cache clear and restart
---
## š® Future Architecture Recommendations
### 1. Development Workflow Improvements
- **Hot Reload**: Implement file watching and automatic restart
- **Build Pipeline**: Add optional compilation step for validation
- **Testing Framework**: Automated testing for tool changes
- **Debug Mode**: Enhanced logging and error reporting
### 2. Code Organization Enhancements
- **Tool Versioning**: Version individual tools independently
- **Configuration Management**: Centralized configuration system
- **Plugin Architecture**: Dynamic tool loading/unloading
- **Error Boundaries**: Better error isolation between tools
### 3. Documentation Standards
- **Tool Documentation**: Standardized documentation for each tool
- **Change Log**: Track changes and their impact
- **Architecture Diagrams**: Visual representation of data flow
- **Performance Metrics**: Track tool execution times and efficiency
---
## ā
Action Items for Current Issue
Based on this analysis, the next steps for resolving the bug fix deployment:
1. **ā
Verify Source Changes**: Confirm modifications are in place
2. **ā
Force Server Restart**: Clear any caching issues
3. **ā
Test Import Resolution**: Verify tool loading
4. **ā
Runtime Debugging**: Check for execution errors
5. **š Document Process**: Update development guidelines
---
**Architecture Analysis Status**: ā
**COMPLETE**
**Key Finding**: Hybrid architecture with proper delegation chain
**Next Step**: Force cache clear and restart to deploy fixes
**Confidence**: High - Architecture supports the intended changes