Overview
ClipSync is built as a Progressive Web App (PWA) using a modern React architecture with real-time synchronization capabilities. The application follows a single-page application (SPA) pattern with a centralized state management approach.Application Architecture
The application uses a monolithic client architecture where all functionality is contained within a single React application. The core architecture consists of:- Client Layer: React 19 application with Vite as the build tool
- Backend Layer: Supabase (Backend-as-a-Service) providing database, storage, and real-time features
- PWA Layer: Service Worker for offline functionality and app installation
High-Level Architecture Diagram
Component Structure
Main Application Component
The application follows a single-component architecture with the mainApp.jsx component handling all functionality. This monolithic approach works well for this focused use case.
src/App.jsx:1-706
Key Modules
Configuration
src/config/supabase.jsInitializes Supabase client with environment variables
Services
src/service/doc.service.jsSession creation and management utilities
Utils
src/utils/index.jsHelper functions (link conversion, text processing)
File Handling
src/compressedFileUpload.jsxImage compression before upload
State Management Approach
ClipSync uses React’s built-in state management with hooks, supplemented by React Query for server state:Local State (useState)
Server State (React Query)
Used for visitor counter management:src/App.jsx:375-383
Persistence Strategy
ClipSync uses multiple persistence layers:
- localStorage: Session codes and theme preferences
- sessionStorage: Temporary clipboard content
- Supabase Database: Persistent clipboard history
Real-Time Sync Architecture
Supabase Realtime Channels
The application uses Supabase Realtime for instant synchronization across devices:src/App.jsx:386-410
How It Works
File Storage Architecture
Upload Flow
Image Compression
Images are automatically compressed before upload usingbrowser-image-compression:
src/compressedFileUpload.jsx:3-16
Default compression settings:
- Max size: 0.2 MB (200KB)
- Max dimension: 1920px
- Uses Web Worker for non-blocking compression
Storage Organization
Files are stored in Supabase Storage with the following structure:Offline Handling
The application monitors online/offline status:src/App.jsx:40-53
Offline Features
- Detects network status changes
- Shows offline banner to users
- Automatically refetches data when back online
- PWA caching allows viewing cached content offline
Database Schema
While not explicitly defined in the client code, the application interacts with these Supabase tables:Tables
sessions
sessions
Stores active session codes
clipboard
clipboard
Stores clipboard entries
counter
counter
Tracks visitor statistics
Performance Optimizations
Lazy Loading
Service Worker caches all assets for instant loading
Image Compression
Reduces upload size by up to 90%
Query Caching
React Query caches visitor counter (5min refresh)
Efficient Updates
Only subscribes to realtime changes when session is active
Next Steps
Tech Stack
Learn about the technologies powering ClipSync
Local Setup
Set up the development environment