This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Yarn workspace monorepo containing two main packages:
- @onekeyhq/transfer-server - End-to-End Encryption server for real-time communication using Socket.IO
- @onekeyhq/cloud-sync-server - OneKey Prime Sync Component using Midway.js framework
yarn install- Install all dependencies for all packagesyarn build- Build all packagesyarn build:sync- Build only cloud-sync-serveryarn dev:sync- Start cloud-sync-server in watch modeyarn dev- Start transfer-server in development modeyarn dev:mock- Start mock application in development modeyarn test- Run tests for all packagesyarn test:sync- Run tests for cloud-sync-serveryarn lint- Run ESLint for all packagesyarn lint:sync- Run ESLint for cloud-sync-serveryarn clean- Clean build artifacts for all packages
yarn dev- Start development server with hot reload (uses nodemon)yarn build- Build TypeScript to JavaScriptyarn start- Start production serveryarn clean- Remove dist folder
yarn build- Build TypeScriptyarn dev- Watch mode for developmentyarn test- Run Jest testsyarn test:watch- Run tests in watch modeyarn test:cov- Run tests with coverageyarn lint- Run ESLintyarn lint:fix- Auto-fix ESLint issues
The transfer server is a Socket.IO-based real-time communication server with end-to-end encryption support.
Key Components:
server.ts- Main server entry with Express and Socket.IO setuproomManager.ts- Manages room creation, joining, and user managemente2eeServerApi.ts&e2eeServerApiProxy.ts- API interface and proxy for E2EE operationsJsBridgeE2EEServer.ts&JsBridgeE2EEClient.ts- Bridge implementation for client-server communicationdecorators/e2eeApiMethod.ts- Method decorator for API endpointsutils/- Utility functions for crypto, buffers, caching, etc.
Socket.IO Events:
- Client→Server:
create-room,join-room,send-encrypted-data,leave-room,get-room-status,get-room-list - Server→Client:
room-created,room-joined,user-joined,user-left,encrypted-data,room-error,room-status
Configuration (via environment variables):
PORT(default: 3868)CORS_ORIGINS(comma-separated list)MAX_USERS_PER_ROOM(default: 2)ROOM_TIMEOUT(default: 3600000ms)MAX_MESSAGE_SIZE(default: 10485760 bytes)
A Midway.js-based component for OneKey Prime synchronization functionality.
Key Components:
configuration.ts- Midway.js component configurationservice/sync.service.ts- Main sync service implementation (PrimeSyncService)dto/sync.dto.ts- Data Transfer Objects for sync operationsinterface/- TypeScript interfaces for adapters and configadapter/- Example adapter implementations for MongoDB and Kafka
Service Architecture:
- Uses dependency injection with Midway.js decorators (@Provide, @Inject, @Config)
- Singleton scope for the main service
- Adapter pattern for MongoDB and Kafka integrations
- Support for custom dependencies provider
- Both packages use Jest for testing
- Test files are located in
test/directories - Mock application available in
examples/mock-app/for integration testing - Run individual package tests with
yarn workspace @onekeyhq/<package-name> test
- TypeScript is used throughout the project
- ESLint configuration with TypeScript plugin
- Prettier integration for code formatting
- Each package has its own
tsconfig.jsonand.eslintrc.js - Node.js version requirement: >= 24
-
Monorepo Structure: Use Yarn workspaces for dependency management. Always install dependencies from the root directory.
-
Error Handling: The transfer-server includes custom error codes (see
errors.ts). The cloud-sync-server uses Midway.js error handling patterns. -
Security:
- CORS is configured but currently allows all origins in development
- Message size limits are enforced
- Room timeouts prevent resource exhaustion
-
State Management:
- Transfer server uses in-memory room management
- Cloud sync server expects external MongoDB and Kafka adapters
-
Deployment:
- Docker support available (see Dockerfile)
- PM2 recommended for production process management
- Health check endpoint available at
/health
-
Dependency Injection: The cloud-sync-server heavily uses Midway.js DI patterns. When adding new services, follow the existing pattern with decorators.
-
Real-time Communication: Socket.IO is configured with specific ping/pong intervals and buffer sizes. Be mindful of these settings when debugging connection issues.