BrainDrive-Core icon indicating copy to clipboard operation
BrainDrive-Core copied to clipboard

Official BrainDrive Functional Component Plugin Template - Interactive Learning Platform

Open bekmuradov opened this issue 1 year ago • 1 comments

Official BrainDrive Functional Component Plugin Template

🎯 Overview

Create an official functional component plugin template for BrainDrive that serves as both a starter template AND an interactive learning platform for plugin developers and contributors.

Repository: https://github.com/bekmuradov/BrainDrive-PluginTemplate-Functional

📚 Purpose

This template is designed to be a comprehensive resource that:

  • ✅ Provides modern React Hooks-based plugin architecture
  • ✅ Teaches developers HOW to use BrainDrive service bridges
  • ✅ Demonstrates ALL 5 service bridges with live, working examples
  • ✅ Serves as documentation through interactive demonstrations
  • ✅ Makes plugin development accessible to new contributors

🌟 Key Features

1. Modern React Hooks Architecture

  • Functional components instead of class components
  • Custom hooks for each service bridge
  • Proper cleanup and lifecycle management
  • TypeScript support throughout

2. Service Bridge Integration

Demonstrates all 5 BrainDrive service bridges:

  • 🎨 Theme Service - Dark/light mode, CSS custom properties
  • 🌐 API Service - HTTP requests (GET, POST, PUT, DELETE, streaming)
  • ⚙️ Settings Service - Persistent user preferences
  • 📡 Event Service - Inter-plugin messaging
  • 📍 Page Context Service - Page-aware behavior

3. Interactive Learning Platform

  • Live working examples you can click and interact with
  • Visual feedback showing services in action
  • Code snippets demonstrating implementation
  • "Try It" buttons for hands-on learning
  • Real-world use case patterns

4. Critical Webpack Configuration

Includes the essential webpack setup for functional components:

// Uses window.React from host (prevents "Invalid hook call" error)
externals: {
  'react': 'React'
}
// NO Module Federation 'shared' config!

5. Comprehensive Documentation

  • docs/SERVICE_BRIDGES.md - Complete service integration guide (12,000+ words)
  • docs/THEMING.md - Styling guide with CSS custom properties (5,000+ words)
  • docs/HOOKS_GUIDE.md - React hooks best practices (8,000+ words)
  • AI_AGENT_INSTRUCTIONS.md - Context for AI coding assistants
  • Inline code comments explaining conversions from class to functional

🎓 Learning Path for Developers

The template enables developers to:

  1. Understand Service Bridges (5 minutes)

    • See what they are through interactive overview
    • Understand which services are available
    • Learn when to use each service
  2. See Services in Action (15 minutes)

    • Click buttons to trigger API calls
    • Toggle theme to see reactivity
    • Save settings and see persistence
    • Send messages between components
    • Navigate pages to see context changes
  3. Get Copy-Paste Code (5 minutes)

    • Every example includes working code snippets
    • Syntax-highlighted and ready to use
    • Commented to explain key concepts
  4. Build Their Own Plugin (Ready to start!)

    • Understand patterns and best practices
    • Have working examples to reference
    • Confidence to implement their ideas

Total time: 30 minutes from zero to confident plugin developer 🚀

📦 What's Included

Custom Hooks (Ready to Use)

// All implemented and documented
import {
  useTheme,          // Theme service integration
  usePageContext,    // Page context service
  useSettings,       // Settings persistence
  useAPI,            // HTTP requests
  useErrorHandler    // Error management
} from './hooks';

Component Library

  • ErrorBoundary.tsx - React error boundary (class component)
  • ErrorDisplay.tsx - User-friendly error display
  • LoadingSpinner.tsx - Loading states
  • SettingsExample.tsx - Settings component example

Complete Project Structure

BrainDrive-PluginTemplate-Functional/
├── src/
│   ├── hooks/              # 5 custom hooks for services
│   ├── components/         # Reusable components
│   ├── services/           # Business logic
│   ├── utils/              # Error handling & utilities
│   └── PluginTemplateFunctional.tsx
├── docs/                   # 25,000+ words of documentation
│   ├── SERVICE_BRIDGES.md
│   ├── THEMING.md
│   └── HOOKS_GUIDE.md
├── webpack.config.js       # Critical externals configuration
├── lifecycle_manager.py    # Plugin metadata
├── AI_AGENT_INSTRUCTIONS.md  # Context for AI coding assistants
└── README.md              # Comprehensive guide

