Skip to content

Commit e7d2e85

Browse files
dannyshmueliclaude
andcommitted
Add architecture diagram and fix file tree in README
Replace the outdated file tree (which referenced nonexistent files like handlers.js, tracker.js, adapter.js, d1.js) with a Mermaid flowchart showing the data flow from clients through auth to platform entry points, plus an accurate file tree showing this repo vs @agent-analytics/core. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 055ccfc commit e7d2e85

1 file changed

Lines changed: 46 additions & 11 deletions

File tree

README.md

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,22 +341,57 @@ Returns event names with counts, first/last seen dates, and all known property k
341341

342342
## Architecture
343343

344+
```mermaid
345+
flowchart TB
346+
subgraph Clients
347+
website["Your Website<br/><small>tracker.js auto-tracks page views</small>"]
348+
agent["AI Agent / CLI<br/><small>npx agent-analytics stats ...</small>"]
349+
end
350+
351+
subgraph Server ["Server (this repo)"]
352+
auth["auth.js<br/><small>Token + API key validation</small>"]
353+
cf["platforms/cloudflare.js<br/><small>CF Worker + D1Adapter</small>"]
354+
node["platforms/node.js<br/><small>Node.js HTTP + SQLite</small>"]
355+
end
356+
357+
subgraph Core ["@agent-analytics/core"]
358+
handler["createAnalyticsHandler()<br/><small>Platform-agnostic routing</small>"]
359+
d1["D1Adapter<br/><small>Cloudflare D1 queries</small>"]
360+
tracker["tracker.js<br/><small>Client-side tracking script</small>"]
361+
helpers["Date helpers, property validation"]
362+
end
363+
364+
website -- "POST /track" --> auth
365+
agent -- "GET /stats · POST /query" --> auth
366+
auth --> cf & node
367+
cf --> handler
368+
node --> handler
369+
cf -.-> d1
370+
node -.-> sqlite[("SQLite")]
371+
handler --> d1 & tracker & helpers
344372
```
345-
src/
346-
handlers.js — Pure request handling (Web API Request/Response)
347-
auth.js — Token + API key validation
348-
tracker.js — Embeddable client-side tracking script
373+
374+
`@agent-analytics/core` does the heavy lifting — it exports `createAnalyticsHandler({ db, validateWrite, validateRead })`, a platform-agnostic request handler. This repo plugs in the auth layer and platform glue: Cloudflare Workers with D1, or Node.js with SQLite. Add a new platform by providing a database adapter and calling the handler factory.
375+
376+
```
377+
src/ (this repo — platform glue + auth)
378+
auth.js — Token + API key validation (constant-time compare)
349379
db/
350-
adapter.js — Shared types and helpers
351-
d1.js — Cloudflare D1 adapter
352-
sqlite.js — better-sqlite3 adapter (self-host)
380+
sqlite.js — better-sqlite3 adapter (self-host)
353381
platforms/
354-
cloudflare.js — CF Worker entry (Queue + ctx.waitUntil)
355-
node.js — Node.js HTTP server entry
382+
cloudflare.js — CF Worker entry (D1Adapter + ctx.waitUntil)
383+
node.js — Node.js HTTP server entry
384+
385+
@agent-analytics/core (npm dependency — does the heavy lifting)
386+
src/
387+
handler.js — Platform-agnostic request routing + response building
388+
db/
389+
adapter.js — Date helpers, shared query logic
390+
d1.js — Cloudflare D1 adapter (D1Adapter, validatePropertyKey)
391+
tracker.js — Client-side tracking script (served at GET /tracker.js)
392+
ulid.js — ULID generation for event IDs
356393
```
357394

358-
Handlers are platform-agnostic — they return data and let the platform decide how to write it. On Cloudflare, writes go through a Queue (if configured) or `ctx.waitUntil`. On Node.js, writes are inline. Add a new adapter to support any database or platform.
359-
360395
## License
361396

362397
MIT

0 commit comments

Comments
 (0)