How chatbotkit/node-sdk works
Project Type and Purpose
• This is a monorepo for an open‑source SDK ecosystem (ChatBotKit Node SDK).
• It packages a core “SDK” and a set of framework‑specific extensions (React, Next.js, NextAuth, Fetch adapter, CLI), plus a scaffolding tool and a suite of examples targeting Node, Next.js, Cloudflare Workers, etc.
• Purpose: provide a unified, multi‑platform JavaScript SDK for building and deploying conversational AI bots, plus CLI tooling and turnkey example apps.
File Structure Analysis
• Top level:
• “packages/” – each subfolder is a published npm package:
– sdk (core API client)
– fetch (isomorphic fetch implementation)
– react (React UI components & hooks)
– next (Next.js helpers for Edge/serverless)
– nextauth (NextAuth.js adapter)
– cli (command‑line interface)
– placeholder (utility stub)
• “tools/create-cbk-app” – project scaffolding CLI wrapper
• “examples/…” – sample consumer applications organized by platform
• “scripts/” – monorepo build/export helpers
• “.changeset/”, GitHub workflows – versioning & CI
• pnpm-workspace.yaml + turbo.json – workspace and build orchestration
README Insights
• Identifies the six main packages and the scaffolding tool.
• Describes serverless compatibility, streaming, multi‑model support.
• Illustrates typical usage flows in Next.js, Cloudflare, Node, etc.
• Emphasizes integration points (SDK → React → Next.js → NextAuth, CLI, & Fetch)
Main Components
a. Core SDK Layer
• @chatbotkit/sdk
• @chatbotkit/fetch (low‑level HTTP adapter)
b. Extension/Integration Layer
• @chatbotkit/react (UI components, hooks)
• @chatbotkit/next (Edge/serverless integration, streaming wrappers)
• @chatbotkit/nextauth (auth adapter)
• @chatbotkit/cli (DevOps/management tool)
c. Tooling & Orchestration
• pnpm & Turborepo (workspace + build pipeline)
• .changeset (versioning)
• GitHub Actions (CI for docs & release)
• “tools/create-cbk-app” (app generator)
d. Consumer Apps / Examples
• Next.js examples (App Router, Pages Router, hybrid)
• Cloudflare Workers example
• Node CLI & SDK examples (CJS, ESM, TS)
e. External Services
• ChatBotKit Backend REST API (conversation, datasets, integrations)
Relationships & Interactions
• “@fetch” feeding HTTP requests for the SDK.
• “@react”, “@next”, “@nextauth” importing core SDK (and fetch) to provide higher‑level abstractions/UI.
• “cli” importing core SDK (and fetch) to provide command‑line commands.
• “create-cbk-app” using “cli” under the hood.
• “examples” depending on the various published packages to demonstrate usage.
• CI/CD pipeline steps (build → docs → release) orchestrated by Turborepo and GitHub Actions.
Architectural Patterns & Principles
• Monorepo with pnpm workspace and Turborepo for incremental builds.
• Modular package‑per‑concern (core vs. adapters vs. UI vs. tooling).
• Clear separation of API client (sdk) vs. transport (fetch) vs. UI (react) vs. framework glue (next/nextauth) vs. CLI.
• Examples as integration tests / reference implementations.
• CI ensures docs & version bump via .changeset.