Frontend Architecture

Technical overview of SonicClout's frontend architecture with Sonic integration

SonicClout's frontend is built with modern web technologies, focusing on performance, user experience, and seamless integration with the Sonic blockchain. This documentation outlines the technical architecture, key components, and design patterns used in the application.

Technology Stack

The SonicClout frontend uses:

  • Next.js 14 - React framework with app router for routing and server components

  • TypeScript - For type safety and better developer experience

  • TailwindCSS - For styling and responsive design

  • React Context API - For state management

  • Sonic SDK - For Sonic blockchain interaction

  • Solana Web3.js - For base Solana compatibility

  • Wallet Adapter - Modified for Sonic wallet connections

  • ShadcnUI - For UI components with a custom theme

Application Structure

app/
├── components/    # Reusable UI components
├── context/       # Context providers for state management
├── app/           # Pages and routes (Next.js app router)
├── lib/           # Utilities and services
│   ├── services/  # Blockchain service integrations
│   ├── hooks/     # Custom React hooks
│   └── utils/     # Helper functions
└── public/        # Static assets

Key Components

App Router Structure

SonicClout uses Next.js App Router, organizing routes as folders:

Context Providers

The app uses React Context API for state management:

Global Context

Network Context

SEGA Context

Sonic Vesting Context

UI Components

SonicClout's UI is built with reusable components:

  • Navbar.tsx - Main navigation bar

  • MobileMenu.tsx - Responsive menu for mobile devices

  • SideNav.tsx - Side navigation for dashboard views

Wallet Integration

  • WalletConnectButton.tsx - Button for connecting Sonic-compatible wallets

  • WalletModal.tsx - Modal for selecting wallet providers

  • WalletDetails.tsx - Component displaying wallet info

  • NetworkSelector.tsx - Switch between Sonic and Solana networks

Trading Interface

  • TradingView.tsx - Main trading interface

  • OrderBook.tsx - Displays buy/sell orders

  • SwapInterface.tsx - Interface for token swaps

  • PoolsList.tsx - Lists available liquidity pools

Content Components

  • ContentCard.tsx - Displays tokenized content

  • CreatorProfile.tsx - Shows creator information

  • ContentFeed.tsx - Feed of tokenized content

State Management

SonicClout uses a hybrid state management approach:

  1. React Context API - For global state and blockchain interactions

  2. React Query - For data fetching, caching, and synchronization

  3. Local Component State - For UI-specific state

  4. URL State - For shareable and persistent UI state

Blockchain Integration

Wallet Connection

Wallet connection is handled through a modified Solana Wallet Adapter for Sonic:

Service Layer

The app uses service classes to interact with smart contracts on Sonic:

Styling and Theming

SonicClout uses TailwindCSS with a custom theme:

UI Components Library

The application uses ShadcnUI components with customizations:

Sonic-Specific Integrations

Sonic SDK Integration

The application integrates with Sonic's SDK for blockchain interaction:

Metaplex Integration

For NFT functionality on Sonic:

Performance Optimizations

SonicClout implements several performance optimizations:

  1. Code Splitting - Using Next.js dynamic imports

  2. Image Optimization - Using Next.js Image component

  3. Server Components - For improved initial load time

  4. Memoization - Using React.memo and useMemo for expensive calculations

  5. Virtualization - For long lists using react-window

  6. Sonic RPC Optimizations - Leveraging Sonic's high-throughput infrastructure

Responsive Design

The application is fully responsive, implementing:

  1. Mobile-first approach - Base styles for mobile, then expand

  2. Breakpoint-based layouts - Using Tailwind's responsive modifiers

  3. Adaptive UI - Different interfaces for different screen sizes

  4. Touch-friendly controls - Larger tap targets on mobile

Development Workflow

Getting Started

Environment Setup

Create a .env.local file with:

Testing Strategy

SonicClout employs several testing strategies:

  1. Unit Tests - Using Jest for utility functions

  2. Component Tests - Using React Testing Library

  3. Integration Tests - For complex component interactions

  4. End-to-End Tests - Using Cypress for critical user flows

  5. Sonic-specific Tests - Ensure compatibility with Sonic chain

Deployment

The SonicClout frontend is deployed using Vercel:

  1. Preview Deployments - For pull requests

  2. Staging Environment - For pre-production testing

  3. Production Environment - For the live site

Next Steps

Last updated