posimai-root/docs/master-architecture.md

284 lines
14 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Posimai Project — マスターアーキテクチャドキュメント
最終更新: 2026-04-20
対象: Claude Code / Cursor / Gemini / 全 AI エージェント
**このドキュメントはプロジェクトの現状を一元管理します。実装の前に必ず読んでください。**
---
## 0. ビジネス体制(確定)
- **Eiji**: 共同経営者。VPS・DNSsoar-enrich.com・Cloudflare 管理・対外窓口・代表。VPS は mai も自由に操作可。
- **mai**: プロダクト開発担当。アプリ設計・実装・AI 活用。
- インフラ・ドメイン共用は設計通り。
---
## 1. 全体構成図2026-04-06 確定)
```
╔══════════════════════════════════════════════════════════╗
║ mai の開発環境Windows 11 PC
║ VS Code / Claude Code CLI ║
╚══════════════════════════════════════════════════════════╝
│ git pushgitea + github の2リモート同時
│ ※ Gitea 廃止は検討中・現状維持
╔══════════════════════════════════════════════════════════╗
║ コード管理 ║
║ GitHub← Vercel 自動デプロイトリガー ║
║ GiteaNAS← バックアップのみ・確認先にしない ║
╚══════════════════════════════════════════════════════════╝
│ GitHub push → Vercel 自動デプロイ
╔══════════════════════════════════════════════════════════╗
║ フロントエンドVercel / CDN
║ posimai.soar-enrich.com → posimai-dashboard ║
║ *.posimai.soar-enrich.com → Vercelワイルドカード設定済
║ 全 30 本前後の PWA静的/Next 混在) ║
╚══════════════════════════════════════════════════════════╝
│ https://api.soar-enrich.com/brain/api/...
╔══════════════════════════════════════════════════════════╗
║ バックエンド本番VPS85.131.245.239 ║
║ Ubuntu 25.04 / AMD EPYC 4コア / 5.8GB RAM ║
║ ║
║ Nginx: api.soar-enrich.com → :8090 ║
║ posimai-apiNode.js / Express / :8090
║ PostgreSQL 16posimai_brain DB
║ VOICEVOX:50021稼働済み ║
╚══════════════════════════════════════════════════════════╝
╔══════════════════════════════════════════════════════════╗
║ Ubuntu PC100.77.11.43 / Tailscale
║ ・posimai-dev:3333ブラウザターミナル + Station ║
║ ・StationHDMI 全画面監視) ║
║ ・Openbox + Chromium kiosk ║
╚══════════════════════════════════════════════════════════╝
╔══════════════════════════════════════════════════════════╗
║ Synology NAS100.76.7.3 / Tailscale のみ) ║
║ ・Gitea:3000git バックアップ ║
║ ・Uptime Kuma:3002死活監視 ║
║ ・旧 API / PostgreSQL 15停止可能・保留中
║ ・Ubuntu PC → NAS rsync バックアップ毎日3時
╚══════════════════════════════════════════════════════════╝
╔══════════════════════════════════════════════════════════╗
║ 外部サービス ║
║ ResendMagic Link メール / noreply@soar-enrich.com
║ Stripeテストモード稼働中 / 月額¥500
║ Gemini APIVPS 経由・gemini-2.5-flash 固定) ║
║ Google Places APIMaps アプリ・フロント直接・要改善) ║
╚══════════════════════════════════════════════════════════╝
```
---
## 2. VPS PostgreSQL — テーブルとデータの実体
| テーブル | 何が入っているか | AIが関与するか |
|---------|----------------|--------------|
| `users` | ユーザー情報・planfree/premium・Stripe ID | なし |
| `auth_sessions` | JWTセッション | なし |
| `articles` | Brain保存記事・**AI要約summaryカラム**・全文・トピック | Gemini が要約生成・VPS に永続保存 |
| `journal_posts` | Journal投稿・タグ | タグはGeminiが提案その場限り |
| `reading_history` | 読んだURL・タイトル・ドメイン | なし |
| `habit_habits` / `habit_log` | 習慣定義・達成ログ | なし |
| `pulse_log` | 気分・エネルギー・集中度・メモ | なし |
| `lens_history` | 写真EXIFデータ・サムネイル | なし |
| `together_groups/members/shares/reactions/comments` | Together全データ2026-04-06 Supabaseから移行済み | 投稿にAI要約あり |
**Supabase は撤退済み2026-04-06。** Together を VPS PostgreSQL に完全移行。
---
## 3. データ保存先(確定)
| 保存先 | 対象 | 状態 |
|--------|------|------|
| VPS PostgreSQL | brain・journal・together・reading_history・habit・pulse・認証 | 稼働中 |
| localStorage永続・移行しない | veil設定・timer設定 | 確定 |
| localStorage将来VPS移行予定 | habit・pulseVPSにテーブルは存在済み | 商用化フェーズで移行 |
| データなし(都度処理) | diff・clean・think・digest・brief・feed・timer | — |
---
## 4. アプリ間パイプライン(設計)
```
Feed発見
↓ 記事クリック
Reader読む→ reading_history に記録2026-04-06 対応済み)
↓ 保存ボタン
Brain保存・AI要約→ articles に記録
↓ 気づきをメモ
Think / Journal内省→ journal_posts
↓ 週次バッチ(未実装)
Digestまとめ→ user_activity から集計して生成
Brief音声→ Digest の内容を VOICEVOX で読み上げ
↓ 公開したいものだけ
Together共有→ together_shares
```
**Pulse/Habit は横断的に記録され、Rewind振り返りアプリの材料になる将来。**
### 未実装・改善が必要なもの
| 課題 | 内容 | 優先度 |
|------|------|--------|
| `user_activity` テーブル | アプリ横断の行動ログ基盤。Digestの週次集計に必要 | 中 |
| habit/pulse → VPS移行 | テーブルはVPSに存在。アプリ側をAPI呼び出しに変えるだけ | 中premium機能として |
| Together に Brain/Journal 連携 | `source_type` / `source_id` カラム追加で Brain記事を直接共有可能 | 低 |
| Digest `/api/digest/weekly` 実装 | user_activityから週次サマリー生成 | 低 |
| Google Places API → VPS経由化 | Mapsアプリのキーがフロントに露出している | 低(急がない) |
---
## 5. 認証フロー(確定・全て稼働中)
```
Magic LinkResend メール → JWT
Google OAuth → VPS → JWT → /auth/verify?type=oauth
GitHub OAuth → VPS → JWT → /auth/verify?type=oauth
WebAuthn / PasskeyrpID: posimai.soar-enrich.com
JWT: { userId, sid, plan }
plan = "free" or "premium"Stripe決済後にDB更新
/auth/session/verify → { ok, userId, plan, purchased }
```
**Supabase Auth は不採用。完全 VPS 自前認証。**
`X-API-Key`・`?init_key=` の旧認証体系は一部アプリが依存しているため変更禁止。
---
## 6. 販売フロー(テストモード稼働中)
```
posimai-storeLP
→ Stripe Payment Link月額¥500・1日無料トライアル
→ Stripe Webhook → VPS → users.plan = "premium"
→ JWT に plan: "premium" が入る
→ 各アプリで purchased フラグで機能出し分け可能
```
**本番切り替え待ち:** Storeデザイン確定 → 特商法記入 → Stripe本番切り替え
---
## 7. アプリ一覧代表・2026-04-20 追記)
| アプリ | バックエンド | 備考 |
|--------|------------|------|
| posimai-dashboard | — | Next.js / メインダッシュボード |
| posimai-brain | VPS API | 記事保存・AI要約 |
| posimai-feed | Vercel Serverless + RSS | フィード(キー不要) |
| posimai-reader | VPS API | 記事リーダーreading_history連携済み |
| posimai-journal | VPS API | CMS / Geminiタグ提案 |
| posimai-together | VPS API | 共有Supabaseから移行済み |
| posimai-brief | VPS TTS | VOICEVOX音声 |
| posimai-daily | VPS API | ブリーフィング |
| posimai-habit | localStorage → VPS予定 | 習慣管理 |
| posimai-pulse | localStorage → VPS予定 | 気分記録 |
| posimai-think | Gemini直接 | AI思考整理 |
| posimai-digest | Gemini直接 | テキスト要約 |
| posimai-maps | Google Places APIフロント直接 | 要VPS化 |
| posimai-tech-events | VPS経由RSS | ITイベント |
| posimai-atlas | VPS API | インフラ構成図 |
| posimai-site | VPS API | 公開ホームページ |
| posimai-lens | — | EXIF表示処理のみ |
| posimai-diff | — | テキスト差分(処理のみ) |
| posimai-clean | — | テキストクリーナー(処理のみ) |
| posimai-timer | — | タイマーlocalStorage |
| posimai-veil | — | アプリランチャー |
| posimai-ambient | open-meteo | 常時表示 |
| posimai-roadmap | — | ロードマップ |
| posimai-widget-dl | — | ウィジェット |
| posimai-events | VPS API | イベント情報モック・Beta |
| posimai-hotels | — | ホテル価格モック・Beta |
| posimai-analytics | — | Next.js / RFM分析 |
| posimai-guard | Gemini API | AI コードセキュリティスキャン |
| posimai-store | Stripe / VPS | アプリ販売 LP |
| posimai-log | — | 開発ログビューワーscribe 連携) |
| posimai-boki | — | 簿記2級 学習 PWAlocalStorage |
| posimai-sc | — | 支援士試験 学習 PWAlocalStorage・非公式補助 |
---
## 8. デプロイパイプライン
```bash
# フロントエンド(全アプリ共通)
git add . && git commit -m "feat/fix/chore: ..." && npm run deploy
# = git push gitea main && git push github main → Vercel 自動デプロイ
# VPS バックエンドserver.js 変更時)
bash deploy-server.sh
# Ubuntu PCposimai-dev/station 変更時)
npm run deploy:dev # git push + scp + systemctl restart
```
- `vercel --prod` 直接実行: **禁止**
- VPS DBバックアップ: 毎日4時自動実行・7日分保持・正常稼働確認済み2026-04-06
---
## 9. 残タスク(優先順)
### 商用化直結maiの決定が必要
| タスク | 状態 |
|--------|------|
| **どのアプリにpremium機能を実装するか決める** | **未決定・最重要** |
| Storeデザイン確定A/B/C/D | Eiji意見待ち |
| 特商法ページ記入(事業者名・住所等) | mai手動作業 |
| Stripe本番モード切り替え | デザイン確定後 |
### AIが対応可能maiの決定後
| タスク | 工数 |
|--------|------|
| 各アプリへのpremiumフラグ実装 | 1アプリ30分 |
| habit/pulse → VPS API移行 | 各2時間 |
| user_activityテーブル追加 | 2時間 |
### 保留・検討中
| 項目 | 状態 |
|------|------|
| Giteaをdeployから外す | 検討中(廃止メリットあり・決定待ち) |
| Uptime Kuma → Ubuntu PC移設 + UptimeRobot追加 | 検討中 |
| Synology 旧コンテナ停止 | 保留 |
---
## 10. 設計判断ログ
| 日付 | 決定事項 |
|------|---------|
| 2026-03-25 | バックエンドを Synology → VPS に移行完了 |
| 2026-03-26 | API URL を `api.soar-enrich.com` に分離完了 |
| 2026-03-29 | Supabase Auth を不採用。VPS 自前認証を正規方針に確定 |
| 2026-04-04 | Google OAuth + GitHub OAuth 実装完了 |
| 2026-04-04 | Stripe Webhook 実装完了・テスト決済確認済み |
| 2026-04-06 | Together を Supabase → VPS PostgreSQL に完全移行61件 |
| 2026-04-06 | *.posimai.soar-enrich.com ワイルドカード DNS 設定済み確認 |
| 2026-04-06 | Reader reading_history を localStorage → VPS に修正済み |
| 2026-04-06 | WebSocket認証・SSRF blocklist・Feed POST認証・e.message修正済み |
---
## 11. 絶対に守るルール(全 AI 共通)
1. **デプロイは `npm run deploy` のみ**`vercel --prod` 禁止)
2. **絵文字禁止**コード・UI・コミット全て
3. **Lucide @0.344.0 固定**`@latest` 禁止)
4. **デザイントークン外の色直接使用禁止**`var(--accent)` を使う)
5. **`git push origin` 禁止**gitea と github の2リモートのみ
6. **Gemini モデルは `gemini-2.5-flash` 固定**
7. **このファイルを変更したら「最終更新」日付を更新する**