Skip to content

BE/FE refactaring#243

Merged
yusuke0610 merged 18 commits into
devfrom
refactor/backend/deadcode
May 15, 2026
Merged

BE/FE refactaring#243
yusuke0610 merged 18 commits into
devfrom
refactor/backend/deadcode

Conversation

@yusuke0610

Copy link
Copy Markdown
Owner

refactor(backend): 非同期タスク責務分離・スキル分類整理・LLM 遅延化

概要

backend_refacter スキルでのレビュー結果(.ghpr/BackendRefactorReview.md)に沿って、High → Medium → Low
の順で保守性リファクタを実施。動作仕様は変更せず、ルーター・ワーカー・スキル分類の責務分離と単体テストの重複削除を行った。

変更内容

High

  • タスク状態機械を AsyncTaskCacheService に集約 (services/tasks/dispatch_service.py 新設)
    3 ルーター (blog / intelligence / career_analysis) の generate+retry に散らばっていた「キャッシュ pending 化 → dispatch → 失敗時 dead_letter」フローを 1
    サービスに集約。_RETRYABLE_TERMINAL_STATUSESservices/tasks/base.py へ移動し is_in_progress / is_retryable_terminal ヘルパで統一。
  • Worker のハンドラ抽象化 (services/tasks/handlers/ パッケージ新設)
    TaskHandler 抽象 + レジストリで _get_task_record の if/elif を排除。GitHubAnalysisHandler / BlogSummarizeHandler / CareerAnalysisHandler
    に各タスクの実装を移動。
  • position_scorer.py の責務分離 (335 → 215 行)
    スキル分類辞書 5 件 (_LANG_SKILL_MAP 等) を skill_taxonomy/ownership_map.py に切り出し。position_scorer.py はスコア算出ロジックのみに縮約。
  • github_collector.py の後方互換シム除去
    _detect_from_root_files 等の再エクスポート 7 件を削除し、テストを github.repo_analyzer 直参照に変更。test_intelligence.py の重複テスト 13 件を削除(pom.xml /
    go.mod のみ残置)、test_worker_timeout.py をタイムアウト伝播 2 件に縮約。

Medium

  • LLM クライアントを遅延化
    llm_summarizer._client / career_analysis._llm_client のモジュールロード時即時化を @lru_cache 経由の遅延ロードに変更。テストでも LLM_PROVIDER
    切替が効くようになる。
  • 不足スキル要件を JSON 化
    _find_missing_skillschecks 辞書を position_weights.jsonrequirement_skill_map に外出し。要件追加時にコード変更が不要に。
  • seed.py を JSON 化 (545 行 → 35 行)
    資格 249 件・技術スタック 128 件のデータを db/seeds/qualifications.json / technology_stacks.json に分離し、seed.py はローダーに縮約。

Low

  • skill_extractor._extract_from_repoadd() クロージャで 5 ソース共通化。
  • github_callback_redirect の HTMLResponse 構築重複を _build_callback_html_response ヘルパに集約。
  • blog/collector.pyhttpx.AsyncClient(timeout=...) 即値を _FETCH_TIMEOUT_SECONDS / _VERIFY_TIMEOUT_SECONDS 定数化。

バグ修正(リファクタ副産物)

  • career_analysis.generate の dispatcher 失敗時に dead_letter を設定していなかった不整合を、AsyncTaskCacheService.dispatch 集約に伴い 3 ルーターで挙動統一。

関連 Issue

closes #

確認事項

  • cd backend && .venv/bin/python -m ruff check app tests alembic_migrations がパスすること
  • cd backend && .venv/bin/python -m pytest -q tests がパスすること(342 件 PASS)
  • frontend 側に影響なし(API スキーマ・エンドポイント・レスポンス形式は不変)
  • dev 環境でデプロイ後、/api/intelligence/analyze / /api/blog/summarize / /api/career-analysis/generate の dispatch + retry が従来通り動作すること

@yusuke0610

