2026-08-08
The org chart should compile
The idea in three files
ceo.ts
export class CeoModel {
owns = [RootEnvironment]
company = {
product: engineering,
trust: security.expectations,
money: finance.expectations
}
}
export const ceo = new CeoModel()
import { engineering } from "./engineering-manager"
import { RootEnvironment } from "./environments"
import { finance } from "./finance-manager"
import { security } from "./security-manager"
engineering-manager.ts
export class EngineeringManagerModel {
deployment = EngineeringDeployment
owns = [EngineeringDeployment, RootEnvironment.test]
awareOf = [RootEnvironment.production, RootEnvironment.beta]
inputs = [UpgradeUser]
outputs = [UserUpgraded, BillingRequested]
store = UserStore
passesUp = {
customerApi: this.deployment.outputs.customerApi,
userDataBoundary: this.deployment.outputs.userDataBoundary
}
}
export const engineering = new EngineeringManagerModel()
import { EngineeringDeployment } from "./TeamDeployment"
import { BillingRequested, UpgradeUser, UserUpgraded } from "./events"
import { RootEnvironment } from "./environments"
import { UserStore } from "./UserStore"
BackendService.ts
export class BackendService {
constructor(private users: UserStore) {}
upgradeUser(userId: string, plan: Plan) {
const user = this.users.find(userId)
const upgraded = { ...user, plan }
this.users.save(upgraded)
return upgraded
}
}
import type { Plan, UserStore } from "./UserStore"
The model connected to production code
ceo.ts
export class CeoModel {
owns = [RootEnvironment]
company = {
product: engineering,
trust: security.expectations,
money: finance.expectations
}
}
export const ceo = new CeoModel()
import { engineering } from "./engineering-manager"
import { RootEnvironment } from "./environments"
import { finance } from "./finance-manager"
import { security } from "./security-manager"
ceo.expectations.test.ts
describe("the company in the CEO's head", () => {
it("upgrades a customer without exposing their data", () => {
const customer = testSystem.backend
.upgradeUser("vanja", "pro")
expect(customer.plan).toBe("pro")
expect(testSystem.datastore.find("vanja").plan).toBe("pro")
expect(ceo.company.product.outputs).toContain(UserUpgraded)
})
})
import { ceo } from "./ceo"
import { UserUpgraded } from "./events"
import { testSystem } from "./TestSystem"
engineering-manager.ts
export class EngineeringManagerModel {
reports = [backendDeveloper, dataDeveloper]
deployment = EngineeringDeployment
owns = [EngineeringDeployment, RootEnvironment.test]
awareOf = [RootEnvironment.production, RootEnvironment.beta]
inputs = [UpgradeUser]
outputs = [UserUpgraded, BillingRequested]
store = UserStore
passesUp = {
customerApi: this.deployment.outputs.customerApi,
billingEvents: this.deployment.outputs.billingEvents
}
}
export const engineering = new EngineeringManagerModel()
import { backendDeveloper } from "./backend-developer"
import { dataDeveloper } from "./data-developer"
import { EngineeringDeployment } from "./TeamDeployment"
import { BillingRequested, UpgradeUser, UserUpgraded } from "./events"
import { RootEnvironment } from "./environments"
import { UserStore } from "./UserStore"
BackendService.ts
export class BackendService {
constructor(private users: UserStore) {}
upgradeUser(userId: string, plan: Plan) {
const user = this.users.find(userId)
const upgraded = { ...user, plan }
this.users.save(upgraded)
return upgraded
}
}
import type { Plan, UserStore } from "./UserStore"
UserStore.ts
export abstract class UserStore {
abstract find(userId: string): User
abstract save(user: User): void
}
export type Plan = "free" | "pro"
export type User = {
userId: string
plan: Plan
}
TestSystem.ts
class ExpectedUserStore extends UserStore {
private users = new Map([
["vanja", { userId: "vanja", plan: "free" as Plan }]
])
find(userId: string) {
return this.users.get(userId)!
}
save(user: User) {
this.users.set(user.userId, user)
}
}
const datastore = new ExpectedUserStore()
export const testSystem = {
backend: new BackendService(datastore),
datastore
}
import { BackendService } from "./BackendService"
import { UserStore, type Plan, type User } from "./UserStore"
ProductionUserStore.ts
export class ProductionUserStore extends UserStore {
find(userId: string) {
return usersTable.get({ userId })
}
save(user: User) {
usersTable.put(user)
}
}
import { usersTable } from "./aws-production-account"
import { UserStore, type User } from "./UserStore"
TeamDeployment.tf
module "backend" {
source = "../../infra/service"
name = "backend"
artifact = var.backend_service_artifact
environment = {
USER_TABLE = aws_dynamodb_table.users.name
METRICS = aws_cloudwatch_log_group.product.name
}
}
resource "aws_dynamodb_table" "users" {
name = "users"
billing_mode = "PAY_PER_REQUEST"
hash_key = "userId"
attribute {
name = "userId"
type = "S"
}
}
resource "aws_cloudwatch_log_group" "product" {
name = "/company/product"
}
output "customer_api" {
value = module.backend.public_url
}
output "user_data_boundary" {
value = aws_dynamodb_table.users.arn
sensitive = true
}
output "billing_events" {
value = module.backend.events["BillingRequested"]
}