codflow
AGENTS.md338 starsChanged 2 months agoApache-2.0View on GitHub
CodFlow is a cash-on-delivery (COD) e-commerce platform for Algeria. Monorepo, TypeScript, deployed on Cloudflare (Workers, D1, R2, KV). - cod-server/ — Cloudflare Workers API (Hono). Merchant /api/*, public /store/*, /webhooks, /images, /mcp. D1 via Drizzle. - cod-client-astro/ — the merchant dashboard (Astro 7). Prerendered static pages + a Worker surface for /api/auth/* and /mcp/oauth/login; React islands fetch data from cod-server through src/lib/api.ts (the only module allowed to call the API). UI strings come from locales/{ar,en,fr} via useT(namespace) — the i18n…
- Reads credentials
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,736 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository20 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- codebase-designSkill
- code-reviewSkill
- codflow-setupSkill
- codflow-updateSkill
- diagnosing-bugsSkill
- domain-modelingSkill
- ecotrackSkill
- implementSkill
- improve-codebase-architectureSkill
- meta-adsSkill
- prototypeSkill
- route-builderSkill
- storefront-vercelSkill
- tddSkill
- to-specSkill
- to-ticketsSkill
- wayfinderSkill
- whatsapp-otpSkill
- zr-expressSkill
The file
We split this AGENTS.md into the rules it gives an agent
9 rules. About 0 are common, 4 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 62
After changing TypeScript: run npm run typecheck in the affected package.
- Very specific: line 63
After changing behavior: run npm test in the affected package.
- Distinctive: line 69
README claims must be code-verified: Never write a feature claim in the README that is not actually implemented.
- Very specific: line 72
Never commit secrets: No live API keys, carrier tokens, or credentials in source, tests, or fixtures.
- Distinctive: line 77
No explanatory code comments unless asked.
- Distinctive: line 85
Ask before adding a production dependency or changing the D1 schema.
- Very specific: line 86
Keep engine logic out of cod-astro/theme01.
- Very specific: line 94
Never create per-package package-lock.json files (see Layout).
- Distinctive: line 212
Verify no behavior changes
≈ “Common” is an estimate: at least 1 in 5 of the 16,597 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CodFlow — repository instructions for coding agents
CodFlow is a cash-on-delivery (COD) e-commerce platform for Algeria. Monorepo, TypeScript, deployed on Cloudflare (Workers, D1, R2, KV).
Layout
cod-server/— Cloudflare Workers API (Hono). Merchant/api/*, public/store/*,/webhooks,/images,/mcp. D1 via Drizzle.cod-client-astro/— the merchant dashboard (Astro 7). Prerendered static pages + a Worker surface for/api/auth/*and/mcp/oauth/login; React islands fetch data from cod-server throughsrc/lib/api.ts(the only module allowed to call the API). UI strings come fromlocales/{ar,en,fr}viauseT(namespace)— the i18n guard test enforces three-locale parity.cod-shared/— shared Drizzle schema, queries, RBAC scopes, error codes. Imported by the apps via relative path (../../cod-shared/...). Not published.cod-astro/theme01/— storefront theme (Astro). It is a swappable theme layer, not a platform package; keep engine logic out. Its commands and boundaries differ — readcod-astro/theme01/AGENTS.mdbefore editing it.
There is one root package.json with npm workspaces and ONE root
package-lock.json. Never add per-package lockfiles. The root also carries the
repo-wide npm overrides: the single-Vite pin (keeps one Vite major across
astro/vitest; npm ignores overrides inside workspace members).
Commands
One install at the repo root covers every package:
npm ci # at repo root — installs all workspaces
cd cod-server && npm run typecheck
cd cod-server && npm test
cd cod-server && npm run dev # wrangler dev :8787Same for cod-client-astro (npm run typecheck, npm test, npm run dev
— astro dev on :4321). Admin bootstrap: cd cod-client-astro &&
npm run seed:admin (sign-up is disabled by design).
cod-astro/theme01 has extra validators — see
cod-astro/theme01/AGENTS.md for its commands.
Cloud resource configuration
Resource names and URLs are not hardcoded in scripts. The seeders, the
D1 migration wrapper (cod-server/scripts/d1.mjs), the R2 CORS setup and
the storefront deploy helper all read <repo-root>/.env through
cod-server/scripts/cloud-env.mjs. Precedence is
process.env > .env > built-in default; the committed template is
<repo-root>/.env.example.
Keys: COD_ACCOUNT_ID, COD_DB_NAME, COD_R2_BUCKET_NAME,
COD_SERVER_URL, COD_MEDIA_DOMAIN. Add a key to DEFAULTS in
cloud-env.mjs and to .env.example together — a key in one and not the
other is how these drift.
Verification
- After changing TypeScript: run
npm run typecheckin the affected package. - After changing behavior: run
npm testin the affected package. - Full CI runs typecheck + tests for cod-server and cod-client-astro, plus
astro check+ tests for theme01 (.github/workflows/ci.yml).
Conventions
- README claims must be code-verified. Never write a feature claim in the README that is not actually implemented. Before editing README feature lists, confirm the code exists.
- Never commit secrets. No live API keys, carrier tokens, or credentials in
source, tests, or fixtures. Real secrets go in
wrangler secrets/.dev.vars(gitignored). Wrangler configs with real resource IDs are gitignored too (wrangler.tomlin cod-server/cod-client-astro) — commit.exampletemplates only. - No explanatory code comments unless asked.
Boundaries
cod-sharedis the single source of truth for the D1 schema, queries, RBAC scopes, and error codes. Do not duplicate schema or scope definitions in cod-server or cod-client-astro.- Migrations: add a new migration; never rewrite an already-applied one.
- Ask before adding a production dependency or changing the D1 schema.
- Keep engine logic out of
cod-astro/theme01; the theme layer is meant to be swappable (seecod-astro/theme01/AGENTS.md). - Dashboard data access goes through the API seam (
cod-client-astro/src/lib/api.ts). Components never callfetchdirectly, and the dashboard does not query D1 for business data — authorization lives in cod-server.
Known traps
- Never create per-package
package-lock.jsonfiles (see Layout). If a workspace's deps look stale, runnpm ciat the repo root. - The Vite pin lives in the root
package.json("overrides": { "vite": "^8.2.2" }) — npm ignoresoverridesinside workspace members. It keeps a single Vite major across astro/vitest; removing it reintroduces the dual-Vite boot crash (Missing field 'moduleType'). Keep it in sync when astro bumps Vite. COD_SERVER_URLdefaults tohttp://localhost:8787so local dev works untouched. A deployed Worker can never reach that, socod-astro/theme01/scripts/deploy.mjsrefuses to deploy a loopback value unless--force-localis passed. Set the real origin in the root.envbefore deploying the storefront.- Local D1 state is shared through
<repo-root>/.wrangler-shared: cod-server's dev/migrate scripts write there via--persist-to, and cod-client-astro's astro dev reads the same files via the Cloudflare adapter'spersistState. Sign-in against an unmigrated local D1 is the #1 "dashboard broken locally" cause — runcod-server npm run db:setup:localfirst, thencod-client-astro npm run seed:admin. PUBLIC_API_URLis a build-time client value:astro:env/clientinlines it into the browser bundle, so changing it requires a rebuild. It does not go incod-client-astro/.env— the Cloudflare adapter pushes wrangler values and.dev.varsintoprocess.env, and Astro reads env with an empty prefix, so Vite's finalprocess.envpass outranks the .env files:.dev.vars>wrangler.toml [vars]>process.env>.env. A value in.envis silently ignored, and.dev.vars— local-only by Cloudflare's definition but still read during a build — once bakedhttp://localhost:8787into production. Set it in.dev.vars(local) andwrangler.toml [vars](production);cod-client-astro npm run deployparks.dev.varsfor the build and refuses to upload a bundle containing a loopback URL. Runtime vars (PUBLIC_APP_URL,PUBLIC_TRUSTED_ORIGINS) live in wrangler.toml[vars].BETTER_AUTH_SECRETandMCP_LOGIN_TICKET_SECRETmust be identical on cod-server and cod-client-astro (shared auth D1 + MCP login-ticket relay).- Better Auth 1.7 schema requirements live in migrations 0010/0011:
accounts.issuer('local:credential', account_id = user id) andjwkss.alg/crv. cod-client-astro ships its own KVsecondaryStorageinsrc/lib/auth/server.tsbecause better-auth-cloudflare@0.3.1 lacks theincrementmethod its rate limiter requires — do not swap back tokv:shortcut. - OAuth provider tables predate better-auth 1.7:
oauthClients,oauthAccessTokens,oauthRefreshTokens,oauthConsentsare missing some 1.7 columns, andoauthResource(s),oauthClientResource(s),oauthClientAssertion(s)do not exist yet. Core auth + dashboard work; MCP client token flows may need that alignment before heavy use. - The dashboard Worker and the storefront both default to port 4321 — run
one on
--port 4322when developing both at once. - Inbound webhooks exist only for Yalidine and ZR Express. NOEST and
EcoTrack tracking is pulled on demand via
GET /orders/:id/tracking— there is no inbound receiver for them. - The shopping cart is off by default, per store (
stores.cart_enabled). A store that never enables it ships no cart markup at all. Rollback for the whole feature isUPDATE stores SET cart_enabled = 0— there is no data migration to reverse, because a multi-line order is a valid CodFlow order the dashboard and carriers already understand. - An order is either a basket or a single product.
items[]supersedes the flatproductId/productName/pricePerUnit, which are optional only whenitems[]is present.cod-shared/queries/cart.ts(normalizeOrderLines) is the single place the shapes meet — do not branch on them anywhere else. - The basket lives in the shopper's browser, never in D1. The client's
pricePerUnitis display-only; every line is re-priced from the catalog server-side. Never trust a cart total that arrived over the wire. - The mock db in cod-server's unit tests maps a full-table
select()positionally by schema column order. Adding a column to a table breaks every fixture for it until the new field is inserted at the same position — this is why those fixtures list columns in schema order with a comment. - cod-server tests run on miniflare + better-sqlite3 locally with no network or credentials required.
- A store is never born with its four legal pages automatically — this
is single-tenant (one deployment per store), so there is no app-level
"create store" flow to hook a seed into.
npm run db:setup:local/db:setup:remote(cod-server) runscripts/seed-store-pages.tsas their last step, which is idempotent (INSERT OR IGNORE) and safe to re-run. A store that already existed before this feature shipped needs one manual catch-up:npm run db:seed:legal-pages:remote -- --store-id=<id>from cod-server, or the dashboard's Pages screen → "Add Terms, Privacy, Refund & Shipping" (calls the samePOST /api/store-pages/seed-defaults). Without this, Meta Ads rejects the store's ads for missing policy pages — seereport-md/LEGAL_PAGES_PLAN.md.
Skills
This project has custom skills for AI agents. When working on specific tasks, activate the relevant skill:
Route Builder (API Endpoints)
For creating or migrating API endpoints, use the route-builder skill:
# Activate the skill (if using Kiro with skills)
disclose_context: route-builderThis skill provides:
- SKILL.md - Quick reference for the defineRoute() pattern
- MIGRATION.md - Step-by-step guide for migrating existing endpoints
- NEW-ENDPOINTS.md - Guide for creating new endpoints
- EXAMPLES.md - Real-world examples from the codebase
Key Patterns
Always use defineRoute() for new endpoints:
import { defineRoute } from "@/lib/route-builder";
import { SCOPES } from "../../../../cod-shared/rbac/scopes";
const myRoute = defineRoute({
method: "get",
path: "/my-resource",
auth: { scope: SCOPES.RESOURCE_READ }, // Always use SCOPES constants
handler: handlers.list,
});
router.openapi(myRoute.route, myRoute.handler);Migration workflow:
- Create
routes.prototype.ts - Convert routes using defineRoute()
- Run tests:
npm test -- <endpoint> - Verify no behavior changes
Available Skills
| Skill | When to Use |
route-builder | Creating or migrating API endpoints |
code-review | Reviewing code changes |
codebase-design | Understanding architecture |
prototype | Building throwaway prototypes |
improve-codebase-architecture | Refactoring or architecture changes |
tdd | Test-driven development |
wayfinder | Navigating the codebase |
codflow-setup | Setting up the project (Cloudflare + Vercel) |
storefront-vercel | Deploying or configuring the customer storefront on Vercel |
whatsapp-otp | WhatsApp OTP verification feature (dzverify) |
Ecotrack | EcoTrack carrier integration |
zr-express | ZR Express delivery platform integration (129 endpoints, organized per domain) |
diagnosing-bugs | Debug production issues (orders, delivery, payments) |
domain-modeling | Design data models for complex domain |
implement | Turn specs into working code |
to-spec | Convert ideas into formal specifications |
to-tickets | Break features into GitHub issues |
For more details on any skill, see the .agents/skills/ directory.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

