Upgrade to Pro — share decks privately, control downloads, hide ads and more …

從混亂到優雅,讓專案不再失控:ATDD 與 Clean Architecture 的後端實戰之路

從混亂到優雅,讓專案不再失控:ATDD 與 Clean Architecture 的後端實戰之路

你是不是也遇過這種情況?每當專案多一個新功能,整個系統就像被隕石砸到一樣,到處都是坑,永遠補不完。這次很高興能和我實習的同事 Dong 一起在 COSCUP 中,向大家分享,我們是怎麼從「隕石式開發」走到擁抱 ATDD 和 Clean Architecture。

Avatar for LINE Developers Taiwan

LINE Developers Taiwan PRO

August 22, 2025
Tweet

More Decks by LINE Developers Taiwan

Transcript

  1. 東東 dongdong867 # Experience iOS Intern @LINE Tech Lead/ Full

    Stack Dev @OpenNCCU # Education Master/ Bachelor of MIS @NCCU
  2. 加了新功能之後, XXX 功能壞了 QA 改完之後換 OOO 功能壞掉了 QA Dev @all

    剛剛推新功能上 beta 了 Dev 改完了, 已經推 hotfix 了 Dev ???
  3. How clean is enough to call it clean code How

    much test is enough for a test
  4. Gherkin Syntax Feature: 登入 As a 使用者 I want to

    登入系統 So that 我可以使用系統內的功能 Scenario: 登入失敗三次後帳號鎖定 Given 進入登入頁面 And 已經登入失敗兩次 When 輸入正確使用者帳號跟錯誤的密碼 And 點擊登入按鈕 Then 接收到帳號被鎖定的訊息
  5. Gherkin Syntax Feature: 登入 As a 使用者 I want to

    登入系統 So that 我可以使用系統內的功能 好多字, 好懶, 不想看 Scenario: 登入失敗三次後帳號鎖定 Given 進入登入頁面 And 已經登入失敗兩次 When 輸入正確使用者帳號跟錯誤的密碼 And 點擊登入按鈕 Then 接收到帳號被鎖定的訊息
  6. Scenario: 登入失敗三次後帳號鎖定 Given 進入登入頁面 And 已經登入失敗兩次 When 輸入正確使用者帳號跟錯誤的密碼 And 點擊登入按鈕

    Then 接收到帳號被鎖定的訊息 Gherkin Syntax Feature: 登入 As a 使用者 I want to 登入系統 So that 我可以使用系統內的功能 好多字, 好懶, 不想看 出口在您的右手邊, 慢走不送
  7. API Route User Entity Post Entity Login UseCase Create Post

    UseCase Get Recommendation UseCase Firebase Service DB Service
  8. API Route User Entity Post Entity Login UseCase Create Post

    UseCase Get Recommendation UseCase Firebase Service DB Service
  9. API Route User Entity Post Entity Login UseCase Create Post

    UseCase Get Recommendation UseCase Firebase Service DB Service
  10. API Route User Entity Post Entity Login UseCase Create Post

    UseCase Get Recommendation UseCase Firebase Service DB Service
  11. How clean is enough to call it clean code How

    much test is enough for a test
  12. API Route User Entity Post Entity Login UseCase Create Post

    UseCase Get Recommendation UseCase Firebase Service DB Service
  13. API Route User Entity Post Entity Login UseCase Create Post

    UseCase Get Recommendation UseCase Firebase Service DB Service
  14. 為什麼我們需要 clean code As is: 使用者登入 → 在 DB 寫入

    user.is_online = true 好友頁面中 → 從 DB 讀取 user.is_online 並顯示在 UI 上
  15. 為什麼我們需要 clean code As is: To be: 使用者登入 → 在

    DB 寫入 user.is_online = true → DB 中的 user.is_online (bool) 欄位變更成 user.status (enum) 好友頁面中 → 從 DB 讀取 user.is_online 並顯示在 UI 上 好友頁面中 → 從 DB 讀取 user.status 並顯示在 UI 上 PM: 我們需要一個請勿打擾的狀態
  16. 為什麼我們需要 clean code As is: To be: 使用者登入後 → 在

    DB 寫入 user.is_online = true → DB 中的 user.is_online 欄位 rename 成 user.status 好友頁面中 → 從 DB 讀取 user.is_online 並顯示在 UI 上 好友頁面中 → 從 DB 讀取 user.status 並顯示在 UI 上 PM: 我們需要一個請勿打擾的狀態 收工 ! 下班回家
  17. Framework - Web API Route POST /api/article { “content”: “Hello”

    } RESPONSE 201 { “id”: 1 } 後端與外部互動的進入點 Entity Use Case Gateway Database Controller API Route
  18. Adapter - Controller & DTO JSON <-> DTO <-> Entity

    create_article_use_case() 處理請求的中間轉譯層 Entity Use Case Gateway Database Controller API Route
  19. Application - Use Case 每個 Use Case 都代表 App 的一個功能

    @ Create Article Use CasD @ Get All Articles Use CasD @ Get Article By ID Use CasD @ Update Article Use Case Entity Use Case Gateway Database Controller API Route
  20. Domain - Entity 核心業務邏輯和資料結構 struct Article { content: String }

    validate() { content != “” } Entity Use Case Gateway Database Controller API Route
  21. Adapter - Gateway & Mapper 處理資料調用的中間轉譯層 Record <-> Mapper <->

    Entity article_db.create() Entity Use Case Gateway Database Controller API Route
  22. Framework - Database & Record 處理資料存儲相關的細節 INSERT INTO article (content)

    RETURNING id Entity Use Case Gateway Database Controller API Route
  23. 依賴反轉 Dependency Inversion Entity Use Case Gateway Database Controller API

    Route 定義抽象介面 維持由外而內的依賴關係
  24. 依賴反轉 Dependency Inversion Entity Use Case Trait Gateway Database Controller

    API Route Trait 定義抽象介面 維持由外而內的依賴關係