Skip to content

Coding guidelines

layters edited this page Nov 25, 2025 · 53 revisions

Overview

Branches

  • main: The main branch in which releases are derived from

Folder Structure

neroshop/
└── src/
    ├── console/            # Neroshop command line interface (neroshop-console)
    ├── core/               # Core functionality of Neroshop
    │   ├── crypto/         # Cryptographic algorithms (SHA-256, RSA, etc.)
    │   ├── database/       # Database-specific code (sqlite3, lmdb)
    │   ├── market/         # Marketplace-specific code (listings, cart, orders)
    │   ├── network/        # Privacy networks (Tor, I2P)
    │   ├── price/          # Cryptocurrency price APIs and exchanges
    │   ├── protocol/       # Protocol implementations
    │   ├── tools/          # Helper and utility code
    │   ├── wallet/         # Blockchain wallet implementations
    │   └── (root files)    # Core root directory files
    ├── daemon/             # Neroshop daemon executable (neroshopd)
    └── gui/                # GUI code interfacing with QML and C++ (neroshop)
└── qml/                    # User interface code (QML files)
└── external/               # Third-party libraries A.K.A "dependencies"
└── assets/                 # Resources (app icons, images, fonts, shaders, etc.)
└── tests/                  # Unit tests (usually broken due to having low priority)
└── qml.qrc                 # QML Resource file embedded in the GUI
└── proto/                  # Protobuf (.proto) files

Naming conventions

Naming conventions - snake_case vs camelCase vs PascalCase

  • camelCase is only allowed in the gui and qml code.
  • Function and variable names should always be in snake_case form in the console, core, and daemon code, excluding the gui and qml code, which will use camelCase for both functions and variables.
  • Class, struct, and enum names must always be in PascalCase form.

Naming conventions - files

  • File names should be lowercase and file names containing separate words should be separated using an underscore _.

  • All cpp files should have a header file, with files containing a int main() function being the exception to the rule. Headers do not need their own cpp files.

Include order and placement

  • Place the minimum necessary includes into a header file, as anyone else who uses that header will be forced to #include all of them too. In larger projects, this leads towards slower builds, dependency issues, and all sorts of other nastiness.

  • Any includes not used in the header file, but used in the source file should be added to the source file instead.

  • Use forward declaration when necessary.

Header files should be included in the particular order (This won't be enforced though so ignore if you want):

    1. hpp file corresponding to this cpp file (if applicable)
    1.1. A blank line
    2. headers from the same component,
    2.1. A blank line
    3. headers from other components (third party)
    3.1. A blank line
    4. system headers (with C system headers being first and C++ system headers being last)

Namespaces

  • Never use using namespace std; as naming conflictions could occur. Use std:: instead. This applies to all namespaces.
  • Namespaces must be lowercase and namespaces containing separate words should be separated using an underscore _.

Indentation

4 spaces for each line of code. No tabs allowed.

Changing parts of the code

version changes:

only change these parts of a version under the following circumstances:

major - when there are many breaking changes that may not be backwards compatible
minor - when a new feature (e.g. new function) is added
patch - when a bug is fixed in existing function(s)
  • src/core/version.hpp
  • CMakeLists.txt: line 7,8,9
  • meson.build: line 1

wallet network type changes:

  • src/core/wallet/wallet.cpp: line 19
  • src/core/protocol/p2p/node.cpp: @ verify() function

default restore height changes:

  • src/core/wallet/wallet.cpp
  • qml/pages/MainPage.qml

settings changes:

  • src/core/settings.{cpp,hpp}
  • src/gui/settings_manager.{cpp,hpp}
  • qml/components/SettingsDialog.qml

Configurations

Pretty much all configuration parameters (e.g. macros, constants, etc.) are defined in src/neroshop_config.hpp.

Reminder

Files from console, daemon, and gui can all depend on files from core but core must never depend on either of them.

Most importantly, core MUST NOT depend on Qt as Qt is intended to be solely used within the user interface code (gui) and the GUI library can be replaced at anytime.

Clone this wiki locally