Documentation

    Concepts, value, and typical clone scenarios — less code.

    Welcome to Ring
    Quick Reference
    Getting Started
    Prerequisites
    Installation
    First Success Validation
    Next Steps
    Features
    Multi-Vendor Store
    Inventory & Stock
    Vendor Management
    Commissions & Settlements
    SubscriptionConductor
    PaymentConductor
    Payments Overview
    Public Pools & DAO Jars
    WayForPay Payment Integration
    Wallet & Credit System
    WalletConductor
    Affiliate & Referral Enablement
    Referral Codes (Refcodes)
    NFT Exhibition Marketplace
    Solana NFT Gates
    Token Staking System
    Owner Project Lab
    Entities
    Opportunities
    Real-Time Messaging
    Ring Tasks
    WebRTC Calls & STUNner TURN
    Peer Games
    News Module
    Member Blogs
    Public Profile Pages
    Ring File Cabinet
    Username Reservation System
    Scientific Editor
    Notifications
    Push Notifications with FCM (Ring-Powered)
    Email AI-CRM
    Ring Mailer & RingdomX Mail
    Tunnel Protocol
    VideoConductor
    MediaConductor
    Generative Gallery
    Authentication
    Security & Compliance
    Admin console
    Admin Wiki
    Manage via Telegram
    Locale System
    Mobile Experience
    Performance Optimization Patterns
    Examples
    Quick Start
    Basic Setup
    White Label
    Custom Branding
    Web3 Integration
    Real World
    Advanced Features
    Customization
    Quick Start — Your First Ring Clone
    Customization Guide
    Branding
    Themes
    Features
    Localization
    Token Economics Setup
    Payment Gateway Integration
    Reference Ring deployments
    Web3
    Token launch jurisdictions
    Wallet
    Wallet Security Tips
    Integrations
    Ethereum wallets (Wagmi v3)
    RingFileBase (object storage API)
    Ring CDN (RingFileBase edge)
    Deployment
    Self-hosted deployment
    Vercel
    Docker
    Environment Configuration
    Monitoring & Analytics
    Performance Optimization
    Backup & Recovery
    Architecture
    Data Model
    Security
    Real Time
    Discovery Mutation Sync
    PaymentConductor architecture
    WalletConductor architecture
    Development
    Ring MCP Server

    Quick entry (CTOs · auditors · agents)

    Welcome — mission & audiences
    Quick Reference
    Getting started
    Architecture & Auth.js
    Backend modes & databases (DB_BACKEND_MODE)
    Self-hosted
    Ring MCP Tools
    Ring MCP Server
    Token economics
    Token launch jurisdictions
    Deploy (Docker · k8s)
    Security & compliance reads
    ringdom.org — LegioX homebase
    Source — MIT license (GitHub)

    Documentation

    Concepts, value, and typical clone scenarios — less code.

    Welcome to Ring
    Quick Reference
    Getting Started
    Prerequisites
    Installation
    First Success Validation
    Next Steps
    Features
    Multi-Vendor Store
    Inventory & Stock
    Vendor Management
    Commissions & Settlements
    SubscriptionConductor
    PaymentConductor
    Payments Overview
    Public Pools & DAO Jars
    WayForPay Payment Integration
    Wallet & Credit System
    WalletConductor
    Affiliate & Referral Enablement
    Referral Codes (Refcodes)
    NFT Exhibition Marketplace
    Solana NFT Gates
    Token Staking System
    Owner Project Lab
    Entities
    Opportunities
    Real-Time Messaging
    Ring Tasks
    WebRTC Calls & STUNner TURN
    Peer Games
    News Module
    Member Blogs
    Public Profile Pages
    Ring File Cabinet
    Username Reservation System
    Scientific Editor
    Notifications
    Push Notifications with FCM (Ring-Powered)
    Email AI-CRM
    Ring Mailer & RingdomX Mail
    Tunnel Protocol
    VideoConductor
    MediaConductor
    Generative Gallery
    Authentication
    Security & Compliance
    Admin console
    Admin Wiki
    Manage via Telegram
    Locale System
    Mobile Experience
    Performance Optimization Patterns
    Examples
    Quick Start
    Basic Setup
    White Label
    Custom Branding
    Web3 Integration
    Real World
    Advanced Features
    Customization
    Quick Start — Your First Ring Clone
    Customization Guide
    Branding
    Themes
    Features
    Localization
    Token Economics Setup
    Payment Gateway Integration
    Reference Ring deployments
    Web3
    Token launch jurisdictions
    Wallet
    Wallet Security Tips
    Integrations
    Ethereum wallets (Wagmi v3)
    RingFileBase (object storage API)
    Ring CDN (RingFileBase edge)
    Deployment
    Self-hosted deployment
    Vercel
    Docker
    Environment Configuration
    Monitoring & Analytics
    Performance Optimization
    Backup & Recovery
    Architecture
    Data Model
    Security
    Real Time
    Discovery Mutation Sync
    PaymentConductor architecture
    WalletConductor architecture
    Development
    Ring MCP Server

    Quick entry (CTOs · auditors · agents)

    Welcome — mission & audiences
    Quick Reference
    Getting started
    Architecture & Auth.js
    Backend modes & databases (DB_BACKEND_MODE)
    Self-hosted
    Ring MCP Tools
    Ring MCP Server
    Token economics
    Token launch jurisdictions
    Deploy (Docker · k8s)
    Security & compliance reads
    ringdom.org — LegioX homebase
    Source — MIT license (GitHub)

    Documentation

    Concepts, value, and typical clone scenarios — less code.

    Welcome to Ring
    Quick Reference
    Getting Started
    Prerequisites
    Installation
    First Success Validation
    Next Steps
    Features
    Multi-Vendor Store
    Inventory & Stock
    Vendor Management
    Commissions & Settlements
    SubscriptionConductor
    PaymentConductor
    Payments Overview
    Public Pools & DAO Jars
    WayForPay Payment Integration
    Wallet & Credit System
    WalletConductor
    Affiliate & Referral Enablement
    Referral Codes (Refcodes)
    NFT Exhibition Marketplace
    Solana NFT Gates
    Token Staking System
    Owner Project Lab
    Entities
    Opportunities
    Real-Time Messaging
    Ring Tasks
    WebRTC Calls & STUNner TURN
    Peer Games
    News Module
    Member Blogs
    Public Profile Pages
    Ring File Cabinet
    Username Reservation System
    Scientific Editor
    Notifications
    Push Notifications with FCM (Ring-Powered)
    Email AI-CRM
    Ring Mailer & RingdomX Mail
    Tunnel Protocol
    VideoConductor
    MediaConductor
    Generative Gallery
    Authentication
    Security & Compliance
    Admin console
    Admin Wiki
    Manage via Telegram
    Locale System
    Mobile Experience
    Performance Optimization Patterns
    Examples
    Quick Start
    Basic Setup
    White Label
    Custom Branding
    Web3 Integration
    Real World
    Advanced Features
    Customization
    Quick Start — Your First Ring Clone
    Customization Guide
    Branding
    Themes
    Features
    Localization
    Token Economics Setup
    Payment Gateway Integration
    Reference Ring deployments
    Web3
    Token launch jurisdictions
    Wallet
    Wallet Security Tips
    Integrations
    Ethereum wallets (Wagmi v3)
    RingFileBase (object storage API)
    Ring CDN (RingFileBase edge)
    Deployment
    Self-hosted deployment
    Vercel
    Docker
    Environment Configuration
    Monitoring & Analytics
    Performance Optimization
    Backup & Recovery
    Architecture
    Data Model
    Security
    Real Time
    Discovery Mutation Sync
    PaymentConductor architecture
    WalletConductor architecture
    Development
    Ring MCP Server

    Quick entry (CTOs · auditors · agents)

    Welcome — mission & audiences
    Quick Reference
    Getting started
    Architecture & Auth.js
    Backend modes & databases (DB_BACKEND_MODE)
    Self-hosted
    Ring MCP Tools
    Ring MCP Server
    Token economics
    Token launch jurisdictions
    Deploy (Docker · k8s)
    Security & compliance reads
    ringdom.org — LegioX homebase
    Source — MIT license (GitHub)
    1. Docs
    2. /Architecture
    3. /Refcodes architecture

    Updated Jun 12, 20263 min listen

    Ring Platform Logo

    Завантаження документації...

    Підготовка контенту платформи Ring

    1. Docs
    2. /Architecture
    3. /Refcodes architecture

    Updated Jun 12, 20263 min listen

    Ring Platform Logo

    Завантаження документації...

    Підготовка контенту платформи Ring

    1. Docs
    2. /Architecture
    3. /Refcodes architecture

    Updated Jun 12, 20263 min listen

    Ring Platform Logo

    Завантаження документації...

    Підготовка контенту платформи Ring

    Refcodes architecture

    Dual-rail: Token minting (this document) pairs with ERP settlements referral commission on the same orderReference. Overview: Affiliate enablement.

    System diagram

    Core modules

    ModulePathResponsibility
    Cookie captureproxy.tsFirst-touch ring_ref from ?ref=
    Code registryrefcode-service.tsCRUD codes per (userId, wallet)
    Attributionattribution-service.tsSelf-ref, first-purchase, wallet overlap guards
    Reward ledgerreferral-reward-service.tsFiat/credit paths, approval, oracle sizing
    On-chain mintreward-minter.tsviem simulateContract + writeContract
    Server walletlib/web3/server-wallet.tsREFERRAL_MINTER_PRIVATE_KEY → viem account

    Integration points

    Store order creation

    app/api/store/orders/route.ts resolves attribution before StoreOrdersService.createOrder. Referral fields are stored in the orders JSONB document:

    • referralCode
    • referrerUserId
    • referrerWallet

    PaymentConductor (fiat)

    lib/payments/conductor/handlers/store-order.ts calls ReferralRewardService.onOrderPaid inside the Approved + isNew branch — after stock deduction and vendor settlement. Failures are logged but do not fail the webhook.

    Internal credit (instant)

    app/api/store/payments/credit/route.ts marks the order paid, deducts stock, writes settlements via settlement-pipeline.ts, then calls onOrderPaid with rail: 'crypto' (auto-approved mint).

    Membership (fiat)

    handlers/membership-upgrade.ts → ReferralRewardService.onMembershipPaid when users.data.referredBy is set (first-touch signup attribution).

    Cron, visits, and checkout

    Endpoint / componentRole
    POST /api/refcodes/tracktrackRefcodeVisit — bumps visits + visitDaily[UTC date] (28-day prune)
    ReferralAttributionEffectPublic layout client beacon when ring_ref_visible is set
    ReferralCheckoutBadgeReview step reads ring_ref_visible
    checkout-referral-flash.tsWayForPay redirect toast survival (30 min TTL)
    GET /api/cron/refcodes-mintprocessApprovedRewards(20) — Authorization: Bearer $CRON_SECRET

    Mint notification (i18n)

    After on-chain success, reward-minter.ts loads copy via lib/i18n/refcodes-labels.ts:

    1. getUserPreferredLocaleForNotifications(referrerUserId) — users.settings.language (DB-only, smoke-safe).
    2. getReferralMintNotificationCopy(locale, { amount, token }) — modules/refcodes.json → notifications.minted.
    3. createNotification with type REFERRAL_REWARD_MINTED.

    Idempotency

    LayerKey
    PostgreSQLUnique index on referral_rewards (data->>'orderReference')
    ServicerewardExistsForOrder short-circuit
    ContractpaidOrders[orderRef] mapping — reverts ReferralRewards__AlreadyPaid

    orderRef on-chain = keccak256(bytes(orderReference)) where orderReference comes from PaymentConductor.

    Contract roles

    i18n

    SurfaceBundle keys
    User/admin UIlocales/{en,uk,ru}/modules/refcodes.json — visits, stats, admin queue
    Checkout toastmodules/store.json → checkout.referralApplied*
    Mint notificationmodules/refcodes.json → notifications.minted (server via refcodes-labels.ts)
    • Scope: modRefcodes in lib/i18n/message-scopes.ts (authenticated + admin)
    • Routes: REFCODES, ADMIN_REFCODES in constants/routes.ts

    Database placement

    EnvironmentDatabaseNotes
    ring-platform.org devring_platformHomebrew Postgres (bootstrap-brew-dev.sh) or Docker ring-postgres-dev
    ring-platform.org prodring_platformpostgres.ring-platform-org.svc.cluster.local
    ring-connect-softwarering_connect_software_dev / prod nameSeparate clone DB
    ring-ringdom-orgring_ringdom_orgSeparate clone DB

    Migration file: data/migrations/005_refcodes_schema.sql.

    Related

    • Feature: Referral Codes
    • Affiliate enablement — dual-rail audit and operator checklist
    • ERP commissions — vendor-funded rail
    • PaymentConductor architecture
    • Proxy and i18n

    Refcodes architecture

    Dual-rail: Token minting (this document) pairs with ERP settlements referral commission on the same orderReference. Overview: Affiliate enablement.

    System diagram

    Core modules

    ModulePathResponsibility
    Cookie captureproxy.tsFirst-touch ring_ref from ?ref=
    Code registryrefcode-service.tsCRUD codes per (userId, wallet)
    Attributionattribution-service.tsSelf-ref, first-purchase, wallet overlap guards
    Reward ledgerreferral-reward-service.tsFiat/credit paths, approval, oracle sizing
    On-chain mintreward-minter.tsviem simulateContract + writeContract
    Server walletlib/web3/server-wallet.tsREFERRAL_MINTER_PRIVATE_KEY → viem account

    Integration points

    Store order creation

    app/api/store/orders/route.ts resolves attribution before StoreOrdersService.createOrder. Referral fields are stored in the orders JSONB document:

    • referralCode
    • referrerUserId
    • referrerWallet

    PaymentConductor (fiat)

    lib/payments/conductor/handlers/store-order.ts calls ReferralRewardService.onOrderPaid inside the Approved + isNew branch — after stock deduction and vendor settlement. Failures are logged but do not fail the webhook.

    Internal credit (instant)

    app/api/store/payments/credit/route.ts marks the order paid, deducts stock, writes settlements via settlement-pipeline.ts, then calls onOrderPaid with rail: 'crypto' (auto-approved mint).

    Membership (fiat)

    handlers/membership-upgrade.ts → ReferralRewardService.onMembershipPaid when users.data.referredBy is set (first-touch signup attribution).

    Cron, visits, and checkout

    Endpoint / componentRole
    POST /api/refcodes/tracktrackRefcodeVisit — bumps visits + visitDaily[UTC date] (28-day prune)
    ReferralAttributionEffectPublic layout client beacon when ring_ref_visible is set
    ReferralCheckoutBadgeReview step reads ring_ref_visible
    checkout-referral-flash.tsWayForPay redirect toast survival (30 min TTL)
    GET /api/cron/refcodes-mintprocessApprovedRewards(20) — Authorization: Bearer $CRON_SECRET

    Mint notification (i18n)

    After on-chain success, reward-minter.ts loads copy via lib/i18n/refcodes-labels.ts:

    1. getUserPreferredLocaleForNotifications(referrerUserId) — users.settings.language (DB-only, smoke-safe).
    2. getReferralMintNotificationCopy(locale, { amount, token }) — modules/refcodes.json → notifications.minted.
    3. createNotification with type REFERRAL_REWARD_MINTED.

    Idempotency

    LayerKey
    PostgreSQLUnique index on referral_rewards (data->>'orderReference')
    ServicerewardExistsForOrder short-circuit
    ContractpaidOrders[orderRef] mapping — reverts ReferralRewards__AlreadyPaid

    orderRef on-chain = keccak256(bytes(orderReference)) where orderReference comes from PaymentConductor.

    Contract roles

    i18n

    SurfaceBundle keys
    User/admin UIlocales/{en,uk,ru}/modules/refcodes.json — visits, stats, admin queue
    Checkout toastmodules/store.json → checkout.referralApplied*
    Mint notificationmodules/refcodes.json → notifications.minted (server via refcodes-labels.ts)
    • Scope: modRefcodes in lib/i18n/message-scopes.ts (authenticated + admin)
    • Routes: REFCODES, ADMIN_REFCODES in constants/routes.ts

    Database placement

    EnvironmentDatabaseNotes
    ring-platform.org devring_platformHomebrew Postgres (bootstrap-brew-dev.sh) or Docker ring-postgres-dev
    ring-platform.org prodring_platformpostgres.ring-platform-org.svc.cluster.local
    ring-connect-softwarering_connect_software_dev / prod nameSeparate clone DB
    ring-ringdom-orgring_ringdom_orgSeparate clone DB

    Migration file: data/migrations/005_refcodes_schema.sql.

    Related

    • Feature: Referral Codes
    • Affiliate enablement — dual-rail audit and operator checklist
    • ERP commissions — vendor-funded rail
    • PaymentConductor architecture
    • Proxy and i18n

    Refcodes architecture

    Dual-rail: Token minting (this document) pairs with ERP settlements referral commission on the same orderReference. Overview: Affiliate enablement.

    System diagram

    Core modules

    ModulePathResponsibility
    Cookie captureproxy.tsFirst-touch ring_ref from ?ref=
    Code registryrefcode-service.tsCRUD codes per (userId, wallet)
    Attributionattribution-service.tsSelf-ref, first-purchase, wallet overlap guards
    Reward ledgerreferral-reward-service.tsFiat/credit paths, approval, oracle sizing
    On-chain mintreward-minter.tsviem simulateContract + writeContract
    Server walletlib/web3/server-wallet.tsREFERRAL_MINTER_PRIVATE_KEY → viem account

    Integration points

    Store order creation

    app/api/store/orders/route.ts resolves attribution before StoreOrdersService.createOrder. Referral fields are stored in the orders JSONB document:

    • referralCode
    • referrerUserId
    • referrerWallet

    PaymentConductor (fiat)

    lib/payments/conductor/handlers/store-order.ts calls ReferralRewardService.onOrderPaid inside the Approved + isNew branch — after stock deduction and vendor settlement. Failures are logged but do not fail the webhook.

    Internal credit (instant)

    app/api/store/payments/credit/route.ts marks the order paid, deducts stock, writes settlements via settlement-pipeline.ts, then calls onOrderPaid with rail: 'crypto' (auto-approved mint).

    Membership (fiat)

    handlers/membership-upgrade.ts → ReferralRewardService.onMembershipPaid when users.data.referredBy is set (first-touch signup attribution).

    Cron, visits, and checkout

    Endpoint / componentRole
    POST /api/refcodes/tracktrackRefcodeVisit — bumps visits + visitDaily[UTC date] (28-day prune)
    ReferralAttributionEffectPublic layout client beacon when ring_ref_visible is set
    ReferralCheckoutBadgeReview step reads ring_ref_visible
    checkout-referral-flash.tsWayForPay redirect toast survival (30 min TTL)
    GET /api/cron/refcodes-mintprocessApprovedRewards(20) — Authorization: Bearer $CRON_SECRET

    Mint notification (i18n)

    After on-chain success, reward-minter.ts loads copy via lib/i18n/refcodes-labels.ts:

    1. getUserPreferredLocaleForNotifications(referrerUserId) — users.settings.language (DB-only, smoke-safe).
    2. getReferralMintNotificationCopy(locale, { amount, token }) — modules/refcodes.json → notifications.minted.
    3. createNotification with type REFERRAL_REWARD_MINTED.

    Idempotency

    LayerKey
    PostgreSQLUnique index on referral_rewards (data->>'orderReference')
    ServicerewardExistsForOrder short-circuit
    ContractpaidOrders[orderRef] mapping — reverts ReferralRewards__AlreadyPaid

    orderRef on-chain = keccak256(bytes(orderReference)) where orderReference comes from PaymentConductor.

    Contract roles

    i18n

    SurfaceBundle keys
    User/admin UIlocales/{en,uk,ru}/modules/refcodes.json — visits, stats, admin queue
    Checkout toastmodules/store.json → checkout.referralApplied*
    Mint notificationmodules/refcodes.json → notifications.minted (server via refcodes-labels.ts)
    • Scope: modRefcodes in lib/i18n/message-scopes.ts (authenticated + admin)
    • Routes: REFCODES, ADMIN_REFCODES in constants/routes.ts

    Database placement

    EnvironmentDatabaseNotes
    ring-platform.org devring_platformHomebrew Postgres (bootstrap-brew-dev.sh) or Docker ring-postgres-dev
    ring-platform.org prodring_platformpostgres.ring-platform-org.svc.cluster.local
    ring-connect-softwarering_connect_software_dev / prod nameSeparate clone DB
    ring-ringdom-orgring_ringdom_orgSeparate clone DB

    Migration file: data/migrations/005_refcodes_schema.sql.

    Related

    • Feature: Referral Codes
    • Affiliate enablement — dual-rail audit and operator checklist
    • ERP commissions — vendor-funded rail
    • PaymentConductor architecture
    • Proxy and i18n
    text
    
    initialize(admin, operator, token, mode)
      ├─ DEFAULT_ADMIN_ROLE → admin (upgrade, pause, setRewardToken/Mode)
      └─ OPERATOR_ROLE      → operator (payReferral)
    
    MINT mode: token must authorize proxy to mint
    TRANSFER mode: contract must hold token balance (treasury-funded)
    text
    
    initialize(admin, operator, token, mode)
      ├─ DEFAULT_ADMIN_ROLE → admin (upgrade, pause, setRewardToken/Mode)
      └─ OPERATOR_ROLE      → operator (payReferral)
    
    MINT mode: token must authorize proxy to mint
    TRANSFER mode: contract must hold token balance (treasury-funded)
    text
    
    initialize(admin, operator, token, mode)
      ├─ DEFAULT_ADMIN_ROLE → admin (upgrade, pause, setRewardToken/Mode)
      └─ OPERATOR_ROLE      → operator (payReferral)
    
    MINT mode: token must authorize proxy to mint
    TRANSFER mode: contract must hold token balance (treasury-funded)