🔥

Mac mini m4pro 64GBでGPT-OSS:120Bが動いたセッティング

に公開

はじめに

8月も末になり、リリースからおおよそ3週間立ってしまったのですが、日々アップデートの激しいLLMのモデルリリースの中でも今回のOpenAIのリリースには大変驚かされ、また実務で助けられてます。
GPT-5のコストと推論のパフォーマンスの高く、Codexの設計と自分のスタンスと噛み合ってるので対話しながらちょっとずつ精度良く回収できているので作業が比較的に楽になりました。

ただ、驚きという意味ではGPT-OSSはさらなりというところで、初日にOllamaから20Bをインストールして色々触った末にトークン生成のスピード出力頻出の高さに驚かされて、顎が外れました。

ただ、あの日は思い出すと同時に悔しさもあったことを思い出します。

gpt-oss-120b と gpt-oss-20b 両方のウェイトは、Hugging Face から無料でダウンロードでき、MXFP4 でネイティブに数値化されています。これにより、 gpt-oss-120B モデルは80GB のメモリ内で実行でき、gpt-oss-20b は16GB のみ必要とします。公式サイトより

「20Bと120B!?うぉぉぉぉぉ!」

そんな気持ちになるとともに、

「オラのMac mini Local LLM用に買ったけどメモリ64GBしかねぇ…もう少し待ってから買えばよかったかも」

そんな少しがっかりした気持ちになりました。

https://openai.com/ja-JP/index/introducing-gpt-oss/

ただ、やっぱりローカルで出たタイミングで120Bを動かしたいという気持ちがあって、諦めきれない部分もあったのでtwitterで成功事例がないかを探していたのですが、
LM Studioで設定すれば動くなどコンフィグまでは乗っていないものの、どうやらできるらしいということでLM Studioで動かし始めました。

動かしてはみたのですが、Q4で細かいコンフィグも入れてなかったので超低速で動いたというのが最初のトライでした。すごく寂しかったです。

だいぶ悔しいので次の日の業務終わりから、一人シコシコとより細かくコンフィグができるllama.cppを使ってGPT-5とともに実験してみました。

今回の記事はできるだけ多くの人が動かせるようになること願って実験結果とコマンドをシェアすることを目的としてます。

解説は別の記事にて

チューニング後の生成速度

llama.cppのパラメータを調整した末に満足のいく結果は出ました。

Q3で量子化した120Bを使って以下のパラメーターで実行したところ、概ねいろんな質問を投げかけると以下のような生成速度とメモリ消費になりました。

項目 結果
生成速度 20tok/sec(トークン/秒)
RAMの消費量 27GB

実用性からいけば十分ですね!

セットアップ

llama.cppをinstall

llama.cppのセットアップは以下のリンクを参照

brew install llama.cpp

https://github.com/ggml-org/llama.cpp/blob/master/docs/install.md

モデルをダウンロード(gguf形式)

hugging faceからQ3_K_L 62.6 GBを落としてください。

https://huggingface.co/bartowski/openai_gpt-oss-120b-GGUF?utm_source=chatgpt.com

ダウンロードの際は分割ファイルなので気をつけてください。

二つとも必要かつ同じディレクトリに収める必要があります。

コマンド

llama.cppを呼び出す際のパラメータをコマンドごとシェアします。
洗い出したプロセスは1つの記事に収まらないので別の記事にします。

とりあえずこれ使ってください!

llama-cli

対話形式でターミナルにて生成する

llama-cli \
  -m <model_dir>/openai_gpt-oss-120b-Q3_K_L-00001-of-00002.gguf \
  --cpu-moe \
  --n-gpu-layers 16 \
  --batch-size 160 \
  --ctx-size 16384 \
  -ctk q8_0 -ctv f16 \
  -t 8 --threads-batch 6 \
  --simple-io

llama-server

デフォルトで8080ポートで公開

llama-server \
  -m <model_dir>/openai_gpt-oss-120b-Q3_K_L-00001-of-00002.gguf \
  --cpu-moe \
  --n-gpu-layers 16 \
  --batch-size 160 \
  --ctx-size 16384 \
  -ctk q8_0 -ctv f16 \
  -t 8 --threads-batch 6

成功した時は正直感無量で、
「クラウドのハイスペックな資源を使うのもいいけど、エンジニアとしてはチューニングできてなんぼだよな」
そんな成功体験を確かめることができました。

出力品質の検証

モダンなフロントアーキテクチャのベストプラクティスについて尋ねてどの程度の推論がなされるのかを試してみました。
単純に聞くだけではつまらないので、プロンプトにはループやセルフフィードバックを行うような文言にしました。

期待と結果

私の想定では

「網羅的なベストプラクティス」を「自己改善ループ」で精緻化し、ベストプラクティス集として生成する

想定でしたが

「網羅的なベストプラクティス集」を吐き出し、その後「自己改善ループ」を回して「成熟度モデル+ロードマップ」まで昇華した

という流れになりました。

おもしれぇじゃねぇか!

※生成内容はあまりに長いので、記事の最後「ここからはGPT-OSS:120Bの吐いたマークダウンです」からご覧ください


項目 内容
質問文 モダンなフロントエンドアーキテクチャのベストプラクティスを洗い出して、ブラッシュアップしてください。
期待値 reasoning:洗い出しと内容チェックのループ, response:結果をまとめて出力
結果 reasoning→response→reasoning→response といった挙動

パフォーマンス

reasoningが重めなせいなのか、単純な命令を実行した場合よりもトークンの生成速度は若干落ちている印象です。
ただこれでも十分早いですね。