Copy link
Copy Markdown
Owner Author

概要

フロントエンドのカスタムフック・ページコンポーネントのリファクタリング。責務の分離・重複テストの整理・不足テストの追加を行い、コードの見通しを改善した。

変更内容

フック抽出

  • useCareerExperienceMutators(新規)
    CareerExperienceSection に散在していた 10 個のネスト更新ハンドラをカスタムフックに抽出。Section 本体を 281 行 → 90 行に削減。
  • useBlogAccountManager リファクタリング
    • PlatformKey 型をエクスポートし、クロスファイルでの重複定義を排除
    • 二重ネストした try/catch を SyncResult 判別共用体 + syncAndReload に置き換え、部分成功パターン(アカウント保存成功・同期失敗)を明示化
    • error を accountError(CRUD 系)と summaryError(AI 分析系)に分離し、UI 側で独立表示できるよう整理

コンポーネント分割

  • BlogPage(309行 → 90行)
    プラットフォーム連携 UI を BlogPlatformList、記事一覧・フィルター・ページネーションを BlogArticleList に切り出し。BlogPage は filter state
    管理とフック呼び出しのみの薄いオーケストレーターに。
  • CareerAnalysisPage(374行 → 115行)
    6 つの結果セクション(GrowthSummary / TechStack / Strengths / CareerPaths / ActionItems / LearningResources)と OFFICIAL_DOCS 定数を
    result/CareerAnalysisResultView.tsx に移設。
  • ProjectModal
    JSON.parse(JSON.stringify(...)) による深いコピーを structuredClone() に置き換え。

テスト整理・追加

  • ProjectModal.test.tsx を 4 ケース → 1 ケース(disabled 確認のみ)に圧縮
  • useProjectModalState.test.ts を 6 ケース → 1 ケース(save パス)に圧縮
  • useProjectModalState.validation.test.ts を廃止し payloadBuilders.test.ts として移設(テスト対象と置き場所を一致させる)
  • 不足していたテストを追加:
    • api/client: POST に X-CSRF-Token が付与されること / GET には付与されないこと
    • useAsyncAnalysisPage: status: "retrying" で polling フェーズに遷移すること
    • useBlogAccountManager: 自動同期成功時に synced_count を含む success メッセージが表示されること
    • useNotifications: openPanel で未読のみが表示されること / markAllAsRead で unreadCount が 0 になること

関連 Issue

closes #

確認事項

  • npm run lint パス
  • npm test(15 ファイル 71 テスト)パス
  • npm run build パス

@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2bf934a5-2fe5-45cf-ad87-ff14df945a41

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/backend/deadcode

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

yusuke0610 and others added 17 commits May 15, 2026 18:25
- flake.nix に opentofu パッケージを追加し、dev shell から `tofu` を提供
- .github/workflows/terraform-ci.yml を opentofu-ci.yml にリネームし、
  hashicorp/setup-terraform を opentofu/setup-opentofu@v1 に差し替え
- 旧 .terraform.lock.hcl を削除(初回 tofu init で registry.opentofu.org
  ベースに再生成する想定)
- Makefile に infra-fmt / infra-validate-{dev,stg,prod} を追加
- .claude/rules/infra/terraform.md を opentofu.md にリネームし内容更新
- README / infra/README / runbook の terraform 表記を tofu / OpenTofu に更新

GCS backend 互換のため state はそのまま流用可能。Branch protection の
status check 名は terraform-* から opentofu-* に変わる点に注意。
@yusuke0610
yusuke0610 force-pushed the refactor/backend/deadcode branch from b6ca4be to 3fff13e Compare May 15, 2026 11:12
@yusuke0610
yusuke0610 force-pushed the refactor/backend/deadcode branch from 58f1b52 to 9363d69 Compare May 15, 2026 11:28
@yusuke0610
yusuke0610 merged commit 8cd8262 into dev May 15, 2026
16 checks passed
This was referenced May 15, 2026
Merged
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants