codflow README

The project's README from github.com/bighadj22/codflow. As one markdown file: README.md.

CodFlow

CodFlow

The open-source, COD-first e-commerce platform for Algeria — built agentic-ready.

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
→ What works today
→ Quick setup guide
→ Production deployment

💻 I want to contribute

Build features or customize CodFlow.

→ Contributing guide
→ Architecture overview
→ AI agent instructions


🎥 See It in Action

Watch the step-by-step setup guide:

CodFlow Setup Guide

▶️ Watch: CodFlow Setup & Deployment Guide


🎯 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)

Merchant Dashboard (cod-client-astro)

Delivery Engine

Growth Engine

AI & Agentic (MCP)

Backend (cod-server)

Known Limitations:
See 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.

Prerequisites

1. Clone & Install

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.

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

# 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

cd cod-server
npm run db:setup:local

cd ../cod-client-astro
[email protected] ADMIN_NAME=Admin npm run seed:admin
# ⚠️ Save the generated password and API key

5. Start Dev Servers

Open three terminals:

# 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 for:

Need more detail? See docs/DEPLOYMENT.md for production deployment.


🚢 Production Deployment

Deploy all three apps to Cloudflare Workers:

# 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
npm run build && 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
# Set COD_SERVER_URL in wrangler.jsonc to your deployed backend URL
npm run build && 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 for API tokens, CORS policy, and custom domain configuration.

Full deployment guide: 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:

More detail: docs/ARCHITECTURE.md


🧪 Testing

# 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 Cloudflare production deployment
docs/ARCHITECTURE.md System map and data flows
docs/CONFIGURATION.md All environment variables and configs
docs/KNOWN_LIMITATIONS.md Incomplete features and platform constraints
docs/WHATSAPP-OTP-VERIFICATION.md WhatsApp OTP verification feature
docs/TURNSTILE.md Cloudflare Turnstile checkout bot protection
docs/EMAIL-SENDING.md Transactional email feature (Sendili)
CONTRIBUTING.md Development standards and PR workflow
AGENTS.md Repository instructions for AI coding assistants

🎬 Video Tutorial

▶️ Watch: How to edit your CodFlow theme


🗺️ Roadmap

Planned

Recently Shipped


🤝 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 for detailed guidelines.


📄 License

Apache License 2.0 — 100% free and open-source.
See LICENSE and NOTICE for details.


🔗 Resources


Version: v1.1.0 — Self-hostable on Cloudflare.
Built with ❤️ for Algerian e-commerce.

codflow (bighadj22/codflow)

Searching Database…

这是什么?CodFlow 是一个专为阿尔及利亚打造的开源货到付款(COD)电商与配送平台,可部署到你自己的 Cloudflare 账号上,零交易手续费。
它是单一应用,还是由多个独立服务组成的完整技术栈?它是自托管的三个应用组成的技术栈——店面(cod-astro)、商家后台(cod-client-astro)和后端(cod-server)——全部运行在配备 D1、R2 和 KV 的 Cloudflare Workers 上。
怎么把它跑起来?克隆仓库,用 Wrangler 创建 Cloudflare D1/R2/KV 资源,配置根目录的 .env,运行数据库/管理员初始化步骤,然后在不同的终端里分别启动店面、后台和后端的开发服务器。
开始之前我需要准备什么?你需要 Node.js 22.12+ 和 npm、Wrangler CLI,以及一个免费的 Cloudflare 账号;不需要 VPS 或外部数据库。
本地或生产环境运行有什么要注意的坑吗?店面和后台默认都用 4321 端口,所以本地运行时其中一个必须换端口;在生产环境中,Cloudflare 禁止 .workers.dev 域名之间的 Worker 相互 fetch,所以至少后端需要绑定自定义域名。
商店数据归谁所有?CodFlow 完全自托管在你自己的 Cloudflare 账号上,D1 数据库和 R2 里的图片都归你所有,没有厂商锁定或数据导出限制。
它支持哪些阿尔及利亚的配送承运商?它集成了 4 家阿尔及利亚承运商外加 EcoTrack,通过一个统一 API 接入 80 多家快递,并为 Yalidine 和 ZR Express 提供经 HMAC 验证的实时 webhook 跟踪。
通过 MCP 集成,AI 智能体能做什么?CodFlow 通过 OAuth 加以保护,开放 15 组受 RBAC 管控的 MCP 工具集(订单、商品、库存、落地页、客户、司机等),让 Claude、Cursor、ChatGPT 或 LibreChat 等助手直接管理商店。
为什么它在送达时而不是结账时触发广告转化事件?Meta Pixel 通常在提交结账时就触发,而货到付款订单有 30–50% 会被买家在门口拒收,因此 CodFlow 可以只在确认送达时触发服务端 Conversions API 事件,把广告花费优化给真实买家。
托管实际要花多少钱?因为一切都在 Cloudflare Workers、D1、R2 和 KV 上以无服务器方式运行,托管费用通常为每月 $0–$5,且零单笔交易手续费。
Creator
bighadj22
Size
12 MB
Stars
372
Age
1mo
Commits · 90 Days