Skip to main content

Overview

BrokerOS organizes all services, frontends, mobile applications, shared domain packages, and third-party integrations into a single high-performance pnpm monorepo orchestrated by Turborepo. This architecture delivers unified TypeScript type safety across backend APIs, Next.js web portals, and native Android code while enabling incremental compilation and cached test execution.

Workspace Topology

The repository is structured into three primary top-level folders: apps/, packages/, and integrations/:

Inter-Package Dependency Flow

Every application consumes domain logic and types from shared packages, while external SaaS calls route strictly through integration adapters:

Turborepo Pipeline & Caching (turbo.json)

Turborepo orchestrates build tasks, unit tests, and code generation across the monorepo. The configuration in turbo.json specifies:
  • Topological Task Sorting (^build): Dependent packages compile before consumer applications.
  • Cache Invalidation Inputs: Hashes source code, dependencies, and environment variables defined in globalEnv.
  • Output Caching: Caches .next/** bundles, dist/** directories, and generated Prisma artifacts.

Environment Variable Law

BrokerOS enforces a strict split architecture to protect infrastructure secrets:

1. Root .env (Heavy Infrastructure Secrets)

Reserved exclusively for backend infrastructure, encryption keys, and third-party SaaS tokens. This file is gitignored and never distributed to client applications:
  • DATABASE_URL: PostgreSQL connection string (direct and pooled)
  • REDIS_URL: Redis host and port for BullMQ and WebSocket pub/sub
  • BETTER_AUTH_SECRET: Secret key for cryptographic session tokens
  • GROQ_API_KEY: Groq AI transcription and LLM inference key
  • BLOB_READ_WRITE_TOKEN: Vercel Blob cloud storage credentials
  • Carrier and telephony bridge keys (Vobiz, Exotel, Twilio)

2. App-Level .env Files (Client Routing & Public Keys)

Located in apps/web/.env, apps/mobile/.env, and apps/api/.env. These contain only public routing URLs and client keys:
  • NEXT_PUBLIC_API_URL: Backend API endpoint for web browser fetch calls
  • EXPO_PUBLIC_API_URL: LAN IPv4 address or emulator alias for the mobile app
  • EXPO_PUBLIC_GOOGLE_MAPS_API_KEY: Android Maps SDK client API key

Monorepo Scripts Policy

All maintenance, database migration, seeding, and testing scripts must live in the repository root inside scripts/:
  • Execution Engine: We execute TypeScript scripts directly using tsx via pnpm run script scripts/your-script.ts.
  • Policy: Never place standalone scripts inside apps/api/scripts/ unless they are strictly bound to internal NestJS test doubles. General maintenance scripts belong at the root.

Testing Architecture

BrokerOS enforces comprehensive headless and browser testing across applications:

Standard Monorepo Commands

Run from the repository root: