Quick Start: Build Your First Component in 10 Minutes
This tutorial will guide you through creating, developing, and publishing your first BoardAPI component using the CLI.
Prerequisites
- Node.js 18+ (download)
- API key from BoardAPI (get one here)
Step 1: Create Project (1 min)
Create a new component project:
bash
npx create-boardapi-app my-counter
cd my-counter
npm installOr initialize in an existing directory:
bash
mkdir my-counter && cd my-counter
npx @boardapi/cli init
npm installChoose Your Framework
The CLI supports Vanilla TypeScript, Vue 3, and React templates:
bash
npx create-boardapi-app my-counter --template vue
npx create-boardapi-app my-counter --template reactStep 2: Explore the Project Structure
Your project contains:
my-counter/
├── manifest.json # Component metadata
├── package.json # Dependencies
├── tsconfig.json # TypeScript config
└── src/
├── main.ts # Entry point
├── index.html # HTML wrapper
└── styles.css # Stylesmanifest.json
Defines your component's properties:
json
{
"name": "my-counter",
"version": "1.0.0",
"title": "Click Counter",
"description": "A simple click counter",
"entry": "component.js",
"dimensions": {
"width": 200,
"height": 150,
"resizable": true
},
"storage": {
"schema": {
"count": { "type": "number", "default": 0 }
}
}
}Step 3: Start Development Server (1 min)
Run the dev server with live reload and simulator:
bash
npm run devThis opens:
- Component:
http://localhost:3000- Your component in isolation - Simulator:
http://localhost:3001- Full testing environment
Simulator Features
The simulator provides:
- Storage Inspector - View and modify shared state
- Event Log - See all SDK events in real-time
- Participants Panel - Simulate multiple users
- Hot Reload - Changes apply instantly
Step 4: Write Your Component
Edit src/main.ts:
typescript
import { BoardAPI } from '@boardapi/sdk';
import './styles.css';
const board = new BoardAPI();
// Get DOM elements
const counterEl = document.getElementById('counter')!;
const incrementBtn = document.getElementById('increment')!;
// Initialize from shared storage
let count = board.storage.get('count', 0);
function render() {
counterEl.textContent = String(count);
}
// Handle clicks
incrementBtn.addEventListener('click', async () => {
count++;
render();
await board.storage.set('count', count);
});
// Sync with other users
board.storage.subscribe('count', (newValue: number) => {
count = newValue;
render();
});
render();
board.ready();Step 5: Build for Production (1 min)
Validate and build your component:
bash
# Validate manifest and structure
npx boardapi validate
# Build for production
npm run buildThis creates:
dist/- Production-ready filesmy-counter-1.0.0.zip- Ready to publish
Step 6: Publish to BoardAPI (2 min)
Set your API key and publish:
bash
# Login (one time)
npx boardapi login
# Publish (dry-run first)
npx boardapi publish --dry-run
# Actually publish
npx boardapi publish --no-dry-runExpected output:
Published my-counter@1.0.0
URL: https://app.boardapi.io/api/v1/components/files/my-counter@1.0.0/index.htmlStep 7: Test on a Board (2 min)
Option A: Via Web UI
- Go to app.boardapi.io
- Click "New Board"
- Open board settings, go to "Components" tab
- Click "Add Component" and select "my-counter@1.0.0"
- Add the component to canvas and test!
Option B: Via API
bash
# Create board with your component
curl -X POST https://app.boardapi.io/api/v1/boards \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "My Counter Board",
"config": {
"components": [{
"type": "my-counter",
"version": "1.0.0"
}]
}
}'Multi-user Test
- Open the board in your browser
- Open the Guest link in incognito mode
- Click the counter in one window
- See it update in real-time in the other!
Next Steps
- Component Structure - Deep dive into manifest.json
- SDK API Reference - Full SDK documentation
- CLI Reference - All CLI commands
- Examples - More complex components
Alternative: Manual Publishing
If you prefer not to use the CLI, you can publish manually:
1. Create ZIP Package
bash
zip -r my-counter-1.0.0.zip manifest.json dist/2. Upload via API
bash
curl -X POST https://app.boardapi.io/api/v1/components/publish \
-F "bundle=@my-counter-1.0.0.zip" \
-F "apiKey=YOUR_API_KEY"See Publishing Components for details.
Troubleshooting
CLI not found
bash
# Install globally
npm install -g @boardapi/cli
# Or use npx
npx @boardapi/cli <command>Build fails
bash
# Check manifest is valid
npx boardapi validate --strict
# Clean and rebuild
rm -rf dist node_modules
npm install
npm run buildPublish fails
- Verify API key is correct
- Check ZIP file size (max 10MB)
- Run
npx boardapi validatefirst
Need Help?
- Documentation: docs.boardapi.io
- CLI Reference: CLI Commands
- Support: support@boardapi.io