|
|
@@ -4,31 +4,44 @@ A flexible, schema-driven CRM foundation built with C++20 and React.
|
|
|
|
|
|
## Overview
|
|
|
|
|
|
-SmartBotic CRM consists of three main components:
|
|
|
+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. **Web UI**: A React + TypeScript + Vite + TailwindCSS admin dashboard for managing workspaces, users, collections, and schema-defined views.
|
|
|
+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
|
|
|
|
|
|
-- Multi-tenant workspace support
|
|
|
+### 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
|
|
|
+- 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.20+
|
|
|
+- CMake 3.22+
|
|
|
- Ninja build system
|
|
|
- Node.js 18+ with pnpm
|
|
|
-- libwebsockets development package
|
|
|
+- System libraries (see below)
|
|
|
|
|
|
### Installing Dependencies (Ubuntu/Debian)
|
|
|
|
|
|
@@ -36,8 +49,10 @@ SmartBotic CRM consists of three main components:
|
|
|
# Build tools
|
|
|
sudo apt install cmake ninja-build build-essential pkg-config
|
|
|
|
|
|
-# libwebsockets
|
|
|
-sudo apt install libwebsockets-dev
|
|
|
+# 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
|
|
|
@@ -45,34 +60,52 @@ nvm install 18
|
|
|
npm install -g pnpm
|
|
|
```
|
|
|
|
|
|
+**Note**: cpp-httplib and jwt-cpp are automatically fetched via CMake FetchContent.
|
|
|
+
|
|
|
## Quick Start
|
|
|
|
|
|
-### 1. Setup and Build
|
|
|
+### 1. Build the Project
|
|
|
|
|
|
```bash
|
|
|
# Clone the repository
|
|
|
-git clone https://github.com/smartbotic/smartbotic-crm.git
|
|
|
+git clone https://github.com/fszontagh/smartbotic-crm.git
|
|
|
cd smartbotic-crm
|
|
|
|
|
|
-# Run setup script
|
|
|
-./scripts/setup.sh
|
|
|
+# 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 three terminal windows:
|
|
|
+Open four terminal windows:
|
|
|
|
|
|
**Terminal 1 - Database:**
|
|
|
```bash
|
|
|
-./scripts/run-db.sh
|
|
|
+./build/database/smartbotic-crm-database --data-dir ./data
|
|
|
```
|
|
|
|
|
|
-**Terminal 2 - Webserver:**
|
|
|
+**Terminal 2 - LLM Service (optional):**
|
|
|
```bash
|
|
|
-./scripts/run-server.sh
|
|
|
+./build/llm/smartbotic-crm-llm
|
|
|
```
|
|
|
|
|
|
-**Terminal 3 - WebUI Development:**
|
|
|
+**Terminal 3 - Webserver:**
|
|
|
+```bash
|
|
|
+# 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):**
|
|
|
```bash
|
|
|
cd webui
|
|
|
pnpm dev
|
|
|
@@ -90,13 +123,14 @@ curl -X POST http://localhost:18080/api/bootstrap \
|
|
|
|
|
|
### 4. Access the Application
|
|
|
|
|
|
-- **WebUI**: http://localhost:3200
|
|
|
-- **API**: http://localhost:18080
|
|
|
+- **WebUI (production build)**: http://localhost:18080
|
|
|
+- **WebUI (development)**: http://localhost:3200
|
|
|
+- **API**: http://localhost:18080/api
|
|
|
- **WebSocket**: ws://localhost:18081/ws
|
|
|
|
|
|
## Development with Systemd User Services
|
|
|
|
|
|
-For persistent local testing, use systemd user services instead of terminal scripts.
|
|
|
+For persistent local testing, use systemd user services. Example service files are available in the `systemd/` directory.
|
|
|
|
|
|
### Setup User Services
|
|
|
|
|
|
@@ -105,67 +139,40 @@ For persistent local testing, use systemd user services instead of terminal scri
|
|
|
mkdir -p ~/.config/systemd/user ~/.config/smartbotic-crm ~/.local/share/smartbotic-crm
|
|
|
```
|
|
|
|
|
|
-2. Copy and customize the service files:
|
|
|
+2. Copy and customize the service files (adjust paths to match your setup):
|
|
|
```bash
|
|
|
-# 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
|
|
|
+# Copy service files
|
|
|
+cp systemd/*.service ~/.config/systemd/user/
|
|
|
|
|
|
-# 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
|
|
|
+# Edit the WorkingDirectory and ExecStart paths in each service file
|
|
|
+nano ~/.config/systemd/user/smartbotic-db.service
|
|
|
```
|
|
|
|
|
|
3. Create the config file:
|
|
|
```bash
|
|
|
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
|
|
|
+SMARTBOTIC_SERVER_STATIC_PATH=/path/to/smartbotic-crm/webui/dist
|
|
|
+SMARTBOTIC_SERVER_LLM_ADDRESS=localhost:50052
|
|
|
EOF
|
|
|
```
|
|
|
|
|
|
4. Enable and start services:
|
|
|
```bash
|
|
|
systemctl --user daemon-reload
|
|
|
-systemctl --user enable smartbotic-crm-database smartbotic-crm-webserver
|
|
|
-systemctl --user start smartbotic-crm-database smartbotic-crm-webserver
|
|
|
+systemctl --user enable smartbotic-db
|
|
|
+systemctl --user start smartbotic-db
|
|
|
+# Add other services as needed
|
|
|
```
|
|
|
|
|
|
5. Check status:
|
|
|
```bash
|
|
|
-systemctl --user status smartbotic-crm-database smartbotic-crm-webserver
|
|
|
+systemctl --user status smartbotic-db
|
|
|
```
|
|
|
|
|
|
6. View logs:
|
|
|
```bash
|
|
|
-journalctl --user -u smartbotic-crm-database -f
|
|
|
-journalctl --user -u smartbotic-crm-webserver -f
|
|
|
+journalctl --user -u smartbotic-db -f
|
|
|
```
|
|
|
|
|
|
### Data Locations (User Services)
|
|
|
@@ -184,13 +191,18 @@ smartbotic-crm/
|
|
|
├── 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 utilities
|
|
|
-├── scripts/ # Utility scripts
|
|
|
+├── 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
|
|
|
```
|
|
|
@@ -201,7 +213,9 @@ smartbotic-crm/
|
|
|
|
|
|
Environment variables:
|
|
|
- `SMARTBOTIC_DB_PORT` - gRPC port (default: 50151)
|
|
|
-- `SMARTBOTIC_DB_DATA_DIR` - Data directory path
|
|
|
+
|
|
|
+Command line options:
|
|
|
+- `--data-dir` - Data directory path for snapshots
|
|
|
|
|
|
### Webserver Node
|
|
|
|
|
|
@@ -210,15 +224,29 @@ Environment variables:
|
|
|
- `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
|
|
|
+- `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)
|
|
|
@@ -226,6 +254,9 @@ Environment variables:
|
|
|
- `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
|
|
|
@@ -234,6 +265,18 @@ Environment variables:
|
|
|
- `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
|
|
|
@@ -246,6 +289,7 @@ Environment variables:
|
|
|
- `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
|
|
|
@@ -255,6 +299,36 @@ Environment variables:
|
|
|
- `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:
|
|
|
@@ -313,22 +387,42 @@ pnpm lint
|
|
|
|
|
|
### Using Systemd
|
|
|
|
|
|
-Copy the service files and customize:
|
|
|
+Copy the service files from the `deploy/` directory and customize for your environment:
|
|
|
|
|
|
```bash
|
|
|
-sudo cp systemd/*.service /etc/systemd/system/
|
|
|
+# 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
|
|
|
-sudo systemctl enable smartbotic-database smartbotic-webserver
|
|
|
-sudo systemctl start smartbotic-database smartbotic-webserver
|
|
|
+
|
|
|
+# Enable services
|
|
|
+sudo systemctl enable smartbotic-db
|
|
|
+# Enable other services as needed
|
|
|
+
|
|
|
+# Start services
|
|
|
+sudo systemctl start smartbotic-db
|
|
|
```
|
|
|
|
|
|
### Environment Variables
|
|
|
|
|
|
-Create `/etc/smartbotic/server.env`:
|
|
|
+Create configuration files in `/etc/smartbotic/`:
|
|
|
|
|
|
+**Database**: Generally uses command-line arguments for data directory
|
|
|
+**Webserver** (`/etc/smartbotic/webserver.env`):
|
|
|
```bash
|
|
|
-SMARTBOTIC_SERVER_JWT_SECRET=your-secure-secret-key
|
|
|
+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`):
|
|
|
+```bash
|
|
|
+SMARTBOTIC_LLM_DATABASE_HOST=localhost
|
|
|
+SMARTBOTIC_LLM_DATABASE_PORT=50151
|
|
|
```
|
|
|
|
|
|
## License
|