OneKey Server Infrastructure
A monorepo containing OneKey's server infrastructure components, including end-to-end encryption server and cloud synchronization services.
๐ Architecture
This monorepo uses Yarn workspaces to manage multiple packages:
e2ee-server/
โโโ packages/
โ โโโ transfer-server/ # E2EE real-time communication server
โ โโโ cloud-sync-server/ # Cloud synchronization component
โโโ examples/
โโโ mock-app/ # Mock application for testing
๐ฆ Packages
End-to-End Encryption Server - A high-performance, secure real-time communication server built with Socket.IO and TypeScript.
- Real-time bidirectional communication
- Room-based message routing
- End-to-end encryption support
- WebSocket with Socket.IO
- Production-ready with health checks
Cloud Sync Component - A Midway.js-based component for OneKey Prime synchronization functionality.
- Midway.js component architecture
- MongoDB and Kafka adapter support
- Dependency injection patterns
- Extensible sync service implementation
Mock Application - Testing and development application for integration testing.
- Midway.js application framework
- Integration test examples
- API endpoint testing
- Development environment setup
๐ Quick Start
Prerequisites
- Node.js >= 24
- Yarn package manager
- MongoDB (for cloud-sync-server)
- Kafka (optional, for cloud-sync-server)
Installation
# Clone the repository
git clone <repository-url>
cd e2ee-server
# Install all dependencies
yarn install
# Build all packages
yarn build
Development
# Start transfer-server in development mode
yarn dev
# Start cloud-sync-server in watch mode
yarn dev:sync
# Start mock application
yarn dev:mock
Production
# Build all packages
yarn build
# Start transfer-server
yarn start
# Start mock application
yarn start:mock
๐ Available Scripts
Root Level Commands
| Command |
Description |
yarn install |
Install all dependencies for all packages |
yarn build |
Build all packages |
yarn build:sync |
Build cloud-sync-server only |
yarn build:mock |
Build mock-app only |
yarn dev |
Start transfer-server in development mode |
yarn dev:sync |
Start cloud-sync-server in watch mode |
yarn dev:mock |
Start mock-app in development mode |
yarn start |
Start transfer-server in production |
yarn start:mock |
Start mock-app in production |
yarn test |
Run tests for all packages |
yarn test:sync |
Run tests for cloud-sync-server |
yarn test:mock |
Run tests for mock-app |
yarn lint |
Run ESLint for all packages |
yarn lint:sync |
Run ESLint for cloud-sync-server |
yarn clean |
Clean build artifacts for all packages |
Package-Specific Commands
Each package has its own set of scripts. Navigate to the package directory or use yarn workspace commands:
# Run command for specific package
yarn workspace @onekeyhq/transfer-server <command>
yarn workspace @onekeyhq/cloud-sync-server <command>
yarn workspace @onekeyhq/mock-app <command>
๐ง Configuration
Environment Variables
Each package can be configured using environment variables. Create .env files in package directories:
transfer-server
PORT=3868
MAX_USERS_PER_ROOM=2
ROOM_TIMEOUT=3600000
MAX_MESSAGE_SIZE=10485760
cloud-sync-server
Configure through Midway.js configuration files in src/config/.
๐ Project Structure
e2ee-server/
โโโ packages/
โ โโโ transfer-server/ # E2EE Server
โ โ โโโ src/
โ โ โ โโโ server.ts # Main server entry
โ โ โ โโโ roomManager.ts # Room management
โ โ โ โโโ e2eeServerApi.ts # API interfaces
โ โ โ โโโ utils/ # Utility functions
โ โ โโโ package.json
โ โ โโโ tsconfig.json
โ โ
โ โโโ cloud-sync-server/ # Sync Component
โ โโโ src/
โ โ โโโ configuration.ts # Midway configuration
โ โ โโโ service/ # Service implementations
โ โ โโโ dto/ # Data transfer objects
โ โ โโโ adapter/ # External adapters
โ โโโ package.json
โ โโโ tsconfig.json
โ
โโโ examples/
โ โโโ mock-app/ # Mock Application
โ โโโ src/
โ โ โโโ configuration.ts
โ โ โโโ controller/
โ โ โโโ service/
โ โโโ package.json
โ
โโโ package.json # Root package.json
โโโ yarn.lock # Yarn lock file
โโโ CLAUDE.md # AI assistant instructions
โโโ README.md # This file
๐งช Testing
# Run all tests
yarn test
# Run tests for specific package
yarn test:sync # Cloud sync server tests
yarn test:mock # Mock app tests
# Run tests with coverage
yarn workspace @onekeyhq/cloud-sync-server test:cov
# Run tests in watch mode
yarn workspace @onekeyhq/cloud-sync-server test:watch
๐ Code Quality
# Run linting for all packages
yarn lint
# Run linting for specific package
yarn lint:sync
# Auto-fix linting issues
yarn workspace @onekeyhq/cloud-sync-server lint:fix
๐ณ Docker Support
Building Docker Images
# Build transfer-server image
docker build -f packages/transfer-server/Dockerfile -t onekey/transfer-server .
# Build cloud-sync-server image
docker build -f packages/cloud-sync-server/Dockerfile -t onekey/cloud-sync-server .
Docker Compose
version: '3.8'
services:
transfer-server:
image: onekey/transfer-server
ports:
- "3868:3868"
environment:
- NODE_ENV=production
- PORT=3868
cloud-sync-server:
image: onekey/cloud-sync-server
ports:
- "7001:7001"
environment:
- NODE_ENV=production
depends_on:
- mongodb
- kafka
mongodb:
image: mongo:latest
ports:
- "27017:27017"
kafka:
image: confluentinc/cp-kafka:latest
ports:
- "9092:9092"
๐ Monitoring
Health Checks
- Transfer Server:
http://localhost:3868/health
- Mock App:
http://localhost:7001/health
Server Statistics
- Transfer Server:
http://localhost:3868/stats
๐ Development Guidelines
Git Workflow
- Create feature branch from
main
- Make changes and commit with conventional commits
- Run tests and linting
- Create pull request
- Merge after review
Commit Convention
feat: Add new feature
fix: Fix bug
docs: Update documentation
style: Format code
refactor: Refactor code
test: Add tests
chore: Update dependencies
Adding New Packages
- Create new directory under
packages/
- Initialize package with
package.json
- Add to workspaces in root
package.json
- Run
yarn install from root
๐ Security
- All sensitive configuration should use environment variables
- Never commit
.env files
- Use HTTPS in production
- Do not treat CORS as access control in transfer-server: it is deliberately
permissive (see
corsOptions in packages/transfer-server/src/server.ts)
- Implement rate limiting
- Regular dependency updates
๐ License
This project is part of the OneKey ecosystem.
๐ค Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature)
- Commit your changes (
git commit -m 'feat: Add amazing feature')
- Push to the branch (
git push origin feature/amazing-feature)
- Open a Pull Request
๐ Support
For issues and questions:
- Open an issue on GitHub
- Contact the OneKey development team
๐ Related Links