How dgarage/nbxplorer works
Project type and purpose
• NBXplorer is a .NET Core service (ASP .NET Web API) that tracks UTXOs for HD wallets.
• It exposes a REST/WS API, schedules background “hosted services,” persists data to Postgres, and talks to Bitcoin (and altcoin) full nodes via RPC.
• It includes a client library (NBXplorer.Client), examples, and a large test suite.
File structure
• Top-level “NBXplorer” folder: server code (Controllers, Backend, HostedServices, Configuration, MessageBrokers, etc.).
• “NBXplorer.Client”: reusable .NET client library.
• “NBXplorer.Tests”: integration/unit tests with Docker setups.
• “Examples”: sample apps using the client library.
• Docker, CI (CircleCI), build scripts, docs.
README insights
• Core components: REST API, WebSockets, long-polling, Postgres persistence, RPC to Bitcoin node, message brokers (RabbitMQ/Azure).
• Architectural notes: MVC-style Controllers, DI, hosted background tasks, repository/data-access layers, DB migrations, pluggable altcoin support.
Main components & interactions
a. API Layer
• ASP .NET Core Web API (Controllers folder)
• Routes: Derivations, Transactions, Groups, Events
b. Business / Core Logic
• Services, HostedServices (UTXOFetcher, RefreshWalletHistory, DatabaseSetup, etc.)
• Analytics, EventAggregator, Broadcaster
• DerivationStrategy modules (P2PKH, P2WPKH, Taproot, multisig)
c. Data Access Layer
• RepositoryProvider → Repository → DbConnectionFactory
• DB scripts (DBScripts folder) handle schema/migrations
• Postgres
d. External Dependencies
• Bitcoin Core / Altcoin node(s) (RPC interface)
• Optional Message Brokers: RabbitMQ or Azure Service Bus
e. Client Library
• NBXplorer.Client (ExplorerClient, Models, JsonConverters, WebsocketNotificationSession)
• Used by external apps (Examples)
f. Tests
• CustomHttpServer, Docker compose setups, data fixtures
Architectural patterns & design principles
• MVC for API (Controllers → Services → Repositories)
• Repository pattern for DB access
• Dependency Injection (ASP .NET Core DI container)
• HostedServices for background, periodic tasks
• Pub/Sub abstraction for events (long-polling, WebSockets, message brokers)
• Strategy pattern for derivation schemes (IStrategy, Direct, Multisig, Taproot)