Skip to main content

core-organization-service

Manages internal organization records and AI-generated organization context. Each organization maps to a Better Auth organization via betterAuthOrgId. Provides org CRUD, member listing (via user service proxy), and async context generation using Workers AI.

Worker name: crow-core-organization-service Domain (prod): internal.orgs.crowai.dev Domain (dev): dev.internal.orgs.crowai.dev

Schema

organization

ColumnTypeNotes
idtext PKInternal UUID
betterAuthOrgIdtextunique, FK to auth service org
nametext
logotextnullable
statustextdefault pending, also active
createdAtintegerepoch ms
updatedAtintegerepoch ms

organization_context

ColumnTypeNotes
idtext PK
organizationIdtext
crawlIdtextlinks to product crawl job
contextTypetextdefault ai_generated_summary
structuredDataJSONAI-generated structured context
generatedAttimestamp

Routes

MethodPathDescription
GET/api/v1/organizations/{id}Get organization by internal ID
GET/api/v1/organizations/by-auth-id/{betterAuthOrgId}Lookup by Better Auth org ID
GET/api/v1/organizations/{id}/membersList org members (proxies to user service)
GET/api/v1/organizations/{id}/contextGet latest AI-generated context
POST/api/v1/organizations/{id}/context/triggerTrigger async context generation
POST/api/v1/organizations/org-buildersCreate org builder (onboarding)
GET/api/v1/organizations/org-builders/{id}Get org builder
POST/api/v1/organizations/org-builders/{id}/finalizeFinalize builder into org
POST/api/v1/organizations/onboardFull onboarding: create org + owner + API key
POST/api/v1/organizations/{organizationId}/membersInvite member to org

Environment Variables

VariableExample
ENVIRONMENTdev
USER_SERVICE_URLhttps://dev.internal.users.crowai.dev
AUTH_SERVICE_URLhttps://dev.internal.auth-api.crowai.dev
PRODUCT_SERVICE_URLhttps://dev.internal.products.crowai.dev

Secrets

SecretPurpose
INTERNAL_GATEWAY_KEYGateway trust validation
SERVICE_API_KEY_GATEWAYAccepted from gateway for internal calls

Bindings

BindingTypeName
DBD1crow-core-organization-service-db
R2_BUCKETR2crow-core-organization-service-store
AIWorkers AIText generation for context
ORGANIZATION_CONTEXT_QUEUEQueue (producer + consumer)crow-organization-context-queue

Queue Configuration

QueueRoleBatch SizeRetriesDLQ
crow-organization-context-queueProducer + Consumer103crow-organization-context-dlq

Context generation is triggered via HTTP (POST .../context/trigger) which enqueues a message. The same worker consumes the queue and runs AI context generation using the Workers AI binding.

Dependencies

  • Inbound: auth service (org sync on create), gateway (by-auth-id lookup for org resolution), pattern service (context retrieval)
  • Outbound: user service (member listing), auth service, product service

Key Behaviors

  • Context generation: Analyzes product catalog and org metadata to generate a structured organizational context summary. This context is used by the interaction and pattern services to provide business-relevant analysis.
  • BOLA: All routes check X-Organization-Id against the resource's organizationId