💻 システム開発

06_scale-finance_分離依頼

最終更新 2026年06月24日 / 31_システム開発部/分離プロジェクト依頼書/06_scale-finance_分離依頼.md

依頼書: SCALE Base から「Finance(経理・財務)」を独立プロジェクトに分離

新しい Claude Code セッション宛て。コピペでそのまま実行可能。完了後 Slack #system_scalebase で大串に報告。


あなたが実行すること

SCALE Base モノリス内の Finance 機能(経理・売上・経費管理)scale-finance プロジェクトに分離。
完了後 scale-base のサイドバー「Finance」をクリックすると新プロジェクトを開く。

注: scale-base 内のディレクトリ名は accounting だが、サイドバー表示名・新プロジェクト名は Finance / scale-finance で統一。

並行セッションでの開発は無いので落ち着いて作業 OK。


SCALE Base 全体情報

項目 内容
scale-base ローカル /Users/oogushiyuuki/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/scale-base/
scale-base 本番 https://scale-base.pages.dev/
Framework Next.js 15+(App Router)
デプロイ Cloudflare Pages(bash scripts/deploy.sh
共有データ Worker https://scale-task-cron.y-ogushi.workers.dev
認証 lib/auth-context.tsx の DEMO_USERS 固定

進捗チェックリスト

  • [ ] ローカル ~/Library/CloudStorage/.../AI/scale-finance/ 作成
  • [ ] Next.js + Tailwind 雛形
  • [ ] scale-base 共通設定コピー
  • [ ] accounting 関連コード移植
  • [ ] パスをトップレベル化
  • [ ] レイアウト + 認証
  • [ ] ローカル動作確認
  • [ ] Cloudflare Pages project scale-finance 作成 + デプロイ
  • [ ] scale-base の systems.ts で accounting に externalUrl + 旧コード退避
  • [ ] scale-base 再デプロイ
  • [ ] Slack 完了報告

Step 1: 雛形

cd ~/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/
npx create-next-app@latest scale-finance --typescript --tailwind --app --src-dir=false --import-alias="@/*" --no-eslint
cd scale-finance

Step 2: 共通設定コピー

SRC=~/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/scale-base
cp "$SRC/tailwind.config.ts" ./
cp "$SRC/app/globals.css" ./app/globals.css
mkdir -p lib
cp "$SRC/lib/auth-context.tsx" ./lib/
cp "$SRC/lib/tasks-api.tsx" ./lib/ 2>/dev/null || true

Step 3: accounting コード移植

mkdir -p app components functions/api
cp -r "$SRC/app/(dashboard)/accounting/." ./app/
cp -r "$SRC/components/accounting" ./components/ 2>/dev/null || true
cp "$SRC"/lib/accounting-*.ts ./lib/ 2>/dev/null || true
cp "$SRC"/lib/finance-*.ts ./lib/ 2>/dev/null || true
cp "$SRC"/functions/api/accounting*.ts ./functions/api/ 2>/dev/null || true
cp "$SRC"/functions/api/finance*.ts ./functions/api/ 2>/dev/null || true

Step 4: パスをトップレベル化

旧 /accounting              → 新 /
旧 /accounting/revenue      → 新 /revenue
旧 /accounting/clients      → 新 /clients
旧 /accounting/expenses     → 新 /expenses
旧 /accounting/tax-legal    → 新 /tax-legal
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' "s|'/accounting/|'/|g" {} \;
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' 's|"/accounting/|"/|g' {} \;
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' "s|'/accounting'|'/'|g" {} \;
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' 's|"/accounting"|"/"|g' {} \;

Step 5: ルートレイアウト

app/layout.tsx

import './globals.css';
import { AuthProvider } from '@/lib/auth-context';

export const metadata = { title: 'SCALE Finance' };

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="ja">
      <body className="bg-bg text-text">
        <AuthProvider>
          <header className="sticky top-0 z-30 bg-bg2 border-b border-border px-4 py-2 flex items-center justify-between">
            <a href="https://scale-base.pages.dev/home/" className="text-xs text-text2 hover:text-text">← SCALE Base に戻る</a>
            <span className="text-sm font-bold text-text">SCALE Finance</span>
          </header>
          <main className="p-4 md:p-6">{children}</main>
        </AuthProvider>
      </body>
    </html>
  );
}

Step 6: 認証ガード

'use client';
import { useEffect } from 'react';
import { useAuth } from '@/lib/auth-context';

export default function Page() {
  const { user, isLoading } = useAuth();
  useEffect(() => {
    if (!isLoading && !user) window.location.href = 'https://scale-base.pages.dev/';
  }, [user, isLoading]);
  // ...
}

Step 7: ローカル確認 + deploy.sh

npm run dev
mkdir -p scripts
cat > scripts/deploy.sh <<'EOF'
#!/bin/bash
set -e
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
TS=$(date +%Y-%m-%d_%H%M%S)
mkdir -p "$ROOT/../scale-finance-backups"
tar --exclude='node_modules' --exclude='.next' --exclude='out' --exclude='.wrangler' \
  -czf "$ROOT/../scale-finance-backups/scale-finance_${TS}_pre-deploy.tar.gz" -C "$ROOT" .
rm -rf .next out
NODE_OPTIONS="--max-old-space-size=8192" npx next build
npx wrangler pages deploy out --project-name=scale-finance --branch=main --commit-message="scale-finance deploy"
tar --exclude='node_modules' --exclude='.next' --exclude='out' --exclude='.wrangler' \
  -czf "$ROOT/../scale-finance-backups/scale-finance_${TS}_post-deploy.tar.gz" -C "$ROOT" .
echo "✓ Deploy complete → https://scale-finance.pages.dev/"
EOF
chmod +x scripts/deploy.sh

Step 8: Cloudflare Pages 作成 + デプロイ

npx wrangler pages project create scale-finance --production-branch=main
bash scripts/deploy.sh

Step 9: scale-base 側更新

scale-base/lib/systems.ts の accounting エントリ:

{
  id: 'accounting',
  name: 'Finance',
  shortName: 'Finance',
  icon: Calculator,
  color: '#14b8a6',
  bgColor: 'rgba(20,184,166,0.15)',
  sections: [],
  externalUrl: 'https://scale-finance.pages.dev/',
},

旧コード退避:

cd ~/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/scale-base
mkdir -p _archived_apps
mv "app/(dashboard)/accounting" "_archived_apps/accounting_$(date +%Y%m%d)"
mv "components/accounting" "_archived_apps/components_accounting_$(date +%Y%m%d)" 2>/dev/null || true
mkdir -p _archived_apps/lib_accounting _archived_apps/functions_accounting
mv lib/accounting-*.ts lib/finance-*.ts _archived_apps/lib_accounting/ 2>/dev/null || true
mv functions/api/accounting*.ts functions/api/finance*.ts _archived_apps/functions_accounting/ 2>/dev/null || true
npx next build
bash scripts/deploy.sh

Step 10: 動作確認 + Slack 報告

#system_scalebase に:

:white_check_mark: scale-finance 分離完了
URL: https://scale-finance.pages.dev/

依頼者: 大串 / 最終更新: 2026-04-29