Тайлбар байхгүй

Fszontagh a947d36b94 fix: system fields display and form handling improvements 6 сар өмнө
common 11cdca7fe9 feat: US-004 - Database Core - Collection Metadata Management 6 сар өмнө
config 8e397f50f8 feat: US-012 - Webserver Core - HTTP/WebSocket Server Setup 6 сар өмнө
database f090c8f381 build: optimize dependencies and add page builder foundation 6 сар өмнө
deploy 85020d57a5 feat: US-011 - Database Configuration and Startup 6 сар өмнө
proto f090c8f381 build: optimize dependencies and add page builder foundation 6 сар өмнө
systemd a55c080d6f fix: improve graceful shutdown for systemd services 6 сар өмнө
tests 4ee2d49c40 feat: US-010 - Database gRPC Server Implementation 6 сар өмнө
webserver 3ad2b63f2a fix: set created_by/updated_by fields and resolve user names 6 сар өмнө
webui a947d36b94 fix: system fields display and form handling improvements 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 f090c8f381 build: optimize dependencies and add page builder foundation 6 сар өмнө
CMakePresets.json 312c855303 feat: US-001 - Project Structure and Build System Setup 6 сар өмнө
README.md 6925a4e41e feat: implement comprehensive RBAC system with webserver services and React WebUI 6 сар өмнө

README.md

SmartBotic CRM

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

Overview

SmartBotic CRM consists of three 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. Web UI: A React + TypeScript + Vite + TailwindCSS admin dashboard for managing workspaces, users, collections, and schema-defined views.

Features

  • Multi-tenant workspace support
  • JWT and API key authentication
  • Schema-driven dynamic forms and views
  • Real-time updates via WebSocket
  • Field-level encryption support
  • Persistent snapshots for data durability
  • Role-based access control

Requirements

  • GCC 11+ or Clang 14+ (C++20 support)
  • CMake 3.20+
  • Ninja build system
  • Node.js 18+ with pnpm
  • libwebsockets development package

Installing Dependencies (Ubuntu/Debian)

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

# libwebsockets
sudo apt install libwebsockets-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

Quick Start

1. Setup and Build

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

# Run setup script
./scripts/setup.sh

2. Start Services

Open three terminal windows:

Terminal 1 - Database:

./scripts/run-db.sh

Terminal 2 - Webserver:

./scripts/run-server.sh

Terminal 3 - WebUI 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 instead of terminal scripts.

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:

    # Database service
    cat > ~/.config/systemd/user/smartbotic-crm-database.service << 'EOF'
    [Unit]
    Description=SmartBotic CRM Database (Development)
    
    [Service]
    Type=simple
    WorkingDirectory=/data/smartbotic-crm
    ExecStart=/data/smartbotic-crm/build/database/smartbotic-crm-database --data-dir %h/.local/share/smartbotic-crm
    Restart=on-failure
    Environment="SMARTBOTIC_DB_PORT=50151"
    
    [Install]
    WantedBy=default.target
    EOF
    
    # Webserver service
    cat > ~/.config/systemd/user/smartbotic-crm-webserver.service << 'EOF'
    [Unit]
    Description=SmartBotic CRM Webserver (Development)
    After=smartbotic-crm-database.service
    Requires=smartbotic-crm-database.service
    
    [Service]
    Type=simple
    WorkingDirectory=/data/smartbotic-crm
    ExecStart=/data/smartbotic-crm/build/webserver/smartbotic-crm-webserver
    EnvironmentFile=%h/.config/smartbotic-crm/server.env
    Restart=on-failure
    
    [Install]
    WantedBy=default.target
    EOF
    
  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=/data/smartbotic-crm/webui/dist
    EOF
    
  4. Enable and start services:

    systemctl --user daemon-reload
    systemctl --user enable smartbotic-crm-database smartbotic-crm-webserver
    systemctl --user start smartbotic-crm-database smartbotic-crm-webserver
    
  5. Check status:

    systemctl --user status smartbotic-crm-database smartbotic-crm-webserver
    
  6. View logs:

    journalctl --user -u smartbotic-crm-database -f
    journalctl --user -u smartbotic-crm-webserver -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
├── webui/              # Web UI (React)
│   ├── src/            # React components
│   └── dist/           # Built static files
├── proto/              # Protocol Buffer definitions
├── common/             # Shared utilities
├── scripts/            # Utility scripts
├── systemd/            # Systemd service files
├── build/              # CMake build output
└── data/               # Runtime data directory

Configuration

Database Node

Environment variables:

  • SMARTBOTIC_DB_PORT - gRPC port (default: 50151)
  • SMARTBOTIC_DB_DATA_DIR - Data directory path

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_JWT_SECRET - JWT signing secret
  • SMARTBOTIC_SERVER_STATIC_PATH - Static files directory

API Endpoints

Authentication

  • POST /api/auth/login - Login with email/password
  • POST /api/auth/refresh - Refresh access token
  • POST /api/auth/logout - Logout

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

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

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
  • 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

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 and customize:

sudo cp systemd/*.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable smartbotic-database smartbotic-webserver
sudo systemctl start smartbotic-database smartbotic-webserver

Environment Variables

Create /etc/smartbotic/server.env:

SMARTBOTIC_SERVER_JWT_SECRET=your-secure-secret-key
SMARTBOTIC_SERVER_STATIC_PATH=/opt/smartbotic-crm/webui/dist

License

Proprietary - All rights reserved.