# CodFlow

**The open-source, COD-first e-commerce platform for Algeria β built agentic-ready.**
[](https://t.me/codflow_dz)
Cash on Delivery meets serverless infrastructure. Self-host your entire commerce stack on Cloudflare with zero transaction fees, connect to Algeria's delivery carriers, and optimize Meta ads for real deliveries instead of door refusals.
---
## Get Started
Choose your path:
|
### π **I want to run CodFlow**
See it in action and deploy your own store.
**[β See It in Action](#-see-it-in-action)**
**[β What works today](#-whats-included)**
**[β Quick setup guide](#-quick-setup)**
**[β Production deployment](./docs/DEPLOYMENT.md)**
|
### π» **I want to contribute**
Build features or customize CodFlow.
**[β Contributing guide](./CONTRIBUTING.md)**
**[β Architecture overview](./docs/ARCHITECTURE.md)**
**[β AI agent instructions](./AGENTS.md)**
|
---
## π₯ See It in Action
Watch the step-by-step setup guide:
[](https://youtu.be/rJPCGQnDZ18)
**[βΆοΈ Watch: CodFlow Setup & Deployment Guide](https://youtu.be/rJPCGQnDZ18)**
---
## π― The Problem CodFlow Solves
E-commerce in Algeria is **95%+ Cash on Delivery (Ψ§ΩΨ―ΩΨΉ ΨΉΩΨ― Ψ§ΩΨ§Ψ³ΨͺΩΨ§Ω
)**. Western platforms like Shopify and local tools charge per-transaction fees, require expensive VPS hosting, and lock your data in their databases.
**CodFlow is the first and only open-source COD e-commerce platform built for Algeria.**
| The Reality | Western/Local Platforms | CodFlow |
| :--- | :--- | :--- |
| **Transaction fees eat margins** | 2β5% per order + monthly SaaS fees | **$0 transaction fees** β pay only Cloudflare hosting ($0β$5/mo) |
| **Your data locked in their system** | Can't export, can't migrate, vendor lock-in | **You own everything** β D1 database, R2 images, full control |
| **Expensive hosting** | VPS servers, maintenance, scaling costs | **Serverless Cloudflare** β auto-scales, zero maintenance |
| **4+ carrier portals** | Juggle Yalidine, ZR, NOEST, EcoTrack separately | **Unified carrier API** β one integration for all carriers |
| **In-house drivers ignored** | No native driver dispatch or per-wilaya pay | **Built-in driver management** with compensation and cash settlement |
| **Ads optimize for form fills, not deliveries** | Meta Pixel fires on checkout submit (30β50% refuse at door) | **Meta CAPI fires at actual delivery** β optimize ads for real buyers |
**Deploy CodFlow to your own Cloudflare account in minutes. No monthly fees. No transaction cuts. 100% open-source (Apache 2.0).**
---
## β
What's Included
CodFlow v1.1.0 β here's what works today:
### Storefront (`cod-astro/theme01`)
- β
**Landing pages (`/lp/[slug]`)** β one-product marketing pages: stacked image story + COD form, no nav chrome
- β
Single-page COD checkout with live shipping calculation
- β
Home delivery **or** carrier stop-desk pickup selection
- β
Quantity-tier offers ("Buy 2 get 10% off", "Buy 3 free shipping")
- β
Order-verified product reviews (star ratings + Arabic/French text)
- β
Trilingual: Arabic (RTL), French, English
- β
Abandoned cart telemetry for recovery campaigns
- β
Optional WhatsApp phone verification at checkout ([DZVerify](https://dzverify.com), off by default)
- β
Optional Cloudflare Turnstile bot protection on the checkout form ([Turnstile](https://www.cloudflare.com/products/turnstile/), off by default)
- β
Legal pages (`/pages/[slug]`) β Terms, Privacy, Refund/Return, Shipping (pre-seeded, merchant-editable) and any custom page, with a checkout consent line linking to them
- β
Merchant-configurable order form β require or hide the address, notes and email, turn a delivery option off, and add up to 5 questions of your own (enforced server-side, not just hidden)
### Merchant Dashboard (`cod-client-astro`)
- β
Order management with full COD lifecycle tracking
- β
Product catalog with multi-attribute variants (size, color, SKU) and image uploads
- β
Inventory tracking with low-stock alerts and adjustment history
- β
Promotion engine (Buy X Get Y, free shipping rules)
- β
**Landing page studio** β two-sidebar builder (image stack + spacing), product-picker-first creation, publish flow, live link copy
- β
**Landing page comparison** β per-product A/B table (views, orders, CVR, revenue) to pick winning creatives
- β
Review moderation (approve, reject, delete)
- β
Customer CRM with profiles, order history, groups, and tags
- β
Delivery: in-house drivers, per-wilaya compensation, cash settlement
- β
Carrier company management (credentials, stop-desk sync, reconciliation)
- β
Team RBAC with granular permission scopes and API keys
- β
Meta Pixel & CAPI configuration UI
- β
Abandoned order recovery
- β
MCP agent connection management
- β
Legal pages editor β TipTap rich-text, per-locale (store's own language first), one-click reset to the current CodFlow template, and the business-details form templates render from
- β
Trilingual: Arabic (RTL), French, English
### Delivery Engine
- β
4 Algerian carriers + EcoTrack (80+ couriers behind one API)
- β
One-click shipment creation with printable labels
- β
Real-time webhook tracking (Yalidine, ZR Express with HMAC verification)
- β
Carrier delivery-zone name sync β dispatches carry the carrier's exact wilaya/commune spellings (Yalidine)
- β
Dispatch-time delivery-type switching (home β stop desk) with wilaya-scoped desk picking
- β
Webhook event log with per-event outcomes (applied / ignored / unmapped / error) per carrier
- β
Stop-desk catalog syncing across 58 wilayas
- β
In-house driver fleet management
- β
Per-wilaya driver compensation with cash settlement
- β
Partial returns with automatic inventory restock
### Growth Engine
- β
Meta Pixel (browser) + Conversions API (server) dual setup with event deduplication
- β
Merchant-chosen conversion event: `Lead` at order placement or `Purchase` at confirmed delivery
- β
Test Mode toggle routes CAPI events to Meta's test stream (`test_event_code`)
- β
Graph API v26.0 with 7-day attribution window compliance
- β
PII hashed per Meta spec (phone, names, city, zip, country, external_id); IP, User-Agent, `fbp`, `fbc` sent unhashed as required
- β
`fbp` and `fbc` attribution preservation
- β
Durable retry with Cloudflare Workflows (network + Meta 5xx, exponential backoff)
- β
CAPI event audit log (`capi_event_log`) for every send attempt
### AI & Agentic (MCP)
- β
RFC 9728 OAuth Protected Resource Discovery with dynamic client registration
- β
OAuth login relay from the dashboard (login-ticket bridge)
- β
15 RBAC-gated tool sets (orders, products, stock, offers, landing pages, reviews, customers, drivers, etc.)
- β
Stateless elicitation with HMAC-sealed confirmation state
- β
Compatible with Claude, Cursor, ChatGPT, LibreChat
### Backend (`cod-server`)
- β
Hono 4 on Cloudflare Workers (sub-5ms cold starts)
- β
Drizzle ORM + D1 (SQLite)
- β
D1 scale layer: indexed hot paths, atomic batched order writes, keyset pagination
- β
Auto-generated OpenAPI 3.1 spec at `/api/docs`
- β
Standardized error envelopes with semantic codes
- β
R2 image storage with edge caching
- β
KV-backed rate limiting
**Known Limitations:**
See [`docs/KNOWN_LIMITATIONS.md`](./docs/KNOWN_LIMITATIONS.md) for honest coverage of incomplete features and platform constraints.
---
## β‘ Quick Setup
Run CodFlow locally in 5 steps:
> π€ **Using an AI Coding Assistant?** CodFlow includes an autonomous setup skill. Tell your agent: *"Set up CodFlow"* and it will follow the [`codflow-setup` runbook](./.agents/skills/codflow-setup/SKILL.md).
**Already set up and want the latest version?** Don't redo the setup. Tell your agent: *"Update CodFlow"* β it will follow the [`codflow-update` runbook](./.agents/skills/codflow-update/SKILL.md), which pulls the latest code from this repository's `main` branch, applies new database migrations, keeps your resources, secrets, and store data intact, rebuilds and redeploys your workers, and reports each step in plain language.
### Prerequisites
- **Node.js 22.12+** and npm
- **Wrangler CLI**: `npm install -g wrangler`
- Free **Cloudflare account**
### 1. Clone & Install
```bash
git clone https://github.com/bighadj22/codflow.git
cd codflow
npm ci
```
### 2. Create Cloudflare Resources
Names are yours to choose β scripts read them from the root `.env`
(see step 3), so nothing is hardcoded.
```bash
wrangler login
wrangler d1 create my-codflow-db
wrangler r2 bucket create my-codflow-images
wrangler kv namespace create RATE_LIMIT
wrangler kv namespace create OAUTH_KV
```
### 3. Configure Environment
```bash
# Repo root β resource names for the seeders, the D1 wrapper, the R2 CORS
# setup and the storefront deploy helper. Precedence: process.env > .env > default.
cp .env.example .env
# Set COD_ACCOUNT_ID, COD_DB_NAME, COD_R2_BUCKET_NAME, COD_SERVER_URL, COD_MEDIA_DOMAIN
# Backend
cd cod-server
cp .dev.vars.example .dev.vars
cp wrangler.toml.example wrangler.toml
# Update wrangler.toml with your D1 database_id, R2 bucket_name, KV ids
# Dashboard
cd ../cod-client-astro
cp wrangler.toml.example wrangler.toml # same D1 database_id as cod-server + your KV id
cp .env.example .env
cp .dev.vars.example .dev.vars
# Set BETTER_AUTH_SECRET (same value as cod-server's, e.g. openssl rand -hex 32)
# Storefront
cd ../cod-astro/theme01
cp .dev.vars.example .dev.vars
```
### 4. Setup Database & Admin
```bash
cd cod-server
npm run db:setup:local
cd ../cod-client-astro
ADMIN_EMAIL=admin@example.com ADMIN_NAME=Admin npm run seed:admin
# β οΈ Save the generated password and API key
```
### 5. Start Dev Servers
Open three terminals:
```bash
# Terminal 1: Backend (http://localhost:8787)
cd cod-server && npm run dev
# Terminal 2: Dashboard (http://localhost:4321)
cd cod-client-astro && npm run dev
# Terminal 3: Storefront (http://localhost:4321 β use a different port, see theme README)
cd cod-astro/theme01 && npm run dev
```
> β οΈ The dashboard and storefront both default to port 4321 β run them on
> different ports (`astro dev --port 4322` for one of them) or run only one
> at a time.
### 6. Enable Image Uploads
Product image uploads require R2 API tokens and CORS configuration. See the [R2 setup guide](./cod-server/src/endpoints/images/README.md) for:
- Creating R2 API tokens
- Setting CORS policy on the bucket
- Adding a custom domain for serving images
**Need more detail?** See [`docs/DEPLOYMENT.md`](./docs/DEPLOYMENT.md) for production deployment.
---
## π’ Production Deployment
Deploy all three apps to Cloudflare Workers:
```bash
# 1. Backend
cd cod-server
npm run deploy -- --env production
wrangler secret put BETTER_AUTH_SECRET
wrangler secret put STORE_API_KEY
# 2. Dashboard
cd ../cod-client-astro
# Production PUBLIC_API_URL comes from wrangler.toml [vars]; deploy builds with it
npm run deploy
wrangler secret put BETTER_AUTH_SECRET # same value as cod-server's
wrangler secret put MCP_LOGIN_TICKET_SECRET # same value as cod-server's
# 3. Storefront
cd ../cod-astro/theme01
# COD_SERVER_URL comes from the repo-root .env β deploy injects it, never wrangler.jsonc
npm run deploy
wrangler secret put STORE_API_KEY
```
**Important:** Cloudflare blocks Worker-to-Worker fetch between `*.workers.dev` hosts. For production, put at least `cod-server` on a custom domain and point `COD_SERVER_URL` at it.
**R2 Image Uploads:** For production image uploads, see [R2 setup guide](./cod-server/src/endpoints/images/README.md) for API tokens, CORS policy, and custom domain configuration.
**Full deployment guide:** [`docs/DEPLOYMENT.md`](./docs/DEPLOYMENT.md)
---
## ποΈ Architecture
```
ββββββββββββββββββββββββββββββββββββββββββββ
β cod-shared β
β D1 schema β’ RBAC scopes β’ queries β
βββββββββββββββββ¬βββββββββββββββββββββββββββ
β relative imports
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ
β β β
βββββββββΌββββββββ ββββββββββΌβββββββββ ββββββββββΌβββββββββ
β Storefront β β Backend β β Dashboard β
β cod-astro βββ/storeββΆ cod-server ββββ/apiββ cod-client-astroβ
β (Astro 7) β API β (Hono + Workflows) API β (Astro 7) β
βββββββββ¬ββββββββ βββββ¬ββββββ¬ββββββββ βββββββββββββββββββ
β β β
β /webhooks β CodCapiWorkflow
β carrier callsβ
β β βββββββββββΆ Meta Conversions API
β β (Purchase @ delivered)
β β
β ββββββββΌββββββ
β β Carriers β Yalidine β’ ZR Express (webhooks)
β β APIs β NOEST β’ EcoTrack (tracking pull)
β βββββββββββββββ
β
β /images (R2) /mcp (AI agents, OAuth-scoped)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββΆ
```
**Tech Stack:**
- **Storefront:** Astro 7, Tailwind CSS v4 β Cloudflare Workers + Static Assets
- **Backend:** Hono 4, Drizzle ORM, Better Auth, Workflows β Cloudflare Workers + D1 + R2 + KV
- **Dashboard:** Astro 7 (prerendered static + auth worker) β Cloudflare Workers + D1 + KV
- **Shared:** Drizzle schema, RBAC scopes, error codes
**More detail:** [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md)
---
## π§ͺ Testing
```bash
# Backend tests (handlers, workflows, OpenAPI, MCP)
cd cod-server && npm test
# Dashboard tests (feature models, i18n guards, API seam)
cd cod-client-astro && npm test
# Storefront tests (property-based, cart calculations)
cd cod-astro/theme01 && npm test
# TypeScript verification
cd cod-server && npm run typecheck
cd cod-client-astro && npm run typecheck
```
CI runs typecheck + tests for cod-server and cod-client-astro, plus
astro check + tests for theme01.
---
## π Documentation
| Document | Purpose |
| :--- | :--- |
| **[docs/DEPLOYMENT.md](./docs/DEPLOYMENT.md)** | Cloudflare production deployment |
| **[docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md)** | System map and data flows |
| **[docs/CONFIGURATION.md](./docs/CONFIGURATION.md)** | All environment variables and configs |
| **[docs/KNOWN_LIMITATIONS.md](./docs/KNOWN_LIMITATIONS.md)** | Incomplete features and platform constraints |
| **[docs/SHOPPING-CART.md](./docs/SHOPPING-CART.md)** | Shopping cart, checkout page, free-delivery threshold |
| **[docs/LEGAL-PAGES.md](./docs/LEGAL-PAGES.md)** | Terms, Privacy, Refund and Shipping pages β pre-seeded, merchant-editable |
| **[docs/WHATSAPP-OTP-VERIFICATION.md](./docs/WHATSAPP-OTP-VERIFICATION.md)** | WhatsApp OTP verification feature |
| **[docs/TURNSTILE.md](./docs/TURNSTILE.md)** | Cloudflare Turnstile checkout bot protection |
| **[docs/CHECKOUT-FORM.md](./docs/CHECKOUT-FORM.md)** | Merchant-configurable storefront order form and custom questions |
| **[docs/EMAIL-SENDING.md](./docs/EMAIL-SENDING.md)** | Transactional email feature (Sendili) |
| **[CONTRIBUTING.md](./CONTRIBUTING.md)** | Development standards and PR workflow |
| **[AGENTS.md](./AGENTS.md)** | Repository instructions for AI coding assistants |
### π¬ Video Tutorial
**[βΆοΈ Watch: How to edit your CodFlow theme](https://youtu.be/zZGWdEeUXVo)**
---
## πΊοΈ Roadmap
### Planned
- π **Deeper dashboard analytics** β revenue, delivery-rate, and return-rate trends
- π¦ **More Themes** β Additional storefront themes beyond `theme01`
- π **Theme Editing Guides** β Comprehensive guides for customizing and creating themes
- βοΈ **CodFlow Cloud** β One-click deployment from dashboard for agencies to resell CodFlow
- π§ **Email order notifications & admin alerts** β extend the Sendili integration beyond transactional mail
### Recently Shipped
- β
**Legal Pages** β Terms, Privacy, Refund/Return, Shipping pre-seeded per store from Algeria-COD-grounded templates, merchant-editable with the dashboard's TipTap editor, and any custom page on the same rails
- β
**Yalidine Hardening** β full 36-status webhook mapping (live-verified return flows), HMAC-SHA256 signature verification, per-carrier delivery-zone name sync, dispatch-time delivery-type switching, and a webhook events log for every webhook-capable carrier
- β
**Landing Pages** β one-product marketing pages (image stack + COD order form) with the Studio builder, per-link stats, A/B comparison, order attribution, and 7 MCP tools
- β
**Astro Dashboard** β the merchant dashboard now runs on Astro (was Next.js)
- β
**WhatsApp OTP Verification** β [DZVerify.com](https://dzverify.com) phone verification at checkout
- β
**Cloudflare Turnstile** β optional per-store bot protection on the checkout form (off by default)
- β
**EcoTrack Integration** β 80+ Algerian couriers behind one API
- β
**Transactional Email (Sendili)** β [Sendili.com](https://sendili.com) powers team-invite emails and password-reset emails; merchants configure their API key and verified sending domain in Settings β Email Sending
---
## π€ Contributing
We welcome contributions from developers across Algeria and the global open-source community.
1. Fork the repo and create a feature branch (`feat/amazing-feature`)
2. Maintain code-verified claims and test coverage
3. Keep credentials and live API keys out of commits
4. Submit a PR referencing the related issue
See **[CONTRIBUTING.md](./CONTRIBUTING.md)** for detailed guidelines.
---
## π License
**Apache License 2.0** β 100% free and open-source.
See [`LICENSE`](./LICENSE) and [`NOTICE`](./NOTICE) for details.
---
## π Resources
- **Repository:** [github.com/bighadj22/codflow](https://github.com/bighadj22/codflow)
- **Video Setup Guide:** [Watch on YouTube](https://youtu.be/rJPCGQnDZ18)
- **Changelog:** [CHANGELOG.md](./CHANGELOG.md)
- **Security Policy:** [SECURITY.md](./SECURITY.md)
---
**Version:** v1.1.0 β Self-hostable on Cloudflare.
Built with β€οΈ for Algerian e-commerce.