Без опису

Claude AI fa22971d80 docs: update README to reflect current codebase state #1 4 місяців тому
common 11cdca7fe9 feat: US-004 - Database Core - Collection Metadata Management 6 місяців тому
config 8e397f50f8 feat: US-012 - Webserver Core - HTTP/WebSocket Server Setup 6 місяців тому
database ec47b89e95 fix: use SMARTBOTIC_CRM_ prefix for all env vars and fix LLM config loading 6 місяців тому
deploy 85020d57a5 feat: US-011 - Database Configuration and Startup 6 місяців тому
llm ec47b89e95 fix: use SMARTBOTIC_CRM_ prefix for all env vars and fix LLM config loading 6 місяців тому
proto e9f57b9a97 feat: implement LLM assistant system with chat UI 6 місяців тому
systemd ec47b89e95 fix: use SMARTBOTIC_CRM_ prefix for all env vars and fix LLM config loading 6 місяців тому
tests 4ee2d49c40 feat: US-010 - Database gRPC Server Implementation 6 місяців тому
webserver ec47b89e95 fix: use SMARTBOTIC_CRM_ prefix for all env vars and fix LLM config loading 6 місяців тому
webui a2f52f92b1 fix: correct port configuration to avoid conflicts 6 місяців тому
.clang-format 312c855303 feat: US-001 - Project Structure and Build System Setup 6 місяців тому
.clang-tidy 312c855303 feat: US-001 - Project Structure and Build System Setup 6 місяців тому
.gitignore 6925a4e41e feat: implement comprehensive RBAC system with webserver services and React WebUI 6 місяців тому
CMakeLists.txt e9f57b9a97 feat: implement LLM assistant system with chat UI 6 місяців тому
CMakePresets.json 312c855303 feat: US-001 - Project Structure and Build System Setup 6 місяців тому
README.md fa22971d80 docs: update README to reflect current codebase state #1 4 місяців тому

README.md

SmartBotic CRM

A flexible, schema-driven CRM foundation built with C++20 and React.

Overview

SmartBotic CRM consists of four main components:

  1. Database Node: An in-memory document database with gRPC interface, supporting collections, JSON documents with metadata, relations, encryption, TTL, and persistent snapshots.

  2. Web Server Node: A REST API server with WebSocket support that communicates with the database via gRPC, handling authentication (JWT + API keys), workspace/user management, and real-time updates.

  3. LLM Service Node: A gRPC service providing AI capabilities with support for multiple LLM providers (OpenAI, Anthropic), session management, and tool execution.

  4. Web UI: A React 19 + TypeScript + Vite + TailwindCSS admin dashboard for managing workspaces, users, collections, and schema-defined views.

Features

Core CRM Features

  • Multi-tenant workspace support with groups and memberships
  • JWT and API key authentication
  • Schema-driven dynamic forms and views
  • Custom pages with markdown support
  • Real-time updates via WebSocket
  • Field-level encryption support
  • Persistent snapshots for data durability
  • Role-based access control with permissions
  • Document collections with flexible schemas

AI/LLM Integration

  • Multi-provider LLM support (OpenAI, Anthropic)
  • Session-based conversation management
  • Streaming and non-streaming message support
  • BYOK (Bring Your Own Key) workspace configuration
  • Provider health monitoring
  • Tool/function calling support

Requirements

  • GCC 11+ or Clang 14+ (C++20 support)
  • CMake 3.22+
  • Ninja build system
  • Node.js 18+ with pnpm
  • System libraries (see below)

Installing Dependencies (Ubuntu/Debian)

# Build tools
sudo apt install cmake ninja-build build-essential pkg-config

# System libraries
sudo apt install libspdlog-dev nlohmann-json3-dev \
                 libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \
                 libwebsockets-dev libssl-dev

# Node.js (via nvm recommended)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install 18
npm install -g pnpm

Note: cpp-httplib and jwt-cpp are automatically fetched via CMake FetchContent.

Quick Start

1. Build the Project

# Clone the repository
git clone https://github.com/fszontagh/smartbotic-crm.git
cd smartbotic-crm

# Configure and build C++ components
cmake --preset release
cmake --build build -j$(nproc)

# Build WebUI
cd webui
pnpm install
pnpm build
cd ..

2. Start Services

Open four terminal windows:

Terminal 1 - Database:

./build/database/smartbotic-crm-database --data-dir ./data

Terminal 2 - LLM Service (optional):

./build/llm/smartbotic-crm-llm

Terminal 3 - Webserver:

# Set required environment variables
export SMARTBOTIC_SERVER_JWT_SECRET=your-secret-key-change-in-production
export SMARTBOTIC_SERVER_STATIC_PATH=./webui/dist

./build/webserver/smartbotic-crm-webserver

Terminal 4 - WebUI Development (optional, for development):

cd webui
pnpm dev

3. Bootstrap the System

On first run, create the admin user:

curl -X POST http://localhost:18080/api/bootstrap \
  -H "Content-Type: application/json" \
  -d '{"email": "admin@example.com", "password": "your-password", "name": "Admin"}'

