> ## Documentation Index
> Fetch the complete documentation index at: https://docs.latwoodtech.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction

> Factory Core is the shared infrastructure layer for all Factory applications.

# Factory Core

Factory Core is a collection of 19 TypeScript packages that provide battle-tested, reusable infrastructure for Cloudflare Workers applications. Every Factory app installs only what it needs.

## Stack

| Layer     | Technology                       |
| --------- | -------------------------------- |
| Runtime   | Cloudflare Workers               |
| Router    | Hono                             |
| Database  | Neon Postgres via Hyperdrive     |
| Auth      | JWT / Web Crypto API             |
| LLM       | Anthropic → Grok → Groq failover |
| Telephony | Telnyx + Deepgram + ElevenLabs   |
| Email     | Resend                           |
| Errors    | Sentry                           |
| Analytics | PostHog + `factory_events`       |

## Packages

| Stage | Package                    | Purpose                                                       |
| ----- | -------------------------- | ------------------------------------------------------------- |
| 1     | `@adrper79-dot/errors`     | Typed error hierarchy, `FactoryError`, `toErrorResponse`      |
| 1     | `@adrper79-dot/monitoring` | Sentry integration for Cloudflare Workers                     |
| 1     | `@adrper79-dot/logger`     | Structured JSON logger with levels and context                |
| 1     | `@adrper79-dot/auth`       | JWT issue/verify/refresh, `jwtMiddleware`, `requireRole`      |
| 1     | `@adrper79-dot/neon`       | Neon Postgres client via Hyperdrive, `withDbRetry`            |
| 1     | `@adrper79-dot/stripe`     | Stripe webhook handling, subscription lifecycle               |
| 2     | `@adrper79-dot/llm`        | Anthropic → Grok → Groq failover, streaming, `withSystem`     |
| 2     | `@adrper79-dot/telephony`  | Deepgram STT, ElevenLabs TTS, Telnyx webhooks, `VoiceSession` |
| 3     | `@adrper79-dot/analytics`  | PostHog + `factory_events` DB table, event tracking           |
| 3     | `@adrper79-dot/deploy`     | Deployment scripts and CI helpers                             |
| 3     | `@adrper79-dot/testing`    | Zero-dep mock factories for all packages                      |
| 4     | `@adrper79-dot/email`      | Resend integration, typed email templates                     |
| 4     | `@adrper79-dot/copy`       | LLM-powered copywriting with structured output                |
| 4     | `@adrper79-dot/content`    | Content management backed by Neon                             |
| 4     | `@adrper79-dot/social`     | Social post scheduling and publishing                         |
| 4     | `@adrper79-dot/seo`        | Meta tag generation, OpenGraph, structured data               |
| 5     | `@adrper79-dot/crm`        | Lead tracking, conversion events, customer view               |
| 5     | `@adrper79-dot/compliance` | TCPA/FDCPA consent and suppression management                 |
| 5     | `@adrper79-dot/admin`      | Admin Hono router: users, events, health, suspend             |

## Design Principles

* **No `process.env`** — every package uses Cloudflare Worker bindings (`env.VAR` / `c.env.VAR`)
* **No Node.js built-ins** — no `fs`, `path`, `crypto`, `Buffer`
* **ESM only** — no CommonJS `require()`
* **Zero `any` in public APIs** — TypeScript strict throughout
* **Explicit error handling** — no raw `fetch` without error checking
