# Internal Platforms
URL: /docs/use-cases/internal-platforms
LLM index: /llms.txt
Description: Shared schema packages for organizations, permissions, and platform modules.

# Internal Platforms

Internal platform teams often own models that many product teams consume.

These packages are a strong fit for Farming Labs ORM because the platform team
usually wants one durable contract while product teams still want freedom over
their final runtime stack.

## Common platform-owned domains

- organizations
- memberships
- roles
- permissions
- audit logs
- feature flags
- environment metadata

## Why a shared schema helps

Without a shared contract, every product team tends to drift:

- different table names
- different field names
- different docs examples
- different migration patterns

Platform packages often have to support:

- generated artifacts for app teams
- runtime helpers for internal services
- setup flows for demos, tests, and sandboxes

That is where the generator and runtime helper story becomes important.

## Platform package example

```ts
export const orgSchema = defineSchema({
  organization: model({
    table: "organizations",
    fields: {
      id: id(),
      slug: string().unique(),
      name: string(),
      createdAt: datetime().defaultNow(),
    },
  }),
  membership: model({
    table: "memberships",
    fields: {
      id: id(),
      userId: string(),
      organizationId: string().references("organization.id"),
      role: string().default("member"),
    },
  }),
});
```

## Multi-package generation

```ts
import { defineConfig } from "@farming-labs/orm-cli";
import { authSchema } from "@acme/auth";
import { billingSchema } from "@acme/billing";
import { orgSchema } from "@acme/org";

export default defineConfig({
  schemas: [authSchema, billingSchema, orgSchema],
  targets: {
    prisma: {
      out: "./generated/prisma/schema.prisma",
      provider: "postgresql",
    },
  },
});
```

If a platform team wants to render artifacts directly instead of going through
the CLI, it can call the generators from the shared schema package:

```ts
import { renderDrizzleSchema, renderPrismaSchema, renderSafeSql } from "@farming-labs/orm";

const prisma = renderPrismaSchema(orgSchema, {
  provider: "postgresql",
});

const drizzle = renderDrizzleSchema(orgSchema, {
  dialect: "pg",
});

const sql = renderSafeSql(orgSchema, {
  dialect: "postgres",
});
```

If a platform-owned service wants to accept a raw client directly:

```ts
import { createOrmFromRuntime } from "@farming-labs/orm-runtime";

const orm = await createOrmFromRuntime({
  schema: orgSchema,
  client: database,
});
```

If the platform package needs to prepare a database in tests, demos, or setup
flows:

```ts
import { pushSchema } from "@farming-labs/orm-runtime/setup";

await pushSchema({
  schema: orgSchema,
  client: database,
});
```

## Helper map for internal platforms

- `renderPrismaSchema(...)`: ship Prisma artifacts to product teams
- `renderDrizzleSchema(...)`: ship Drizzle schema modules from the shared platform contract
- `renderSafeSql(...)`: emit SQL setup artifacts for direct SQL consumers
- `createOrmFromRuntime(...)`: let platform services accept raw clients directly
- `pushSchema(...)`: prepare test, sandbox, or setup databases for platform-owned modules
- `bootstrapDatabase(...)`: prepare a live database and return the ORM in one step

## Why platform teams care

- one place to evolve shared models
- one set of docs examples
- fewer app-specific reinterpretations
- cleaner onboarding for product teams

This is one of the highest-leverage uses of the project in a monorepo.