Development
Running Locally
Section titled “Running Locally”# Start the dev server (hot-reload)npm run dev# Equivalent to: wrangler dev
# The server runs at http://localhost:8787Wrangler dev mode uses local D1 (SQLite file in .wrangler/) and local KV. Run migrations and seed locally before starting:
npm run db:migratenpm run seed > seed.sqlwrangler d1 execute lattice-db --local --file=seed.sqlnpm run devVerifying the Setup
Section titled “Verifying the Setup”# Health checkcurl http://localhost:8787/health
# Get the company entitycurl -H "X-Lattice-Role: ceo" http://localhost:8787/api/v1/entities/lat_com_meridian
# List all teamscurl "http://localhost:8787/api/v1/entities?type=team"
# Get the full org treecurl http://localhost:8787/api/v1/tree/lat_com_meridian
# Test role-based filtering: compare CEO vs team_member viewcurl -H "X-Lattice-Role: ceo" http://localhost:8787/api/v1/entities/lat_com_meridian | jq '.entity.telos.budget'curl -H "X-Lattice-Role: team_member" http://localhost:8787/api/v1/entities/lat_com_meridian | jq '.entity.telos.budget'# CEO sees full budget; team_member sees empty arrayProject Structure
Section titled “Project Structure”Lattice/├── src/│ ├── schema/│ │ ├── entity.ts # Entity, TelosState, extensions, workflow types│ │ ├── api.ts # Request/response types, event types, error types│ │ └── index.ts # Barrel export│ ├── workers/│ │ ├── gateway.ts # Hono app: all API routes, explorer UI, error handling│ │ └── helpers.ts # D1 query helpers: entity reconstruction, events, cache│ ├── middleware/│ │ └── policy.ts # Role-based field filtering middleware│ ├── db/│ │ └── migrations/│ │ └── 0001_init.sql # Full D1 schema: 10 tables, indexes│ ├── seed/│ │ └── generate.ts # Seed data generator for Meridian Systems│ ├── ui/│ │ └── explorer.html # Lattice Explorer single-page app│ └── env.d.ts # HTML module declaration for text imports├── wrangler.toml # Cloudflare Workers configuration├── package.json # Dependencies and scripts└── LATTICE.md # Full specification