TCF CRM – Atomic Architecture & Backend Implementation

Generated: 2025-06-19 17:15:51

1  Objectives

• Lean runtime — no external message bus; Postgres is the heartbeat.

• Straight-through UX — reps act from mobile with <5 s freshness via polling.

2  Key Changes Adopted

Change Rationale
Single-transaction stored procedures Guarantees ACID behaviour and encloses business rules in one place.
Polling > WebSockets Cuts LISTEN/NOTIFY & WS server; still near-real-time with 3–5 s refresh.
TTL column (status_expires_at) on slabs Removes cron job; stale holds auto-release inline.
Enum consolidation Fewer columns to keep in sync.

3  Repository Layout

tcf-crm/

├── .env.example

├── package.json

├── tsconfig.json

├── docker-compose.yml           # pg-dev + app for local hacking

├── Dockerfile                   # multistage, ≤45 MB final image

├── src/

│   ├── app.ts                   # entry; sets up Express & routes

│   ├── db/

│   │   ├── index.ts             # pg-pool + drizzle helper