How appflowy-io/appflowy-chat works
Project type and purpose
• This is a TypeScript/React component library (npm package) named “AppFlowy Web Chat.”
• Purpose: provide a fully-featured, themeable chat UI (with AI-writing helpers) that integrates with an AppFlowy Cloud backend.
File structure
• Top-level build & config: vite.config.ts, tsconfig.json, postcss.config.ts, tailwind.config.ts, jest.config.js, eslint.config.js, GitHub workflows.
• Core source (src/):
• UI components (src/components/*, src/chat/*, src/writer/*, src/ui/*)
• State & context providers (src/provider/*)
• Hooks & utilities (src/hooks/*, src/lib/*)
• API clients (src/request/*.ts)
• i18n (src/i18n/*), assets & styles
• Demo app (src/dev/*) to preview and test locally.
README for additional insights
• Public API: <Chat {...ChatProps} /> plus ChatRequest and optional callbacks (onOpenView, onCloseSelectionMode, etc.).
• Dependencies: expects an AppFlowy Cloud instance for persisting messages and AI-writing tokens.
Main components & their relationships
a. UI Layer
• Chat container (src/chat/index.tsx, src/chat/main.tsx)
• Message list & input (src/components/chat-messages/*, src/components/chat-input/*)
• AI-writer module (src/components/ai-writer/*, src/writer/*)
b. State & Context Providers
• ChatSessionProvider, MessagesProvider, AIWriterProvider, SelectionModeProvider, etc.
c. Data/API Layer
• ChatRequest → AppFlowy Cloud chat REST endpoints
• WriterRequest → AI-service backend for writing enhancements
d. Utility Layer
• Hooks (use-chat-settings-loader, use-views-loader, etc.)
• Helpers (animations.ts, copy.ts, requets.ts, utils.ts)
e. External Services
• AppFlowy Cloud API
• (Optional) AI service endpoint
f. Dev & Build Tooling
• Vite dev server, bundling, testing, linting, CI workflows
Architectural patterns & design principles
• Component-driven UI with clear separation of presentation and logic
• Context-based state management for global concerns (messages stream, theming, selection mode)
• API abstraction layers to decouple HTTP from components
• Hook-driven data fetching for side-effects and caching
• Theming via CSS variables and darkMode dataset attribute
• i18n integration at the root
• UI Components
• Context Providers
• Hooks & Utils
• API Clients
• External Services
• Dev/Demo/Build
• UI → Providers (consumes context)
• Providers → Hooks/Utils (for data loading)
• Hooks → API Clients (invoke HTTP requests)
• API Clients → AppFlowy Cloud / AI Service (external)
• Build tool → Demo App and Library output
c. Patterns:
• Context boundary
• Hook-based side-effects
• API request flow
d. Technologies:
• React/TSX
• Vite, TailwindCSS, PostCSS
• pnpm, Jest, ESLint
• i18next for localization