項目 合計時間 (ms) トークン数 / 実行回数 1トークンあたり時間 (ms) 1秒あたりトークン数
Sampling 435.53 3810 runs 0.11 8747.98
Load 32510.11 - - -
Prompt Eval 7133.70 103 tokens 69.26 14.44
Eval 757346.49 12386 runs 61.15 16.35
Total 942684.87 12489 tokens - -
Graphs Reused - 11998 - -

終わり

このログやllama.cpppについては別の記事で解説します、カロリーが高すぎて1つの記事では詰め込めれないので…

みなさん、「Mac mini 64GBでもこんな出力ができるんだ!やったね!」と思っていただければ嬉しいです!

一緒にLocal LLMを楽しみましょう!

コミュニティの紹介

ローカルLLMのコミュニティを札幌や全国でやっており、今回の検証はこの時にデモでご紹介したものをみなさんに使っていただくためにシェアしたものになります。
出たばかりでナレッジがない中ではあるので、多少雑ではありますが私としては一つ成功体験を作っていただいていろんな方が発信されるといいなと思い、ある意味捨て石になっております。

よかったら参加してください!

https://sapporo-sugoi-ai.connpass.com/event/365245/

https://lllm-jp.connpass.com/event/365498/

ここからはGPT-OSS:120Bの吐いたマークダウンです

モダンなフロントエンドアーキテクチャのベストプラクティスを洗い出して、ブラッシュアップしてください。
一般的なものを洗い出し→一般的なものからの漏れ内容チェックのループを100点と言えるまで
抽出したプラクティスをチェックの上さらに良いものを生み出す。
<|channel|>analysis<|message|>We need to produce best practices for modern front-end architecture, and "brush up". Provide list, categories: project structure, component design, state management, styling, performance, testing, CI/CD, security, accessibility, documentation, etc. Also mention tools: React, Vue, Angular, Svelte, etc. Provide guidelines, patterns: atomic design, feature-sliced, monorepo, micro frontends, etc. Also talk about bundlers (Vite, Webpack, Rollup), module federation, SSR, Edge functions, etc. Provide bullet points and explanations. Also mention progressive enhancement, design system, theming. Provide examples. Also include code snippets maybe. Also mention adoption steps. Provide a checklist. Provide references.

We need to "brush up" meaning refine and polish. So produce a comprehensive, organized, well-structured answer. Possibly include sections: 1. Foundations, 2. Architecture Patterns, 3. Tooling, 4. Code Quality, 5. Performance, 6. Security, 7. Deployment, 8. Governance. Provide best practices for each, with rationale, examples, and recommended tools.

Also note trending: Vite, esbuild, Turborepo, etc. Use micro frontends, module federation. Use TypeScript, linting, pre-commit hooks. Use component libraries, design tokens, Storybook. Use testing: unit, integration, e2e (Jest, React Testing Library, Cypress). Use CI pipelines: GitHub Actions, Nx, etc.

Also mention progressive web apps, SSR (Next.js, Nuxt, SvelteKit). Provide guidelines for caching, lazy loading, code splitting, hydration, etc.

Also talk about maintainability: feature-sliced design, domain-driven design.

Also talk about environment config, secrets management.

Also talk about monitoring: Sentry, LogRocket.

Ok let's produce.<|end|><|start|>assistant<|channel|>final<|message|># モダンフロントエンドアーキテクチャ  ― ベストプラクティス集

目的
スケーラブルで保守性の高いフロントエンドを、開発スピード・品質・パフォーマンス・セキュリティのすべての観点から実現する
以下は 「フレームワーク/ライブラリは何でも」 と前提にしたうえで、現在(2024 年)主流の技術スタックに合わせて 実務で即使える 形にまとめたチェックリストです。


1️⃣ 基盤(Project Scaffold & Tooling)

カテゴリ ベストプラクティス 推奨ツール・設定例
リポジトリ構成 - Monorepo で UI コンポーネント、ユーティリティ、ドキュメントを一元管理
- Package per feature(feature‑sliced)で依存関係を明示
pnpm + turborepo / nx
ビルドツール - Vite (or esbuild) → 超高速 HMR
- Webpack 5Module Federation でマイクロフロントエンド実装
vite@latest
webpack@5 + @module-federation/webpack
TypeScript - strict モード徹底
- isolatedModules + noEmit で型チェックだけ実行
tsconfig.jsonstrict: true
パッケージマネージャ - pnpm → ディスク容量・インストール速度が最適
- lockfile(pnpm-lock.yaml)を CI で必ず検証
pnpm i -r
Lint/Format - ESLint + PrettierZero‑Config で統一
- husky + lint‑stagedpre‑commit フック
husky add .husky/pre-commit "npx lint-staged"
コミット規約 - Conventional Commits → 自動リリース・CHANGELOG 生成
- commitlint で CI で検証
commitlint --config conventional
CI/CD - GitHub Actions / GitLab CIPR → Lint → Test → Build → Deploy のパイプライン
- Preview Deploy(Vercel/Netlify)で PR 毎にステージング環境を自動生成
.github/workflows/ci.yml
環境変数 - dotenv + type‑safe schema(zod / yup)で runtimebuildtime を分離
- Secret Management(GitHub Secrets, Vault)で平文保存禁止
zod env schema

2️⃣ UI アーキテクチャ(コンポーネント設計)

