Modelo de Dados
Diagrama ER
erDiagram
User {
int id PK
string email UK
string first_name
string last_name
string role "admin|student"
boolean is_active
}
School {
int id PK
string name
string slug UK
int owner_id FK
boolean is_active
}
Course {
int id PK
int school_id FK
string name
string purchase_url
boolean is_active
}
Agent {
int id PK
int course_id FK "OneToOne"
string name
uuid access_request_token UK
text system_prompt
json suggested_prompts
boolean enable_follow_up_suggestions
int credits_per_student "default 50"
boolean is_trained
boolean is_active
}
AgentDocument {
int id PK
int agent_id FK
string file
string file_type "pdf|markdown|txt|csv|xlsx|docx|srt"
boolean is_processed
}
AgentSkill {
int id PK
int agent_id FK
string name
text description
string skill_type "builtin|custom"
json config
boolean is_active
int created_by_id FK
}
AgentMCPServer {
int id PK
int agent_id FK
string name
text description
string server_url
string transport_type "stdio|sse|streamable_http"
json config
boolean is_active
int created_by_id FK
}
StudentSkillOverride {
int id PK
int student_id FK
int skill_id FK
boolean is_active
}
AccessRequest {
int id PK
int agent_id FK
string full_name
string email
string whatsapp
string status "pending|approved|denied"
int reviewed_by_id FK
datetime reviewed_at
}
StudentMCPServer {
int id PK
int student_id FK
int agent_id FK
string name
string server_url
string transport_type
json config
boolean is_active
}
StudentSkill {
int id PK
int student_id FK
int agent_id FK
string name
text description
boolean is_active
}
Enrollment {
int id PK
int student_id FK
int course_id FK
int school_id FK
boolean is_active
}
ChatSession {
int id PK
int student_id FK
int agent_id FK
string title
}
ChatMessage {
int id PK
int session_id FK
string role "user|assistant"
text content
string model_used
int token_count
int input_token_count
decimal message_cost
decimal estimated_time_saved_minutes
json suggested_follow_ups
}
ChatAttachment {
int id PK
int message_id FK
string file
string file_type "pdf|txt|md|csv|xlsx|srt"
string original_filename
text extracted_text
}
ChatMessageFeedback {
int id PK
int message_id FK "OneToOne"
int student_id FK
string feedback_type "like|dislike"
}
Subscription {
int id PK
int school_id FK "OneToOne"
int plan_ref_id FK
string plan
boolean is_active
datetime trial_ends_at
}
Plan {
int id PK
string name
string slug UK
decimal price_monthly
int max_students
int max_courses
int max_messages_per_month
}
AIModel {
int id PK
string model_code UK
decimal cost_per_1m_input_tokens
decimal cost_per_1m_output_tokens
decimal minutes_per_100_tokens
boolean supports_vision
}
StudentMessageCredit {
int id PK
int student_id FK
int school_id FK
int agent_id FK
int messages_used
int messages_limit
int extra_credits
date period_start
date period_end
}
MessagePackage {
int id PK
string name
int messages
decimal price
boolean is_active
}
MessagePurchase {
int id PK
int student_id FK
int school_id FK
int package_id FK
int agent_id FK
int messages_amount
decimal price_paid
}
StudentAchievement {
int id PK
int student_id FK
string achievement_id
datetime unlocked_at
}
User ||--o{ School : "owns"
School ||--o{ Course : "has"
Course ||--|| Agent : "has one"
Agent ||--o{ AgentDocument : "has"
Agent ||--o{ AgentSkill : "has"
Agent ||--o{ AgentMCPServer : "has"
AgentSkill ||--o{ StudentSkillOverride : "overridden by"
User ||--o{ StudentSkillOverride : "configures"
User ||--o{ StudentMCPServer : "creates"
Agent ||--o{ StudentMCPServer : "receives"
User ||--o{ StudentSkill : "creates"
Agent ||--o{ StudentSkill : "receives"
User ||--o{ Enrollment : "enrolled"
Course ||--o{ Enrollment : "has"
Agent ||--o{ AccessRequest : "receives"
User ||--o{ AccessRequest : "reviews"
User ||--o{ ChatSession : "owns"
Agent ||--o{ ChatSession : "receives"
ChatSession ||--o{ ChatMessage : "contains"
ChatMessage ||--o{ ChatAttachment : "has"
ChatMessage ||--|| ChatMessageFeedback : "has"
School ||--|| Subscription : "has"
Plan ||--o{ Subscription : "defines"
Plan }o--o{ AIModel : "allows"
User ||--o{ StudentMessageCredit : "has"
School ||--o{ StudentMessageCredit : "tracks"
Agent ||--o{ StudentMessageCredit : "scoped to"
User ||--o{ MessagePurchase : "buys"
MessagePackage ||--o{ MessagePurchase : "sold as"
Agent ||--o{ MessagePurchase : "receives credits"
User ||--o{ StudentAchievement : "unlocks"
Entidades Principais
| Entidade | Responsabilidade |
| User | Usuario com role admin ou student. Login por email. |
| School | Escola multi-tenant. Pertence a um admin. |
| Course | Curso dentro de uma escola. |
| Agent | Agente de IA 1:1 com o curso. Armazena personalidade, prompts e creditos por aluno. |
| AgentDocument | Arquivos para treinar o agente via RAG. |
| AgentSkill | Skill de IA do agente (builtin ou custom). Implementada como tool do LangChain. |
| AgentMCPServer | MCP Server do agente para conexao com servicos externos. |
| StudentSkillOverride | Override de ativacao de skill por aluno. |
| AccessRequest | Solicitação de acesso de um aluno a um agente restrito através de link externo compartilhado com um token UUID. Pode ser aprovado ou recusado por admins da escola. |
| StudentMCPServer | MCP Server personalizado criado pelo aluno. |
| StudentSkill | Skill personalizada criada pelo aluno. |
| Enrollment | Matricula do aluno no curso (acesso ao agente). |
| ChatSession | Sessao de conversa entre aluno e agente. |
| ChatMessage | Mensagem individual com metadados de tokens e custo. |
| ChatAttachment | Arquivo anexado a uma mensagem de chat. |
| ChatMessageFeedback | Avaliacao like/dislike de uma mensagem do assistente. |
| Subscription | Plano ativo da escola. Campo trial_ends_at para trial de 14 dias. |
| Plan | Definicao de plano com limites e modelos de IA disponiveis. |
| AIModel | Modelo de IA com custos e configuracoes gerenciaveis via Admin. |
| StudentMessageCredit | Controle granular de creditos por aluno, por agente, por periodo. |
| MessagePackage | Pacote avulso de creditos disponivel para compra. |
| MessagePurchase | Registro de compra de pacote de creditos, vinculado a um agente. |
| StudentAchievement | Registro de troféus e recompensas (gamificação) alcançadas pelo aluno. |