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 /healthGET /customersGET /jobs|POST /jobsPOST /jobs/{id}/assignmentsPOST /inventory/checkPOST /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.