---
# System prepended metadata

title: 討論網站架構
tags: [note]

---

# 討論網站架構


## 隨筆記
MVC
    MVVM
    MVP





* entity = database table
* model = entities + relations
* dto = entity - uninteresting fields
* view = dtos + relations


* project
    * user interface 表現層
        * model
            * view object
        * view
        * controller
    * business logical layer 業務邏輯層
        * business object
    * data access layer 資料訪問層
        * value object
        * persistent object

```mermaid
graph LR;
    project[project]
    ui[ user interface 表現層]
    model[model]
    view_object[view object]
    view[view]
    controller[controller]
    business[business logical layer 業務邏輯層]
    business_object[business object]
    data_access[data access layer 資料訪問層]
    value_object[value object]
    persistent_object[persistent object]

    project --> ui
    ui --> model
    model --> view_object
    model --> view
    model --> controller
    project --> business
    business --> business_object
    project --> data_access
    data_access --> value_object
    data_access --> persistent_object
```

---


DO -> data object (實體對象)與 database table 資料表結構對應，並通過dao傳輸資料的物件
BO -> business object (業務對象)由 service layer 封裝並輸出的業務邏輯物件
AO -> application object (應用對象)在 web layer 與 service layer 間傳輸應用的物件，通常用於展示
VO -> view object (顯示對象)
Query -> (資料查詢對象)將上層查詢的資料封裝起來的物件



```mermaid
graph LR;
    model[領域對象]
    relation[按包含關係劃分]
    repository[按資料傳輸層劃分]
    service[按業務對象劃分]
    POJO
    pojo_bo[BO]
    pojo_vo[VO]
    pojo_dto[DTO]
    pojo_po[PO]
    BO
    bo_po[PO]
    bo_vo[VO]
    bo_entity[Entity]
    dto[DTO 業務邏輯及表示層]
    po[PO 資料層]
    entity[Entity 有唯一識別]
    vo[VO 無]

    model --> relation
    model --> repository
    model --> service
    relation --> POJO
    POJO --> pojo_bo
    POJO --> pojo_vo
    POJO --> pojo_dto
    POJO --> pojo_po
    relation --> BO
    BO --> bo_po
    BO --> bo_vo
    BO --> bo_entity
    repository --> dto
    repository --> po
    service --> entity
    service --> vo
```


```mermaid
graph TD;
    subgraph 展示層
    webpage1[頁面] --- VO1[VO] --- webService1[業務解釋] --- DTO
    webpage2[頁面] --- VO2[VO] --- webService2[業務解釋] --- DTO
    webpage3[頁面] --- VO3[VO] --- webService3[業務解釋] --- DTO
    end
    DTO
    subgraph 業務邏輯層
    DTO --- service[業務處理] --- BO
    end
    BO
    subgraph 數據訪問層
    BO --- PO1[PO] --- DAO
    BO --- PO2[PO] --- DAO
    BO --- PO3[PO] --- DAO
    end
    DAO --- database[資料庫]
    
```



參考資料：
[浅析POJO、DTO、DO、VO、BO、PO、Entity](https://www.cnblogs.com/binbingg/p/17771923.html)
[如何撰寫 API 所需具備架構概念](https://blog.yosheng.tw/how-write-api-architecture)
[Web Application Architecture (Repository Pattern)](https://sdwh.dev/posts/2022/12/Web-Application-Architecture/)
[[今晚我想來點 Express 佐 MVC 分層架構] DAY 19 - Service Layer Pattern](https://ithelp.ithome.com.tw/articles/10248878)