4. Access the Application

Development with Systemd User Services

For persistent local testing, use systemd user services. Example service files are available in the systemd/ directory.

Setup User Services

  1. Create the config directory:

    mkdir -p ~/.config/systemd/user ~/.config/smartbotic-crm ~/.local/share/smartbotic-crm
    
  2. Copy and customize the service files (adjust paths to match your setup):

    # Copy service files
    cp systemd/*.service ~/.config/systemd/user/
    
    # Edit the WorkingDirectory and ExecStart paths in each service file
    nano ~/.config/systemd/user/smartbotic-db.service
    
  3. Create the config file:

    cat > ~/.config/smartbotic-crm/server.env << 'EOF'
    SMARTBOTIC_SERVER_JWT_SECRET=dev-testing-secret-change-in-production
    SMARTBOTIC_SERVER_STATIC_PATH=/path/to/smartbotic-crm/webui/dist
    SMARTBOTIC_SERVER_LLM_ADDRESS=localhost:50052
    EOF
    
  4. Enable and start services:

    systemctl --user daemon-reload
    systemctl --user enable smartbotic-db
    systemctl --user start smartbotic-db
    # Add other services as needed
    
  5. Check status:

    systemctl --user status smartbotic-db
    
  6. View logs:

    journalctl --user -u smartbotic-db -f
    

Data Locations (User Services)

  • Config: ~/.config/smartbotic-crm/
  • Data: ~/.local/share/smartbotic-crm/
  • Logs: journalctl --user

Project Structure

smartbotic-crm/
├── database/           # Database node (C++)
│   ├── include/        # Header files
│   └── src/            # Source files
├── webserver/          # Webserver node (C++)
│   ├── include/        # Header files
│   └── src/            # Source files
├── llm/                # LLM service node (C++)
│   ├── include/        # Header files
│   └── src/            # Source files
├── webui/              # Web UI (React)
│   ├── src/            # React components
│   └── dist/           # Built static files
├── proto/              # Protocol Buffer definitions
├── common/             # Shared C++ utilities
├── config/             # Configuration files
├── deploy/             # Deployment configurations
├── systemd/            # Systemd service files
├── tests/              # Test files
├── build/              # CMake build output
└── data/               # Runtime data directory

Configuration

Database Node

Environment variables:

  • SMARTBOTIC_DB_PORT - gRPC port (default: 50151)

Command line options:

  • --data-dir - Data directory path for snapshots

Webserver Node

Environment variables:

  • SMARTBOTIC_SERVER_HTTP_PORT - HTTP port (default: 18080)
  • SMARTBOTIC_SERVER_WS_PORT - WebSocket port (default: 18081)
  • SMARTBOTIC_SERVER_DATABASE_HOST - Database host (default: localhost)
  • SMARTBOTIC_SERVER_DATABASE_PORT - Database port (default: 50151)
  • SMARTBOTIC_SERVER_LLM_ADDRESS - LLM service address (default: localhost:50052)
  • SMARTBOTIC_SERVER_JWT_SECRET - JWT signing secret (required)
  • SMARTBOTIC_SERVER_STATIC_PATH - Static files directory (required)

LLM Service Node

Environment variables:

  • SMARTBOTIC_LLM_PORT - gRPC port (default: 50052)
  • SMARTBOTIC_LLM_DATABASE_HOST - Database host (default: localhost)
  • SMARTBOTIC_LLM_DATABASE_PORT - Database port (default: 50151)

API Endpoints

System

  • GET /api/health - Health check
  • GET /api/version - Version information
  • POST /api/bootstrap - Create first admin user

Authentication

  • POST /api/auth/login - Login with email/password
  • POST /api/auth/refresh - Refresh access token
  • POST /api/auth/logout - Logout
  • GET /api/auth/me - Get current user info

Users

  • POST /api/users - Create user (superadmin)
  • GET /api/users - List users
  • GET /api/users/:id - Get user
  • PATCH /api/users/:id - Update user
  • DELETE /api/users/:id - Delete user
  • POST /api/users/:id/api-keys - Create API key
  • GET /api/users/:id/api-keys - List API keys
  • DELETE /api/users/:id/api-keys/:keyId - Revoke API key

Workspaces

  • POST /api/workspaces - Create workspace
  • GET /api/workspaces - List workspaces
  • GET /api/workspaces/:id - Get workspace
  • PATCH /api/workspaces/:id - Update workspace
  • DELETE /api/workspaces/:id - Delete workspace

Groups & Memberships

  • POST /api/workspaces/:wid/groups - Create group
  • GET /api/workspaces/:wid/groups - List groups
  • GET /api/workspaces/:wid/groups/:id - Get group
  • PATCH /api/workspaces/:wid/groups/:id - Update group
  • DELETE /api/workspaces/:wid/groups/:id - Delete group
  • POST /api/workspaces/:wid/members - Add member
  • GET /api/workspaces/:wid/members - List members
  • GET /api/workspaces/:wid/members/:userId - Get member
  • PUT /api/workspaces/:wid/members/:userId - Update member groups
  • DELETE /api/workspaces/:wid/members/:userId - Remove member

Collections

  • POST /api/workspaces/:wid/collections - Create collection
  • GET /api/workspaces/:wid/collections - List collections
  • GET /api/workspaces/:wid/collections/:name - Get collection
  • PUT /api/workspaces/:wid/collections/:name - Update collection
  • DELETE /api/workspaces/:wid/collections/:name - Delete collection

Documents

  • POST /api/workspaces/:wid/collections/:name/documents - Create document
  • GET /api/workspaces/:wid/collections/:name/documents - List documents
  • GET /api/workspaces/:wid/collections/:name/documents/:id - Get document
  • PUT /api/workspaces/:wid/collections/:name/documents/:id - Update document
  • PATCH /api/workspaces/:wid/collections/:name/documents/:id - Partial update
  • DELETE /api/workspaces/:wid/collections/:name/documents/:id - Delete document

Views

  • POST /api/workspaces/:wid/views - Create view
  • GET /api/workspaces/:wid/views - List views
  • GET /api/workspaces/:wid/views/:id - Get view
  • PATCH /api/workspaces/:wid/views/:id - Update view
  • DELETE /api/workspaces/:wid/views/:id - Delete view

Pages

  • POST /api/workspaces/:wid/pages - Create page
  • GET /api/workspaces/:wid/pages - List pages
  • GET /api/workspaces/:wid/pages/sidebar - List sidebar pages
  • GET /api/workspaces/:wid/pages/slug/:slug - Get page by slug
  • GET /api/workspaces/:wid/pages/:id - Get page
  • PATCH /api/workspaces/:wid/pages/:id - Update page
  • PATCH /api/workspaces/:wid/pages/:id/share - Update page sharing
  • DELETE /api/workspaces/:wid/pages/:id - Delete page

LLM (AI Features)

  • POST /api/llm/sessions - Create LLM session
  • GET /api/llm/sessions - List sessions
  • GET /api/llm/sessions/:id - Get session
  • DELETE /api/llm/sessions/:id - Delete session
  • POST /api/llm/sessions/:id/messages - Send message
  • POST /api/llm/sessions/:id/stream - Stream message
  • POST /api/llm/sessions/:id/clear - Clear messages
  • GET /api/llm/providers - List providers
  • GET /api/llm/models - List models
  • POST /api/llm/models/refresh - Refresh models
  • GET /api/llm/providers/:id/health - Provider health
  • GET /api/llm/admin/providers - Admin: List providers
  • POST /api/llm/admin/providers - Admin: Create provider
  • PUT /api/llm/admin/providers/:id - Admin: Update provider
  • DELETE /api/llm/admin/providers/:id - Admin: Delete provider
  • PUT /api/llm/workspaces/:wid/key - Set workspace LLM key (BYOK)
  • GET /api/llm/workspaces/:wid/key - Get workspace LLM key
  • DELETE /api/llm/workspaces/:wid/key - Delete workspace LLM key

WebSocket Protocol

Connect to ws://localhost:18081/ws and authenticate:

{ "type": "auth", "token": "your-jwt-token" }

Subscribe to collection changes:

{ "type": "subscribe", "workspace_id": "...", "collection": "name" }

Receive document events:

{
  "type": "document",
  "action": "create|update|delete",
  "workspace_id": "...",
  "collection": "...",
  "document_id": "...",
  "data": { ... }
}

Development

Building

# Configure
cmake --preset release

# Build
cmake --build build -j$(nproc)

Code Quality

# C++ formatting
clang-format -i database/src/*.cpp webserver/src/*.cpp

# C++ linting
clang-tidy database/src/*.cpp webserver/src/*.cpp

# WebUI
cd webui
pnpm typecheck
pnpm lint

Production Deployment

Using Systemd

Copy the service files from the deploy/ directory and customize for your environment:

# Copy service files
sudo cp deploy/*.service /etc/systemd/system/

# Edit service files to match your installation paths
sudo nano /etc/systemd/system/smartbotic-db.service

# Reload systemd
sudo systemctl daemon-reload

# Enable services
sudo systemctl enable smartbotic-db
# Enable other services as needed

# Start services
sudo systemctl start smartbotic-db

Environment Variables

Create configuration files in /etc/smartbotic/:

Database: Generally uses command-line arguments for data directory Webserver (/etc/smartbotic/webserver.env):

SMARTBOTIC_SERVER_JWT_SECRET=your-secure-secret-key-min-32-chars
SMARTBOTIC_SERVER_STATIC_PATH=/opt/smartbotic-crm/webui/dist
SMARTBOTIC_SERVER_LLM_ADDRESS=localhost:50052

LLM Service (/etc/smartbotic/llm.env):

SMARTBOTIC_LLM_DATABASE_HOST=localhost
SMARTBOTIC_LLM_DATABASE_PORT=50151

License

Proprietary - All rights reserved.