Media Buying CRM
The internal operating system of a media-buying team: traffic, finance, people and AI tooling in one app with 13 roles.
- Custom CRM / business management
- Next.js 16 / TypeScript / PostgreSQL 17 / RLS / Passkeys + MFA / Cloudflare Workers / S3 / OpenAI API / Docker Compose / Vitest + Playwright / GitHub Actions
Problem
The team worked in a tracker, ad accounts, spreadsheets and chats at once. Buyer, finance, designer and HR each saw a different slice of one picture, and the head assembled it by hand.
Solution
One application where every role gets its own menu and its own slice of data, with access checked three times: in navigation, on the server and in the database through RLS.
- 13
- roles
- 112
- screens
- 139
- API handlers
- 365
- database migrations
- ~190
- tables
- 437
- RLS policies
- 65
- scheduled jobs
- 1 300+
- test files
Roles
Every role has its own menu, its own slice of data and its own limits. Here is what was built for each.
Owner
- Full menu and every workspace
- The only role with the AI studio and the creatives board
- Finance editing
Head
- Route, Performance and the rules Command Center
- Triage of incoming tasks
- Finance management and ad-intel access
Partner
- A buyer who runs their own workspace
- Every request is narrowed to that workspace
- Sees the ledger and P&L of their own line
Team Lead
- Buyer menu plus subordinate buyers' data through RLS
- Shares flows with their own team
- Read-only recruiting calendar
Buyer
- Campaigns, flows, creatives, landings, accounts, domains
- Own reports only: someone else's returns 404
- Own costs in finance
Finance
- Finance split into separate menu sections
- Balance, operations, P&L, cash flow, payroll, planned payments
- Finance manager and editor rights
Designer
- Creative archive, compression, audio splitting
- Reference library
- Library rows limited to their owner through RLS
Design Lead
- Designer menu plus the whole creatives board
- Read-only recruiting calendar
Landing Developer
- Landings: tracker inject and verify, drop-off analysis
- Tasks that can be assigned to this role
- Compression only in creatives
HR
- Recruiting pipeline: candidates, vacancies, calendar
- Employees and onboarding
Spy Analyst
- Creatives and ad-intel
- Narrow access without finance or traffic
Tech
- Tasks and the technical section
- No access to finance
Modules
- Traffic
- Campaigns from the tracker, Route with weights and toggles, flows and rotations, landings, creatives, domains and click log
- Finance
- Balance, operations, P&L, cash flow, planned payments, payroll, break-even, buyer costs
- People
- Recruiting with pipeline and calendar, onboarding, Performance by department, task kanban with a triage buffer
- Automation and AI
- Command Center with auto-rules, AI assistant, a campaign-creation agent with tools, a persona studio, control of cloud Android devices
Integrations
- Binom
- Campaigns, stats, click log, conversions, rotations and landers
- Meta Graph API
- OAuth and stats; tokens encrypted with AES-GCM
- MetricFlow
- Ad accounts, insights, quotas
- Cloudflare
- Zones, routes, Workers KV for redirects
- Spaceship
- Domain registration
- Google Safe Browsing
- Domain ban checks
- Google Calendar
- Candidate calls in recruiting
- VMOS
- Cloud Android phones with a live screen
- SpyTrend
- Ad-intel through JSON-RPC over SSE
- OpenAI / DeepSeek
- Chat, tools, images, transcription
- Backblaze B2 / S3
- Files, media and database backups
- Web Push
- Browser notifications
Architecture
- Next.js 16 App Router and TypeScript: 112 screens, 139 API handlers, server actions
- Self-hosted PostgreSQL 17: 365 migrations, about 190 tables, 437 RLS policies, realtime on six tables
- Authentication: passkeys (WebAuthn), mandatory TOTP MFA, local JWT verification
- A cron runner with a queue, locks and retries; 65 scheduled jobs: syncs, rules, cache warming, purges
- An ffmpeg media worker with its own least-privilege database role
- A redirect worker on Cloudflare Workers: a KV lookup and a 302 to the tracker
- Docker Compose with ten services behind Caddy with automatic TLS
- Daily backups rotated 14 days / 8 weeks / 6 months, with a freshness check
Engineering decisions
- Access in three layers: a per-role menu, a server-side section check, RLS in the database. Role sets are one constant shared by UI and server, with invariant tests
- Traffic share is weight divided by the sum of weights of enabled landers. Switch one off and the rest split 100% with no manual recalculation
- Passwordless passkey sign-in: the server verifies the signature and creates the session itself, no email is sent
- The media worker processes untrusted video, so it has its own database role restricted by RLS
- Docker images are built in CI, not on the server: deploys used to load production for 5–16 minutes. The deploy key is restricted to one command, with rollback to the previous image
- Separate request pools for live and bulk calls to external APIs, so a backfill never blocks the interface
What was delivered
- 13 roles with their own menus
- Routing with weights and toggles
- Financial accounting and P&L
- Recruiting and onboarding
- Task kanban
- Auto-rules
- AI assistant and campaign agent
- 12 external integrations
- Passkeys and MFA
- CI with migration replay
- Backups and monitoring
Need something similar?
Start a project