Skip to content

CR8 Platform Architecture Overview

Current Architecture: Fully On-Chain (No Backend)

The CR8 DApp is a frontend-only application that connects directly to the blockchain. There is no backend server.

How It Works

User's Browser

Next.js DApp (Frontend)

Wagmi + Viem (Blockchain SDK)

RPC Provider (Sepolia/Mainnet)

Smart Contracts (On-Chain)

Data Flow

Reading Data (View Functions)

  1. User opens DApp → Frontend loads
  2. User connects wallet → Wallet address available
  3. Frontend calls contract → Uses useReadContract hook
  4. Wagmi queries blockchain → Via RPC (e.g., Sepolia RPC)
  5. Contract returns data → Displayed in UI

Example:

typescript
// In component
const { data: balance } = useReadContract({
  address: tokenAddress,
  abi: CR8_TOKEN_ABI,
  functionName: 'balanceOf',
  args: [userAddress]
});
// Direct blockchain read - no backend involved

Writing Data (Transactions)

  1. User clicks action → e.g., "Stake Tokens"
  2. Frontend prepares transaction → Using useWriteContract
  3. User approves in wallet → MetaMask/WalletConnect
  4. Transaction sent to blockchain → Via RPC
  5. Transaction mined → State updated on-chain
  6. Frontend refetches → Shows updated data

Example:

typescript
// In component
const { writeContract } = useWriteContract();

writeContract({
  address: stakingAddress,
  abi: STAKING_ABI,
  functionName: 'stake',
  args: [amount]
});
// Direct blockchain write - no backend involved

What's Stored Where

On-Chain (Smart Contracts)

  • ✅ Token balances
  • ✅ Staking positions
  • ✅ Agent registry
  • ✅ Vesting allocations
  • ✅ Fee distributions
  • ✅ Ownership data
  • ✅ All financial state

Frontend Only (Browser)

  • ✅ UI state (React state)
  • ✅ User preferences (localStorage)
  • ✅ Wallet connection state
  • ✅ Cached contract data (React Query cache)

No Backend Database

  • ❌ No user accounts
  • ❌ No server-side authentication
  • ❌ No API endpoints
  • ❌ No database
  • ❌ No server-side logic

Benefits of This Architecture

✅ Advantages

  1. Decentralized: No single point of failure
  2. Trustless: Users interact directly with contracts
  3. Simple: No backend to maintain
  4. Cost-effective: No server costs
  5. Transparent: All data on-chain, verifiable
  6. Censorship-resistant: Can't be shut down

⚠️ Limitations

  1. Gas Costs: Every action costs gas
  2. Read Performance: RPC calls can be slow
  3. No Off-Chain Data: Can't store large files cheaply
  4. No Server-Side Processing: All logic must be on-chain
  5. RPC Dependencies: Relies on RPC provider availability

When You Might Need a Backend

Consider adding a backend if you need:

1. Off-Chain Data Storage

  • Agent metadata (descriptions, images)
  • User profiles
  • Historical analytics
  • Large files (IPFS is alternative)

2. Server-Side Processing

  • Complex calculations
  • API integrations (OpenAI, etc.)
  • Scheduled tasks
  • Webhooks

3. Performance Optimization

  • Caching frequently accessed data
  • Indexing blockchain events
  • Aggregating data from multiple sources
  • Rate limiting

4. User Management

  • Email/password authentication
  • User accounts
  • Session management
  • Access control

Current Implementation

What We Have

Frontend (Next.js)

  • React components
  • Wagmi for blockchain interactions
  • RainbowKit for wallet connections
  • React Query for data fetching/caching
  • Direct contract calls via RPC

Smart Contracts (Solidity)

  • CR8Token
  • CR8Staking
  • AgentDeposit
  • TokenVesting

No Backend

  • No API routes
  • No database
  • No server-side logic
  • No authentication server

Future Architecture Options

Option 1: Keep Fully On-Chain (Current)

  • ✅ Simplest
  • ✅ Most decentralized
  • ✅ Best for MVP
  • ⚠️ Limited by on-chain storage costs

Option 2: Add Indexer/API Layer

  • Index blockchain events
  • Provide fast queries
  • Cache contract data
  • Still no backend logic, just data access

Option 3: Hybrid (Backend + On-Chain)

  • Backend for metadata, analytics
  • On-chain for financial transactions
  • Best of both worlds
  • More complex to maintain

Data Sources

Current Data Flow

  1. Contract State → RPC → Frontend
  2. User Wallet → Wallet Provider → Frontend
  3. No Backend API → Everything is on-chain

Example: Viewing Token Balance

User → DApp → useReadContract → RPC → CR8Token.balanceOf() → Display

No backend involved at any step!

Summary

Your DApp is:

  • ✅ Frontend-only (Next.js)
  • ✅ Direct blockchain connection (Wagmi/Viem)
  • ✅ No backend server
  • ✅ No database
  • ✅ Fully on-chain data

Everything happens:

  • In the user's browser
  • Directly on the blockchain
  • Via RPC calls to the network

This is a pure Web3 architecture - decentralized, trustless, and simple!

CR8 Platform Documentation