graphwork-core
v2.0.1
Published
Core engine of GraphWork Framework 2.0
Downloads
211
Maintainers
Readme
Core
Core engine of GraphWork Framework 2.0
Overview
The Core module is the central engine of the GraphWork Framework. It provides the foundational infrastructure that coordinates all other modules, manages the knowledge base, integrates with AI services, and handles template processing.
Installation
npm install graphwork-coreFeatures
- Central Coordination: Orchestrates interactions between all framework modules
- Knowledge Management: Manages project context and knowledge base
- AI Integration: Provides interfaces for AI model integration
- Template Processing: Handles template-based code generation
- Plugin Architecture: Supports extensible plugin system
- Event System: Publish-subscribe pattern for inter-module communication
Usage
Basic Setup
import { GraphWorkCore } from 'graphwork-core';
import { KnowledgeBase } from 'graphwork-knowledge-base';
import { AIIntegration } from 'graphwork-ai-integration';
import { TemplateEngine } from 'graphwork-templates';
// Initialize components
const knowledgeBase = new KnowledgeBase();
const aiIntegration = new AIIntegration({
provider: 'openai', // or 'anthropic', 'gemini'
model: 'gpt-4',
apiKey: process.env.OPENAI_API_KEY
});
const templateEngine = new TemplateEngine();
// Create core instance
const core = new GraphWorkCore({
knowledgeBase,
aiIntegration,
templateEngine
});
// Initialize the core
await core.initialize();Working with Context
import { ContextManager } from 'graphwork-core';
const contextManager = new ContextManager(core);
// Load project context
await contextManager.loadProjectContext('./work');
// Get context for a specific area
const architectureContext = contextManager.getContext('architecture');
// Update context
contextManager.updateContext('requirements', {
functional: 'User authentication system',
nonFunctional: 'High performance, secure'
});Event Handling
import { EventEmitter } from 'graphwork-core';
// Subscribe to events
core.events.on('codeGenerated', (data) => {
console.log('Code generated:', data);
});
// Emit events
core.events.emit('validationStarted', {
component: 'user-service',
timestamp: Date.now()
});API
GraphWorkCore
Constructor
new GraphWorkCore(config: CoreConfig)Methods
initialize(): Promise<void>- Initialize the core enginegetContextManager(): ContextManager- Get the context managergetAIIntegration(): AIIntegration- Get the AI integration servicegetTemplateEngine(): TemplateEngine- Get the template enginegetEventManager(): EventEmitter- Get the event manager
ContextManager
Methods
loadProjectContext(path: string): Promise<void>- Load project context from directorygetContext(area: string): any- Get context for a specific areaupdateContext(area: string, data: any): void- Update context for an areagetAllContext(): Record<string, any>- Get all context data
EventEmitter
Methods
on(event: string, listener: Function): void- Subscribe to an eventemit(event: string, data: any): void- Emit an eventoff(event: string, listener: Function): void- Unsubscribe from an event
Configuration
CoreConfig
interface CoreConfig {
knowledgeBase: KnowledgeBase;
aiIntegration: AIIntegration;
templateEngine: TemplateEngine;
plugins?: Plugin[];
}Architecture
The Core module follows a modular architecture with the following components:
- Context Manager: Handles project context and knowledge base
- AI Coordinator: Manages AI model interactions
- Template Processor: Processes templates for code generation
- Plugin Manager: Manages framework plugins
- Event System: Facilitates communication between modules
Extending Core
Creating Plugins
import { Plugin } from 'graphwork-core';
export class CustomPlugin implements Plugin {
name = 'CustomPlugin';
version = '1.0.0';
async initialize(core: GraphWorkCore): Promise<void> {
// Plugin initialization logic
}
async destroy(): Promise<void> {
// Cleanup logic
}
}Registering Plugins
import { CustomPlugin } from './CustomPlugin';
const core = new GraphWorkCore({
knowledgeBase,
aiIntegration,
templateEngine,
plugins: [new CustomPlugin()]
});Contributing
See our Contributing Guide for information on how to contribute to this package.
License
This package is licensed under the MIT License. See the LICENSE file for details.
