# Dokumentasi Koinkamu / Sahamkamu

Selamat datang di dokumentasi teknis untuk platform **Koinkamu / Sahamkamu** — Crypto & Stock Trading Analysis Platform dengan **151+ fitur trading** dalam **22 wave development**.

## Daftar Dokumen

| Dokumen | Deskripsi |
|---------|-----------|
| [Getting Started](getting-started) | Setup awal — install, konfigurasi, database, seed data |
| [Features](features) | Daftar lengkap 151+ fitur trading dalam 22 wave |
| [Architecture](architecture) | Arsitektur teknis, pattern, dan konvensi kode |
| [CLI Scripts](cli-scripts) | Semua command-line scripts dan cara penggunaannya |
| [Data Sync](data-sync) | Cara kerja sinkronisasi data (Yahoo, CoinGecko, Indodax) |
| [Deployment](deployment) | Deploy ke production (Gunicorn, Nginx, cron) |

## Platform Overview

| Metrik | Jumlah |
|--------|--------|
| Total Fitur | 151+ |
| Development Waves | 22 |
| Service Files | 166 |
| Admin Routes | 164 |
| API Endpoints | 249 |
| Template Files | 164 |

## Arsitektur Singkat

```
investasi.kamu.co.id/
├── app/                          # Flask application
│   ├── blueprints/               # Route handlers
│   │   ├── admin/routes.py       # 164 admin page routes
│   │   ├── api/v1/market.py      # 249 API endpoints (~6600 lines)
│   │   ├── auth/                 # Authentication (user + admin)
│   │   └── market/               # Public market pages
│   ├── models/                   # SQLAlchemy models
│   │   ├── coin.py               # Coin, CoinProfile
│   │   ├── range_score.py        # RangeTradingScore
│   │   ├── bullish_score.py      # BullishMomentumScore
│   │   ├── signal.py             # TradingSignal
│   │   ├── ml_prediction.py      # MLPrediction
│   │   └── ...                   # User, Admin, Portfolio, dll.
│   ├── services/                 # 166 business logic services
│   │   ├── data_sync/            # Provider sync (Yahoo, CoinGecko, Indodax)
│   │   ├── buy_recommender.py    # Core: BuyRecommender aggregator
│   │   ├── multibagger_screener.py
│   │   ├── position_sizer.py
│   │   └── ...                   # 160+ analysis services
│   ├── helpers/                  # Utility functions
│   │   ├── auth.py               # @admin_required, @login_required
│   │   └── formatters.py         # Number/currency formatting
│   └── templates/                # 164 Jinja2 + Alpine.js templates
│       ├── admin/                # Admin dashboard pages
│       ├── market/               # Public market pages
│       └── base.html             # Master layout (~3500 lines)
├── scripts/                      # CLI scripts (seed, sync, migrate)
├── docs/                         # Dokumentasi (file ini)
├── .env                          # Environment variables (tidak di-commit)
├── requirements.txt              # Python dependencies
└── run.py                        # Development server entry point
```

## Tech Stack

- **Backend:** Flask 3.x + SQLAlchemy + PyMySQL
- **Database:** MySQL / MariaDB
- **Frontend:** Tailwind CSS (dark theme) + Alpine.js + Chart.js
- **Data Sources:** Yahoo Finance, CoinGecko, Indodax
- **ML:** scikit-learn, XGBoost, LightGBM
- **Server:** Gunicorn + Nginx (production)

## Mode Aplikasi

Aplikasi mendukung 3 mode aset:

| Mode | Label | Currency | Contoh |
|------|-------|----------|--------|
| `crypto` | Koinkamu | IDR (Rp) | Bitcoin, Ethereum |
| `stock` | Sahamkamu | IDR (Rp) | BBCA, TLKM |
| `stock_us` | Sahamkamu US | USD ($) | AAPL, MSFT |

## Wave Development Summary

| Wave | Tema | Fitur | Warna |
|------|------|-------|-------|
| 1-3 | Foundation & Core | 1-21 | Default |
| 4-5 | Portfolio & ML | 22-35 | Default |
| 6-8 | Charts & Analytics | 36-56 | Default |
| 9-10 | Watchlist & Recommendations | 57-70 | Default |
| 11-12 | US Stocks & Market Intelligence | 71-84 | Blue |
| 13 | Market Analytics | 85-91 | Default |
| 14-15 | Compound Growth & Heatmap | 92-105 | Default |
| 16-17 | Risk Management & Pattern | 106-119 | Default |
| 18-19 | Green Wave | 120-133 | Green |
| 20 | Violet Wave | 134-137 | Violet |
| 21 | Cyan Wave | 138-141 | Cyan |
| 22 | Profit Maximizer Engine | 142-151 | Orange |

> Lihat [Features](features) untuk daftar lengkap semua fitur per wave.

## Service Pattern

Semua service mengikuti pattern yang konsisten:

```python
class ServiceName:
    """Deskripsi service."""

    def scan_all(self, filters...):
        """Main entry point — returns paginated results."""
        # 1. Lazy import models
        from app.models.coin import Coin, CoinProfile
        from app.models.signal import TradingSignal

        # 2. Query precomputed data
        # 3. Compute scores
        # 4. Filter, sort, paginate
        # 5. Return standard response format
        return {
            'items': [...],
            'total': int,
            'page': int,
            'limit': int,
            'has_more': bool,
            'stats': {...}
        }
```

## Quick Links

- **Login User:** `/login` (admin / admin123)
- **Login Admin:** `/admin/login` (admin / admin123)
- **API Base:** `/api/v1/market/`
- **Admin Dashboard:** `/admin/`
- **Dev Server:** `http://localhost:8888`
