botserver/docs/src/appendix-i
2025-10-25 15:59:06 -03:00
..
README.md Revise documentation in Chapter 01 to improve clarity and structure, including updates to the installation instructions and session management overview. 2025-10-25 15:59:06 -03:00
relationships.md Add comprehensive documentation for GeneralBots, including keyword references, templates, and user guides 2025-10-25 14:50:14 -03:00
schema.md Add comprehensive documentation for GeneralBots, including keyword references, templates, and user guides 2025-10-25 14:50:14 -03:00
tables.md Add comprehensive documentation for GeneralBots, including keyword references, templates, and user guides 2025-10-25 14:50:14 -03:00

AppendixI Database Model

The core database schema for GeneralBots is defined in src/shared/models.rs. It uses Diesel with SQLite (or PostgreSQL) and includes the following primary tables:

Table Description
users Stores user accounts, authentication tokens, and profile data.
sessions Tracks active BotSession instances, their start/end timestamps, and associated user.
knowledge_bases Metadata for each .gbkb collection (name, vector store configuration, creation date).
messages Individual chat messages (role=user/assistant, content, timestamp, linked to a session).
tools Registered custom tools per session (name, definition JSON, activation status).
files References to files managed by the .gbdrive package (path, size, MIME type, storage location).

Relationships

  • User ↔ Sessions Onetomany: a user can have many sessions.
  • Session ↔ Messages Onetomany: each session contains a sequence of messages.
  • Session ↔ KnowledgeBase Manytoone: a session uses a single knowledge base at a time.
  • Session ↔ Tools Onetomany: tools are scoped to the session that registers them.
  • File ↔ KnowledgeBase Optional link for documents stored in a knowledge base.

Key Fields (excerpt)

pub struct User {
    pub id: i32,
    pub username: String,
    pub email: String,
    pub password_hash: String,
    pub created_at: NaiveDateTime,
}

pub struct Session {
    pub id: i32,
    pub user_id: i32,
    pub started_at: NaiveDateTime,
    pub last_active: NaiveDateTime,
    pub knowledge_base_id: i32,
}

pub struct Message {
    pub id: i32,
    pub session_id: i32,
    pub role: String, // "user" or "assistant"
    pub content: String,
    pub timestamp: NaiveDateTime,
}

The schema is automatically migrated by Diesel when the server starts. For custom extensions, add new tables to models.rs and run diesel migration generate <name>.