← Index
Source: docs/tasks/first-phase-design.md (auto-generated by scripts/generate-docs-html.mjs — edit the .md, not this file)

First Phase Design

Requirements

To Do List

Request

Design by Claude

0. Summary

Phase 1 evolves the v0 PoC into a mode-aware, deployable app: one codebase that runs locally (password login + local Ollama) and on GCP Cloud Run (Google login + cloud LLM). It is fronted by know.html as the landing page, shows an investment-summary dashboard (ETH / BTC / S&P 500 / KOSPI) right after login, adds an AI chat page, and ships with a single deploy.sh for GCP.

1. Run modes — one switch, APP_MODE

APP_MODE = local | cloud (default: auto-detect Cloud Run via the K_SERVICE env var).

concern local cloud (GCP)
auth password (Credentials provider) Google OAuth (existing NextAuth)
AI backend Ollama @ localhost:11434 hosted LLM via API key
secrets .env.local GCP Secret Manager

2. Auth & session (req: Google in cloud, password in local, ~1h session)

3. Main page = know.html (req: main page should be know.html)

4. Investment summary — default post-login view (req: ETH, BTC, S&P, KOSPI)

5. AI chat page (req: chat page; API key in cloud, local Ollama in local)

6. GCP deploy via shell script (To-Do: deploy to GCP with a shell script)

scripts/deploy.sh automates the README §9 run book, idempotent (safe to re-run), reading values from a git-ignored scripts/deploy.env:

  1. gcloud config set project, enable run / cloudbuild / artifactregistry / secretmanager APIs.
  2. create-or-update Secret Manager secrets (auth-secret, google-id/secret, market-key, ai-key).
  3. gcloud run deploy rabbit --source . --region … --no-allow-unauthenticated --set-env-vars APP_MODE=cloud,… --set-secrets ….
  4. update AUTH_URL to the deployed domain; print the reminder to add the OAuth redirect URI.

7. Config / env matrix

var local cloud purpose
APP_MODE local cloud mode switch
AUTH_SECRET ✅ (secret) NextAuth signing
SESSION_MAX_AGE 3600 3600 1-hour session
LOCAL_PASSWORD local login
AUTH_GOOGLE_ID/SECRET ✅ (secret) Google login
ALLOWED_EMAILS email allowlist
AUTH_URL callback base URL
AI_PROVIDER / AI_API_KEY ✅ (secret) cloud LLM
OLLAMA_BASE_URL / OLLAMA_MODEL local LLM
MARKET_API_KEY ✅ (secret) S&P / KOSPI data

8. New / changed files

auth.ts (conditional providers + 1h session) · middleware.ts · app/login/page.tsx · public/know.html + / route · app/summary/page.tsx + app/api/indices/route.ts · app/chat/page.tsx + app/api/chat/route.ts + lib/ai.ts · lib/market.ts · scripts/deploy.sh + scripts/deploy.env.example · .env.example updates.

9. What you (jay) need to provide (req: "Tell me what I should provide")

Before I implement, please provide / confirm:

  1. GCP — project ID, billing enabled, region (default asia-northeast3), gcloud auth login done.
  2. Google OAuth — client ID + secret (or OK for me to walk you through creating them), allowed email(s) [linked0@gmail.com?], redirect URIs.
  3. Local password — pick LOCAL_PASSWORD (or I generate one).
  4. AI — cloud provider choice (OpenAI / Anthropic / …) + API key; local Ollama model name; fix Ollama first.
  5. Market data (S&P / KOSPI) — provider choice (Alpha Vantage free tier / Twelve Data) + API key.
  6. know.html — serve as-is, or adapt its local links? (Q-A)
  7. (optional) custom domain.

AUTH_SECRET I can generate (npx auth secret).

10. Open questions

11. Suggested build order

  1. APP_MODE switch + auth (Google/cloud, password/local, 1h session).
  2. know.html landing + route guard.
  3. /summary with 4 indices (+ /api/indices).
  4. /chat (Ollama local / API cloud).
  5. scripts/deploy.sh + first GCP deploy.