Why this matters
If you cannot draw a system on one sheet of paper, you cannot tell whether a new feature strengthens the product or just adds noise. For a founder, the risk is paying weeks of engineering time for extra screens while the core customer journey still cannot run from start to finish. That exact failure happened here: in seven days the repository grew to roughly 980,000 lines, 93 API route files, 31 public pages, 58 UI primitives and 28 read-only preflight calculators, yet nobody could sign in, connect an ad account or send a real conversion event. The independent review of 2 December 2026 caught the gap, and owner decision OD-18 redirected every wave that followed onto one real end-to-end path. When you understand the map of this system and the five status words, you can look at any folder or status update and know immediately what exists, what is proven and what is still missing.
The ideas
One owned operating ledger, eight hard rules and twelve refusals
Every small business running paid advertising faces a common trap: separate tools hold web events, ad campaigns, customer leads and SEO reports, while an agency often holds the logins. When the contract ends, years of audience and conversion history leave with the agency.
This product replaces that sprawl with one business-owned operating ledger. Ad spend, server-side signals, a closed-loop customer pipeline and five SEO tasks live inside one workspace that belongs strictly to the business. An outside specialist works inside owner-set limits without ever holding accounts or cash.
Two lists in the product frame turn that thesis into concrete boundaries: eight hard rules (R1 to R8) and twelve refusals (N1 to N12).
| Rule or refusal | Plain meaning | Mistake it stops |
|---|---|---|
R1, N1 (account sovereignty) | Business owns ad accounts, pixels, shop and CRM; zero password sharing; one-click revoke | Agencies holding accounts hostage |
R2 | 90-second read-only audit before any credit card | Paywalling an empty screen |
R3, N6 | Dual Meta CAPI and Google Data Manager with separate hashing behind a hard consent gate | Broken match quality or unconsented data dispatch |
R4, N2 | Neither marketers nor AI spend directly; every binding change uses an expiring SHA-256 preview approved by the owner | Overnight spend spikes from unchecked clicks or black-box automation |
R5, N7, N8 | Marketer badges come from read-only APIs and safeguarded payment records; the product never promises a guaranteed ROAS | Edited screenshots, fake star scores and false return claims |
R6, N3–N5, N11 | One-click cancel, zero ad-spend markup, licensed iyzico Pazaryeri safeguarded payments, verified company billing | Pooling client cash illegally or phone cancellation traps |
R7 | Moving a consented CRM deal to qualified or won queues conversion feedback in the same transaction | Ad platforms optimizing for junk leads |
R8, N12 | At most five SEO tasks from an isolated crawler instead of 400 raw rows | Dashboard sprawl |
A common mistake is treating product rules as marketing slogans. Here, every rule above maps to code, database checks or automated gates covered in later lessons.
Who uses it and the five places
A small-business tool breaks down when every user holds the same privileges or navigation sprawls across fourteen tabs. This product separates two roles and five calm places:
- The business owner owns the workspace, connects OAuth accounts, sets daily ceilings and step caps, toggles the kill switch, approves proposals, releases safeguarded payments and revokes access in one click.
- The hired marketer works inside a time-bound, scoped grant, inspects diagnostics, proposes changes into the approval queue and never sees OAuth vault tokens or billing controls.
Signed-in navigation exposes five places plus a Settings icon:
- Overview (
Özet): 30-day spend, verified revenue, signal health, kill-switch status and pending approvals. - Signals and Connections (
Sinyal & Bağlantılar): OAuth connections, signal studio and live event debugger. - Marketers (
Uzmanlar): vetted specialist dossiers and safeguarded-payment engagements. - Customers (
Müşteriler): closed-loop CRM pipeline feeding consented sales back to ad platforms. - SEO (
SEO): Core Web Vitals, Search Console summary and at most five prioritized fixes.
Advanced modules (profit margins, AI copy proposals, raw ingest inspection) open one click beneath their parent place. This lesson covers the map only; sign-in and roles belong to lesson 04.
The seven runtime parts and what each may touch
Think of a restaurant kitchen that separates the front counter, the cash register, the locked safe and the delivery scooter. If a stranger walks up to the front counter, they cannot open the safe because the counter clerk does not even hold the key. Software architecture uses the same idea: split the running system into a small number of distinct processes so a bug in one part cannot automatically compromise every secret.
That analogy stops being exact at one point: in software, splitting into too many tiny services creates more network failures and operational drag than a small team can handle. That is why bounded architecture keeps this entire system to seven well-defined runtime pieces rather than dozens of microservices.
Browser (Owner / Marketer / Shopper)
| |
| HTTPS pages | Tracking beacon
v v
[1. Web App (apps/web)] [6. Edge Collector (apps/collector)]
| HTTP JSON only | Signed HTTPS batch
v v
[2. API Server (apps/api/src/server.ts)] -----> Meta Graph API (test budget execution)
| app login + vault login
v
[3. PostgreSQL 18 Database] <---- [4. Background Worker (worker-main.ts)] (app login only)
^
| app login + vault login
[5. Dispatch Process (dispatch-main.ts)] -----> Meta CAPI & Google Data Manager
[7. SEO Crawler (apps/seo-worker)] -----> Public shop URLs only (zero DB or vault secrets)Each of the seven runtime parts has a strict job and an explicit list of what it must never touch:
| Runtime part | Job | May touch | Must never touch |
|---|---|---|---|
| 1. Web app | Renders Turkish and English screens in Next.js | Browser HTTP calls to the API and closed UI primitives | PostgreSQL directly, OAuth vault tokens, raw secrets |
| 2. API server | Handles auth, workspace routes, approvals and Meta budget execution | App database login, vault login and master key when configured | Unverified client totals or direct browser DOM |
| 3. PostgreSQL 18 database | Stores tenant rows, auth sessions, vault ciphertexts and audit log | Tenant rows filtered by forced row-level security; separate auth and vault schemas | Calling external ad APIs directly |
| 4. Background worker | Runs database housekeeping and queue sweeping | App database login only (DATABASE_URL) | Vault database login, vault master key or live ad-platform delivery |
| 5. Dispatch process | Sends stored conversion events and refreshes OAuth tokens | App database login plus vault login and master key | Serving public browser HTTP requests |
| 6. Edge collector | Receives storefront and browser events, hashes personal data and signs batches | Public event payloads and edge signing secret | PostgreSQL, vault secrets or raw long-term PII storage |
| 7. SEO crawler | Fetches public shop pages and runs technical SEO checks | Public HTTPS targets checked by SSRF guards | Any database URL, vault key, payment key or ad-platform secret |
The most common mistake in early web apps is letting the frontend framework query the database directly or giving every background worker full database superuser access. Separating the vault-less worker from the dispatch process and blocking every secret at startup inside the SEO crawler shrinks the blast radius if any single component fails.
Three journeys end to end
Tracing three real journeys shows how the seven parts cooperate across boundaries.
Journey 1: a page request
When a signed-in owner opens /w/{workspaceId}/overview, the frontend asks the backend API for workspace data.
Browser -> Web App (reads workspaceId from URL)
-> API GET /v1/w/:workspaceId/overview (checks session cookie + role)
-> PostgreSQL (sets transaction-local workspace context)
-> API returns JSON DTO (Cache-Control: no-store) -> Web App rendersThe workspace ID stays in the URL so two open tabs for two shops never mix, and the web app never queries PostgreSQL directly.
Journey 2: a tracked event
Shopper browser -> Edge Collector (hashes email/phone per platform, signs batch)
-> API ingest endpoint (verifies signature + consent gate, stores row)
-> Dispatch Process (claims row, decrypts token from vault, sends to Meta/Google)
-> PostgreSQL updated with delivery receipt (or skipped_no_consent)Platform-specific hashing and consent rules belong to lesson 07; vault encryption belongs to lesson 05.
Journey 3: an approval
Marketer -> API POST /v1/w/:workspaceId/approvals (checks ceilings, hashes payload, stores pending row)
Owner -> Reviews Approval Drawer (exact integer diff, expiry timer, SHA-256 preview)
Owner -> Approves with step-up -> API re-verifies hash, expiry, ceiling and kill switch
-> API reads Meta budget, writes new budget, reads back to confirm -> Audit log receiptRe-verifying the hash and ceilings on the server stops any browser tamper after approval. The full approval state machine and crash recovery belong to lesson 08.
The map of the repository
This codebase is structured as a monorepo: one Git repository holding all applications, shared libraries, design contracts, documentation, verification tools and tests together. One commit can update a shared library and every app that depends on it at the same time.
| Top-level folder | What lives there | Example |
|---|---|---|
apps/ | The four runnable applications | apps/web, apps/api, apps/collector, apps/seo-worker |
packages/ | Ten shared internal libraries imported by apps | packages/db, packages/vault, packages/approvals, packages/ui, packages/signals |
design/ | The product frame, all UI copy, design decisions, visual tokens and prototypes | design/FRAME.md, design/WORDS.md, design/DECISIONS.md |
docs/ | Architecture records, schema, OpenAPI contract, runbooks, owner decisions, wave reports and lessons | docs/schema.sql, docs/openapi.yaml, docs/adr/, docs/lessons/ |
tools/ | Zero-dependency verification runner, static gates, learning builder and local dev stack | tools/verify, tools/gates.manifest.json, tools/learning/build.mjs |
tests/ | Cross-cutting contract, security fuzz, chaos, load and real-browser journey suites | tests/contracts/, tests/security/, tests/browser/ |
A typical newcomer mistake is editing generated outputs directly or putting product copy inside packages/ui. Knowing the folder roles tells you immediately where a change belongs: shared UI parts live in packages/ui with zero product strings, user-facing strings start in design/WORDS.md, and cross-package rules live in packages/.
How decisions are recorded and what the five status words mean
Large projects break down when product rules, legal trade-offs and technical choices live only in someone's memory. This repository records decisions in four linked places:
- The design triad under
design/:FRAME.mddefines product scope and rules,WORDS.mdholds every Turkish and English screen string (with the one named exception OD-23 for English lessons and dictionary content), andDECISIONS.mdrecords numbered design decisions (D01toD40) and founder open questions (Q1toQ10). - The owner decision register in
docs/OWNER-DECISIONS.md, recording business and governance calls (OD-01onward) that only the two founders can answer. - Ten architecture decision records (
0001to0010) indocs/adr/, explaining major technical choices such as passwordless sign-in (ADR-0010) and the closed UI kit (ADR-0003). - The root rulebook AGENTS.md, which binds every person and agent with 22 numbered rules, including using the brand slot (
{ürün}/{product}) until OD-01 settles the public name.
Finally, every claim about any feature must use one of five exact status words:
- researched: studied from external sources or competitor evidence, not yet designed or coded.
- designed: written down in a specification, decision record or contract, not yet coded.
- built: code exists on the branch, with no claim yet that tests passed.
- verified: built code passed concrete, recorded checks on a named commit and environment.
- deployed: running on a real server reachable by owners or customers.
Saying "done" hides the difference between a document, untested code and a live server. Using these five words keeps every conversation grounded in facts.
How this repository does it
Every boundary sketched above is enforced in concrete files on this branch today:
- Rules and product contract:
AGENTS.mdlists all 22 repository rules;design/FRAME.mdsets outR1toR8,N1toN12, the twelve Release 1 screens and the three supporting surfaces;design/WORDS.mdholds bilingual screen strings;design/DECISIONS.mdanddocs/OWNER-DECISIONS.mdtrackD01toD40,Q1toQ10andOD-decisions;docs/adrholds ADRs0001to0010. - Workspace packages:
pnpm-workspace.yamlregistersapps/*(web,api,collector,seo-worker) andpackages/*(ai,approvals,auth,connectors,db,payments,shared,signals,ui,vault). If a package boundary were broken—for instance, ifapps/webimportedpackages/dbdirectly—architecture and web-budget checks would fail. - API composition root:
server.tsis the API composition root. Before opening any HTTP port,loadApiRuntimeConfigvalidates environment variables (logging codes only, never values),runSchemaGuardverifies the database schema version, andserver.tsrefuses to start in production ifOAUTH_FAKE_PROVIDER_BASEis set. It builds the app database pool (DATABASE_URL), the optional vault pool (VAULT_DATABASE_URL) and the real Meta budget executor (createMetaBudgetExecutor), then passes them tocreateApiAppinapp.ts. Removing this composition root would scatter secret parsing and let production accidentally start with sample memory data or test stubs. - Separate background processes:
worker-main.tsruns vault-less database queues and hourly housekeeping (auth.cleanup_login_challengesand expired OAuth flow purges) using onlyDATABASE_URL.dispatch-main.tsruns as the separate least-privilege dispatch process holdingDATABASE_URL,VAULT_DATABASE_URLand the vault master key;runDispatchMainClirunsSignalDispatchEngine.runCycleand periodic token refresh (runConnectionRefreshCycle) and refuses the fake provider in production. Removing that split would force the general worker to hold vault credentials unnecessarily. - Edge and crawler isolation:
app.tsimplements the Hono edge collector with CORS, rate limiting and edge hashing;env-guard.tslistsFORBIDDEN_EXACT_ENV_VARSandFORBIDDEN_ENV_PREFIXES(DATABASE_,VAULT_,POSTGRES_,IYZICO_) and abortsapps/seo-workerat startup if any forbidden secret is present. Removingenv-guard.tswould remove the startup guarantee that a compromised crawler cannot read database or payment keys. - Workspace shell and endpoints:
WorkspaceShell.tsxrenders the five places and URL-based workspace switcher, whileapps/api/src/routesimplements every HTTP endpoint described indocs/openapi.yaml. - What is true today on this branch: Passwordless sign-in, OAuth ad-account connection (against a production-refused local fake provider), stored event ingest, the dispatch process and the Meta budget approval executor are built and verified locally (and Waves 46 and 47 ran green on GitHub Actions, as recorded in
LOG.md).
Not built yet
What went wrong once
Breadth outran the critical path
- What happened: During the first week of rapid parallel building, the repository accumulated roughly 980,000 lines, 93 API route files (including 28 read-only preflight calculators), 31 public pages, 58 UI components and 81 documents. Despite that volume, a real person still could not create an account, sign in, connect a Meta or Google ad account, send a real event or execute an approved budget change.
- How it was noticed: The independent review recorded in
docs/INDEPENDENT-REVIEW-2026-12-02.mdchecked every core promise from a clean clone instead of judging progress by file counts. - Cause in plain words: Earlier checks measured growth by minimum counts (more routes, more pages, more docs), so adding sideways surfaces stayed green while wiring the hard end-to-end journey remained unfinished.
- Fix: The founders recorded owner decision
OD-18(depth-first engineering, deletion allowed), retired growth-only count checks and focused Waves 46, 47 and 48 on finishing the four-step critical path: sign in, connect an account, deliver a test event and execute one approved budget change. - General lesson: Progress is the shortest complete path a real customer can walk from end to end, never the count of screens or documents.
Decisions on paper and the code drifted apart
- What happened: Early records
ADR-0001andADR-0004named Better Auth, pg-boss, Drizzle and Node 26, yet the actual code used none of those libraries and ran on Node 24. MeanwhileREADME.mdhad grown into a 124 KB log summary that never told a newcomer how to start the project. - How it was noticed: The 2 December 2026 review compared the ADRs and
README.mdline by line againstpackage.jsonand the live source code. - Cause in plain words: Code evolved quickly while architecture documents were treated as one-time write-only artifacts instead of living records.
- Fix: In Wave 46 the founders accepted
OD-14andADR-0010for passwordless sign-in in own code, amendedADR-0001,ADR-0004anddocs/SYSTEM.md, and placed a short "Start here" section at the top ofREADME.md. - General lesson: A decision record that contradicts running code misleads every future contributor; when the code changes, amend the record the same day.
Three finished parts that did not add up to a working sign-in
- What happened: In Wave 46, three parallel workstreams built auth storage (A), sign-in API routes (B) and login screens (C), and each passed its own tests. Yet taken together, the sign-in routes were not mounted in the app, the development CORS rule blocked the browser's request header, sign-out left new cookies behind and a new workspace fell back to displaying a sample business's name.
- How it was noticed: Wave 46 included a dedicated wiring workstream (F) whose real-browser journey tested the whole flow in Chromium against the live API and database, recorded in
docs/wave46/reports/F-REPORT.md. - Cause in plain words: Each part was tested in isolation against stand-ins for the other two parts, and browser rules like CORS preflights only trigger in a real browser.
- Fix: Workstream F mounted the routes, added the cookie-mutation origin guard, unified token reading into one leaf module, cleared all three cookies on sign-out and proved the full flow with
sign-in-journey-e2e.mjs. - General lesson: Passing unit tests on separate pieces never proves the pieces work together; integration needs its own owner and an end-to-end test.
Try it yourself
Every step below is read-only and safe to run on Windows. None of these commands touch your running local dev stack on ports 3000, 4000 or 5432, and none call Meta or Google.
Step 1: list the fourteen workspace packages in PowerShell
Get-ChildItem apps, packages -Directory | Select-Object Parent, NameYou should see four directories under apps (api, collector, seo-worker, web) and ten directories under packages (ai, approvals, auth, connectors, db, payments, shared, signals, ui, vault). That list matches pnpm-workspace.yaml and shows the full footprint of the monorepo.
Step 2: inspect the ten architecture decision records in PowerShell
Get-ChildItem docs/adr -File | Select-Object NameYou should see ten numbered Markdown files from 0001-web-first-nextjs-fastify-postgres.md through 0010-durable-sessions-and-passwordless-sign-in.md. Open 0010 to see how a real decision records its context, rejected alternatives and consequences.
Step 3: verify the SEO crawler's startup secret guard in PowerShell
Select-String -Path apps/seo-worker/src/env-guard.ts -Pattern "FORBIDDEN_ENV_PREFIXES|DATABASE_URL|VAULT_DATABASE_URL"You should see DATABASE_URL, VAULT_DATABASE_URL and FORBIDDEN_ENV_PREFIXES (DATABASE_, VAULT_, POSTGRES_, IYZICO_). This confirms in live code that Zone 3 refuses to start if any database, vault or payment secret is ever injected into its environment.
Step 4: check the verification plan without executing anything in Git Bash
bash tools/verify --listGit Bash prints the complete ordered list of checks from tools/gates.manifest.json grouped into core, static, suites, postgres, deploy, scanners, build and browser, without starting any server or changing any file. Seeing the plan tells you exactly what "verified" covers on this branch.
Check yourself
0 / 6Why does the dispatch process run separately from the general background worker?
A feature's code is merged on a branch and its local tests passed on your Windows machine, but no server is running it for customers. Which status words accurately describe it?
Why must every workspace URL include /w/:workspaceId/... instead of storing the active workspace in a session cookie?
If an attacker tricks the SEO crawler into reading environment variables while scanning a hostile storefront page, why can they not steal customer OAuth tokens?
What did the 2 December 2026 independent review reveal about building 28 read-only preflight calculators before real sign-in existed?
A proposed screen needs to show a new Turkish button label and bend hard rule R4 so AI can raise budgets automatically without approval. What must happen first according to AGENTS.md?
Words to know
33Go deeper
- Repository rules and product constitution:
AGENTS.md,design/FRAME.md,design/DECISIONS.mdanddocs/OWNER-DECISIONS.md. - System overview and decision records:
docs/SYSTEM.md,docs/adr/0001-web-first-nextjs-fastify-postgres.mdanddocs/adr/0010-durable-sessions-and-passwordless-sign-in.md. - Real history behind the depth-first shift:
docs/INDEPENDENT-REVIEW-2026-12-02.mdandLOG.md. - Archived lessons this lesson replaces (historical only, not a source of current facts):
archived lesson 10,archived lesson 13,archived lesson 16,archived lesson 20andthe archive index. - External documentation for core web technologies used here: MDN overview of HTTP, TypeScript documentation, Fastify documentation, Next.js App Router documentation, Cloudflare Workers documentation and OpenAPI Specification.