This guide covers setting up a development environment for Smartbotic Microbit and building the project from source.
Build Tools:
Development Tools (recommended):
Debian/Ubuntu:
sudo apt update
sudo apt install -y \
build-essential \
cmake \
git \
pkg-config \
libssl-dev \
libcurl4-openssl-dev \
libprotobuf-dev \
protobuf-compiler \
libgrpc++-dev \
libspdlog-dev \
nlohmann-json3-dev
Optional dependencies:
# For systemd integration
sudo apt install -y libsystemd-dev
# For development tools
sudo apt install -y clangd gdb valgrind
# Install Node.js 18+ (using NodeSource)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
# Verify installation
node --version # Should be v20.x or later
npm --version
# Clone with submodules (important!)
git clone --recursive https://github.com/fszontagh/smartbotic-microbit.git
cd smartbotic-microbit
If you already cloned without --recursive:
git submodule update --init --recursive
The project includes the following submodule:
external/smartbotic-database: Custom database service# Create build directory
mkdir build
cd build
# Configure (Release build)
cmake .. -DCMAKE_BUILD_TYPE=Release
# Or configure for Debug build with tests
cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON
CMake Options:
| Option | Default | Description |
|---|---|---|
CMAKE_BUILD_TYPE |
Release |
Build type: Release, Debug, RelWithDebInfo |
BUILD_TESTS |
OFF |
Build test suite |
BUNDLE_DATABASE |
OFF |
Include database service in build |
CMAKE_INSTALL_PREFIX |
/usr/local |
Installation prefix |
# Build with all CPU cores
make -j$(nproc)
# Or use ninja for faster builds
# cmake .. -GNinja
# ninja
Build artifacts:
build/
├── src/smartbotic-microbit # Main executable
├── lib/ # Compiled libraries
└── external/smartbotic-database/ # Database service (if BUNDLE_DATABASE=ON)
# From the build directory
cd build
# Run with default config (from source tree)
./src/smartbotic-microbit --config ../config/microbit.json
# The server will start on http://localhost:8090
Environment Variables:
Set these before running for proper configuration:
export JWT_SECRET="your-secret-key-change-this"
export DB_ADDRESS="localhost:9004"
export SMTP_HOST="" # Leave empty to disable email
export CALLERAI_API_URL="http://localhost:8080"
export CALLERAI_API_KEY=""
export WEBUI_PATH="../webui/dist"
cd webui
npm install
# Start Vite dev server (with hot reload)
npm run dev
# The dev server will start on http://localhost:5173
# It proxies API requests to the backend
The dev server features:
# Build optimized production bundle
npm run build
# Output will be in webui/dist/
npm run preview
# Build the database service
cd build
cmake .. -DBUNDLE_DATABASE=ON
make -j$(nproc)
# Run the database
cd external/smartbotic-database/src
./smartbotic-database --config ../../../../config/storage.json
cd build
export JWT_SECRET="dev-secret-key"
export WEBUI_PATH="../webui/dist"
./src/smartbotic-microbit --config ../config/microbit.json
cd webui
npm run dev
Now access:
C++ Code Style:
clang-format for formatting (config in .clang-format)TypeScript/React:
After making changes:
# Backend
cd build
make -j$(nproc)
# WebUI (in dev mode, automatically rebuilds)
# Just save your files
Backend Debugging with GDB:
# Build with debug symbols
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc)
# Run with debugger
gdb ./src/smartbotic-microbit
(gdb) run --config ../config/microbit.json
WebUI Debugging:
Tests are currently under development. To enable test building:
cd build
cmake .. -DBUILD_TESTS=ON
make -j$(nproc)
# Run tests
ctest --output-on-failure
Recommended Extensions:
Configuration (.vscode/settings.json):
{
"cmake.buildDirectory": "${workspaceFolder}/build",
"cmake.configureOnOpen": true,
"clangd.arguments": [
"--compile-commands-dir=${workspaceFolder}/build"
],
"editor.formatOnSave": true,
"C_Cpp.intelliSenseEngine": "disabled"
}
CLion has built-in CMake support:
Define the route handler in src/routes/{feature}_routes.cpp:
void setupMyRoutes(httplib::Server& svr, App& app) {
svr.Get("/api/v1/my-endpoint", [&app](const httplib::Request& req, httplib::Response& res) {
// Handle request
});
}
Register routes in src/app.cpp:
#include "routes/my_routes.hpp"
void App::setupRoutes() {
// ...
setupMyRoutes(*httpServer_, *this);
}
Rebuild:
cd build && make
src/stores/my_store.{hpp,cpp}toJson(), fromJson())src/app.{hpp,cpp}config/migrations/webui/src/pages/webui/src/App.tsxwebui/src/api/client.tsProblem: CMake can't find packages
# Make sure all dependencies are installed
sudo apt install -y libprotobuf-dev libgrpc++-dev libssl-dev libcurl4-openssl-dev
# Clear CMake cache
rm -rf build
mkdir build && cd build
cmake ..
Problem: Submodule errors
# Update submodules
git submodule update --init --recursive
Problem: Database connection failed
# Ensure database service is running
ps aux | grep smartbotic-database
# Check the port
netstat -tuln | grep 9004
Problem: WebUI can't connect to API
config/microbit.jsonProblem: JWT errors
# Make sure JWT_SECRET is set
export JWT_SECRET="your-secret-key"
# Check for memory leaks
valgrind --leak-check=full ./src/smartbotic-microbit --config ../config/microbit.json
# Profile performance
valgrind --tool=callgrind ./src/smartbotic-microbit --config ../config/microbit.json
kcachegrind callgrind.out.*
# Record performance
perf record -g ./src/smartbotic-microbit --config ../config/microbit.json
# View report
perf report
# Build with coverage flags
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="--coverage"
make -j$(nproc)
# Run tests
ctest
# Generate coverage report
lcov --capture --directory . --output-file coverage.info
genhtml coverage.info --output-directory coverage_html
The project can be integrated with CI/CD pipelines:
GitHub Actions Example:
name: Build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y build-essential cmake libssl-dev \
libcurl4-openssl-dev libprotobuf-dev protobuf-compiler \
libgrpc++-dev libspdlog-dev nlohmann-json3-dev
- name: Build
run: |
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
- name: Test
run: cd build && ctest --output-on-failure
When contributing to the project:
main