The aidran package, end to end.
The published aidran npm package is a CLI plus a typed schema surface — not a hosted API client. It bundles the aidran binary, re-exports @aidran/contracts (Zod event & DTO schemas), and re-exports @aidran/db (Drizzle ORM schemas for the corpus tables). Everything below is verifiable against the public scaffold.
Published packages · 4
aidranOne-install meta-package. Ships the `aidran` binary plus namespace re-exports of contracts and db. Start here.
View on npm ↗@aidran/contractsShared TypeScript types and Zod schemas for events, API DTOs, webhooks, tier policies, errors, and branded IDs.
View on npm ↗@aidran/dbDrizzle ORM schemas and bundled SQL migrations for the corpus tables. Bring your own Postgres connection.
View on npm ↗@aidran/cliCLI internals. Normally consumed transitively via the `aidran` binary; published separately for embedding.
View on npm ↗1 · The aidran binary
Bare aidran in a TTY launches the interactive wizard; with a subcommand it runs that step directly. In a non-TTY context (CI, piped) the wizard is skipped and help is printed so logs never hang.
aidranInteractive setup wizard (when run in a TTY). Prompts for DATABASE_URL, generates AIDRAN_API_KEY, writes config, runs migrate + verify.
DATABASE_URL (prefilled if set)aidran initScaffold .env.example and drizzle.config.ts in the current directory. Drizzle config points at the bundled @aidran/db schema.
—aidran migrateApply the bundled @aidran/db migrations to the database at $DATABASE_URL. Idempotent — re-running is safe once schema is current.
DATABASE_URLaidran verifyConfirm $DATABASE_URL is reachable and required tables exist. Exits non-zero on a missing or mis-shaped schema.
DATABASE_URLaidran helpPrint usage. Also runs implicitly when invoked non-interactively (e.g. piped or in CI) so logs never hang.
—2 · Import patterns
Three ways to bring the surface in. Namespace gives you collision-free access via contracts.* and db.*. Subpaths narrow the import. Scoped packages skip the meta-package entirely.
// One install. Namespaced for collision-free access.import { contracts, db } from 'aidran';const event = contracts.RecordIngestedSchema.parse(payload);const records = db.records;
aidranBoth namespaces — `import { contracts, db } from "aidran"`aidran/contractsDirect re-export of @aidran/contracts (all named exports)aidran/dbDirect re-export of @aidran/db (schemas + Database type)aidran/db/migrations-pathThe `migrationsFolder` constant — feed to drizzle-kit or drizzle-orm migrator3 · contracts — types & schemas
Everything under @aidran/contracts is re-exported. Zod schemas suffixed *Schema parse runtime payloads; inferred TS types share the base name.
aidran/contracts (events.ts)Events
Past-tense facts emitted between services. Used as Render Workflow task payloads. Every event has a *Schema (Zod) and an inferred *TS type.
- RecordIngestedSchema · RecordIngested
- EntitiesExtractedSchema · EntitiesExtracted
- EmbeddingReadySchema · EmbeddingReady
- TopicAssignedSchema · TopicAssigned
aidran/contracts (api.ts)API DTOs
Request and response shapes for the public /v1/* HTTP API. Zod-validated at the route boundary; TS-typed on the way out.
- HealthResponse
- StoryListQuerySchema · StoryListQuery · StorySummary
- StoryDetailResponse · StoryReferenceSummary
- RecordListQuerySchema · RecordSummary
- SignalListQuerySchema · SignalSummary
aidran/contracts (enums.ts)Enums
Canonical enum value lists, kept byte-aligned with the Postgres enums in @aidran/db. Imported by events, DTOs, and webhooks.
- SOURCE_KINDS · SourceKindSchema · SourceKind
- STORY_TYPES · StoryTypeSchema · StoryType
- SIGNAL_SEVERITIES · SignalSeveritySchema
- ARC_STATUSES · ArcStatusSchema · ComputedArcStatusSchema
- CONTENT_TYPES · CONTENT_VARIANT_TYPES · CITATION_TYPES
aidran/contracts (webhooks.ts)Webhooks
Outbound webhook envelopes for hosted-AIDRAN integrations. Discriminated union over event_type so a single handler can switch over WebhookEvent.
- StoryPublishedEventSchema
- SignalDetectedEventSchema
- EntityMentionedEventSchema
- ArcUpdatedEventSchema
- SavedSearchMatchEventSchema
- WebhookEventSchema · WEBHOOK_EVENT_TYPES
aidran/contracts (tiers.ts)Tier policies
Subscription tier definitions and per-tier limit tables. The same constants enforced by the Delivery gateway in front of the API.
- TIERS · Tier
- TIER_LIMITS · TierLimits
- WORKSPACE_ROLES · WORKSPACE_KINDS
aidran/contracts (errors.ts)Errors
Canonical error code constants. Match the response.code field returned by the Delivery API on 4xx / 5xx.
- ERROR_UNAUTHORIZED · ERROR_FORBIDDEN
- ERROR_RATE_LIMITED · ERROR_QUOTA_EXCEEDED
- ERROR_TIER_LIMIT_EXCEEDED · ERROR_EXPORT_THROTTLED
- ERROR_WORKSPACE_ROLE_REQUIRED · ERROR_WORKSPACE_SEAT_EXCEEDED
aidran/contracts (ids.ts)Branded IDs
Branded string / number ID types so RecordId, StoryId, EntityId, etc. cannot be accidentally swapped. Constructor functions cast safely at trusted boundaries.
- RecordId · StoryId · EntityId
- TopicId · SignalId · SourceId
4 · db — Drizzle ORM
Tables grouped by service-boundary ownership. AIDRAN's discipline: services do not import from one another; they read shared schemas from @aidran/db and write only to their owned tables.
- A
Records
Ingestion team writesaidran/db (schema/records.ts)- · sources — source adapters and ingest cursors
- · records — every ingested document, link, post, paper
- · sourceKindEnum · recordCategoryEnum · contentTypeEnum
- B
Analysis
Analysis team writesaidran/db (schema/analysis.ts)- · entities · entityMentions
- · topics · topicAssignments
- · embeddings · analysisCursors
- C
Signals
Signal team writesaidran/db (schema/signals.ts)- · signals — novelty / velocity / divergence detections
- · signalEvidence — joined records that justified each signal
- · signalSeverityEnum · evidenceTargetEnum
- D
Editorial
Editorial team writesaidran/db (schema/editorial.ts)- · stories · storyCitations · storyReferences
- · storyContentVariants · storyRelated
- · storyArcs · storyArcMembership
- · seoMetadata
- · storyTypeEnum · arcStatusEnum · citationTypeEnum
- E
Search-sync
Search-sync team writesaidran/db (schema/search-sync.ts)- · searchSyncCheckpoints — per-target index sync watermarks
5 · Common workflows
Three load-bearing patterns. Validate an inbound event at the boundary; query the corpus through Drizzle; apply migrations programmatically when the CLI isn't in your runtime.
import { RecordIngestedSchema } from 'aidran/contracts';// Validate at the boundary — anything that survives parse() is typed.const event = RecordIngestedSchema.parse(payload);// event: { recordId, kind, contentType, externalId, capturedAt }// - kind narrowed to a SourceKind union// - capturedAt typed as an ISO datetime string
import { drizzle } from 'drizzle-orm/node-postgres';import { Pool } from 'pg';import * as schema from 'aidran/db';import { type Database } from 'aidran/db';const pool = new Pool({ connectionString: process.env.DATABASE_URL });const db: Database = drizzle(pool, { schema });// Pull the 50 most recent records, typed end to end.const rows = await db.select().from(schema.records).orderBy(schema.records.capturedAt).limit(50);
import { drizzle } from 'drizzle-orm/node-postgres';import { migrate } from 'drizzle-orm/node-postgres/migrator';import { Pool } from 'pg';import { migrationsFolder } from 'aidran/db/migrations-path';const pool = new Pool({ connectionString: process.env.DATABASE_URL });await migrate(drizzle(pool), { migrationsFolder });
Prefer the CLI (aidran migrate) for one-shot setup; use this pattern when you need to migrate from inside an existing service or test harness.
Every command, export, and subpath listed here is verifiable in github.com/AIDRAN/aidran under packages/aidran, packages/contracts, and packages/db.