Idiomark Adapter Framework - Implementation Summary
Overview
The Idiomark Adapter Framework has been successfully designed and implemented. This framework provides a scalable, plugin-based architecture for connecting 500+ platforms to the Idiomark.
What Was Created
1. Documentation
File: docs/adapter-framework.md
Comprehensive framework documentation including:
- Design principles (Convention over Configuration, Progressive Enhancement, Fail-Safe, Observable)
- Component diagrams and data flow
- Base adapter class specification
- Adapter templates (REST, GraphQL, Scraping, RSS, Email, Forum)
- Config-driven adapter system
- Adapter registry specification
- CLI generator specification
- Testing framework
- Performance optimization strategies
- Migration guide
- Code examples
2. Base Adapter Class
File: packages/core/src/adapters/base.ts
Core functionality built-in:
- Rate Limiter - Token bucket algorithm with per-endpoint limits and dynamic adjustment
- Cache Manager - Multi-level (L1 in-memory LRU, L2 persistent) with TTL expiration
- Retry Handler - Exponential backoff with jitter and retryable error detection
- Auth Manager - Support for bearer token, OAuth2, API key, and basic auth
- Error Handler - Categorized errors with retry detection
- Metrics Collector - Request counting, latency tracking, and performance metrics
- Event Emitter - Observer pattern for adapter lifecycle events
3. Adapter Registry
File: packages/core/src/adapters/registry.ts
Central registry for adapter management:
- Register/unregister adapters
- Dynamic loading from npm packages or local files
- Search and filter adapters
- Health checking
- Metrics aggregation
- Batch processing
4. REST API Template
File: packages/core/src/adapters/templates/rest.ts
Pre-built implementation for standard REST APIs:
- Automatic pagination handling
- Query parameter building
- Response format detection
- Auth header management
- URL interpolation
5. Testing Framework
File: packages/core/src/adapters/testing/index.ts
Comprehensive testing utilities:
- Mock HTTP server for testing
- Test suite builders
- Benchmarking tools
- Assertion helpers
- Memory leak detection
- Test data generators
Architecture
┌─────────────────────────────────────────────────────────────────────────┐
│ BaseAdapter │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌───────────────┐ │
│ │ Rate Limiter │ │ Cache Manager│ │ Retry Handler│ │ Auth Manager │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ └───────────────┘ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌───────────────┐ │
│ │ Error Handler│ │ Metrics │ │ Event Emitter│ │ ... │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ └───────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────────────┐
│ Adapter Templates │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌────────────┐ │
│ │ REST │ │ GraphQL │ │ Scraping │ │ RSS │ │ Email │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────────────┐
│ Platform Adapters │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌────────────┐ │
│ │ Twitter │ │ GitHub │ │ Reddit │ │ LinkedIn │ │ ... 497 │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘
Usage Examples
Creating a New Adapter (REST API)
import { RESTAdapterTemplate } from '@idiomark/core/adapters'
import type { NormalizedContent, FetchOptions, RawContent } from '@idiomark/core'
export class GitHubAdapter extends RESTAdapterTemplate {
protected baseURL = 'https://api.github.com'
protected endpoints = {
user: '/user',
repos: '/users/{username}/repos',
commits: '/repos/{owner}/{repo}/commits'
}
protected getEndpoint(options: FetchOptions): string {
return '/users/{username}/repos'
}
protected mapResponseItem(item: any): RawContent {
return {
id: item.id,
type: 'repository',
text: item.description || '',
created_at: item.created_at,
author: {
id: item.owner.id,
username: item.owner.login,
name: item.owner.login
},
raw: item
}
}
normalize(raw: RawContent): NormalizedContent {
return raw as unknown as NormalizedContent
}
}
Using the Adapter Registry
import { adapterRegistry, extractFromMultiple } from '@idiomark/core/adapters'
import { GitHubAdapter } from '@idiomark/adapter-github'
import { TwitterAdapter } from '@idiomark/adapter-twitter'
// Register adapters
adapterRegistry.registerMany([
{
name: 'github',
displayName: 'GitHub',
description: 'GitHub adapter',
version: '1.0.0',
type: 'code',
category: 'development',
authType: 'bearer_token',
factory: (auth) => new GitHubAdapter(auth)
},
{
name: 'twitter',
displayName: 'Twitter/X',
description: 'Twitter adapter',
version: '1.0.0',
type: 'code',
category: 'social',
authType: 'bearer_token',
factory: (auth) => new TwitterAdapter(auth)
}
])
// Extract from multiple sources
const results = await extractFromMultiple([
{ name: 'github', auth: { token: process.env.GITHUB_TOKEN } },
{ name: 'twitter', auth: { bearerToken: process.env.TWITTER_TOKEN } }
])
Testing an Adapter
import { createMockServer, createAdapterTestSuite } from '@idiomark/core/adapters/testing'
describe('MyAdapter', () => {
createAdapterTestSuite({
adapterName: 'myadapter',
adapterFactory: (auth) => new MyAdapter(auth),
mockConfig: {
routes: [
{
path: '/api/posts',
method: 'GET',
response: { data: [{ id: '1', text: 'Hello' }] }
}
]
},
validAuth: { token: 'test' },
sampleResponse: { id: '1', text: 'Hello' },
sampleNormalized: {
id: '1',
platform: 'myadapter',
type: 'post',
text: 'Hello',
timestamp: '2026-02-10T00:00:00Z',
author: { id: '123', username: 'test', name: 'Test' }
}
})
})
Key Features
1. Convention Over Configuration
Default behaviors work for 80% of services:
- Automatic rate limiting based on response headers
- Smart caching with TTL
- Retry logic with exponential backoff
- Auth header management
2. Progressive Enhancement
Start simple, add complexity when needed:
- Config-only adapters (simplest)
- Template-based adapters (most common)
- Full custom adapters (complex APIs)
3. Fail-Safe by Default
Adapters never crash the extraction process:
- Graceful error handling
- Partial result returns
- Detailed error reporting
4. Observable Everything
All operations emit events:
rateLimitWait- When rate limitingretry- When retrying requestscacheHit- When cache is usedfetchComplete- When fetch completeserror- When errors occur
Performance Considerations
For 500+ Adapters
- Lazy Loading - Adapters load only when needed
- Connection Pooling - Reuse HTTP connections
- Batch Processing - Process multiple adapters concurrently
- Smart Caching - Reduce API calls
- Efficient Rate Limiting - Token bucket algorithm
Memory Management
- LRU cache with size limits
- Automatic resource disposal
- Memory leak detection tools
Migration Path
Existing GitHub Adapter
The existing GitHub adapter can be migrated to use the REST template:
Before: ~680 lines with duplicated code After: ~50 lines using REST template
// Before: Custom rate limiter, cache, retry
export class GitHubAdapter implements PlatformAdapter {
private rateLimiter = new RateLimiter({ /* ... */ })
private cache = new CacheManager({ /* ... */ })
private retry = new RetryHandler({ /* ... */ })
// ... 600+ more lines
}
// After: Use template
export class GitHubAdapter extends RESTAdapterTemplate {
protected baseURL = 'https://api.github.com'
async fetchContent(options) { /* GitHub-specific logic */ }
normalize(raw) { /* GitHub-specific normalization */ }
}
Next Steps
- Build the core package to verify compilation
- Migrate existing GitHub and Twitter adapters to use the framework
- Add more templates (GraphQL, Scraping, RSS)
- Implement config-driven adapter loader
- Create adapter generator CLI tool
- Write comprehensive tests for all components
File Structure
packages/core/src/adapters/
├── index.ts # Main exports
├── base.ts # Base adapter class + utilities
├── registry.ts # Adapter registry
├── templates/
│ └── rest.ts # REST API template
└── testing/
└── index.ts # Testing framework
docs/
└── adapter-framework.md # Complete documentation
Benefits
- Developer Productivity - Add new adapters in minutes instead of hours
- Consistency - All adapters follow the same patterns
- Reliability - Built-in error handling and retry logic
- Scalability - Designed for 500+ adapters
- Testability - Comprehensive testing utilities
- Maintainability - DRY principle - code written once, used everywhere
Conclusion
The Idiomark Adapter Framework provides a solid foundation for connecting hundreds of platforms to the Idiomark. By following the convention-over-configuration principle and providing powerful templates, the framework makes it trivial to add new adapters while maintaining consistency across all implementations.