カテゴリ ベストプラクティス 推奨ツール・概念
Atomic Design - Atoms → Molecules → Organisms → Templates → Pages で階層的に分割
- Storybook で各階層をドキュメント化
storybook
Feature‑Slice(Domain‑Driven) - コンポーネントは 機能単位(例: profile/Avatar, cart/CartItem)でまとめ、UI だけでなく state, hooks, tests も同梱 src/features/profile/Avatar.tsx
コンポーネント API - Props は最小化(データは context / store から取得)
- Controlled / Uncontrolled を明確に分離
- forwardRefdisplayName を必ず設定
React.forwardRef
スタイル - CSS‑in‑JS(styled‑components, emotion) or CSS Modules でスコープ化
- Design Tokens(color, spacing, typography)を JSON / JS で一元管理
- TailwindCSSJIT モードでユーティリティ駆動
tailwind.config.cjs
アクセシビリティ - auto‑a11y テスト (jest-axe)
- ARIA ラベルは必ず付与
- キーボードナビゲーションを意識した UI コンポーネント
jest-axe
テスト - Unit: Jest + React Testing Library
- Interaction: Storybook Playwright
- E2E: Cypress / Playwright (CI で実行)
npm test, storybook test
ドキュメント - StorybookDocs ページ
- Typedoc で API 生成
- README.md をコンポーネントフォルダーに必ず置く
typedoc

3️⃣ 状態管理(State Management)

カテゴリ ベストプラクティス 推奨ツール
ローカル UI 状態 - useState / useReducer を優先
- ContextProvider が 1 つ のみ(過剰な再レンダー防止)
React useState, useReducer
アプリケーションレベル - Redux ToolkitRTK Query でデータフェッチ & キャッシュ
- Zustand / Jotai のシンプルストアを feature‑slice に埋め込む
@reduxjs/toolkit
サーバーサイドステート - React Query / SWRStale‑While‑Revalidate パターン
- Prefetchroute change で自動実行
@tanstack/react-query
型安全 - RTK QuerycreateApiendpoint → type を自動生成
- Zod で API レスポンスの runtime validation
zod
永続化 - localStorage / IndexedDBredux‑persist or zustand‑persist で自動シリアライズ
- 暗号化 必要なら crypto-jsAES 暗号化
redux-persist

4️⃣ パフォーマンス最適化

カテゴリ ベストプラクティス 推奨ツール
コード分割 - Route‑level (React Router lazy)
- Component‑level (dynamic import() + Suspense)
React.lazy, loadable-components
画像 - next‑image / vite‑image‑optimizerWebP 自動生成
- Lazy‑load (loading="lazy") + blur‑up プレースホルダー
vite-plugin-imagemin
CSS - Critical CSS 抽出 (@vitejs/plugin-legacy)
- Tailwind JIT で未使用クラス除外
purgecss
JS - esbuild / SWCESM → CJS 変換
- Tree‑shaking を有効化 (sideEffects: false in package.json)
esbuild, swc
SSR / SSG - Next.jsISR (Incremental Static Regeneration)
- SvelteKit / Nuxt 3Hybrid Rendering
next, nuxt
キャッシュ - Service Worker(Workbox)で runtime caching
- HTTP cache‑control ヘッダーを CDN で設定
workbox-build
測定 - Lighthouse CI(GitHub Action)
- Web Vitals (web-vitals lib) をリアルタイムで送信
@lhci/cli

5️⃣ セキュリティ

カテゴリ ベストプラクティス 推奨ツール
依存関係 - npm audit + GitHub Dependabot の自動 PR
- pnpm auditlockfile の整合性検証
pnpm audit
XSS 防止 - Reactauto‑escaping に依存
- dangerouslySetInnerHTMLDOMPurify でサニタイズ
dompurify
CSP - Content‑Security‑Policy ヘッダーで script‑src 'nonce' を設定
- Hash‑based スクリプト許可
helmet (Node)
CSRF - SameSite=Lax + CSRF token (double submit)
- AxiosxsrfHeaderName で自動付与
csurf
サードパーティスクリプト - Subresource Integrity (SRI) で外部 CDN の改竄防止
- npm packageintegritynpm ci 時に検証
srihash
認証 - OAuth2 / OpenID ConnectAuthorization Code PKCE
- Refresh Token Rotationrevoke を実装
oidc-client

6️⃣ デプロイ & インフラ

カテゴリ ベストプラクティス 推奨ツール
ホスティング - Edge Functions(Vercel Edge, Cloudflare Workers)で SSR/ISR の低レイテンシ Vercel, Cloudflare
CDN - Static assetsimmutable なキャッシュ(max‑age 1y)
- Asset versioninghash ファイル名)
Cloudflare, AWS CloudFront
Docker - multi‑stage ビルドで runtime imagenode:alpine に最小化
- Healthcheckreadiness probe を設定
Dockerfile
IaC - Terraform / Pulumiインフラコード化
- GitOps(ArgoCD, Flux)で デプロイ自動化
Terraform, Pulumi
Observability - Error tracking(Sentry, LogRocket)
- Performance(Web Vitals, Lighthouse CI)
- Real‑user monitoring(Google Analytics 4)
Sentry, Grafana Loki

7️⃣ 開発フロー(チームの習慣化)

ステップ 内容 ツール例
1. ブランチ戦略 GitFlowGitHub Flow(Trunk‑Based)を選択し、feature‑branch → PR → merge gitflow, github flow
2. PR テンプレート 変更点・テスト・リリースノートの必須項目を テンプレート .github/pull_request_template.md
3. CI ステータス All checks must pass (lint, test, build, security audit) required_status_checks
4. デプロイ Preview DeployStagingProduction
Canary / Blue‑Green デプロイでリスク低減
Vercel Preview, Netlify Deploy Previews
5. ロールバック Git tag + GitHub Release + Rollback script (e.g. vercel rollback <tag>) vercel, git tag
6. ドキュメント Design System(Storybook + Docs)
Architecture Decision Records (ADR)docs/adr/ に保存
adr-tools

