# rmtPocketWatcher

A cross-platform desktop application that tracks real-money trading (RMT) prices for Star Citizen AUEC. Provides a Bloomberg-style terminal interface displaying real-time AUEC price data from multiple vendors.

Developed by Lambda Banking Conglomerate - A Star Citizen Organization

## Features

- 🔄 Automated scraping from Eldorado and PlayerAuctions every 5 minutes
- 📊 Track all seller listings with historical data
- 💰 Real-time lowest price tracking across all vendors
- 📈 Historical price charts by seller, platform, or overall lowest
- 🔔 Client-side price alerts with native notifications
- 🌐 REST API + WebSocket for real-time updates
- 🗄️ PostgreSQL + Prisma for reliable data storage

## Quick Start

### 1. Start Backend (Using Docker Compose - Recommended)

```bash
# Clone the repository
git clone <repository-url>
cd rmtPocketWatcher

# Start backend and database
docker-compose up -d

# View logs
docker-compose logs -f backend

# Access the API
curl http://localhost:3000/health
```

The backend will be available at `http://localhost:3000`

### 2. Run Flutter App

```bash
cd flutter_app

# Install dependencies
flutter pub get

# Configure environment
cp .env.example .env
# Edit .env if needed (default connects to localhost:3000)

# Run on Windows
flutter run -d windows

# Run on Android
flutter run -d android

# Run on iOS
flutter run -d ios
```

### Local Backend Development

```bash
# Start database only
docker-compose up -d postgres

# Setup backend
cd backend
npm install
npm run db:generate
npm run db:push
npx playwright install chromium

# Run development server
npm run dev

# Or test scraper manually
npm run scrape
```

## Project Structure

```
rmtPocketWatcher/
├── backend/                 # TypeScript backend server
│   ├── src/
│   │   ├── scrapers/       # Playwright scraping modules
│   │   ├── api/            # Fastify REST + WebSocket API
│   │   ├── database/       # Prisma client and repository
│   │   └── index.ts        # Main server entry point
│   ├── prisma/             # Database schema and migrations
│   └── Dockerfile
├── flutter_app/            # Flutter cross-platform app
│   ├── lib/
│   │   ├── models/         # Data models
│   │   ├── providers/      # State management
│   │   ├── services/       # API, WebSocket, Storage
│   │   ├── screens/        # UI screens
│   │   └── widgets/        # Reusable components
│   └── pubspec.yaml
├── electron-app/           # Legacy Electron app (deprecated)
├── docker-compose.yml      # Docker orchestration
└── README.md
```

## API Endpoints

### Prices
- `GET /api/prices/latest` - Get all current listings
- `GET /api/prices/lowest` - Get current lowest price
- `GET /api/prices/by-seller?seller=&platform=` - Filter by seller
- `GET /api/prices/by-platform?platform=` - Filter by platform
- `GET /api/prices/history?from=&to=&seller=&platform=` - Historical data

### Index
- `GET /api/index/history?range=7d|30d|90d|all` - Lowest price over time
- `GET /api/index/ws` - WebSocket for real-time updates

### Health
- `GET /health` - Server health check

## Configuration

Edit `.env` or set environment variables:

```env
DATABASE_URL=postgresql://rmtpw:rmtpw_password@localhost:5432/rmtpocketwatcher
PORT=3000
SCRAPE_INTERVAL_MINUTES=5
SCRAPER_HEADLESS=true
NODE_ENV=production
```

## Technology Stack

**Backend:**
- TypeScript + Node.js
- Fastify (REST API + WebSocket)
- Playwright (web scraping)
- PostgreSQL + Prisma ORM
- Node Scheduler (cron jobs)

**Frontend:**
- Flutter 3.38+ (cross-platform: Windows, macOS, Linux, Android, iOS)
- Dart 3.10+
- Provider (state management)
- fl_chart (charting)
- Material Design 3

## Development

```bash
# Run tests
npm test

# Lint and type check
npx tsc --noEmit

# Database management
npm run db:studio    # Open Prisma Studio
npm run db:push      # Push schema changes
npm run db:migrate   # Create migration

# Manual scrape test
npm run scrape
```

## Docker Commands

```bash
# Build and start
docker-compose up --build

# Stop services
docker-compose down

# View logs
docker-compose logs -f backend

# Restart backend only
docker-compose restart backend

# Remove everything including volumes
docker-compose down -v
```

## License

MIT

## Disclaimer

This application is for informational and tracking purposes only. It does not facilitate any real-money trading transactions. Users are responsible for complying with all applicable laws and game terms of service.
