BotServer uses PostgreSQL as its primary database with Diesel ORM for type-safe database operations. The schema is designed to support multi-tenant bot hosting with comprehensive session management, user authentication, and content storage.
## Core Architecture
The database schema follows these design principles:
- **UUID Primary Keys**: All tables use UUIDs for globally unique identifiers
- **Timestamps**: Created/updated timestamps for audit trails
- **Foreign Key Relationships**: Referential integrity between related entities
- **JSON Fields**: Flexible storage for dynamic configuration and metadata
## Schema Categories
### 1. Organization & Bot Management
- **organizations**: Multi-tenant organization support
- **bots**: Bot instances and configurations
- **bot_configuration**: Bot-specific settings and parameters
- **bot_memories**: Persistent key-value storage for bots
### 2. User & Authentication
- **users**: User accounts with secure password storage
- **user_sessions**: Active user sessions with tokens
- **user_login_tokens**: Authentication tokens for login
- **user_preferences**: User-specific settings
### 3. Conversation & Messaging
- **message_history**: Complete conversation history
- **clicks**: User interaction tracking
- **system_automations**: Scheduled tasks and automation rules
### 4. Knowledge Base
- **kb_collections**: Knowledge base collection definitions
- **kb_documents**: Documents stored in collections
- **user_kb_associations**: User access to knowledge bases
- **session_tool_associations**: Tools available in sessions