8️⃣ チェックリスト(実装前に必ず走査)

# 0️⃣ 前提:Node >= 18, pnpm >= 8
# ----------------------------------------------------
# ① パッケージ構成
pnpm i -r && pnpm audit && pnpm doctor

# ② Lint / Format
pnpm lint && pnpm format

# ③ TypeScript 型チェック
pnpm tsc --noEmit

# ④ ユニットテスト
pnpm test:unit

# ⑤ UI コンポーネントテスト (Storybook + Playwright)
pnpm test:storybook

# ⑥ E2E テスト (Cypress)
pnpm test:e2e

# ⑦ ビルド & サイズ測定
pnpm build && pnpm size-report

# ⑧ Lighthouse CI (PR 用)
pnpm lhci autorun

# ⑨ デプロイ (preview)
pnpm deploy:preview

# ⑩ セキュリティチェック
pnpm audit && pnpm snyk test

実務のポイント

  • 失敗は早期に:CI の first‑stagelint → type → unit を配置し、ビルドはその後に行う。
  • 失敗は必ずブロック:GitHub の branch protection rulerequired checks を設定。
  • スコープは小さく:Feature‑slice で 1 つの PR が 1 つの機能 に限定、変更範囲が 500 行未満を目安にする。

9️⃣ 代表的なスタック例(実装サンプル)

スタック 主な構成要素
React + Vite react@18, vite, typescript, eslint, prettier, tailwindcss, zustand, react-query, storybook, cypress
Next.js (Full‑Stack) next@13, react@18, typescript, eslint, prettier, tailwindcss, next‑auth, next‑image, rtk‑query, sentry, vercel
Vue 3 + Vite vue@3, vite, typescript, eslint, prettier, pinia, vue‑router, unocss, storybook, cypress
SvelteKit sveltekit, typescript, eslint, prettier, tailwindcss, @sveltejs/adapter-vercel, playwright

10️⃣ まとめ

  1. **設計は「機能単位」**で切る(Feature‑Slice) → 変更が他箇所に波及しにくい。
  2. 型安全 + ランタイム検証(Zod + RTK Query)で API 破壊的変更に即座に気付く。
  3. ビルドは Vite + Module Federation で高速かつマイクロフロントエンドへ拡張しやすい。
  4. テストは 3 層(Unit, Storybook Interaction, E2E)を必ず CI に組み込む。
  5. パフォーマンスはコード分割 + 画像最適化 + Edge CDN でフロントエンドのボトルネックを排除。
  6. セキュリティは CI で自動監査(audit, Snyk, Dependabot)+ ランタイム対策(CSP, SRI, XSS 防止)を徹底。
  7. デプロイは Preview → Staging → ProductionGitOps フローでリスク最小化。

次のアクション
1️⃣ 既存リポジトリに pnpm + Turborepo を導入し、monorepo
2️⃣ Storybookdesign‑tokens を作成、Atomic Design に沿って UI カタログ化
3️⃣ RTK Query + Zod で API 層をリファクタリングし、型安全なデータ取得に移行
4️⃣ CILighthouse CISnyk を追加し、PR で自動スコアと脆弱性レポートを取得

この手順を スプリント単位 で実施すれば、保守性・品質・デリバリースピード が同時に向上します。 🚀

<|channel|>analysis<|message|>The user says: "一般的なものを洗い出し→一般的なものからの漏れ内容チェックのループを100点と言えるまで". Japanese: "Identify the general items, then loop through checking for missing items from the general ones until you can say it's 100 points." So they want to create a checklist of general best practices, then iterate to fill missing items until it's perfect. So they want a loop: Identify general items -> check for missing items -> repeat until complete.

Thus we need to produce a systematic approach: start with categories: architecture, tooling, code quality, testing, security, performance, CI/CD, documentation, team processes, design system, accessibility, etc. Then propose a method: create a master checklist, then review each project, fill gaps, refine checklist.

We can also propose a "loop" process: initial audit, generate missing items, prioritize, implement, re-audit, repeat.

We need to be specific: a list of items, then a loop process.

Also maybe provide a template for a checklist and a flowchart.

Thus answer: Provide a comprehensive checklist of modern front-end best practices, then a loop method: audit, identify missing, implement, re-audit, etc. Also include a "definition of Done" and a scoring system.

Let's produce a detailed answer with categories, items, and a loop process, maybe a table for each category with "check" column.

Also include suggestions on automating the check: use linters, CI checks, scripts.

Ok.<|end|><|start|>assistant<|channel|>final<|message|>## 1️⃣ まずは「一般的なベストプラクティス」を全領域で洗い出す
カテゴリ項目チェックポイント の 3 階層で構造化)

カテゴリ ベストプラクティス項目 具体的なチェックポイント(YES/NO)
A. プロジェクト構成 1. Monorepo / pnpm workspace - pnpm-workspace.yaml が存在するか
- ルートに packages/ があるか
2. Feature‑Slice(ドメイン単位) - 各ドメイン (src/features/**) に components / hooks / store / tests が同梱されているか
3. CI/CD パイプライン - .github/workflows/*.ymlLint → Test → Build → Deploy を順に実行しているか
B. ビルド・ランタイム 1. Vite / esbuild で高速 HMR - vite.config.ts が存在し server.hmr が有効か
2. Module Federation(必要時) - webpack.config.jsModuleFederationPlugin が設定されているか
3. Edge / SSR / SSG の選択 - next.config.js / nuxt.config.ts 等で SSR/ISR が有効か
C. 言語・型 1. TypeScript strict モード - tsconfig.jsonstrict: true が設定されているか
2. 型安全 API クライアント - zod / yup 等で レスポンスバリデーション が実装されているか
D. コーディング規約 1. ESLint + Prettier の統一 - package.jsonlint / format スクリプトがあるか
2. Commitlint + Conventional Commits - commitlint.config.cjs が存在し CI で commitlint が走っているか
E. コンポーネント設計 1. Atomic / Feature‑Slice デザイン - src/components/atomsmoleculesorganisms があるか
2. Storybook(Docs + Playwright) - storybook が起動でき、playwright テストが CI に組み込まれているか
3. デザイントークン - tokens/ 配下に JSON/JS で color / spacing / typography が定義されているか
F. 状態管理 1. UI ローカルは useState / useReducer - useReducer の利用が過剰でないか(過度なグローバル化を防止)
2. アプリケーションレベルは Redux‑Toolkit / Zustand - store/createSlice が存在し、RTK QuerybaseQuery を持つか
3. データフェッチは React Query / SWR - useQuerystale‑while‑revalidate の設定で呼び出されているか
G. パフォーマンス 1. Route / Component Code‑Splitting - React.lazy / loadableSuspense と組み合わせているか
2. 画像最適化 - vite-plugin-imagemin 等で WebP 自動生成が走っているか
3. CSS‑in‑JS か CSS‑Modules のスコープ化 - styled-components / emotion*.module.css が使用されているか
H. テスト 1. Unit (Jest + RTL) - npm testカバレッジ ≥ 80% を出力しているか
2. Interaction (Storybook Playwright) - storybook test が成功しているか
3. E2E (Cypress / Playwright) - npm run test:e2eステージング環境 に対して走っているか
I. アクセシビリティ 1. axe‑core で自動検証 - npm test:axeA、AA 基準をクリアしているか
2. ARIA ラベル必須 - src/**/*.tsxaria- 系属性が不足していないか
J. セキュリティ 1. npm audit / Snyk - npm audit0 vulnerabilities を返すか
2. CSP / SRI 設定 - helmetContent‑Security‑Policy を出力しているか
3. XSS 対策 (DOMPurify) - dangerouslySetInnerHTMLDOMPurify.sanitize でラップされているか
K. デプロイ・インフラ 1. Preview Deploy (Vercel/Netlify) - PR 作成時に自動で preview URL が生成されているか
2. CDN キャッシュ設定 - Cache‑Control: immutable, max‑age=31536000 が静的資産に付与されているか
3. Observability (Sentry / LogRocket) - errorBoundarySentry.captureException を呼んでいるか
L. ドキュメント・ガバナンス 1. ADR (Architecture Decision Record) - docs/adr/最新 の決定記録があるか
2. Design System (Storybook Docs) - 各コンポーネントに MDX で API Docs が埋め込まれているか
3. Release‑Note 自動生成 - standard-versionCHANGELOG.md を自動生成しているか

チェックリストはスプレッドシートや Notion のテーブルに落とし、
✅ / ❌ の 2 つだけで完結させると、見える化 がすぐにできる。


2️⃣ それでも「漏れがあるか?」を検証する ループ手順

Step0️⃣ 前提:ベースラインチェックリスト(上表)を Git リポジトリにコミット しておく

(例:docs/checklist/front‑end‑baseline.md

Step1️⃣ 自動化スクリプトで一次スキャン

# 例: npm run checklist
npm run checklist   # → Markdown → JSON → GitHub Check Run に結果を出力
  • 実装例scripts/checklist.jsglobby で対象ファイルを走査し、上表の YES/NO を JSON にして process.exit(code) で CI 失敗させる。
  • GitHub Actionchecklistrequired status check に設定されていれば、PR が合格 になるまで漏れは解消できる。

Step2️⃣ 手動レビューで「抜け項目」 を拾う

手順 実施内容
2‑1 checklistFAIL した項目を Issue に自動作成(actions/create-issue
2‑2 担当者が Issue を解決 → PR にリンク
2‑3 解決したら npm run checklist を再実行し PASS になることを確認

Step3️⃣ 実装フェーズ(漏れを埋める)

項目 実装例
Lint/Format eslint --fixprettier --write
型安全 zod でスキーマ追加、tsc --noEmit でエラー解消
コンポーネント src/components/atoms/Button.tsx を作り、Storybook に Button.stories.tsx を追加
テスト Button.test.tsx → カバレッジ 90% 以上
CI npm run lint && npm test && npm run build がすべて成功することを保証

Step4️⃣ 再スキャンPASS したら 次のサイクル に移行

  • サイクルの回数2 回 以上走査し、新たな FAIL が出なければ 100 点 と判定。
  • 例外業務上不要 と判断した項目は #skip コメントで checklist.js に除外設定し、ドキュメント(ADR)で根拠を残す。

Step5️⃣ 定期的リフレッシュ(月次 / スプリント)

頻度 内容
スプリント開始前 npm run checklist未実装項目 があれば バックログ へ自動追加
リリース前 全項目必ず PASS させる(CI の required ルール)
年1回 ベストプラクティス を業界最新(React 18 → Server Components、Vite 5、Edge‑first)に合わせて 項目追加

3️⃣ 具体的な「自動チェック」スクリプト例

// scripts/checklist.js
import fs from 'fs';
import globby from 'globby';
import { execSync } from 'child_process';

// 1️⃣ 期待ファイル/設定のリスト
const EXPECTED = {
  // project structure
  'pnpm-workspace.yaml': () => fs.existsSync('pnpm-workspace.yaml'),
  'src/**/*.tsx': files => files.length > 0,
  // lint
  '.eslintrc.cjs': () => fs.existsSync('.eslintrc.cjs'),
  // type strict
  'tsconfig.json': () => {
    const cfg = JSON.parse(fs.readFileSync('tsconfig.json','utf8'));
    return cfg.compilerOptions?.strict === true;
  },
  // storybook
  'storybook/**/main.ts': () => fs.existsSync('storybook/main.ts'),
  // csp
  'src/server/**/helmet.ts': () => {
    const txt = fs.readFileSync('src/server/helmet.ts','utf8');
    return /contentSecurityPolicy/.test(txt);
  },
  // etc...
};

// 2️⃣ 実行
(async () => {
  const failures = [];

  for (const [key, checker] of Object.entries(EXPECTED)) {
    let ok = false;
    try {
      if (key.includes('**')) {
        const files = await globby(key);
        ok = checker(files);
      } else {
        ok = checker();
      }
    } catch (_) { ok = false; }

    if (!ok) failures.push(`${key}`);
  }

  if (failures.length) {
    console.error('❌ Checklist failed:\n', failures.join('\n'));
    process.exit(1);
  } else {
    console.log('✅ Checklist passed');
    process.exit(0);
  }
})();
  • GitHub Actions に組み込むだけで 必須チェック が完成します。
name: Checklist
on: [pull_request]

jobs:
  checklist:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v2
        with:
          version: 9
      - run: pnpm i
      - name: Run checklist
        run: pnpm run checklist

4️⃣ 100 点(すべての項目が PASS)になるまでの イテレーション例

イテレーション 実施内容 追加・削除したチェック項目
① 初回スキャン npm run checklist → 12 件 FAIL - pnpm-workspace.yaml が無い → 追加
- tailwind.config.cjs が無い → 追加
② 実装① Monorepo 設定、Tailwind 導入、Storybook 初期化 - 失敗項目 9 件に減少
③ 再スキャン npm run checklist → 9 件 FAIL(型 strict、CSP、RTK Query) - tsconfig.json の strict 追記
- src/server/helmet.ts に CSP 追加
④ 実装② 型安全 API クライアント、RTK Query + Zod、CSP 設定 - 失敗項目 4 件に減少
⑤ 再スキャン npm run checklist → 4 件 FAIL(E2E、Accessibility、Snyk、Preview Deploy) - E2E テストのベースを作成
- axe テスト追加
⑥ 実装③ Cypress 導入、Snyk CI、Vercel Preview 設定 - 失敗項目 1 件に減少
⑦ 最終スキャン npm run checklistPASS 100 点 完成!

ポイント

  • 失敗項目だけ小さく分割(1〜2 個)して実装する → フィードバックが早く、リグレッションが起きにくい
  • 各イテレーションの 成果物(スクリプト、設定ファイル、ドキュメント)は 必ず PR でマージし、次サイクルのベース とする。

5️⃣ まとめ ― 「ベストプラクティス → チェックリスト → ループ」 の実装フロー

  1. ベストプラクティスを 3 階層(カテゴリ・項目・チェック)で洗い出す(上表参照)。
  2. scripts/checklist.js自動スキャン を実装し、CI の必須チェック に組み込む。
  3. FAIL が出たら自動で Issue を作り、バックログ に入れる。
  4. Issue を解決コード/設定/テスト を追加 → 再スキャン
  5. PASS が出たら 次のイテレーション に進む。
  6. 全項目が PASS したら「100 点」=ベストプラクティス完全実装 とみなす。
  7. 月次 / スプリントチェックリストを更新(新技術・新要件が増えたら項目追加)し、同じループ を繰り返す。

このサイクル が「漏れが無い」ことを 機械的に 確認でき、チーム全体の品質基準 として 永続的に 活用できるようになります。


🎯 あなたがすぐに取れるアクション

# 今すぐやること
1 上記 ベストプラクティス表プロジェクトの README に貼り、カテゴリ別 にタスク化(GitHub Projects / Jira)
2 scripts/checklist.jsリポジトリに作成(上のコードをコピペ)
3 GitHub ActionsChecklist ジョブを追加し、branch protection に必須ステータスとして設定
4 最初のスキャン を走らせ、FAIL が出たら Issue 化してバックログへ投入
5 1 週間ごとに チェックリストレビュー ミーティングを開催し、新技術(例: React Server Components) を項目に追記

この手順を 1 スプリント で回すだけで、「漏れのないフロントエンド」 が手に取るように見えてくるはずです。 🚀

<|channel|>analysis<|message|>User wants to "抽出したプラクティスをチェックの上さらに良いものを生み出す。" Means: "Take the extracted practices, check them, and further create better ones." So they want to refine and improve the practices they have extracted, possibly by evaluating and generating higher-quality practices. We need to take the checklist we made and propose improvements, maybe more advanced best practices, like using type-safe GraphQL, micro-frontend, edge caching, etc. Also propose a process to iterate: review, prioritize, upgrade.

We need to produce a refined list with higher-level guidelines, perhaps categorize into core, advanced, future-proof. Provide suggestions for each category: e.g., for state management, move to TanStack Query; for testing, adopt component contract tests; for CI, use dependabot, scanning, etc. Also talk about measuring and improving.

Maybe propose a maturity model: Level 1 (basic), Level 2 (advanced), Level 3 (excellence). Provide guidelines to upgrade.

Also propose a systematic evaluation: scoring each practice, then identify gaps, then propose enhancements.

Thus answer: Provide refined practices, with rationale, code examples, and a process to keep improving.

Let's structure:

  1. Review current checklist, assign maturity levels.
  2. For each category, propose next-level practice.
  3. Provide a "Improvement Loop" steps: audit, prioritize, prototype, adopt.
  4. Provide specific advanced practices: e.g., Edge Functions, incremental static regeneration, GraphQL codegen, microfrontend, design token with Style Dictionary, etc.
  5. Provide a checklist of advanced items.

Let's produce in Japanese.<|end|><|start|>assistant<|channel|>final<|message|>## Ⅰ.まずは「現行ベストプラクティス」を成熟度で俯瞰する

カテゴリ 現行プラクティス(ベース) 成熟度レベル
(★=1, ★★=2, ★★★=3)
プロジェクト構成 Monorepo + pnpm workspace ★★
ビルド/ランタイム Vite + HMR / Module‑Federation(必要時)
言語・型 TypeScript strict ★★
コーディング規約 ESLint + Prettier + Conventional‑Commits ★★
コンポーネント設計 Atomic / Feature‑Slice + Storybook ★★
状態管理 useState / useReducer + Redux‑Toolkit(RTK‑Query)
パフォーマンス Route/Component Code‑Splitting + 画像最適化 ★★
テスト Unit (Jest/RTL) + Interaction (Storybook‑Playwright) + E2E (Cypress) ★★
アクセシビリティ axe‑core 自動検証 + ARIA 必須
セキュリティ npm audit + CSP + DOMPurify ★★
デプロイ/インフラ Preview Deploy (Vercel/Netlify) + CDN キャッシュ
ドキュメント/ガバナンス ADR + Design‑System (Storybook Docs) + CHANGELOG ★★

目標:全項目を ★★★(最高成熟度)に引き上げる。
そのために「足りない」 部分を洗い出し、次世代プラクティス を導入する。


Ⅱ.「足りない」ポイントを抽出し、上位プラクティス に昇格させる

カテゴリ 現行→上位へのギャップ 推奨上位プラクティス(★★★) 具体的な実装例
プロジェクト構成 Package‑level versioning が無い Zero‑Install monorepo(pnpm + changeset)で パッケージ単位の semver を自動生成 pnpm i -rchangeset initnpm run version
ビルド/ランタイム SSR/Edge がオプション Edge‑first(Vercel Edge Functions / Cloudflare Workers)+ Incremental‑Static‑Regeneration(Next.js ISR) next.config.jsoutput: 'standalone'revalidate を設定
言語・型 型の自動生成 が未実装 OpenAPI/GraphQL Codegen型定義自動生成openapi-typescript-codegen, graphql-code-generator npm run codegensrc/generated/*.ts
コーディング規約 Git‑hook のスコープ が緩い ESLint → @typescript-eslint/strict‑config + husky + lint‑stagedpre‑committype‑check まで走らせる husky add .husky/pre-commit "npm run typecheck && npm run lint"
コンポーネント設計 デザイントークンの一元管理 が手作業 Style Dictionary + Token‑Driven Theming(CSS‑Vars + postcss-simple-vars)で テーマ切替 をコードだけで完結 tokens/*.jsondist/css/tokens.css
状態管理 サーバーサイド同期 が手動 TanStack Query v5 + React Server ComponentsデータフェッチとキャッシュSSR 時点で自動ハイドレーション useSuspenseQueryawait できる
パフォーマンス ファーストインタラクション が測定外 Web Vitals(CLS, LCP, FID)を real‑time で送信し、SLO を CI に組み込む import {onCLS} from 'web-vitals'
テスト コンポーネント契約テスト が無い Contract Tests(Storybook → playwrightexpect(page).toHaveURL(...))で UI/API相互依存 を保証 npm run test:contract
アクセシビリティ 自動リフレッシュ が手作業 aXe CI + Lighthouse CIPR 毎に走らせ、スコアが 90 以上 でしかマージできない .github/workflows/a11y.yml
セキュリティ 依存関係の脆弱性 が手動更新 Dependabot + SnykAuto‑Fix PR + GitHub‑Advanced‑SecuritySecret Scanning dependabot.yml
デプロイ/インフラ Blue/Green デプロイ が未実装 Canary Release(Vercel Preview → Production → Canary → Full)+ Rollback API vercel --prod --confirmvercel rollback <hash>
ドキュメント/ガバナンス ドキュメントの自動生成 が手作業 Typedoc + Markdown‑Generator + Storybook DocsCI で自動生成し、gh-pages に自動デプロイ npm run docs:build

Ⅲ.成熟度向上サイクル(実装→評価→改善)

1️⃣ ① 現行チェックリスト実行 → FAIL → Issue 化
2️⃣ ② ① の Issue を「上位プラクティス」へマッピング(上表参照)
3️⃣ ③ プロトタイプ実装(PoC) → 小規模機能ブランチでマージ
4️⃣ ④ 再度全チェックリスト実行 → すべて PASS したら ★★★ に昇格
5️⃣ ⑤ ★★★ に到達した項目は **Maturity‑Gate** として CI の **required‑status** に追加
6️⃣ ⑥ 定期(2‑4 週間)に **新技術スキャン** → 追加すべき ★★★ 項目を **バックログ** に投入
  • スコアリング:各項目を 0‑5 点で自己評価し、総合スコア ≥ 4.5 で「100 点」とみなす。
  • 優先度ビジネスインパクト × 実装コストスプリント単位 に割り振る(例: Edge‑first は 高インパクト・中コスト で次スプリントへ)。

Ⅳ.実装サンプル(代表的な 3 つ)

1️⃣ Edge‑First + ISR(Next.js 13+)

// next.config.mjs
import { defineConfig } from 'next';
export default defineConfig({
  output: 'standalone',
  experimental: { appDir: true },
  images: { remotePatterns: [{ hostname: '**' }] },
  // Incremental‑Static‑Regeneration
  async rewrites() {
    return [{ source: '/:path*', destination: '/api/edge/:path*' }];
  },
});
  • デプロイvercel --prodvercel rollback <hash> で即時ロールバック。
  • テストnpm run test:e2eEdge Functioncypress からリクエスト。

2️⃣ Style Dictionary + CSS‑Vars(Design Token)

// tokens/color.json
{
  "color": {
    "primary": { "value": "#1e40af" },
    "secondary": { "value": "#ff6b6b" }
  }
}
// scripts/build-tokens.js
import StyleDictionary from 'style-dictionary';
StyleDictionary.extend({
  source: ['tokens/**/*.json'],
  platforms: {
    css: {
      transformGroup: 'css',
      buildPath: 'src/styles/',
      files: [{ destination: 'tokens.css', format: 'css/variables' }],
    },
  },
}).buildAllPlatforms();
  • 利用<html style="--color-primary:#1e40af;">テーマ切替document.documentElement.style.setProperty('--color-primary', '#...') だけで完結。

3️⃣ TanStack Query v5 + React Server Components(Next.js App Router)

// src/app/dashboard/page.tsx (Server Component)
import { Suspense } from 'react';
import { QueryClientProvider } from '@tanstack/react-query';
import { queryClient } from '@/lib/queryClient';
import Dashboard from '@/components/Dashboard';

export default function DashboardPage() {
  return (
    <QueryClientProvider client={queryClient}>
      <Suspense fallback={<p>Loading…</p>}>
        <Dashboard />
      </Suspense>
    </QueryClientProvider>
  );
}
// src/lib/queryClient.ts
import { QueryClient } from '@tanstack/react-query';
export const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      staleTime: 5 * 60 * 1000, // 5min
      refetchOnWindowFocus: false,
      retry: 2,
    },
  },
});
  • 効果:SSR 時点で データが事前取得Hydration が即座に完了、CLS が低減。

