How gemwalletcom/core works
Project Purpose and Nature
• This is the core engine for Gem Wallet, a decentralized multi-chain crypto wallet built in Rust. It provides backend services for transaction indexing, asset pricing, notifications, name resolution (like ENS), NFT handling, swap operations, staking, and fiat ramping.
• It serves both backend APIs (for web or services) and mobile integrations (via the Gemstone library for iOS and Android).
Main Architectural Components
• API Server:
– Located in “apps/api” and responsible for handling client requests. It interacts with the core logic (via various crates) and the database.
• Daemon/Background Jobs:
– Found under “apps/daemon”, this component processes periodic updates such as asset prices, NFT updates, price alerts, transaction processing, etc.
• Parser Service:
– Under “apps/parser”, used to parse blockchain/transaction data and possibly feed it to the API and daemon.
• Setup Tools:
– “apps/setup” which can manage initial data migrations or configuration.
• Command-line Utilities:
– Various binaries in “bin” (e.g., generate, img-downloader, swapper-dump, uniffi-bindgen) that support auxiliary processes like code generation or asset management.
• Core Libraries (Crates):
– Located in “crates”: They cover blockchain connectivity (e.g., “blockchain”, “gem_chain_rpc”, “gem_evm”, “gem_solana”, “gem_ton”, “gem_sui”), API connectors, fiat operations, NFT processing, name resolution, caching, job running, and more. They are the building blocks that support the higher-level applications.
• Storage:
– The “crates/storage” directory along with diesel migration files provides the persistence layer (database connectivity and schema).
• Mobile Integration Library:
– The “gemstone” directory bundles the cross-platform library used for native mobile integration (iOS and Android). It abstracts core functionality (async networking, transaction handling, etc.) so that mobile apps can easily integrate with the core engine.
• Configuration, Settings, and Infrastructure:
– Various configuration files (e.g., Cargo.toml, Settings.yaml, diesel.toml, Dockerfile, docker-compose.yml) and CI/CD setups (in .github/workflows) highlight deployment, testing, and build components.
Relationships and Data Flow
• The API Server acts as the entry point for client requests and communicates with the Database (managed by Storage crates) to read/write data.
• The Daemon periodically executes background tasks such as updating asset prices, verifying blockchain state via the blockchain-related crates, and pushing notifications.
• The Parser Service ingests data from external blockchain nodes via connectors and feeds processed events to the API and Daemon.
• The Mobile Library (Gemstone) acts as a bridge on client devices, communicating with the API and possibly embedding some of the core functionalities from the crates.
• Common dependencies such as the blockchain connectors, fiat providers, and swap modules are shared across applications building up a cohesive ecosystem.
• The CI/CD pipelines (GitHub workflows) ensure that all components (API, Daemon, mobile libraries, CLI utilities, etc.) remain integrated and well-tested.
Architectural Patterns and Design Principles
• Modular Design: The use of “crates” demonstrates a highly modular architecture, where each service (blockchain communication, storage, swap logic, etc.) is encapsulated.
• Service Separation: There is a clear division between stateless API endpoints, background daemon processes for asynchronous tasks, and specialized utilities (parser, setup).
• Infrastructure as Code: Dockerfiles, docker-compose and CI workflows indicate that deployment, testing, and build processes are automated.
• Cross-Platform Integration: The Gemstone library abstracts the core functionalities for native mobile consumption while the backend remains in Rust.