How matiasbattocchia/open-bsp-ui works
1. High-level shape
- This repository is a single-page frontend application called OpenBSP UI.
- It is built with React + TypeScript + Vite and deployed as static assets.
- The app is the user interface for the external OpenBSP API / Supabase-backed backend; there is no application server in this repo.
2. Primary boundary: UI vs backend
- The frontend talks to Supabase through src/supabase/client.ts and typed DB models in src/supabase/db_types.ts.
- Backend interaction is organized mostly through src/queries/*, which encapsulate remote reads/writes for domain resources.
- Real-time chat updates come from Supabase Realtime, not polling.
3. Navigation and page architecture
- Routing is handled by TanStack Router with a nested route tree under src/routes/.
- The app has a public/auth boundary: login, oauth/callback, and onboarding routes are separate from the authenticated shell in _auth.
- The authenticated area contains resource-specific subtrees for agents, contacts, conversations, integrations, settings, and stats.
4. Domain modules
- The authenticated experience is split into clear product domains:
- Conversations: chat list, chat view, message composer, filters, search, and footer/header controls.
- Contacts: CRUD screens for address book entries.
- AI Agents: agent creation/configuration, tool setup, instructions.
- Templates: WhatsApp template editor, picker, preview, and variable handling.
- Integrations: WhatsApp onboarding/signup and media preprocessing.
- Settings: organization, members/roles, API keys, webhooks.
- Stats: usage and quota dashboards.
5. Chat and messaging subsystem
- The chat UI is decomposed into dedicated components under src/components/Chat* and src/components/Message/*.
- Messages support text, images, audio, and documents, plus delivery/status indicators.
- Conversation state is managed with a combination of query data, local UI state, and the chatSlice Zustand store.
- Utility modules such as MessageUtils, ConversationUtils, and MessageStatusUtils centralize message formatting and status logic.
6. State management layers
- TanStack Query is used for server state and resource fetching/mutations across agents, contacts, organizations, templates, webhooks, billing, and WhatsApp signup.
- Zustand is used for local app state, especially UI and chat-related transient state in src/stores/.
- There are also shared React contexts and hooks for cross-cutting concerns like WhatsApp integration and timed refresh ticks.
7. Realtime and lifecycle flows
- The app’s most important live flow is the conversation stream: backend events arrive via Supabase Realtime and update chat UI immediately.
- src/hooks/useRealtimeSubscription.ts and the query layer likely coordinate these updates with cached data.
- Initial app data and active organization context are handled by hooks like useInitalDataFetch and useSetActiveOrg, which establish the authenticated tenant scope before rendering domain pages.
8. Multi-tenant organization model
- The UI is explicitly multi-org: users switch organizations and all domain resources are scoped to the active org.
- Organization-specific resources include members, addresses, templates, webhooks, billing/statistics, and WhatsApp integrations.
- This tenant boundary is a core architectural constraint; most queries and routes are organized around org membership and org address IDs.
9. WhatsApp integration flow
- WhatsApp Embedded Signup and onboarding are first-class flows under src/routes/_auth/integrations/whatsapp/*.
- The UI supports connecting WhatsApp Business accounts, then managing org addresses and message templates for that integration.
- Optional environment variables in the README (VITE_META_APP_ID, VITE_FB_LOGIN_CONFIG_ID) indicate external Meta/Facebook integration points that shape the onboarding flow.
10. Internationalization and presentation layer
- All user-facing text goes through src/hooks/useTranslation.tsx, with source strings in Spanish and translation files in public/locales/*.json.
- The UI includes Spanish, English, Portuguese, French, and Swahili resources, with a script to sync translation keys.
- The component layer is broad but reusable: forms, headers, modals/menus, avatar/button primitives, chat controls, and stats widgets are shared across routes.
11. Offline/assets/runtime concerns
- public/service-worker.js, manifest.json, and notification.mp3 show some PWA-like client capabilities, especially for notifications and app shell behavior.
- Static assets and locale files are bundled with the frontend, while the app itself remains a browser-executed SPA.
- src/utils/IdbUtils.ts suggests some local persistence or browser storage support for selected data flows.
12. Build and deployment pipeline
- The project is built with Vite, linted with ESLint, formatted with Prettier, and checked in CI via GitHub Actions.
- Deployment is intentionally simple: build to dist and host on any static platform, with Cloudflare Pages called out in the README.
- Runtime configuration is entirely environment-driven through VITE_* variables, reinforcing the frontend/backend boundary.
13. How to draw the architecture
- At the center is a React SPA shell with router-driven screens.
- On one side, the SPA consumes Supabase/OpenBSP API for auth, data CRUD, file/media metadata, billing, and realtime events.
- On the other side, shared UI components, query hooks, and store slices fan out into the product domains: conversations, contacts, agents, templates, integrations, settings, and stats.
Main entry points: _auth.tsx Auth Shell · queryKeys.ts Queries · index.tsx Conversations · __root.tsx Root Router
Components 21
App Shell
Routing, auth boundary, and bootstrapping for the SPA.
- Main App · Vite entrypoint that mounts the client application.
src/main.tsx - Root Router · Top-level route tree and app shell composition.
src/routes/__root.tsx - Auth Shell · Protected layout that wraps the signed-in application.
src/routes/_auth.tsx - Public Routes · Login, OAuth callback, and onboarding entry screens.
src/routes/login.tsx
Product Domains
Authenticated feature areas exposed through the route tree.
- Conversations · Conversation list and conversation detail routes.
src/routes/_auth/conversations/index.tsx - Contacts · Contact list and CRUD screens for address book entries.
src/routes/_auth/contacts/index.tsx - Agents · AI agent creation and configuration screens.
src/routes/_auth/agents/index.tsx - Templates · WhatsApp template management under integration scope.
src/routes/_auth/integrations/whatsapp/$orgAddressId/templates/index.tsx - WhatsApp · WhatsApp onboarding, signup, and org address management.
src/routes/_auth/integrations/whatsapp/index.tsx - Settings · Organization, members, API keys, and webhooks screens.
src/routes/_auth/settings/index.tsx - Stats · Usage and quota dashboards.
src/routes/_auth/stats/index.tsx
Data Layer
Server-state, local state, and backend access adapters.
- Queries · TanStack Query hooks for agents, contacts, orgs, templates, billing, keys, webhooks, and signup.
src/queries/queryKeys.ts - Stores · Transient UI and chat state slices.
src/stores/useBoundStore.ts - App Hooks · Bootstrapping, auth, active org, realtime subscription, translation, and timing hooks.
src/hooks/useInitalDataFetch.ts - Supabase Client · Supabase client and typed database models used for auth, CRUD, and realtime.
src/supabase/client.ts
Shared Support
Cross-cutting UI, i18n, and lifecycle helpers.
- Chat UI · Conversation view, list, filters, search, header, footer, and composer controls.
src/components/Chat.tsx - Messages · Renderers for text, image, audio, and document messages plus status indicators.
src/components/Message/Message.tsx - Template UI · Editor, picker, preview, and variable handling for templates.
src/components/TemplateEditor.tsx - WhatsApp UI · Embedded signup and WhatsApp setup components.
src/components/WhatsAppIntegration.tsx - Stats UI · Quota and usage charts used by the stats pages.
src/components/stats/StatsCenter.tsx - Translations · Translation runtime and locale bundles for multilingual UI copy.
src/i18n/translations.ts
Connections 28
- Main App → Root Router: bootstraps · Application entry mounts the router-driven SPA.
- Root Router → Public Routes: public · Routes for login, OAuth callback, and onboarding.
- Root Router → Auth Shell: protected · Authenticated shell wraps the main application.
- Auth Shell → Conversations: screens · Conversation area under authenticated navigation.
- Auth Shell → Contacts: screens · Contact management area.
- Auth Shell → Agents: screens · Agent management area.
- Auth Shell → WhatsApp: screens · WhatsApp integration and onboarding area.
- Auth Shell → Templates: screens · Template management nested under WhatsApp integration.
- Auth Shell → Settings: screens · Organization administration area.
- Auth Shell → Stats: screens · Usage and quota dashboards.
- Conversations → Chat UI: uses · Conversation pages are built from chat components.
- Conversations → Messages: renders · Message body types and status indicators.
- Templates → Template UI: uses · Template screens rely on editor and preview components.
- WhatsApp → WhatsApp UI: uses · Onboarding and connection screens use WhatsApp-specific UI.
- Stats → Stats UI: uses · Stats pages render charts and quota widgets.
- Conversations → Queries: fetches · Conversation data and mutations flow through query hooks.
- Contacts → Queries: fetches · Contacts and addresses are server-state resources.
- Agents → Queries: fetches · Agent CRUD uses query hooks.
- Templates → Queries: fetches · Template CRUD and org-address scoped data.
- WhatsApp → Queries: fetches · WhatsApp signup and onboarding state.
- Settings → Queries: fetches · Org admin resources such as members, keys, and webhooks.
- Stats → Queries: fetches · Usage and billing data come from query hooks.
- App Hooks → Supabase Client: connects · Auth, active org, and realtime hooks bind to Supabase.
- Queries → Supabase Client: reads/writes · Server-state hooks call the backend adapter.
- Stores → Chat UI: state · Chat slice supports transient UI and message stream state.
- App Hooks → Translations: loads · Translation hook resolves locale bundles and strings.
- Chat UI → Stores: uses · Chat interactions coordinate with local UI state.
- Auth Shell → App Hooks: initializes · Authenticated shell depends on bootstrapping hooks.