Ⅴ.チェックリスト(★★★ 版) ― そのまま CI に流すだけ

# ★★★ Front‑End Maturity Checklist

- [x] Monorepo (pnpm) + changeset で自動バージョニング
- [x] Vite + Edge‑Function (Vercel) + ISR (revalidate)
- [x] TypeScript strict + OpenAPI/GraphQL Codegen
- [x] ESLint strict + husky + lint‑staged (type‑check pre‑commit)
- [x] Atomic‑Design + Feature‑Slice + Storybook + Design‑Tokens (Style Dictionary)
- [x] TanStack Query v5 + React Server Components
- [x] Route/Component Code‑Splitting + Web Vitals real‑time reporting
- [x] Jest + RTL + Storybook‑Playwright contract tests + Cypress (E2E)
- [x] axe‑core + Lighthouse CI (A/AA ≥ 90)
- [x] Dependabot + Snyk + GitHub Advanced Security (Secret Scanning)
- [x] Canary/Canary‑Rollout + Vercel Preview → Production → Canary
- [x] Typedoc + Storybook Docs + ADR (auto‑generated on CI)

CI 設定例(GitHub Actions)

name: Maturity‑Check
on: [pull_request]

jobs:
  checklist:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v2
        with: { version: 9 }
      - run: pnpm i
      - name: Run ★★★ checklist
        run: |
          npm run lint && npm run typecheck && npm run test && npm run build && npm run checklist

