# CryptoEditorial — PRD

## Original Problem Statement
> "berikan saya info, mata crypto apa yang bisa menghasilkan bayak uang di bulan ini, dan beritahu saya kapan harus beli dan jual"
(Indonesian: tell me which crypto can make money this month and when to buy/sell)

User chose option E: combination platform with live tracker, AI signal analyzer, portfolio tracker, top gainers. Then in iteration 2, accepted Daily AI Newsletter feature.

## Tech Stack & Integrations
- **Backend**: FastAPI + Motor + APScheduler (cron jobs), bcrypt + PyJWT auth, httpx async client, emergentintegrations (Gemini 3 Pro)
- **Frontend**: React 19 + react-router-dom v7 + Tailwind + Framer Motion + Recharts + lucide-react + Outfit/Manrope/JetBrains Mono fonts
- **Email**: Resend (`resend>=2.0.0`) with custom domain `cryp.epnd.my.id` (sender: `news@cryp.epnd.my.id`)
- **Database**: MongoDB collections — `users`, `holdings`, `login_attempts`, `subscribers`, `newsletter_runs`
- **External APIs**: CoinGecko v3 (free tier — supports optional Demo API key for higher rate limits), Gemini 3 Pro

## User Choices Captured
- AI Model: Gemini 3 Pro (`gemini-3.1-pro-preview`)
- Currency: USD + IDR dual toggle
- Auth: Custom email/password (JWT in httpOnly cookies)
- Design: Editorial Brutalist (Swiss high-contrast)
- Newsletter: Resend, sender `news@cryp.epnd.my.id`, 08:00 Asia/Jakarta daily

## What's Been Implemented (2026-05-10)
### Iteration 1 — MVP
- ✅ Full backend API (`/api/auth/*`, `/api/crypto/*`, `/api/ai/analyze`, `/api/portfolio/*`)
- ✅ Bcrypt + JWT (httpOnly cookies) auth with X-Forwarded-For brute-force key
- ✅ Admin seeding, MongoDB indexes
- ✅ CoinGecko proxy with caching (45-300s TTLs) + retry-on-429 + stale fallback
- ✅ Gemini 3 Pro analyzer producing structured JSON signals in Bahasa Indonesia
- ✅ Editorial Brutalist UI — hero, markets table with sparklines, top gainers, coin detail with Recharts, portfolio CRUD with P&L
- ✅ USD/IDR toggle persisted in localStorage

### Iteration 2 — Daily AI Newsletter
- ✅ Subscriber model + `/api/newsletter/subscribe` (public)
- ✅ `/api/newsletter/unsubscribe` HTML page (one-click)
- ✅ `/api/newsletter/preview` HTML preview
- ✅ `/api/newsletter/test-send` and `/api/newsletter/send-now` (admin only)
- ✅ APScheduler running daily cron at 08:00 Asia/Jakarta — sends to all active subscribers
- ✅ Newsletter HTML composer: brutalist editorial design, top 5 gainers (24h) + 1 AI pick (Gemini 3 Pro analysis on top gainer) + USD/IDR rate
- ✅ Frontend: `NewsletterCTA` section on homepage with subscribe form
- ✅ Resend integration via `asyncio.to_thread` (non-blocking)

## Test Results
### Iteration 1 (backend testing agent)
- 22/26 pytest tests passed; 3 skipped due to CoinGecko external rate-limit; 1 HIGH bug fixed (X-Forwarded-For brute force)
- AI analyzer verified manually working

### Iteration 2 (manual)
- ✅ Subscribe endpoint returns OK
- ✅ Newsletter preview generates 6.9KB HTML
- ✅ Resend test-send returned email ID (delivery depends on domain verification at Resend)
- ✅ Scheduler logs: "Newsletter scheduler started — daily at 08:00 Asia/Jakarta"

## Known Issues & User Action Items
1. **Resend domain verification needed**: Sender `news@cryp.epnd.my.id` requires DNS records added at the registrar to be verified in Resend dashboard (https://resend.com/domains). Until verified, emails may bounce silently. Until then, emails go to verified-inbox-only mode.
2. **CoinGecko free tier rate limits aggressive**: ~30 req/min hard cap. Backend caches help, but heavy testing has temporarily throttled the preview pod. **Recommend**: user signs up for CoinGecko Demo API key (free, 10K req/month) at https://www.coingecko.com/en/api/pricing — paste into `COINGECKO_API_KEY=` in `/app/backend/.env`. Already wired in `cached_fetch`.
3. **Emergent LLM Key budget shared**: Heavy use can deplete. Top up at Profile → Universal Key → Add Balance.

## Prioritized Backlog
### P1 (next)
- Connect homepage subscribe form to actual UI (already done — section on homepage)
- Welcome email on subscribe
- Show subscriber count in admin dashboard
- "View in browser" link in newsletter (route to /api/newsletter/preview?token=X)

### P2
- Watchlist (favorite coins)
- Multi-buy averaging in portfolio
- Browser push notifications when AI signal flips
- Multi-language toggle (EN/ID)
- Newsletter analytics (open/click via Resend webhooks)

### P3
- News/headlines integration per coin
- Social sentiment indicators
- Premium tier — personalized AI alerts when price hits buy/sell zones

## Test Credentials
See `/app/memory/test_credentials.md`
