Contractor OS: A Monorepo for Scheduling and Inventory

github repo

A monorepo for a scheduling, task, and inventory platform for small-to-midsize contractors β€” built fast, agent-first, and designed to scale.

Hybrid of Option C (Turborepo monorepo) + Option D (orchestrator & policies).


✨ What you get

  • API (FastAPI + Postgres): jobs, customers, inventory, purchase orders (minimal).
  • Orchestrator (agents): function-calling router with guardrails and confirmations.
  • Contracts: OpenAPI + JSON Schemas (tools + structured outputs).
  • SDK: generated TypeScript client from OpenAPI.
  • Workers: background jobs (low-stock scan, nightly PO drafts).
  • Infra: docker-compose for local dev (Postgres, API, Orchestrator, pgAdmin).
  • Seed data + smoke test that runs an end-to-end flow (schedule β†’ assign β†’ reserve β†’ low-stock check).

πŸ“ Repo layout

contractor-os/
β”œβ”€ turbo.json                 # Turborepo pipelines
β”œβ”€ package.json               # workspace scripts
β”‚
β”œβ”€ apps/
β”‚  β”œβ”€ api/                    # FastAPI service (Dockerized)
β”‚  β”œβ”€ web/                    # Next.js owner/portal (later)
β”‚  β”œβ”€ mobile/                 # React Native crew app (later)
β”‚  └─ worker/                 # Python worker for events/cron
β”‚
β”œβ”€ services/
β”‚  └─ orchestrator/           # Agent router, guardrails, memory
β”‚
β”œβ”€ packages/
β”‚  β”œβ”€ sdk/                    # Generated TS client
β”‚  β”œβ”€ schemas/                # JSON Schemas (tools + outputs)
β”‚  β”œβ”€ bot-runtime/            # Tool-calling helpers
β”‚  β”œβ”€ design/                 # UI tokens/Tailwind (for web/mobile)
β”‚  └─ config/                 # eslint, tsconfig, prettier
β”‚
β”œβ”€ contracts/
β”‚  β”œβ”€ openapi.yaml            # API contract β†’ generates packages/sdk
β”‚  β”œβ”€ tools.schema.json       # LLM tool-call contracts
β”‚  └─ structured-outputs/     # JSON Schemas for validated outputs
β”‚
β”œβ”€ policies/
β”‚  β”œβ”€ risk-levels.md          # Confirmation matrix
β”‚  β”œβ”€ prompts/                # Agent instruction sets
β”‚  └─ redlines.md             # Forbidden actions, escalation
β”‚
β”œβ”€ db/
β”‚  β”œβ”€ schema.sql              # Core schema
β”‚  β”œβ”€ seed.sql                # Demo data
β”‚  └─ migrations/             # Alembic (optional initially)
β”‚
β”œβ”€ infra/
β”‚  β”œβ”€ docker-compose.yml      # Postgres, API, Orchestrator, pgAdmin
β”‚  β”œβ”€ Dockerfile.api
β”‚  β”œβ”€ Dockerfile.orchestrator
β”‚  β”œβ”€ Dockerfile.worker
β”‚  β”œβ”€ k8s/                    # (later)
β”‚  └─ terraform/              # (later)
β”‚
β”œβ”€ scripts/
β”‚  β”œβ”€ dev-up.sh               # compose up + healthchecks
β”‚  β”œβ”€ db-reset.sh             # drop/create/migrate/seed
β”‚  β”œβ”€ codegen-sdk.ts          # OpenAPI β†’ /packages/sdk
β”‚  └─ smoke.sh                # E2E: scheduleβ†’assignβ†’reserveβ†’report
β”‚
└─ .ai/
   β”œβ”€ context.md              # System prompt for dev/agents
   β”œβ”€ routines.md             # Diff-only, test-first, etc.
   └─ evals/                  # Golden prompts & expected JSON

🧰 Prerequisites

  • Docker + Docker Compose
  • Node 20+ (for scripts/SDK)
  • Python 3.11+ (API & worker)

πŸš€ Quick Start

# 1) clone repo
git clone <your-fork> contractor-os && cd contractor-os

# 2) (optional) generate SDK from OpenAPI
node scripts/codegen-sdk.ts

# 3) launch local stack (Postgres, pgAdmin, API, Orchestrator)
./scripts/dev-up.sh
# or: docker compose -f infra/docker-compose.yml up --build -d

# 4) seed DB (if needed)
./scripts/db-reset.sh

# 5) run smoke test (schedule β†’ assign β†’ reserve β†’ low-stock)
./scripts/smoke.sh

Services (defaults)

  • API: http://localhost:8000 (Swagger at /docs)
  • Orchestrator: http://localhost:8080
  • pgAdmin: http://localhost:5050 (admin@example.com / admin)
  • Postgres: localhost:5432 (user: contractor, pass: contractor)

πŸ” Environment

Copy infra/.env.example to infra/.env and add secrets as needed.

PGUSER=contractor
PGPASSWORD=contractor
PGDATABASE=contractor
PGHOST=db
PGPORT=5432
PGADMIN_EMAIL=admin@example.com
PGADMIN_PASSWORD=admin
TZ=America/New_York

πŸ§ͺ Local Development (Docker Compose)

See infra/docker-compose.yml (also self-documented in comments).


🌐 API (FastAPI)

App entry: apps/api/app/main.py. Routes: apps/api/app/routers/ (customers, jobs, inventory).

Key endpoints (MVP):

  • GET /health
  • GET /customers
  • GET /jobs | POST /jobs
  • POST /jobs/{id}/assignments
  • POST /inventory/check
  • POST /inventory/reserve

Swagger UI at http://localhost:8000/docs.


πŸ€– Orchestrator (Agents)

Entry: services/orchestrator/src/index.ts. Responsibilities: parse intent β†’ validate β†’ call tools (API) β†’ emit events β†’ confirm high-risk actions.

Tool contracts defined in contracts/tools.schema.json.


πŸ“œ Contracts & SDK

  • OpenAPI spec: contracts/openapi.yaml.
  • Generate client to packages/sdk: node scripts/codegen-sdk.ts.
  • Structured Outputs schemas in contracts/structured-outputs/.

βœ… Testing

  • API tests under apps/api/tests/ (add later).
  • Orchestrator tests under services/orchestrator/tests/ (add later).

πŸ›« Deploy (later)

Enterprise Deployment Summary (for later reference)

  • One container per service: API, Orchestrator, Worker, Web.
  • Ingress/Gateway fronts API & Orchestrator; workers internal-only.
  • Start w/ one Postgres; evolve to database-per-service or separate schemas.
  • Reliability: message bus, idempotency keys, retries with jitter, DLQs.
  • Observability: OpenTelemetry, structured logs, RED metrics.
  • Security: service identities (JWT/mTLS), least-priv DB roles, SBOM/vuln scans.
  • CI/CD: pipeline per service; contract-first; canary/blue-green.
hjkl / arrows Β· / search Β· :family Β· :tag Β· :datefrom Β· :dateto Β· ~/entries/slug Β· Ctrl+N/Ctrl+P for suggestions Β· Ctrl+C/Ctrl+G to cancel
entries 201/201 Β· entry -/-
:readyentries 201/201 Β· entry -/-