Ⅵ.次の一手 ― 3 か月で 100 点に到達するロードマップ

期間 目的 具体的タスク
W1‑W2 Edge‑First + ISR の PoC next.config.mjs 設定、Vercel Preview デプロイ、Lighthouse CI で LCP < 2 s
W3‑W4 Design‑Token + Style Dictionary の導入 tokens/ 作成 → npm run build:tokens → CSS‑Vars でテーマ切替
W5‑W6 GraphQL Codegen + Typed API の自動生成 graphql-codegen 設定 → src/generated/* → CI で型チェック
W7‑W8 TanStack Query v5 + React Server Components へ移行 主要ページを SSR 化、useSuspenseQuery に差し替え
W9‑W10 Canary ReleaseRollback API の本格化 vercel.jsonroutesrewrites 設定 → npm run deploy:canary
W11‑W12 Maturity‑Gate(★★★ 必須)を branch protection に組み込み GitHub Settings → required‑status‑checksMaturity‑Check 追加
以降 技術スキャン(例: Web Vitals SLOGraphQL Persisted Queries)を バックログ に入れ、次スプリントで順次実装 -

結果:12 週間で 全項目 ★★★ へ昇格、CI が全チェックを通過 したら「100 点」と宣言できる。
以降は 新技術(例:React Server Actions、Edge‑Only SSR、AI‑generated Component Docs) が出たら同様に ★→★★→★★★ の 3 段階で取り込むだけで、継続的に成熟度を保てる


🎯 まとめ

  1. 現行ベストプラクティス → ★★★ 版へギャップを洗い出す
  2. 上位プラクティス(Edge‑first、Token‑Driven、Contract‑Test 等)PoC → 本番 のサイクルで実装
  3. チェックリスト → CI の必須ステータス に組み込み、PASS し続ける ことが 100 点 の定義になる
  4. 定期スキャン & バックログ化次世代技術段階的に ★→★★→★★★ に昇格させる

このフレームワークを 1 スプリント で 1 つずつ導入すれば、「漏れのないモダンフロントエンド」 が確実に手に入ります。

Discussion