# Manadeck A deck management system with Mana Core authentication and credit system integration. ## Features - 🔐 **Mana Core Authentication** - Complete auth system with JWT tokens, device tracking, and automatic token refresh - ⚡ **Credit System** - Mana-based billing for operations (10 mana to create a deck, 5 for AI features, etc.) - 📱 **React Native/Expo** - Cross-platform mobile app (iOS, Android, Web) - 🚀 **NestJS Backend** - Type-safe API with AuthGuard protection - 💾 **Supabase** - Database and real-time features - 🎨 **NativeWind** - Tailwind CSS for React Native styling ## Quick Start ### Prerequisites - Node.js 18+ - npm or yarn - Expo CLI (`npm install -g expo-cli`) - Supabase account - Mana Core credentials (APP_ID, SERVICE_KEY) ### Backend Setup 1. **Navigate to backend directory**: ```bash cd backend ``` 2. **Install dependencies**: ```bash npm install ``` 3. **Configure environment variables**: ```bash cp .env.example .env ``` Edit `.env` and add your credentials: ```env # Mana Core MANA_SERVICE_URL=https://mana-core-middleware-111768794939.europe-west3.run.app APP_ID=your-app-id-from-mana-core SERVICE_KEY=your-service-key-from-mana-core # Required for credits # Supabase SUPABASE_URL=https://your-project.supabase.co SUPABASE_ANON_KEY=your-anon-key SUPABASE_SERVICE_KEY=your-service-key # Server NODE_ENV=development PORT=8080 ``` 4. **Start the backend**: ```bash npm run start:dev ``` Backend will be available at `http://localhost:8080` ### Frontend Setup 1. **Navigate to mobile app directory**: ```bash cd apps/mobile ``` 2. **Install dependencies**: ```bash npm install ``` 3. **Configure environment**: ```bash cp .env.example .env ``` Edit `.env`: ```env # Supabase EXPO_PUBLIC_SUPABASE_URL=https://your-project.supabase.co EXPO_PUBLIC_SUPABASE_ANON_KEY=your-anon-key # Backend API EXPO_PUBLIC_API_URL=http://localhost:8080 # For local development # EXPO_PUBLIC_API_URL=https://your-production-backend.com # For production ``` 4. **Start Expo**: ```bash npm start ``` 5. **Run on platform**: - Press `i` for iOS simulator - Press `a` for Android emulator - Press `w` for web browser ## Architecture ``` ┌─────────────────────┐ │ Mobile App │ React Native + Expo │ (Frontend) │ - Authentication UI │ │ - Credit balance display │ │ - Deck management └──────────┬──────────┘ │ HTTPS/JSON │ Bearer Token Auth ▼ ┌─────────────────────┐ │ Backend API │ NestJS │ │ - AuthGuard protection │ │ - Credit validation │ │ - Business logic └──────────┬──────────┘ │ ├─────────────────────┐ │ │ ▼ ▼ ┌─────────────────┐ ┌──────────────────┐ │ Mana Core │ │ Supabase │ │ - Auth │ │ - Database │ │ - Credits │ │ - Storage │ │ - Transactions │ │ - Real-time │ └─────────────────┘ └──────────────────┘ ``` ## Credit System Manadeck uses **Mana** as its credit currency. Operations cost credits: | Operation | Cost | |-----------|------| | Create Deck | 10 mana | | Create Card | 2 mana | | AI Card Generation | 5 mana | | Export Deck | 3 mana | ### How it Works 1. **Pre-flight Validation**: Backend checks if user has enough credits 2. **Operation**: Performs the requested operation (create deck, etc.) 3. **Consumption**: Deducts credits only if operation succeeds 4. **Response**: Returns success + credits used ### Frontend Integration The frontend automatically handles insufficient credits with a modal: ```typescript import { useInsufficientCredits } from '../hooks/useInsufficientCredits'; import { InsufficientCreditsModal } from '../components/InsufficientCreditsModal'; function MyScreen() { const insufficientCredits = useInsufficientCredits(); const handleAction = async () => { try { await post('/api/decks', data); } catch (error) { // Automatically shows modal if insufficient credits insufficientCredits.handleCreditError(error); } }; return ( <>