🚀 Proposed Enhancements

Phase 1: Interactive Showcase (Priority)

Transform the main component into a tabbed interface that demonstrates each service:

Tabs:

  • 📖 Overview - What are service bridges?
  • 🎨 Theme - Live theme switching demo
  • 🌐 API - Real HTTP requests with loading/error states
  • ⚙️ Settings - Form that saves/loads preferences
  • 📡 Events - Send/receive messages demo
  • 📍 Context - Page navigation tracking
  • 🧪 Patterns - Complete use cases combining services
  • 🔧 Developer - Service inspector, debugging tools

Each tab includes:

  • Live interactive example
  • Visual feedback
  • Code snippet showing implementation
  • "Try It" button to test immediately

Phase 2: Real-World Examples

Add complete mini-applications demonstrating:

  • Data dashboard (API + Settings + Theme)
  • Collaboration tool (Events + Settings)
  • Configuration panel (Settings + Validation)
  • External integration (API + Error handling)

Phase 3: Developer Tools

Built-in debugging features:

  • Service availability inspector
  • Console logger for service calls
  • Performance monitoring
  • State inspector

💡 Why This Matters

Current Problem

New BrainDrive plugin developers struggle because:

  • Service bridges are abstract concepts
  • Documentation is scattered
  • Existing examples are class-based, not using modern React Hooks
  • Unclear when/why to use each service
  • Steep learning curve

This Solution Provides

Developers learn by DOING:

  • See service bridges in action immediately
  • Interact with live examples
  • Copy working code snippets
  • Understand patterns through demonstration
  • Build confidence quickly

Result: Lower barrier to entry for BrainDrive plugin development

🎯 Success Metrics

For Developers:

  • ⏱️ Reduce time from "How do I develop a BrainDrive Plugin?" to "I built a plugin!" from days to hours
  • 📈 Increase number of community-contributed plugins
  • 💪 Developers feel confident using service bridges
  • 📚 Template becomes primary learning resource for plugin development

For Template:

  • ✅ All 5 service bridges demonstrated with working examples
  • ✅ Every service method has a code snippet
  • ✅ Interactive examples for all common use cases
  • ✅ Positive feedback from new developers

🔗 Integration with BrainDrive Ecosystem

Links to Core

  • Uses same service bridge interfaces as BrainDrive-Core
  • Compatible with BrainDrive plugin system
  • Follows official naming conventions
  • Matches lifecycle_manager.py patterns

Links to Documentation

  • Complements official docs at https://docs.braindrive.ai
  • Provides hands-on counterpart to written documentation
  • Can be referenced from docs site
  • Examples can be embedded in docs

Community Impact

  • Lowers barrier for contributors
  • Encourages plugin ecosystem growth
  • Provides standard for functional component plugins
  • Teaching tool for workshops/tutorials

📋 Implementation Checklist

Completed ✅

  • [x] Modern functional component architecture
  • [x] 5 custom hooks for all services
  • [x] Comprehensive documentation (25,000+ words)
  • [x] Working theme integration
  • [x] Error handling patterns
  • [x] TypeScript support
  • [x] Critical webpack configuration
  • [x] Component library
  • [x] AI agent instructions

Phase 1 Enhancement ✅

  • [x] Interactive tabbed interface
  • [x] Live API request examples
  • [x] Settings form demonstrations
  • [x] Event messaging demo
  • [x] Page context examples

Future Enhancements 📅

  • [ ] Complete use case patterns
  • [ ] Developer debugging tools
  • [ ] Video walkthroughs
  • [ ] Integration testing
  • [ ] Community feedback iteration

🛠️ Technical Details

Webpack Configuration (Critical!)

The template uses a specific webpack pattern that prevents React duplication:

// ✅ CORRECT - Uses window.React from host
externals: {
  'react': 'React'
}

// ❌ WRONG - Causes "Invalid hook call" errors
shared: {
  react: { singleton: true, eager: true }
}

Why: BrainDrive host exposes window.React. Using externals prevents bundling React, which is essential for hooks to work correctly.

Custom Hooks Pattern

Each service has a dedicated hook that:

  • Initializes service connection
  • Manages subscriptions
  • Handles cleanup automatically
  • Provides type-safe API
  • Includes error handling

Component Patterns

  • Functional components with TypeScript
  • Props interface for all components
  • Error boundaries for resilience
  • Loading and error states
  • Theme-aware styling

