Skip to content

Firestore Schema

All types defined in shared/types.ts, re-exported from web/src/types/index.ts.

businesses/{uid}

One document per business. uid = Firebase Auth UID of the owner.

Type: Business

typescript
{
  profile: BusinessProfile       // name, phone, address, hours, locations, practitioners, fees, booking, etc.
  ai: AIConfig                   // aiName, greeting, tone, gender, voiceProvider, avatar, verification settings
  knowledge: KnowledgeEntry[]    // FAQ entries (id, question, answer)
  escalation: EscalationRule[]   // trigger → action (transfer/message/end) + target
  integrations: BusinessIntegrations  // googleCalendar, twilio
  subscription?: Subscription    // Stripe billing state
  site?: LandingSite             // published static site (slug, url, pages)
  onboardingStatus: "incomplete" | "complete"
  createdAt: FirestoreTimestamp
  updatedAt: FirestoreTimestamp
}

Subcollections

businesses/{uid}/interactions/{id} — Type: Interaction Call/chat session logs. Channel, outcome, transcript, actions taken, duration.

businesses/{uid}/staff/{staffUid} — Type: StaffMember Staff accounts with role-based permissions.

businesses/{uid}/appointments/{id} — Type: Appointment Calendar appointments synced from Google Calendar.

businesses/{uid}/callers/{id} — Type: Caller Known callers with phone, name, DOB, status (lead/patient/blocked), verification state.

businesses/{uid}/articles/{id} — Type: KnowledgeArticle Long-form knowledge base articles (title, content, category).

businesses/{uid}/import-tasks/{id} — Type: ImportTask Website crawler import progress tracking.

visitors/{visitorId}/businesses/{businessId}

Portal visitor tracking. Records which businesses a visitor has chatted with.

config/{document=**}

Admin-managed configuration. Includes:

  • config/prompts/templates/{id} — prompt templates with placeholders
  • config/tools/definitions/{name} — tool JSON definitions for OpenAI function calling

calendar_oauth_states/{stateId}

Server-only. Temporary OAuth state tokens for Google Calendar connection flow.

portal_tokens/{tokenId}

Server-only. SMS verification tokens for portal access.

Security Rules

Three access tiers:

  1. sysAdmin (request.auth.token.sysAdmin == true) — read/write all businesses and config
  2. Owner (request.auth.token.biz.id == uid && biz.role == "owner") — read/write own business and all subcollections
  3. Member (request.auth.token.biz.id == uid) — read-only on business, interactions, appointments, callers, articles; read own staff record

Server-only collections (calendar_oauth_states, portal_tokens) deny all client access.

Path Builders

typescript
import { paths } from '@humanlike/shared'

paths.business(uid)                    // "businesses/{uid}"
paths.interactions(uid)                // "businesses/{uid}/interactions"
paths.staff(uid)                       // "businesses/{uid}/staff"
paths.appointments(uid)                // "businesses/{uid}/appointments"
paths.callers(uid)                     // "businesses/{uid}/callers"
paths.articles(uid)                    // "businesses/{uid}/articles"
paths.importTasks(uid)                 // "businesses/{uid}/import-tasks"
paths.visitorBusinesses(visitorId)     // "visitors/{visitorId}/businesses"
paths.configPromptTemplates()          // "config/prompts/templates"
paths.configTools()                    // "config/tools/definitions"

Last updated: