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
| Column | Type | Notes |
|---|---|---|
| id | text PK | Internal UUID |
| betterAuthOrgId | text | unique, FK to auth service org |
| name | text | |
| logo | text | nullable |
| status | text | default pending, also active |
| createdAt | integer | epoch ms |
| updatedAt | integer | epoch ms |
organization_context
| Column | Type | Notes |
|---|---|---|
| id | text PK | |
| organizationId | text | |
| crawlId | text | links to product crawl job |
| contextType | text | default ai_generated_summary |
| structuredData | JSON | AI-generated structured context |
| generatedAt | timestamp |
Routes
| Method | Path | Description |
|---|---|---|
| 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}/members | List org members (proxies to user service) |
| GET | /api/v1/organizations/{id}/context | Get latest AI-generated context |
| POST | /api/v1/organizations/{id}/context/trigger | Trigger async context generation |
| POST | /api/v1/organizations/org-builders | Create org builder (onboarding) |
| GET | /api/v1/organizations/org-builders/{id} | Get org builder |
| POST | /api/v1/organizations/org-builders/{id}/finalize | Finalize builder into org |
| POST | /api/v1/organizations/onboard | Full onboarding: create org + owner + API key |
| POST | /api/v1/organizations/{organizationId}/members | Invite member to org |
Environment Variables
| Variable | Example |
|---|---|
| ENVIRONMENT | dev |
| USER_SERVICE_URL | https://dev.internal.users.crowai.dev |
| AUTH_SERVICE_URL | https://dev.internal.auth-api.crowai.dev |
| PRODUCT_SERVICE_URL | https://dev.internal.products.crowai.dev |
Secrets
| Secret | Purpose |
|---|---|
| INTERNAL_GATEWAY_KEY | Gateway trust validation |
| SERVICE_API_KEY_GATEWAY | Accepted from gateway for internal calls |
Bindings
| Binding | Type | Name |
|---|---|---|
| DB | D1 | crow-core-organization-service-db |
| R2_BUCKET | R2 | crow-core-organization-service-store |
| AI | Workers AI | Text generation for context |
| ORGANIZATION_CONTEXT_QUEUE | Queue (producer + consumer) | crow-organization-context-queue |
Queue Configuration
| Queue | Role | Batch Size | Retries | DLQ |
|---|---|---|---|---|
crow-organization-context-queue | Producer + Consumer | 10 | 3 | crow-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-Idagainst the resource'sorganizationId