Files
Feeding_control_system/doc/md/Arch.md
2025-11-01 17:33:26 +08:00

7.5 KiB
Raw Blame History

子系统关系图示例

1. 系统上下文图System Context Diagram

graph TD
    subgraph 外部实体
        User[用户]
        CustomerSystem[客户系统]
        SupplierSystem[供应商系统]
        PaymentGateway[支付网关]
    end
    
    subgraph 核心系统
        MainSystem[主系统]
        
        subgraph 子系统A[子系统A - 订单管理]
            OrderService[订单服务]
            InventoryService[库存服务]
            PricingService[定价服务]
        end
        
        subgraph 子系统B[子系统B - 用户管理]
            AuthService[认证服务]
            ProfileService[用户档案服务]
            PermissionService[权限服务]
        end
        
        subgraph 子系统C[子系统C - 数据分析]
            ReportService[报表服务]
            AnalyticsService[分析服务]
            DashboardService[仪表盘服务]
        end
        
        subgraph 子系统D[子系统D - 通知中心]
            EmailService[邮件服务]
            SMSGateway[短信网关]
            PushService[推送服务]
        end
    end
    
    subgraph 数据存储
        DB[(数据库)]
        Cache[(缓存)]
        LogStorage[(日志存储)]
    end
    
    %% 外部实体连接
    User --> MainSystem
    CustomerSystem <--> MainSystem
    SupplierSystem <--> MainSystem
    PaymentGateway <--> MainSystem
    
    %% 主系统与子系统连接
    MainSystem --> OrderService
    MainSystem --> AuthService
    MainSystem --> ReportService
    MainSystem --> EmailService
    
    %% 子系统内部连接
    OrderService --> InventoryService
    OrderService --> PricingService
    AuthService --> ProfileService
    AuthService --> PermissionService
    ReportService --> AnalyticsService
    ReportService --> DashboardService
    EmailService --> SMSGateway
    EmailService --> PushService
    
    %% 子系统与数据存储连接
    OrderService --> DB
    InventoryService --> DB
    ProfileService --> DB
    PermissionService --> DB
    AnalyticsService --> DB
    
    PricingService --> Cache
    AuthService --> Cache
    
    EmailService --> LogStorage
    SMSGateway --> LogStorage
    PushService --> LogStorage

2. 子系统交互流程图

sequenceDiagram
    participant Client as 客户端
    participant Main as 主系统
    participant Order as 订单子系统
    participant User as 用户子系统
    participant Payment as 支付子系统
    participant Notify as 通知子系统
    participant DB as 数据库
    
    Client->>Main: 请求创建订单
    Main->>User: 验证用户身份和权限
    User->>DB: 查询用户信息
    DB-->>User: 返回用户数据
    User-->>Main: 验证通过
    
    Main->>Order: 创建订单请求
    Order->>DB: 查询库存
    DB-->>Order: 返回库存状态
    
    alt 库存充足
        Order->>DB: 锁定库存
        Order->>Payment: 发起支付请求
        Payment->>DB: 创建支付记录
        DB-->>Payment: 支付记录创建成功
        Payment-->>Order: 支付已发起
        Order->>DB: 更新订单状态为"等待支付"
        Order-->>Main: 订单创建成功
        Main->>Notify: 发送订单确认通知
        Notify-->>Client: 推送订单确认消息
    else 库存不足
        Order-->>Main: 库存不足
        Main-->>Client: 返回错误信息
    end

3. 子系统依赖关系图

