This document describes the architecture and design of the Smartbotic Microbit platform.
Smartbotic Microbit is a multi-tier application consisting of three primary components:
┌─────────────────┐
│ Web Browser │ (React/TypeScript SPA)
└────────┬────────┘
│ HTTP/REST
▼
┌─────────────────┐
│ Microbit Service│ (C++ HTTP Server)
└────────┬────────┘
│ gRPC
▼
┌─────────────────┐
│ Database Service│ (Custom Storage Engine)
└─────────────────┘
The main application server implemented in C++20, providing RESTful API endpoints and business logic.
App (src/app.cpp)
HTTP Layer
cpp-httplib for HTTP serversrc/
├── main.cpp # Application entry point
├── app.{hpp,cpp} # Main app class
├── routes/ # HTTP route handlers
│ ├── auth_routes # Authentication endpoints
│ ├── user_routes # User management
│ ├── workspace_routes # Workspace CRUD
│ ├── assistant_routes # AI assistant management
│ ├── calendar_routes # Calendar & appointments
│ ├── invitation_routes # Team invitations
│ └── settings_routes # Settings management
├── services/ # Business logic layer
│ ├── auth_service # Authentication logic
│ ├── workspace_service # Workspace operations
│ ├── invitation_service# Invitation workflow
│ ├── assistant_service # Assistant management
│ └── calendar_service # Calendar operations
└── stores/ # Data access layer
├── user_store # User data operations
├── workspace_store # Workspace data
├── assistant_store # Assistant data
├── calendar_store # Calendar data
├── invitation_store # Invitation data
└── settings_store # Settings data
lib/
├── auth/ # Authentication & authorization
│ ├── jwt_utils # JWT token generation/validation
│ ├── bcrypt_utils # Password hashing
│ └── auth_middleware # Request authentication
├── common/ # Common utilities
│ ├── config_loader # Configuration parsing
│ ├── logging # Logging utilities
│ └── utils # General utilities
├── smtp/ # Email sending
│ └── smtp_client # SMTP client implementation
└── callerai/ # CallerAI integration
└── callerai_client # CallerAI API client
Custom database service providing persistent storage via gRPC interface.
Location: external/smartbotic-database (git submodule)
Key Features:
Client Interface: smartbotic::database::Client
Modern single-page application built with React and TypeScript.
webui/
├── src/
│ ├── main.tsx # Application entry point
│ ├── App.tsx # Root component & routing
│ ├── api/ # Backend API client
│ ├── pages/ # Page components
│ │ ├── auth/ # Login, Register
│ │ ├── dashboard/ # Main dashboard
│ │ ├── members/ # Team member management
│ │ ├── invitations/ # Invitation management
│ │ ├── assistants/ # AI assistant pages
│ │ └── calendar/ # Calendar & appointments
│ ├── components/ # Reusable UI components
│ └── stores/ # Client-side state (Zustand)
├── package.json
└── vite.config.ts
Key Technologies:
User
id: Unique identifier (usr_xxx)email: User email (unique)password_hash: BCrypt hashed passworddisplay_name: User's display namestatus: Account status (active, suspended)Workspace
id: Unique identifier (ws_xxx)name: Workspace namecompany_name: Company nameaddress: Physical addressphone: Contact phone numberWorkspaceMember
id: Unique identifier (wm_xxx)workspace_id: Reference to workspaceuser_id: Reference to userrole: Member role (owner, admin, member, guest)Assistant (AI Voice Assistant)
id: Unique identifier (ast_xxx)workspace_id: Owning workspacename: Assistant namephone_number: Phone number for callsinstructions: AI behavior instructionscallerai_id: CallerAI platform IDstatus: Active/inactive statusCalendar
id: Unique identifier (cal_xxx)workspace_id: Owning workspacename: Calendar nameassistant_id: Associated assistant (optional)TimeSlot
id: Unique identifier (ts_xxx)calendar_id: Parent calendarday_of_week: Day (0=Sunday, 6=Saturday)start_time: Slot start time (HH:MM)end_time: Slot end time (HH:MM)Appointment
id: Unique identifier (apt_xxx)calendar_id: Associated calendarstart_time: Appointment start (ISO 8601)end_time: Appointment end (ISO 8601)customer_name, customer_phone, customer_email: Customer infonotes: Appointment notesstatus: pending, confirmed, cancelledInvitation
id: Unique identifier (inv_xxx)workspace_id: Target workspaceemail: Invitee emailrole: Intended roletoken: Unique invitation tokenstatus: pending, accepted, rejectedSession
id: Unique identifier (ses_xxx)user_id: Associated userRegistration: POST /api/v1/auth/register
Login: POST /api/v1/auth/login
Token Refresh: POST /api/v1/auth/refresh
JWT Claims:
sub: User IDemail: User emailrole: Global role (currently "user")exp: Expiration timestampWorkspace Roles (per workspace):
Role Hierarchy:
Owner > Admin > Member > Guest
Request → Auth Middleware → Route Handler
│
├─ Extract JWT from Authorization header
├─ Validate token signature
├─ Check expiration
├─ Store AuthContext (user_id, email, role)
└─ Continue or reject (401)
Route handlers check workspace membership and roles as needed.
JSON-based configuration with environment variable substitution:
{
"database": {
"rpc_address": "${DB_ADDRESS:localhost:9004}"
},
"auth": {
"jwt_secret": "${JWT_SECRET:change-me-in-production}"
}
}
Syntax: ${VAR_NAME:default_value}
ConfigLoader class:
config/microbit.json/etc/smartbotic/microbit.json/etc/smartbotic/smartbotic.env (sourced by systemd)Purpose: Create and manage AI-powered voice assistants
Client: callerai::CallerAIClient
Operations:
Configuration:
callerai.api_url: CallerAI API endpointcallerai.api_key: API authentication keycallerai.timeout_sec: Request timeoutPurpose: Send email notifications (invitations, etc.)
Client: smtp::SmtpClient
Operations:
Configuration:
smtp.host: SMTP server hostnamesmtp.port: SMTP server port (default 587)smtp.username: SMTP authentication usernamesmtp.password: SMTP authentication passwordsmtp.from_address: Sender email addresssmtp.use_tls: Enable TLS (recommended)HTTP Request
│
├─ CORS Middleware (if enabled)
│ └─ Add CORS headers
│
├─ Rate Limiting (if enabled)
│ └─ Check request count
│
├─ Auth Middleware (protected routes)
│ └─ Validate JWT token
│
└─ Route Handler
├─ Parse request body
├─ Validate input
├─ Check authorization (workspace roles)
├─ Call service layer
├─ Access data via stores
└─ Return JSON response
Standard error responses:
{
"error": "Error message"
}
HTTP Status Codes:
200 OK - Success201 Created - Resource created400 Bad Request - Invalid input401 Unauthorized - Missing/invalid token403 Forbidden - Insufficient permissions404 Not Found - Resource not found500 Internal Server Error - Server errorThe HTTP server can serve the WebUI static files:
{
"http": {
"static_files": {
"enabled": true,
"path": "webui/dist"
}
}
}
When enabled, all non-API routes serve static files from the configured path.
CMakeLists.txt # Root build configuration
├── cmake/
│ ├── CompilerFlags.cmake # Compiler settings
│ ├── FindPackages.cmake # External package detection
│ └── Dependencies.cmake # Dependency management
├── lib/CMakeLists.txt # Library builds
│ ├── auth/
│ ├── common/
│ ├── smtp/
│ └── callerai/
└── src/CMakeLists.txt # Main application build
CMAKE_BUILD_TYPE: Release|Debug (default: Release)BUILD_TESTS: Build tests (default: OFF)BUNDLE_DATABASE: Include database service in build (default: OFF)System Libraries:
Bundled Libraries (via CMake FetchContent):
Two systemd services run the platform:
smartbotic-database.service
/var/lib/smartbotic/database/smartbotic-microbit.service
/opt/smartbotic/
├── bin/
│ ├── smartbotic-database
│ └── smartbotic-microbit
└── share/smartbotic/
└── nginx/
└── smartbotic.conf.template
/etc/smartbotic/
├── database.json
├── microbit.json
└── smartbotic.env
/var/lib/smartbotic/
├── database/
│ ├── storage/
│ └── migrations/
└── microbit/
└── webui/
/var/log/smartbotic/
├── database.log
└── microbit.log
Browser → Nginx (443) → Microbit Service (8090)
Nginx provides:
Configuration template: packaging/nginx/smartbotic.conf.template
Log Levels:
trace: Detailed debug informationdebug: Debug informationinfo: General information (default)warn: Warning messageserror: Error conditionscritical: Critical errorsConfiguration: log_level in config file
Output:
/var/log/smartbotic/microbit.log)rate_limit.requests_per_minuteBUILD_TESTS)The Smartbotic Microbit platform follows a layered architecture with clear separation of concerns:
This design promotes maintainability, testability, and extensibility while providing a robust foundation for workspace management and AI assistant deployment.