# ahmedselim1234/khodarak architecture

> Architecture diagram of the GitHub repository ahmedselim1234/khodarak, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahmedselim1234/khodarak
- Repository: https://github.com/ahmedselim1234/khodarak

## Overview

Khodarak is an Arabic RTL produce-subscription storefront. Customers browse products, assemble a cart and recurring delivery plan, pay by card, and manage the subscription; scheduled renewals reprice, charge the saved card, and create subsequent orders. Administrators manage the catalog, delivery rules, orders, subscriptions, payments, and settings. The graph includes the principal customer and renewal workflows plus administrative capabilities. Some page and API implementations are unsampled, so those links rely on README documentation; source-level links are limited to indexed excerpts.

Main entry points: [`app/api/cron/renewals/route.ts`](https://github.com/ahmedselim1234/khodarak/blob/main/app/api/cron/renewals/route.ts) (Renewal scheduler), [`app/browse/page.tsx`](https://github.com/ahmedselim1234/khodarak/blob/main/app/browse/page.tsx) (Browse catalog), [`app/api/subscriptions/route.ts`](https://github.com/ahmedselim1234/khodarak/blob/main/app/api/subscriptions/route.ts) (Subscription API), [`lib/payments/moyasarClient.ts`](https://github.com/ahmedselim1234/khodarak/blob/main/lib/payments/moyasarClient.ts) (Moyasar client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_customer["Customer shopping"]
  node_browse["Browse catalog<br/>[page.tsx]"]
  node_product["Product details<br/>[page.tsx]"]
  node_cart["Shopping cart<br/>[CartView.tsx]"]
end

subgraph group_subscription["Subscription lifecycle"]
  node_wizard["Subscription setup"]
  node_paymentui["Card payment<br/>[PaymentSection.tsx]"]
  node_dashboard["Subscription dashboard"]
  node_renewals["Renewal scheduler<br/>[route.ts]"]
end

subgraph group_admin["Administration"]
  node_adminproducts["Product management<br/>[page.tsx]"]
  node_adminintervals["Delivery intervals<br/>[page.tsx]"]
  node_adminorders["Order management<br/>[page.tsx]"]
  node_adminsubscriptions["Subscription management<br/>[page.tsx]"]
  node_adminpayments["Payment monitoring<br/>[page.tsx]"]
  node_admincities["Delivery cities<br/>[page.tsx]"]
  node_adminsettings["Store settings<br/>[page.tsx]"]
end

subgraph group_services["Application services"]
  node_cartstate["Cart state<br/>[useCart.ts]"]
  node_catalogdata["Product queries<br/>[queryProducts.ts]"]
  node_pricing["Pricing engine<br/>[calculate.ts]"]
  node_subscriptionapi["Subscription API<br/>[route.ts]"]
  node_payapi["Payment API<br/>[route.ts]"]
  node_moyasarclient["Moyasar client<br/>[moyasarClient.ts]"]
  node_subscriptionmanage["Subscription management<br/>[route.ts]"]
  node_repricing["Renewal repricing<br/>[reprice.ts]"]
  node_renewaloutcome["Renewal outcome"]
end

node_customer(("Customer"))
node_moyasar["Moyasar"]
node_admin(("Administrator"))
node_supabase[("Supabase")]

node_customer -->|"browses"| node_browse
node_browse -->|"opens products"| node_product
node_product -->|"adds items"| node_cart
node_cart -->|"updates cart"| node_cartstate
node_browse -.->|"loads products"| node_catalogdata
node_customer -->|"builds subscription"| node_wizard
node_wizard -.->|"submits plan"| node_subscriptionapi
node_subscriptionapi -->|"calculates price"| node_pricing
node_customer -->|"pays by card"| node_paymentui
node_paymentui -.->|"initiates payment"| node_payapi
node_payapi -.->|"creates charge"| node_moyasarclient
node_moyasarclient -->|"calls payment API"| node_moyasar
node_customer -->|"manages subscription"| node_dashboard
node_dashboard -.->|"edits plan"| node_subscriptionmanage
node_renewals -->|"reprices renewal"| node_repricing
node_renewals -->|"charges saved card"| node_moyasarclient
node_renewals -->|"processes result"| node_renewaloutcome
node_admin -->|"manages products"| node_adminproducts
node_admin -->|"sets delivery discounts"| node_adminintervals
node_admin -->|"tracks orders"| node_adminorders
node_admin -->|"tracks subscriptions"| node_adminsubscriptions
node_admin -->|"tracks payments"| node_adminpayments
node_admin -->|"manages delivery cities"| node_admincities
node_admin -->|"manages pricing"| node_adminsettings
node_subscriptionapi -->|"stores subscription"| node_supabase
node_renewals -->|"reads renewal data"| node_supabase
node_cartstate -.->|"loads signed-in cart"| node_supabase

click node_browse "https://github.com/ahmedselim1234/khodarak/blob/main/app/browse/page.tsx"
click node_product "https://github.com/ahmedselim1234/khodarak/blob/main/app/browse/%5Bid%5D/page.tsx"
click node_cart "https://github.com/ahmedselim1234/khodarak/blob/main/components/cart/CartView.tsx"
click node_cartstate "https://github.com/ahmedselim1234/khodarak/blob/main/lib/cart/useCart.ts"
click node_catalogdata "https://github.com/ahmedselim1234/khodarak/blob/main/lib/products/queryProducts.ts"
click node_wizard "https://github.com/ahmedselim1234/khodarak/blob/main/components/subscription/SubscriptionWizard.tsx"
click node_pricing "https://github.com/ahmedselim1234/khodarak/blob/main/lib/pricing/calculate.ts"
click node_subscriptionapi "https://github.com/ahmedselim1234/khodarak/blob/main/app/api/subscriptions/route.ts"
click node_paymentui "https://github.com/ahmedselim1234/khodarak/blob/main/components/payment/PaymentSection.tsx"
click node_payapi "https://github.com/ahmedselim1234/khodarak/blob/main/app/api/subscriptions/%5Bid%5D/pay/route.ts"
click node_moyasarclient "https://github.com/ahmedselim1234/khodarak/blob/main/lib/payments/moyasarClient.ts"
click node_dashboard "https://github.com/ahmedselim1234/khodarak/blob/main/components/dashboard/SubscriptionDashboard.tsx"
click node_subscriptionmanage "https://github.com/ahmedselim1234/khodarak/blob/main/app/api/subscriptions/%5Bid%5D/route.ts"
click node_renewals "https://github.com/ahmedselim1234/khodarak/blob/main/app/api/cron/renewals/route.ts"
click node_repricing "https://github.com/ahmedselim1234/khodarak/blob/main/lib/subscription/reprice.ts"
click node_renewaloutcome "https://github.com/ahmedselim1234/khodarak/blob/main/lib/payments/processRenewalOutcome.ts"
click node_adminproducts "https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/products/page.tsx"
click node_adminintervals "https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/delivery-intervals/page.tsx"
click node_adminorders "https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/orders/page.tsx"
click node_adminsubscriptions "https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/subscriptions/page.tsx"
click node_adminpayments "https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/payments/page.tsx"
click node_admincities "https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/cities/page.tsx"
click node_adminsettings "https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/settings/page.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browse,node_product,node_cart toneBlue
class node_wizard,node_paymentui,node_dashboard,node_renewals,node_supabase toneAmber
class node_adminproducts,node_adminintervals,node_adminorders,node_adminsubscriptions,node_adminpayments,node_admincities,node_adminsettings toneMint
class node_cartstate,node_catalogdata,node_pricing,node_subscriptionapi,node_payapi,node_moyasarclient,node_subscriptionmanage,node_repricing,node_renewaloutcome toneRose
class node_customer,node_moyasar,node_admin toneIndigo
```

## Components

### Customer shopping

- [Browse catalog](https://github.com/ahmedselim1234/khodarak/blob/main/app/browse/page.tsx): `app/browse/page.tsx`
- [Product details](https://github.com/ahmedselim1234/khodarak/blob/main/app/browse/%5Bid%5D/page.tsx): `app/browse/[id]/page.tsx`
- [Shopping cart](https://github.com/ahmedselim1234/khodarak/blob/main/components/cart/CartView.tsx): `components/cart/CartView.tsx`

### Subscription lifecycle

- [Subscription setup](https://github.com/ahmedselim1234/khodarak/blob/main/components/subscription/SubscriptionWizard.tsx): `components/subscription/SubscriptionWizard.tsx`
- [Card payment](https://github.com/ahmedselim1234/khodarak/blob/main/components/payment/PaymentSection.tsx): `components/payment/PaymentSection.tsx`
- [Subscription dashboard](https://github.com/ahmedselim1234/khodarak/blob/main/components/dashboard/SubscriptionDashboard.tsx): `components/dashboard/SubscriptionDashboard.tsx`
- [Renewal scheduler](https://github.com/ahmedselim1234/khodarak/blob/main/app/api/cron/renewals/route.ts): `app/api/cron/renewals/route.ts`

### Administration

- [Product management](https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/products/page.tsx): `app/admin/products/page.tsx`
- [Delivery intervals](https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/delivery-intervals/page.tsx): `app/admin/delivery-intervals/page.tsx`
- [Order management](https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/orders/page.tsx): `app/admin/orders/page.tsx`
- [Subscription management](https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/subscriptions/page.tsx): `app/admin/subscriptions/page.tsx`
- [Payment monitoring](https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/payments/page.tsx): `app/admin/payments/page.tsx`
- [Delivery cities](https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/cities/page.tsx): `app/admin/cities/page.tsx`
- [Store settings](https://github.com/ahmedselim1234/khodarak/blob/main/app/admin/settings/page.tsx): `app/admin/settings/page.tsx`

### Application services

- [Cart state](https://github.com/ahmedselim1234/khodarak/blob/main/lib/cart/useCart.ts): `lib/cart/useCart.ts`
- [Product queries](https://github.com/ahmedselim1234/khodarak/blob/main/lib/products/queryProducts.ts): `lib/products/queryProducts.ts`
- [Pricing engine](https://github.com/ahmedselim1234/khodarak/blob/main/lib/pricing/calculate.ts): `lib/pricing/calculate.ts`
- [Subscription API](https://github.com/ahmedselim1234/khodarak/blob/main/app/api/subscriptions/route.ts): `app/api/subscriptions/route.ts`
- [Payment API](https://github.com/ahmedselim1234/khodarak/blob/main/app/api/subscriptions/%5Bid%5D/pay/route.ts): `app/api/subscriptions/[id]/pay/route.ts`
- [Moyasar client](https://github.com/ahmedselim1234/khodarak/blob/main/lib/payments/moyasarClient.ts): `lib/payments/moyasarClient.ts`
- [Subscription management](https://github.com/ahmedselim1234/khodarak/blob/main/app/api/subscriptions/%5Bid%5D/route.ts): `app/api/subscriptions/[id]/route.ts`
- [Renewal repricing](https://github.com/ahmedselim1234/khodarak/blob/main/lib/subscription/reprice.ts): `lib/subscription/reprice.ts`
- [Renewal outcome](https://github.com/ahmedselim1234/khodarak/blob/main/lib/payments/processRenewalOutcome.ts): `lib/payments/processRenewalOutcome.ts`

### Other components

- **Customer**
- **Moyasar**
- **Administrator**
- **Supabase**

## Connections

- Customer → Browse catalog: browses
- Browse catalog → Product details: opens products
- Product details → Shopping cart: adds items
- Shopping cart → Cart state: updates cart (evidence: `lib/cart/useCart.ts`)
- Browse catalog → Product queries: loads products
- Customer → Subscription setup: builds subscription
- Subscription setup → Subscription API: submits plan
- Subscription API → Pricing engine: calculates price (evidence: `app/api/subscriptions/route.ts`)
- Customer → Card payment: pays by card
- Card payment → Payment API: initiates payment
- Payment API → Moyasar client: creates charge
- Moyasar client → Moyasar: calls payment API (evidence: `lib/payments/moyasarClient.ts`)
- Customer → Subscription dashboard: manages subscription
- Subscription dashboard → Subscription management: edits plan
- Renewal scheduler → Renewal repricing: reprices renewal (evidence: `app/api/cron/renewals/route.ts`)
- Renewal scheduler → Moyasar client: charges saved card (evidence: `app/api/cron/renewals/route.ts`)
- Renewal scheduler → Renewal outcome: processes result (evidence: `app/api/cron/renewals/route.ts`)
- Administrator → Product management: manages products
- Administrator → Delivery intervals: sets delivery discounts
- Administrator → Order management: tracks orders
- Administrator → Subscription management: tracks subscriptions
- Administrator → Payment monitoring: tracks payments
- Administrator → Delivery cities: manages delivery cities
- Administrator → Store settings: manages pricing
- Subscription API → Supabase: stores subscription (evidence: `app/api/subscriptions/route.ts`)
- Renewal scheduler → Supabase: reads renewal data (evidence: `app/api/cron/renewals/route.ts`)
- Cart state → Supabase: loads signed-in cart
