This guide describes the recommended workflow for contributing to the Edge Mining project.
Monorepo note: This project uses a monorepo layout. Backend code lives in
core/, frontend infrontend/. Docker build and orchestration files are at the repository root.
The project uses Hexagonal Architecture (Ports and Adapters) to clearly separate the business logic (Domain and Application Layer) from infrastructural dependencies (Database, external APIs, Hardware Control, User Interfaces).
edge_mining/domain: Contains the pure business logic, subdomains and their models (Entities, Value Objects), domain exceptions, and the interfaces (Ports) that define the contracts with the outside world.edge_mining/application: Contains the application services that orchestrate the use cases, utilizing the Domain's Ports.edge_mining/adapters: Contains the concrete implementations of Ports.domain: Adapters strictly used by domain elements.infrastructure: Infrastructure adapters, used cross-domain (logger, persistence, api).
edge_mining/shared: Shared elements (and interfaces) used cross-domain.test: Contains application tests.edge_mining/__main__.py: Main entry point, responsible for "wiring" dependencies (Dependency Injection).
git clone https://github.com/edge-mining/app.git
cd appCreate a Python virtual environment (if you have not created it yet).
python -m venv .venvand activate it before running other commands.
source .venv/bin/activate.venv\Scripts\activateInstall the required dependencies and development tools:
pip install -r core/requirements.txtpip install -r core/requirements-dev.txtConfigure environment variables by copying .env.example to .env and editing the values as needed.
cp .env.example .env
nano .env # Edit the .env fileKey settings:
TIMEZONE: Set your local timezone (e.g.,UTC,America/New_York)LATITUDEandLONGITUDE: Set your location for sunrise/sunset calculationsDB_PATH: Database URL (e.g.,sqlite:///data/db/edgemining.dbor PostgreSQL URL)RUN_MIGRATIONS_ON_STARTUP: Set totrueto automatically apply database migrationsSCHEDULER_INTERVAL_SECONDS: Set the interval for the optimization scheduler (default:60)
Note: By default, the application uses SQLAlchemy with SQLite for the database. Migrations are managed with Alembic. See docs/ALEMBIC_MIGRATIONS.md for detailed migration management.
Run the setup command to install the required dependencies.
NOTE: Use the make command if you are on Linux or you are on WSL. Use dev-tools.ps1 or dev-tools.bat if you are on Windows.
For more details, see DEV_TOOLS.md.
make setupThis sets up both backend and frontend environments.
cd core
make setupThis command:
- Installs development dependencies from
requirements-dev.txt. - Configures pre-commit hooks for automatic code quality checking.
The application stores all user data in the data/ directory:
mkdir -p data/db/backups data/policies data/examplesDirectory structure:
data/db/- Database file and automatic backupsdata/policies/- Your optimization policy YAML filesdata/examples/- Example rules for reference (templates only)
Run the following command to check code formatting, linting, and tests before starting development. This ensures your environment is set up correctly and all pre-commit checks pass.
make pre-commitYou can run the application in different modes via the main entry point:
- Standard Mode (Default): Starts the main automation loop that checks available energy and controls miners at regular intervals. Starts a REST API (FastAPI) server also to interact with the system programmatically.
python -m core/edge_mining
# Or by explicitly specifying
python -m core/edge_mining standard- CLI Mode: Access the command line interface with an interactive menu to manage miners, energy sources, controller, policies, etc.
python -m core/edge_mining cli interactive
You can use the --help flag to see all available options:
python -m core/edge_mining cli --helpThe API will be available at http://localhost:8001 (or the configured port). You can access the interactive documentation (Swagger UI) at http://localhost:8001/docs.
main is the active integration and development branch. Start new work from main, push changes to a feature branch, and open a pull request back into main.
# Clean temporary files
make clean
# Update dependencies if necessary
make install-devRun the following command to automatically format your code according to the project's style guidelines.
make formatUse this command to check your code for linting issues and ensure it meets quality standards.
make lintExecute this command to run all tests and verify your changes do not break existing functionality.
make testPre-commit hooks run automatically, but you can run them manually.
make pre-commitIf there are errors, fix them and try again.
git checkout main
git pull
git checkout -b feat/feature-description
git add .
git commit -m "feat: feature description"
git push -u origin feat/feature-descriptionThen open a pull request from your feature branch to main.
make lint-fixmake clean
# Remove virtual environment if necessary
rm -rf .venv
python -m venv .venv
make setupmake test-covThis will generate an HTML report in htmlcov/index.html
bandit -r core/edge_mining/mypy core/edge_mining/See the DEV_TOOLS.md file for detailed information about the tools used in this project.
# Reinstall pre-commit
pre-commit uninstall
make pre-commit-install
# Update hooks
pre-commit autoupdate# Check virtual environment
which python
# Should point to .venv/bin/python
# Reinstall dependencies
make clean
make install-dev# Mypy is configured to be permissive during development
# Errors don't block commits but it's good to resolve them
# To run mypy manually:
mypy core/edge_mining/make format
make lint
# The makefile is configured to handle most conflicts- Always run
make pre-commitbefore committing - Use
make formatto automatically format code - Write tests for new features
- Maintain high test coverage
- Use type hints when possible
- Follow Python naming conventions (PEP 8)
- Write docstrings for public functions and classes
Use conventional commits:
feat:for new featuresfix:for bug fixesdocs:for documentation updatesstyle:for formatting changesrefactor:for code refactoringtest:for adding/modifying testschore:for maintenance tasks
Example commit messages:
git commit -m "feat: add energy monitoring adapter for solar panels"
git commit -m "fix: resolve memory leak in optimization service"
git commit -m "docs: update API documentation for miner endpoints"