refactor: コードベース負債の修正とルール整備#325
Conversation
backend / frontend / infra / CI / docs の全領域を静的調査し、 技術的負債をフェーズ分けで解消するための計画を .report/ に作成。 - Phase 0: 計測基盤・ベースライン確定(jscpd / カバレッジ) - Phase 1: クイックウィン(FIELD_ENCRYPTION_KEY TODO・テスト統合・ADR 整理) - Phase 2: Backend 責務分離(PDF generator / blog collector / router ロジック漏れ) - Phase 3: Frontend 責務分離(CareerResumeForm 分割・props drilling 解消) - Phase 4: テスト補強(巨大テスト分割・FE API 層 / Redux テスト追加) - Phase 5: CI/インフラ最適化(デプロイジョブ統合・WeasyPrint 共通化) - Phase 6: 仕上げ・再発防止(jscpd 閾値引き上げ・ADR 起票) https://claude.ai/code/session_01GBcTxFo79GGmT7FcCuREVT
router/service/repository/model 各層の禁止事項を .claude/rules/backend/layers.md に 新規作成(Bad/Good 例付き)。今回の調査で発見した3パターンの負債を記録: - router への外部 API 例外処理の漏れ - router 内への DB クエリ直書き - ORM model への表示ロジック混入(sort_utils import) CLAUDE.md「失敗から学んだ知見」に同3パターンを再発防止ルールとして追記し、 layers.md / component-design.md(次 PR)への参照を追加。 https://claude.ai/code/session_01GBcTxFo79GGmT7FcCuREVT
コンポーネント肥大化・props drilling の再発防止ルールを .claude/rules/frontend/component-design.md に新規作成。 - 行数目安(300行超:分割検討、500行超:必ず分割、フック150行超) - props drilling の定義と Context 導入の判断基準(3層以上素通し) - モーダル管理パターン(Bad/Good 例付き) - useProjectModalState 等の既存良パターンへの参照 CLAUDE.md 1コミット前の追記から参照される。 https://claude.ai/code/session_01GBcTxFo79GGmT7FcCuREVT
ブランチ戦略: - develop ブランチを廃止済みとして表から削除 - PR 作成先を develop → main に修正 - 廃止経緯の Note を追記 ADR 一覧: - ADR-0007(codegen-drift)/ 0009x2(toast/textlint)/ 0010(Agent)を追加 - ADR-0008 のステータスを Accepted → Superseded by ADR-0010 に修正 https://claude.ai/code/session_01GBcTxFo79GGmT7FcCuREVT
.github/PULL_REQUEST_TEMPLATE.md: PR ごとの確認漏れを防ぐ最小限チェックリストを新規作成。 必須確認(make ci・日本語コメント)と条件付き確認 (codegen-types・E2E・env_keys 4箇所同期・messages リテラル禁止)を分離。 .claude/settings.json: common/duplication.md で参照されていた Stop hook を実装。 セッション終了時に make dupe-check をバックグラウンド実行し、 次セッション開始時に jscpd-report.json を参照できる状態にする。 https://claude.ai/code/session_01GBcTxFo79GGmT7FcCuREVT
|
Warning Review limit reached
More reviews will be available in 35 minutes and 15 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis PR adds architecture and component design guidelines, a six-phase refactoring roadmap, branch/PR workflow updates, and moves several backend behaviors into service helpers with matching test adjustments and small model ordering changes. ChangesArchitecture & Process Governance
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.claude/settings.json:
- Line 9: Update the "command" entry that currently contains "make dupe-check
2>/dev/null &" so the duplication check runs synchronously and errors are
visible: remove the background ampersand and the stderr redirection so the value
becomes a plain "make dupe-check" (update the "command" key in
.claude/settings.json referencing the existing "make dupe-check" invocation).
In @.github/PULL_REQUEST_TEMPLATE.md:
- Around line 18-20: Update the PR title example to include the required
"<type>" placeholder so it matches the later convention; specifically edit the
PR title format line near the "### 破壊的変更" section to use the pattern "type: <内容>
— short description" (or include "<type>" where it was omitted) so contributors
are guided to produce well-formed titles consistent with the template’s listed
convention.
In @.report/refactoring-plan-20260612.md:
- Around line 23-27: The fenced diagram block is unlabeled and triggers
markdownlint MD040; update the code fence that contains the phase diagram (the
triple-backtick block showing "Phase 0 ─→ Phase 1 ─→ Phase 2...") by adding a
language label such as text after the opening backticks (i.e., change ``` to
```text) so the fence is explicitly labeled and markdownlint-cli2 no longer
flags it.
In `@CONTRIBUTING.md`:
- Around line 78-82: Rename the duplicate ADR entry labelled "ADR-0009" to the
next unused ADR number (e.g., change the second "ADR-0009" row to "ADR-0011"),
and update its Markdown link and document filename reference accordingly (the
table cell containing "ADR-0009" and
"docs/adr/0009-frontend-textlint-proofread.md" should be updated to the new
identifier and matching docs/adr/00XX-frontend-textlint-proofread.md); also
search for and update any cross-references to the old ADR-0009 identifier
elsewhere in the repo (including README or other ADR docs) to the new ADR
number.
- Around line 18-20: In CONTRIBUTING.md update the PR title format example to
show the full placeholder by replacing the incomplete "`: <内容>`" with "`<type>:
<内容>`" and ensure the example line still reads like the rest of the doc (e.g.,
keep the example "`feat: GitHub 連携スコア計算の追加`") so the PR title format is
unambiguous across the workflow docs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2404a139-6958-4a26-9abb-176ff582e62b
📒 Files selected for processing (7)
.claude/CLAUDE.md.claude/rules/backend/layers.md.claude/rules/frontend/component-design.md.claude/settings.json.github/PULL_REQUEST_TEMPLATE.md.report/refactoring-plan-20260612.mdCONTRIBUTING.md
|
|
||
| ### 破壊的変更 | ||
|
|
There was a problem hiding this comment.
Fix the PR title format text.
Line 19 omits the required <type> placeholder, even though the template later lists the correct type: <内容> convention. As written, this will steer contributors toward malformed titles.
Suggested fix
-- PR タイトルは `: <内容>` の形式(例: `feat: GitHub 連携スコア計算の追加`)
+- PR タイトルは `<type>: <内容>` の形式(例: `feat: GitHub 連携スコア計算の追加`)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ### 破壊的変更 | |
| - PR タイトルは `<type>: <内容>` の形式(例: `feat: GitHub 連携スコア計算の追加`) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/PULL_REQUEST_TEMPLATE.md around lines 18 - 20, Update the PR title
example to include the required "<type>" placeholder so it matches the later
convention; specifically edit the PR title format line near the "### 破壊的変更"
section to use the pattern "type: <内容> — short description" (or include "<type>"
where it was omitted) so contributors are guided to produce well-formed titles
consistent with the template’s listed convention.
- models/resume.py: sort_utils(services 層)の import を除去し、@Property を list(self.<xxx>_rows) に簡略化。save 時に sort_order で順序確定済みのため動作不変。 - routers/blog/accounts.py + account_service.py: add_account のロジックを BlogAccountService へ移設し、router から collector を直接 import しないようにした。 BlogAccountAlreadyRegisteredError 例外を新規追加。 - routers/github_link.py: _get_or_create_cache(DB クエリ直書き)を github_link_service.get_or_create_github_link_cache へ移設。 - 影響するテストのモックパスを router → service に更新 (test_accounts.py, test_sync.py, test_idor.py, test_mass_assignment.py) 全テスト 505 passed。 https://claude.ai/code/session_01GBcTxFo79GGmT7FcCuREVT
CareerResumeForm(534行)に存在した3つのモーダル用useState (showDeleteConfirm / showSaveConfirm / editingField)と関連ハンドラ (handleDelete / handleConfirmSave)をuseCareerFormModalsフックに集約。 component-design.mdの「3個以上のモーダルuseStateは専用フックに切り出す」 ルールに対応。コンポーネントの見通しを改善しハンドラを単独でテスト可能にする。 https://claude.ai/code/session_01GBcTxFo79GGmT7FcCuREVT
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/app/services/blog/account_service.py (1)
32-48: 💤 Low valueConsider more descriptive exception message for debugging.
Line 40 passes only
platformtoBlogAccountAlreadyRegisteredError, resulting in an exception message like "zenn". While the router converts this to a localized user-facing message, a more descriptive message would aid debugging and logging.💡 Optional improvement
- raise BlogAccountAlreadyRegisteredError(platform) + raise BlogAccountAlreadyRegisteredError(f"Account already registered for platform: {platform}")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/app/services/blog/account_service.py` around lines 32 - 48, The current add_account raises BlogAccountAlreadyRegisteredError(platform) which yields an unhelpful message; update the raise to include a descriptive context string (e.g. "account already registered: {platform}/{normalized_username}") using the normalized_username variable so logs/debugging show both platform and username; change the raise in add_account to pass the constructed message to BlogAccountAlreadyRegisteredError instead of just platform.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@backend/app/services/blog/account_service.py`:
- Around line 32-48: The current add_account raises
BlogAccountAlreadyRegisteredError(platform) which yields an unhelpful message;
update the raise to include a descriptive context string (e.g. "account already
registered: {platform}/{normalized_username}") using the normalized_username
variable so logs/debugging show both platform and username; change the raise in
add_account to pass the constructed message to BlogAccountAlreadyRegisteredError
instead of just platform.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 51261494-72d0-44b5-82fe-1015a755350f
📒 Files selected for processing (9)
backend/app/models/resume.pybackend/app/routers/blog/accounts.pybackend/app/routers/github_link.pybackend/app/services/blog/account_service.pybackend/app/services/intelligence/github_link_service.pybackend/tests/blog/test_accounts.pybackend/tests/blog/test_sync.pybackend/tests/security/test_idor.pybackend/tests/security/test_mass_assignment.py
…n> に修正してビルドエラーを解消 useDocumentForm の save は Promise<boolean> を返すが、useCareerFormModals が () => Promise<void> と宣言していたため tsc -b で TS2322 が発生していた。 (...args: never[]) => Promise<unknown> に変更することで両方の型を受け入れられるようにした。 https://claude.ai/code/session_01GBcTxFo79GGmT7FcCuREVT
- settings.json: Stop hookのdupe-checkを同期実行に変更(エラーが見えるよう2>/dev/null &を削除) - CONTRIBUTING.md: PRタイトル形式の表記を「: <内容>」→「<type>: <内容>」に修正 - CONTRIBUTING.md: 重複ADR-0009エントリをADR-0011に修正 - docs/adr: 0009-frontend-textlint-proofread.md を 0011-frontend-textlint-proofread.md にリネーム - .report/refactoring-plan-20260612.md: 未ラベルのコードフェンスにtextを追加 https://claude.ai/code/session_01GBcTxFo79GGmT7FcCuREVT
リモート実行環境にはnixが存在せず、同期実行に変更したStop hookが `nix: not found` でエラー終了していた。 `command -v nix` でnixの存在を確認してから実行するよう変更。 nixがある環境では同期実行・エラー可視のまま動作する。 https://claude.ai/code/session_01GBcTxFo79GGmT7FcCuREVT
変更概要
リファクタリング計画書(
.report/refactoring-plan-20260612.md)に基づき、BE_refacter / FE_refacter で検知した技術的負債を修正し、同じ負債の再発を防ぐためのルール・設定を整備した。Backend 修正(3件)
パターン C — ORM model への表示ロジック混入
backend/app/models/resume.pyからsort_utilsの import を削除Resume.experiences/Resume.qualifications/ResumeClient.projectsの@propertyがソート済みリストを返していたが、repository のsort_orderと relationship のorder_byで既に順序保証されていたため二重ソートを解消パターン A — router から collector を直接 import
routers/blog/accounts.pyがnormalize_username/verify_user_existsを直接呼び、外部 API 例外を router 内で処理していたBlogAccountService.add_account()を新設し router を service への委譲のみに変更app.routers.blog.accounts.*→app.services.blog.account_service.*に修正パターン B — router 内 DB クエリ直書き
routers/github_link.pyの_get_or_create_cache()をgithub_link_service.pyのget_or_create_github_link_cache()として移設Backend テスト: 505 件 pass
Frontend 修正(1件)
モーダル useState が 3 個以上(component-design.md 違反)
CareerResumeForm.tsx(534 行)のshowDeleteConfirm/showSaveConfirm/editingField+handleDelete/handleConfirmSaveをuseCareerFormModalsフックに集約useCareerFormModals.test.ts)Frontend テスト: 329 件 pass
ルール・設定整備
再発防止のため以下を追加・修正:
.claude/rules/backend/layers.md— 層ごとの禁止事項と Bad/Good 例(パターン A/B/C).claude/rules/frontend/component-design.md— コンポーネント設計ルール.claude/CLAUDE.md— 「失敗から学んだ知見」に 3 項目追記CONTRIBUTING.md— ブランチ戦略修正・ADR 一覧更新(ADR-0007〜0010 追加).github/PULL_REQUEST_TEMPLATE.md— PR チェックリスト.claude/settings.json— Stop hook(セッション終了時にmake dupe-checkをバックグラウンド実行)セルフレビューチェックリスト
make ci相当が pass している(backend: 505 tests、frontend: 329 tests)https://claude.ai/code/session_01GBcTxFo79GGmT7FcCuREVT