MiningOS Logo
Contribute To MiningOS

Repository Structure

Overview of MiningOS repository organization, inheritance hierarchy, and naming conventions.

This document provides a comprehensive overview of the MiningOS repositories. It explains the organizational patterns, inheritance hierarchy, and standard conventions used across all worker repositories.

For the system architecture and component relationships, see Architecture. For contribution workflow, see Contribution Workflow.


Overview

MiningOS follows a modular, inheritance-based architecture. Functionality is distributed across multiple Git repositories. Each repository serves a specific purpose in the hierarchy, from foundational worker utilities to concrete device implementations.

Design Philosophy

The repository structure embodies several key principles:

PrincipleDescriptionRelated Documentation
Inheritance over compositionBase classes provide core functionality that specialized workers extendAdding New Worker
Convention over configurationStandard directory layouts and naming patterns reduce cognitive overheadStandard Directory Structure
Separation of concernsEach repository focuses on a single abstraction level or device categoryArchitecture — Core Architecture
ReusabilityCommon patterns are extracted into template repositories for maximum code sharingRepository Hierarchy

Repository Hierarchy

Regarding the workers for physical devices, the MiningOS ecosystem consists of repositories organized into five distinct levels. For the complete architecture diagram, see Architecture — Object Model.

Level 1: Foundation
└── bfx-wrk-base                    # Core worker primitives

Level 2: Platform Base
└── tether-wrk-base                 # Tether/MiningOS worker foundation

Level 3: Thing Management
└── miningos-tpl-wrk-thing          # Abstract "thing" device management

Level 4: Device Category Templates
├── miningos-tpl-wrk-miner          # Mining hardware template
├── miningos-tpl-wrk-container      # Container infrastructure template
├── miningos-tpl-wrk-sensor         # Environmental sensor template
├── miningos-tpl-wrk-powermeter     # Power monitoring template
└── miningos-tpl-wrk-electricity    # Electricity usage 

Level 5: Concrete Implementations
├── miningos-wrk-miner-whatsminer   # WhatsMiner devices (like m53s)
├── miningos-wrk-miner-antminer     # Antminer devices (like s19xp)
├── miningos-wrk-miner-avalon       # Avalon devices (like a1346)
├── miningos-wrk-container-antspace # Antspace miner containers (like hk3)
├── miningos-wrk-container-microbt  # MicroBT miner containers (like kehua)
├── miningos-wrk-sensor-temp-seneca # Seneca temperature sensors
├── miningos-wrk-powermeter-satec   # Satec power meters (like PM180)
└── miningos-wrk-powermeter-schneider # Schneider power meters (like PM5340)

For creating new workers at each level, see Adding New Worker Type. For supported device specifications, see Supported Devices.

Standard Directory Structure

All MiningOS worker repositories follow a consistent directory layout. Below is the canonical structure:

.
├── config/                              # [REQUIRED] Configuration directory
│   ├── common.json.example              # [REQUIRED] Worker-wide settings
│   ├── base.thing.json.example          # [COMMON LEVEL 3+] Thing-specific configuration
│   ├── <worker>.json.example            # [OPTIONAL] Worker-specific settings
│   └── facs/                            # [REQUIRED] Facilities configuration
│       ├── net.config.json.example      # [REQUIRED] Network/RPC server configuration
│       ├── store.config.json.example    # [COMMON LEVEL 3+] Hyperbee storage configuration
│       └── miningos-net.config.json.example # [OPTIONAL] MiningOS network (DHCP workers only)

├── mock/                                # [OPTIONAL] Mock implementations for testing
│   └── mock-control-agent.js            # [COMMON] Simulated device controller

├── tests/                               # [OPTIONAL] Test suite
│   ├── cases/                           # Test case definitions
│   │   └── stats.js                     # Statistics test cases
│   ├── schema/                          # Response schema validators
│   │   └── stats.js                     # Statistics schema
│   ├── executors.js                     # Test execution utilities
│   ├── utils.js                         # Test helpers
│   └── <worker>.test.js                 # Main test file