graph LR
    subgraph 基础服务层
        ConfigSvc[配置服务]
        LogSvc[日志服务]
        SecuritySvc[安全服务]
        CommonLib[公共库]
    end
    
    subgraph 核心业务层
        UserMgmt[用户管理子系统]
        ProductMgmt[产品管理子系统]
        OrderMgmt[订单管理子系统]
        PaymentMgmt[支付管理子系统]
    end
    
    subgraph 应用服务层
        API_Gateway[API网关]
        MobileApp[移动应用服务]
        WebPortal[Web门户服务]
        ReportSvc[报表服务]
    end
    
    subgraph 集成层
        ExternalAPI[外部API集成]
        MessageQueue[消息队列]
        EventBus[事件总线]
    end
    
    %% 依赖关系
    UserMgmt --> ConfigSvc
    UserMgmt --> LogSvc
    UserMgmt --> SecuritySvc
    UserMgmt --> CommonLib
    
    ProductMgmt --> ConfigSvc
    ProductMgmt --> LogSvc
    ProductMgmt --> CommonLib
    
    OrderMgmt --> UserMgmt
    OrderMgmt --> ProductMgmt
    OrderMgmt --> LogSvc
    OrderMgmt --> ConfigSvc
    OrderMgmt --> CommonLib
    
    PaymentMgmt --> OrderMgmt
    PaymentMgmt --> LogSvc
    PaymentMgmt --> SecuritySvc
    PaymentMgmt --> ConfigSvc
    
    API_Gateway --> UserMgmt
    API_Gateway --> ProductMgmt
    API_Gateway --> OrderMgmt
    API_Gateway --> PaymentMgmt
    API_Gateway --> SecuritySvc
    
    MobileApp --> API_Gateway
    WebPortal --> API_Gateway
    ReportSvc --> UserMgmt
    ReportSvc --> OrderMgmt
    ReportSvc --> ProductMgmt
    
    UserMgmt --> ExternalAPI
    PaymentMgmt --> ExternalAPI
    OrderMgmt --> MessageQueue
    PaymentMgmt --> MessageQueue
    UserMgmt --> EventBus
    OrderMgmt --> EventBus
    ProductMgmt --> EventBus
    PaymentMgmt --> EventBus

4. C4模型系统上下文图

graph TD
    subgraph 系统边界
        System[企业资源规划系统]
        
        subgraph 功能模块
            HR[人力资源管理]
            Finance[财务管理]
            Inventory[库存管理]
            Sales[销售管理]
            Production[生产管理]
        end
        
        System --> HR
        System --> Finance
        System --> Inventory
        System --> Sales
        System --> Production
    end
    
    %% 系统间关系
    HR <--> Finance: 薪资数据
    Sales <--> Finance: 订单数据
    Sales <--> Inventory: 库存查询
    Production <--> Inventory: 物料需求
    Production <--> Finance: 成本核算
    
    %% 外部系统
    ExtCRM[外部CRM系统] <--> Sales: 客户数据
    ExtSupplier[供应商系统] <--> Inventory: 采购数据
    ExtBank[银行系统] <--> Finance: 支付结算
    
    %% 用户
    HR_User[HR人员] --> HR
    Finance_User[财务人员] --> Finance
    Inventory_User[仓库人员] --> Inventory
    Sales_User[销售人员] --> Sales
    Prod_User[生产人员] --> Production

说明

以上子系统关系图展示了不同类型的系统间关系表示方法:

  1. 系统上下文图:展示了系统的整体架构,包括核心子系统、外部实体和数据存储之间的关系。适合高层次架构设计。

  2. 子系统交互流程图:使用时序图展示子系统之间的交互过程和消息传递顺序,适合描述业务流程中的系统协作。

  3. 子系统依赖关系图:展示了子系统之间的依赖关系,包括基础服务、核心业务、应用服务和集成层的层次结构。

  4. C4模型系统上下文图遵循C4模型方法论展示了企业级系统中的子系统边界和它们之间的关系。

Mermaid图表类型选择建议

对于展示子系统之间的关系推荐使用以下Mermaid图表类型

  • graph TD/LR:适用于系统上下文图、依赖关系图等静态关系展示
  • sequenceDiagram:适用于展示子系统间的交互流程和消息传递
  • flowchart:适用于展示更复杂的业务流程和子系统协作
  • classDiagram:如果需要展示子系统的类结构和它们之间的关系

选择图表类型时,应根据具体需求考虑:是需要展示静态结构关系,还是动态交互过程;是需要高层次概览,还是详细的交互细节。