---
config:
    layout: elk
---
classDiagram
    %% Models
    class commands {
        +CharField title
        +CharField command
        +CharField describe
        +DateTimeField creation_time
        +DateTimeField last_modify_time
        +__str__()
    }

    class EmailSendLog {
        +CharField emailto
        +CharField title
        +TextField content
        +BooleanField send_result
        +DateTimeField creation_time
        +__str__()
    }

    %% Admin Classes
    class CommandsAdmin {
        +list_display
    }

    class EmailSendLogAdmin {
        +list_display
        +readonly_fields
        +has_add_permission()
    }

    %% WeChat Robot Components
    class MemcacheStorage {
        +prefix
        +cache
        +is_available
        +key_name()
        +get()
        +set()
        +delete()
    }

    class MessageHandler {
        +message
        +session
        +userid
        +userinfo
        +is_admin
        +is_password_set
        +save_session()
        +handler()
    }

    class WxUserInfo {
        +isAdmin
        +isPasswordSet
        +Count
        +Command
    }

    %% External API Classes
    class BlogApi {
        <<External>>
        +search_articles()
        +get_category_lists()
        +get_recent_articles()
    }

    class CommandHandler {
        <<External>>
        +run()
        +get_help()
    }

    class ChatGPT {
        <<External>>
        +chat()
    }

    class WeRoBot {
        <<External>>
        +token
        +config
        +filter()
        +handler()
    }

    %% Test Classes
    class ServerManagerTest {
        +setUp()
        +test_chat_gpt()
        +test_validate_comment()
    }

    %% App Config
    class ServermanagerConfig {
        +name
    }

    %% URL Configuration
    class URLConfig {
        +robot
    }

    %% External Models (for testing)
    class BlogUser {
        <<External>>
        +create_superuser()
    }

    class Category {
        <<External>>
    }

    class Article {
        <<External>>
        +title
        +body
        +get_full_url()
    }

    %% Relationships
    CommandsAdmin --> commands : 管理
    EmailSendLogAdmin --> EmailSendLog : 管理
    
    MemcacheStorage ..> WeRoBot : 会话存储实现
    MessageHandler o-- WxUserInfo : 组合
    MessageHandler --> CommandHandler : 使用
    MessageHandler --> ChatGPT : 使用
    
    WeRoBot --> MessageHandler : 消息处理
    WeRoBot --> BlogApi : 博客API调用
    WeRoBot --> MemcacheStorage : 会话存储
    
    %% Robot Filter Functions
    WeRoBot ..> search : 注册过滤器
    WeRoBot ..> category : 注册过滤器  
    WeRoBot ..> recents : 注册过滤器
    WeRoBot ..> help : 注册过滤器
    WeRoBot ..> weather : 注册过滤器
    WeRoBot ..> idcard : 注册过滤器
    
    %% Test Relationships
    ServerManagerTest --> commands : 测试
    ServerManagerTest --> MessageHandler : 测试
    ServerManagerTest --> CommandHandler : 测试
    ServerManagerTest --> BlogUser : 测试依赖
    ServerManagerTest --> Category : 测试依赖
    ServerManagerTest --> Article : 测试依赖
    
    URLConfig --> WeRoBot : 路由配置