Scaffold Next.js apps with optional Velt Presence, Cursor, and ReactFlow CRDT
npm install @veltdev/add-veltš Smart CLI tool to add Velt real-time collaboration features to your existing Next.js application.
- ā
Smart Project Analysis: Automatically detects your project structure, package manager, and router type
- šÆ Zero Config: Works out of the box with App Router and Pages Router
- š¦ Intelligent Dependency Management: Handles peer dependency conflicts with multiple fallback strategies
- š ReactFlow CRDT Support: Optional collaborative canvas with real-time synchronization
- šØ UI Customization: Includes Velt Wireframe components for easy customization
- š Secure Token Generation: Backend route for JWT token generation
- š„ User Authentication: Demo user system with localStorage persistence
- š Environment Management: Built-in support for managing API keys and auth tokens
``bash`
npx @veltdev/add-velt add --all
`bash`
cd add-velt-next-js
npm link
Navigate to your existing Next.js project and run:
`bashAdd all Velt features
velt add --all
Command Reference
$3
`bash
velt add [options]
`$3
#### Feature Flags
-
--presence - Add Velt Presence (live avatars)
- --cursor - Add Velt Cursor tracking
- --reactflow-crdt - Add ReactFlow CRDT integration for collaborative canvas
- --all or -all - Add all collaboration features (recommended)
- --shadcn - Include shadcn/ui dependencies#### Installation Flags
-
--force or -f - Force install and overwrite existing files
- --legacy-peer-deps - Use legacy peer dependencies (npm only, useful for resolving conflicts)#### Environment Variable Flags
-
--env - Enable environment variable management in .env.local
- --api-key="KEY" - Set NEXT_PUBLIC_VELT_API_KEY value (requires --env)
- --auth-token="TOKEN" - Set VELT_AUTH_TOKEN value (requires --env)Usage Examples
$3
`bash
velt add --all
`This will:
- Analyze your project structure
- Install all required dependencies
- Generate all Velt integration files
- Create
.env.local with placeholders$3
`bash
velt add --all --env --api-key="your_velt_api_key" --auth-token="your_velt_auth_token"
`This will also populate your environment variables automatically.
$3
`bash
velt add --presence --cursor
`Add only presence and cursor tracking without ReactFlow CRDT.
$3
`bash
velt add --all --force
`Overwrites existing files if you want to update to the latest version.
$3
`bash
velt add --all --legacy-peer-deps
`Uses npm's
--legacy-peer-deps flag to resolve peer dependency conflicts.$3
`bash
velt add --reactflow-crdt
`Adds collaborative ReactFlow canvas with CRDT synchronization.
Files Generated
The CLI generates the following file structure:
`
your-project/
āāā .env.local # Environment variables
āāā app/
ā āāā api/
ā ā āāā velt/
ā ā āāā token/
ā ā āāā route.ts # JWT token generation endpoint
ā āāā userAuth/
ā āāā AppUserContext.tsx # User context provider
ā āāā useAppUser.ts # User hook export
ā āāā users.ts # Demo users
ā āāā LoginPanel.tsx # Login UI component
āāā components/
āāā velt/
āāā VeltCollaboration.tsx # Main collaboration component
āāā VeltInitializeUser.tsx # User authentication hook
āāā VeltInitializeDocument.tsx # Document initialization
āāā VeltTools.tsx # Presence, Sidebar, Notifications
āāā ReactFlowComponent.tsx # (optional) Collaborative canvas
āāā hooks/
ā āāā useCurrentDocument.ts # Document state hook
āāā ui-customization/
āāā VeltCustomization.tsx # Wireframe customization wrapper
āāā VeltComponent1Wf.tsx # Customization component 1
āāā VeltComponent2Wf.tsx # Customization component 2
āāā styles.css # Custom styles
`Setup After Installation
$3
In your
app/layout.tsx:`tsx
import { VeltProvider } from '@veltdev/react';
import { AppUserProvider } from '@/app/userAuth/useAppUser';
import { useVeltAuthProvider } from '@/components/velt/VeltInitializeUser';export default function RootLayout({ children }) {
return (
{children}
);
}function VeltProviderWrapper({ children }) {
const { authProvider } = useVeltAuthProvider();
return (
{children}
);
}
`$3
In any page or component:
`tsx
import { VeltCollaboration } from '@/components/velt/VeltCollaboration';
import VeltTools from '@/components/velt/VeltTools';
import LoginPanel from '@/app/userAuth/LoginPanel';export default function MyPage() {
return (
<>
{/ Your page content /}
>
);
}
`$3
`tsx
import ReactFlowComponent from '@/components/velt/ReactFlowComponent';export default function CanvasPage() {
return (
);
}
`$3
If you didn't use
--env flags during installation, manually add to .env.local:`bash
NEXT_PUBLIC_VELT_API_KEY=your_api_key_here
VELT_AUTH_TOKEN=your_auth_token_here
`Get your keys from Velt Dashboard.
$3
`bash
npm run dev
or
pnpm dev
or
yarn dev
`Open multiple browser windows to
http://localhost:3000 to test real-time collaboration!Project Analysis
The CLI automatically detects:
- ā
Package Manager: pnpm, yarn, or npm (based on lockfiles)
- ā
Router Type: App Router or Pages Router
- ā
Existing Dependencies: Avoids reinstalling existing packages
- ā
Tailwind Configuration: Detects if Tailwind is already set up
- ā
TypeScript Support: Generates TypeScript files by default
- ā
ReactFlow Version: Ensures compatibility between
reactflow v11 and @xyflow/react v12Dependency Management
The CLI uses smart installation strategies:
1. Standard Install: Tries normal package installation
2. Force Install: Uses
--force flag if standard fails
3. Legacy Peer Deps: Falls back to --legacy-peer-deps (npm only)
4. Combined Strategy: Uses both flags as last resortThis ensures successful installation even with complex dependency trees.
ReactFlow CRDT Integration
The CLI includes support for collaborative ReactFlow canvases:
- ā
Uses
@xyflow/react v12+ for best compatibility
- ā
Integrates @veltdev/reactflow-crdt for real-time synchronization
- ā
Includes Yjs for CRDT data structures
- ā ļø Skips CRDT if your project uses reactflow v11 (shows migration guidance)Troubleshooting
$3
`bash
velt add --all --force
or
velt add --all --legacy-peer-deps
`$3
Use
--force to overwrite:`bash
velt add --all --force
`$3
The CLI auto-detects your package manager, but you can ensure the correct one by having the appropriate lockfile:
-
pnpm-lock.yaml ā uses pnpm
- yarn.lock ā uses yarn
- package-lock.json ā uses npm$3
Make sure you're using the
--env flag:`bash
velt add --all --env --api-key="KEY" --auth-token="TOKEN"
`Or manually check your
.env.local file has both:
- NEXT_PUBLIC_VELT_API_KEY
- VELT_AUTH_TOKENKey Features Explained
$3
The CLI generates a secure backend route (
app/api/velt/token/route.ts) that:
- Validates user credentials
- Generates JWT tokens using Velt's v2 API
- Never exposes your auth token to the frontend
- Handles errors gracefully$3
Includes a complete user authentication system:
-
AppUserProvider: React Context for user state
- useAppUser: Hook to access user data
- LoginPanel: Ready-to-use login UI
- Demo users (Michael, Jim, Pam from The Office)
- LocalStorage persistence$3
All Velt components are wrapped with:
-
VeltWireframe: For deep UI customization
- VeltCustomization: Centralized customization component
- Separate customization files for organization
- CSS file for custom styles$3
Includes document initialization system:
-
useCurrentDocument: Hook for current document state
- VeltInitializeDocument`: Component that syncs with Velt SDK- Next.js: v13.4.0+ (App Router or Pages Router)
- React: v18.2.0+
- TypeScript: v5.0.0+
- @veltdev/react: v4.5.2-beta.2+
- @xyflow/react: v12.3.0+ (for ReactFlow CRDT)
- Node.js: v16+
Contributions are welcome! Please ensure:
- Code matches the existing style
- All features are tested
- Documentation is updated
- š Velt Documentation
- š¬ Discord Community
- š§ Email Support
Built with ā¤ļø by the Velt team