├── workers/                             # [REQUIRED] Worker implementation directory
│   ├── lib/                             # [REQUIRED] Shared library modules
│   │   ├── base.js                      # [COMMON] Base device class
│   │   ├── alerts.js                    # [COMMON LEVEL 3+] Alert definitions
│   │   ├── constants.js                 # [OPTIONAL] Worker constants
│   │   ├── stats.js                     # [COMMON] Statistics collection logic
│   │   ├── utils.js                     # [COMMON] Utility functions
│   │   └── wrk-fun-stats.js             # [OPTIONAL] Statistics persistence
│   │
│   └── rack.<device>.wrk.js             # [REQUIRED] Main worker class

├── worker.js                            # [REQUIRED] Entry point
├── package.json                         # [REQUIRED] Node.js project metadata
├── package-lock.json                    # [REQUIRED] Locked dependency versions (derived file)
├── LICENSE                              # [REQUIRED] Apache 2.0 license
├── README.md                            # [REQUIRED] Repository documentation
├── setup-config.sh                      # [REQUIRED] Config file initialization
└── upstream-merge.sh                    # [COMMON] Parent repository merge script

For testing guidelines, see Testing & Linting Guidelines. For documentation standards, see Code Documentation Standards.

Directory Purpose Reference

Directory/FilePurposeRelated Documentation
config/All configuration files with .example templatesInstallation — Configuration
config/facs/Facility-specific configuration (network, storage)Key Files Explained
mock/Test doubles for device simulationTesting Guidelines
tests/Brittle test framework test suiteTesting Guidelines
workers/Core worker implementationWorker Implementation Files
workers/lib/Shared utilities and base classesAdding New Worker
worker.jsCLI entry point for worker startupInstallation
setup-config.shCopies .example files to active configsContribution Workflow — Configure the Worker
upstream-merge.shMerges changes from parent templateBranching Conventions — Upstream Synchronization

Naming Conventions

Repository names

PatternExampleDescriptionDocumentation
bfx-wrk-baseBitfinex foundation workerArchitecture — Level 1
tether-wrk-baseTether platform baseArchitecture — Level 2
miningos-tpl-wrk-<type>miningos-tpl-wrk-minerTemplate/abstract workerAdding New Worker — Level 4
miningos-wrk-<type>-<brand>miningos-wrk-miner-whatsminerConcrete implementationAdding New Worker — Level 5
miningos-wrk-ext-<service>miningos-wrk-ext-mempoolExternal service integrationArchitecture — External API Workers

Class names

ComponentConventionExampleDocumentation
Worker classWrk<Device>RackWrkMinerRackAdding New Worker
Base device classBase<Device>BaseMinerAdding New Worker — Level 4
Device controller<Brand><Device>WhatsminerMinerAdding New Worker — Level 5
Model-specific worker classWrk<Device>Rack<Model>WrkMinerRackM56sAdding New Worker — Level 5

Key files explained

FilePurposeRelated Documentation
worker.jsThe entry point for all workers. This file is minimal and delegates to the bfx-svc-boot-js frameworkAdding New Worker — Worker Entry Point
package.jsonStandard Node.js package manifest with MiningOS-specific conventionsAdding New Worker — Package.json Structure
setup-config.shUtility script that creates active configuration files from '.example' filesContribution Workflow — Configure the Worker
upstream-merge.shMerges changes from parent templateBranching Conventions — Upstream Synchronization
config/base.thing.jsonConfigures thing management behaviorAdding New Worker — Configuration Templates
config/facs/net.config.jsonConfigures RPC server and network access. Structure varies by repositoryArchitecture — RPC Protocol
config/facs/store.config.jsonConfigures Hyperbee persistent storage. This facility typically requires no additional configurationArchitecture — Data Persistence

Worker implementation files

FilePurposeRelated Documentation
workers/[model].rack.[device].wrk.jsThe main worker class implementing device-specific logicAdding New Worker — Main Worker Implementation
workers/lib/base.jsBase class for device interactionsAdding New Worker — Device Library Class
workers/lib/alerts.jsAlert definitions for the device typeAlerts Manual
workers/lib/constants.jsWorker constants and configuration valuesCode Documentation — Constants Documentation
workers/lib/stats.jsStatistics collection and aggregation logicDashboard
workers/lib/utils.jsUtility functions shared across the workerCode Documentation

Contributor Guide

General Documentation

Operator Manual

On this page