---
config:
    layout: elk
---

classDiagram
    %% 基础模型类
    class BaseModel {
        <<abstract>>
        +id
        +creation_time
        +last_modify_time
        +save()
        +get_full_url()
        +get_absolute_url()*
    }

    %% 核心模型类
    class Article {
        +title
        +body
        +pub_time
        +status
        +comment_status
        +type
        +views
        +article_order
        +show_toc
        +body_to_string()
        +get_category_tree()
        +viewed()
        +comment_list()
        +get_admin_url()
        +next_article()
        +prev_article()
        +get_first_image_url()
    }

    class Category {
        +name
        +parent_category
        +slug
        +index
        +get_category_tree()
        +get_sub_categorys()
    }

    class Tag {
        +name
        +slug
        +get_article_count()
    }

    class Links {
        +name
        +link
        +sequence
        +is_enable
        +show_type
    }

    class SideBar {
        +name
        +content
        +sequence
        +is_enable
    }

    class BlogSettings {
        +site_name
        +site_description
        +site_seo_description
        +site_keywords
        +article_sub_length
        +sidebar_article_count
        +sidebar_comment_count
        +article_comment_count
        +show_google_adsense
        +google_adsense_codes
        +open_site_comment
        +global_header
        +global_footer
        +beian_code
        +analytics_code
        +show_gongan_code
        +gongan_beiancode
        +comment_need_review
        +clean()
    }

    %% 枚举类型
    class LinkShowType {
        <<enumeration>>
        I, L, P, A, S
    }

    %% 表单类
    class BlogSearchForm {
        +querydata
        +search()
    }

    %% 管理类
    class ArticlelAdmin {
        +list_display
        +list_filter
        +actions
        +link_to_category()
        +get_form()
        +get_view_on_site_url()
    }

    class TagAdmin
    class CategoryAdmin
    class LinksAdmin
    class SideBarAdmin
    class BlogSettingsAdmin

    %% 视图类
    class ArticleListView {
        <<abstract>>
        +page_type
        +link_type
        +get_queryset_cache_key()*
        +get_queryset_data()*
        +get_queryset()
        +get_context_data()
    }

    class IndexView
    class ArticleDetailView {
        +get_context_data()
    }
    class CategoryDetailView
    class AuthorDetailView
    class TagDetailView
    class ArchivesView
    class LinkListView
    class EsSearchView

    %% 中间件类
    class OnlineMiddleware {
        +__call__()
    }

    %% 搜索索引类
    class ArticleIndex {
        +text
        +get_model()
        +index_queryset()
    }

    %% Elasticsearch 文档类
    class GeoIp {
        +continent_name
        +country_iso_code
        +country_name
        +location
    }

    class UserAgentBrowser
    class UserAgentOS
    class UserAgentDevice
    class UserAgent

    class ElapsedTimeDocument {
        +url
        +time_taken
        +log_datetime
        +ip
        +geoip
        +useragent
    }

    class ElaspedTimeDocumentManager {
        +build_index()
        +delete_index()
        +create()
    }

    class ArticleDocument {
        +body
        +title
        +author
        +category
        +tags
        +pub_time
        +status
        +comment_status
        +type
        +views
        +article_order
    }

    class ArticleDocumentManager {
        +create_index()
        +delete_index()
        +convert_to_doc()
        +rebuild()
        +update_docs()
    }

    %% 应用配置类
    class BlogConfig

    %% 测试类
    class ArticleTest

    %% 继承关系
    BaseModel <|-- Article
    BaseModel <|-- Category
    BaseModel <|-- Tag
    ArticleListView <|-- IndexView
    ArticleListView <|-- CategoryDetailView
    ArticleListView <|-- AuthorDetailView
    ArticleListView <|-- TagDetailView
    ArticleListView <|-- ArchivesView
    ArticleDetailView --|> DetailView
    LinkListView --|> ListView
    EsSearchView --|> SearchView
    UserAgentOS --|> UserAgentBrowser

    %% 关联关系
    Article --> Category : Foreign Key
    Article --> Tag : Many-to-Many
    Article --> settings.AUTH_USER_MODEL : Foreign Key
    Category --> Category : Self-reference (Parent Category)
    Links --> LinkShowType : Uses
    ArticleDocument --> Article : Mapping
    ElapsedTimeDocument --> GeoIp : Contains
    ElapsedTimeDocument --> UserAgent : Contains
    UserAgent --> UserAgentBrowser : Contains
    UserAgent --> UserAgentOS : Contains
    UserAgent --> UserAgentDevice : Contains

    %% 管理关系
    ArticlelAdmin --> Article : 管理
    TagAdmin --> Tag : 管理
    CategoryAdmin --> Category : 管理
    LinksAdmin --> Links : 管理
    SideBarAdmin --> SideBar : 管理
    BlogSettingsAdmin --> BlogSettings : 管理

    %% 视图与模型关系
    IndexView --> Article : 查询
    ArticleDetailView --> Article : 详情
    CategoryDetailView --> Category : 查询
    AuthorDetailView --> Article : 查询
    TagDetailView --> Tag : 查询
    ArchivesView --> Article : 查询
    LinkListView --> Links : 查询

    %% 搜索关系
    ArticleIndex --> Article : 索引
    BlogSearchForm --> SearchForm : 继承

    %% 文档管理关系
    ArticleDocumentManager --> ArticleDocument : 管理
    ElaspedTimeDocumentManager --> ElapsedTimeDocument : 管理

    %% 测试关系
    ArticleTest --> Article : 测试
    ArticleTest --> Category : 测试
    ArticleTest --> Tag : 测试
    ArticleTest --> SideBar : 测试
    ArticleTest --> Links : 测试