📝 Documentation Structure

For New Developers

  1. Start with README.md - Overview and quick start
  2. Explore interactive examples in plugin
  3. Reference SERVICE_BRIDGES.md for deep dives
  4. Review HOOKS_GUIDE.md for React patterns
  5. Check THEMING.md for styling

For AI Assistants

  • AI_AGENT_INSTRUCTIONS.md provides full context for AI coding agents
  • Ensures continuity when using AI coding tools to develop or extend plugins

🤖 Compounding Engineering

This template embodies the compounding engineering paradigm - where each feature makes the next feature easier to build, rather than harder.

Traditional Engineering vs Compounding Engineering

Traditional Engineering: Each new feature adds complexity, making future features harder to implement.

Compounding Engineering: Each feature codifies learnings that make future features easier to implement.

How This Template Achieves Compounding Engineering

  1. Codified Learnings

    • All conversion patterns from class to functional components documented
    • Common pitfalls (like stale closures, dependency arrays) explained with solutions
    • Webpack configuration issues and solutions preserved in documentation
    • 25,000+ words capturing every lesson learned during development
  2. AI Agent Instructions

    • AI_AGENT_INSTRUCTIONS.md captures the complete context of WHY decisions were made
    • Documents what worked, what didn't, and what to avoid
    • Enables AI coding assistants to continue work without repeating mistakes
    • Includes testing checklist, common commands, and troubleshooting guide
  3. Making Future Features Easier

    • Custom hooks abstract service complexity - future plugins just import and use them
    • Error handling patterns established - copy-paste for consistent behavior
    • Component library provides reusable building blocks
    • TypeScript types ensure correctness automatically
    • Interactive examples serve as templates for new features
  4. Captured in the Process

    • Planning phase documented what we expected vs what we found
    • Testing phase revealed issues (theme switching bug) that became documented patterns
    • Every challenge encountered became a code comment or doc section
    • AI agent context files ensure next iteration builds on this foundation

Result

The next plugin developer or AI agent can:

  • Build functional component plugins in 30 minutes instead of days
  • Avoid all the pitfalls we discovered (React duplication, hook errors, stale closures)
  • Reference working examples for every service bridge
  • Extend the template without understanding all the historical context

This is compounding engineering in action - each lesson learned compounds into making the next feature easier to build.

🌐 Resources

  • Template Repository: https://github.com/bekmuradov/BrainDrive-PluginTemplate-Functional
  • BrainDrive Core: https://github.com/BrainDriveAI/BrainDrive
  • Documentation Site: https://docs.braindrive.ai
  • Community Forum: https://community.braindrive.ai

💬 Discussion

Questions for Community

  1. Which service bridge is MOST confusing for new developers?
  2. What real-world use cases should we demonstrate?
  3. Should interactive examples be default view or toggle?
  4. What level of complexity for examples (simple vs realistic)?
  5. Should we include video tutorials?

Feedback Welcome On

  • Service bridge examples (what's missing?)
  • Documentation clarity (what's confusing?)
  • Interactive features (what would help?)
  • Use case patterns (what do you want to build?)
  • Developer experience (pain points?)

🎉 Vision

Transform BrainDrive plugin development from:

  • ❌ "I don't know where to start"
  • ❌ "Service bridges are confusing"
  • ❌ "Where do I find examples?"

To:

  • ✅ "I understand service bridges!"
  • ✅ "I can build what I need!"
  • ✅ "The template taught me everything!"

Make the template the FIRST STOP for anyone wanting to build BrainDrive plugins.


🚀 Getting Started

As a Developer Learning BrainDrive

  1. Clone: git clone https://github.com/bekmuradov/BrainDrive-PluginTemplate-Functional
  2. Install: npm install
  3. Explore: Read README.md
  4. Build: npm run build
  5. Install in BrainDrive and explore interactive examples

This template bridges the gap between "How do I build a BrainDrive plugin?" and "I built something awesome with BrainDrive!" 🌉

This serves as the ultimate plugin development learning tool - from which developers can easily understand patterns, learn service bridges, and create their own custom plugins with confidence.

Let's make BrainDrive plugin development accessible, enjoyable, and productive for everyone! 💪

bekmuradov avatar Nov 13 '25 13:11 bekmuradov

Closing — shipped or superseded. Tracked in BrainDrive Library pulse system.

davewaring avatar Feb 01 '26 14:02 davewaring