# MarketScope – Deployment Guide ## Prerequisites - Node.js 18+ - Docker & Docker Compose - MySQL 8.0 (or use Docker) - Redis 7+ (or use Docker) - DOKU Checkout account (sandbox/production) --- ## 🚀 Quick Start (Development) ### 1. Backend Server ```bash cd server # Copy environment file cp .env.example .env # Edit .env with your credentials # Start MySQL + Redis via Docker docker compose up mysql redis -d # Install dependencies npm install # Generate Prisma client & run migrations npx prisma generate npx prisma migrate dev --name init # Start dev server npm run dev # → API running at http://localhost:3000 ``` ### 2. Dashboard ```bash cd dashboard # Install dependencies npm install # Start dev server npm run dev # → Dashboard at http://localhost:3001 ``` ### 3. Chrome Extension ``` 1. Open Chrome → chrome://extensions/ 2. Enable "Developer mode" 3. Click "Load unpacked" 4. Select the `extension/` folder 5. Pin the extension from toolbar ``` --- ## 🐳 Docker Deployment (Production) ### Full Stack ```bash cd server # Configure production env cp .env.example .env # Set NODE_ENV=production, real DOKU keys, DB credentials, etc. # Build and start all services docker compose up --build -d # Run database migration docker compose exec api npx prisma migrate deploy # Check logs docker compose logs -f api ``` ### Dashboard Build ```bash cd dashboard npm run build npm start # Or deploy to Vercel/Netlify ``` --- ## ⚙️ PM2 Deployment (VPS) ```bash cd server # Build TypeScript npm run build # Start with PM2 pm2 start ecosystem.config.js --env production # Save PM2 process list pm2 save # Setup startup script pm2 startup ``` --- ## 🔐 DOKU Configuration 1. Go to [DOKU Dashboard](https://dashboard.doku.com) 2. Get **Client ID** and **Secret Key** 3. Set notification URL: `https://yourdomain.com/api/v1/subscriptions/webhook/doku` 4. Update `.env`: ``` DOKU_CLIENT_ID=your-client-id DOKU_SECRET_KEY=your-secret-key DOKU_API_URL=https://api.doku.com # production DOKU_NOTIFICATION_URL=https://yourdomain.com/api/v1/subscriptions/webhook/doku ``` --- ## 🌐 Nginx Setup ```bash # Copy nginx config sudo cp server/nginx.conf /etc/nginx/sites-available/marketscope sudo ln -s /etc/nginx/sites-available/marketscope /etc/nginx/sites-enabled/ # Test and reload sudo nginx -t sudo systemctl reload nginx ``` ### SSL with Certbot ```bash sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com ``` --- ## 📦 API Endpoints | Method | Endpoint | Description | |--------|----------|-------------| | POST | `/api/v1/auth/register` | Register | | POST | `/api/v1/auth/login` | Login | | POST | `/api/v1/auth/refresh-token` | Refresh JWT | | GET | `/api/v1/auth/me` | Current user | | POST | `/api/v1/licenses/validate` | Validate license | | GET | `/api/v1/licenses/my` | User license | | POST | `/api/v1/scans` | Create scan | | GET | `/api/v1/scans` | Scan history | | GET | `/api/v1/scans/:id` | Scan detail | | GET | `/api/v1/subscriptions/plans` | Plan list | | POST | `/api/v1/subscriptions/subscribe` | Subscribe (DOKU) | | POST | `/api/v1/subscriptions/webhook/doku` | DOKU webhook | | GET | `/api/v1/admin/dashboard` | Admin stats | | GET | `/api/v1/admin/users` | User list | --- ## 🔑 Default Credentials (Development) The following accounts are available if you run `npx prisma db seed`: | Role | Email | Password | License Key | |------|-------|----------|-------------| | **ADMIN** | `admin@marketscope.com` | `Password123!` | `MS-ADMIN-DEV-001` | | **PRO** | `pro@marketscope.com` | `Password123!` | `MS-PRO-MONTHLY-002` | | **FREE** | `user@marketscope.com` | `Password123!` | `MS-FREE-TRIAL-003` | --- ## 🔒 Security Checklist - [x] Helmet HTTP headers - [x] CORS restricted - [x] Rate limiting (API + Auth + Scan) - [x] JWT authentication - [x] Password hashing (bcrypt, 12 rounds) - [x] XSS protection - [x] HPP protection - [x] SQL injection (Prisma ORM) - [x] Environment variables (.env) - [ ] Code obfuscation (extension) → use webpack/terser for production build - [ ] CSP headers for production