# TGBOT Builder Pro: Reusable Add Bot Screen, Ready-to-Use Bots Marketplace, Paid Modules & Subscription Plans

## Goal Description
Build an end-to-end commercial mobile application for **TGBOT Builder** featuring:
1. **Dedicated Reusable "Add Bot Screen"**:
   - A standalone, full-featured screen (`Screen.AddBotScreen`) used both for initial onboarding and for adding subsequent bots in the future.
   - 3 Modes/Tabs:
     - **Tab 1: Auto-Detect via Telegram** (MTProto Session auto-fetches created bots from `@BotFather`).
     - **Tab 2: Manual Bot Token** (Interactive step-by-step visual tutorial with deep-link button to `@BotFather`).
     - **Tab 3: Ready-To-Use Bots Marketplace** (Pre-built commercial bots deployed in 1-click).
2. **Ready-To-Use Bots (Marketplace - Paid/Premium)**:
   - 🛒 **Store & E-Commerce Bot**: Product catalog, cart, customer orders.
   - 🔒 **VIP Channel & Paid Subscription Bot**: Paywall, single-use Telegram invite links, auto-kick on expiry.
   - 🤖 **AI Assistant & Chat Bot**: Gemini / ChatGPT powered auto-replies and query handler.
   - 💬 **Live Customer Support Ticket Bot**: Multi-agent forwarding, ticketing, broadcast channel.
3. **Paid / Pro Modules System**:
   - **Free Modules**: Welcome Greeting, Force Join (1 channel), Standard Broadcast, Event Logs.
   - **Pro Modules (Paid)**:
     - ⭐ Multi-Channel Force Join (Up to 5 channels/groups).
     - ⭐ AI Auto-Responder (Contextual smart replies).
     - ⭐ Payment & Crypto Gateway (UPI / Stripe / Crypto checkout).
     - ⭐ Promo & Voucher Redeem Code System.
     - ⭐ Advanced Analytics & Subscriber CSV/Excel Export.
4. **Subscription Plans & Monetization Tier ("Bot Chalane Ka Plan")**:
   - **Free Plan**: 1 Bot, 500 Users, Core Modules, ₹0/mo.
   - **Pro Plan (₹499/mo)**: 5 Bots, 10,000 Users, All Pro Modules Unlocked, High-speed server.
   - **Business Plan (₹1,499/mo)**: Unlimited Bots, Unlimited Users, All Ready-to-Use Bots Included.
   - In-app Plan Comparison & Upgrade Modal triggered when quota is reached or Pro features are tapped.
5. **Animated Login Screen (No Guest Mode)**:
   - Telegram Session Login (Phone + OTP + Cloud 2FA password).
   - Telegram Web / Bot Auth.
   - Email / Password Login.
6. **Indian Legal & Play Store Compliance**:
   - Terms & Conditions and Privacy Policy complying with the **Information Technology Act, 2000**, **IT Rules, 2021**, and **DPDP Act, 2023**.
   - Grievance Officer details and statutory disclosures.
   - Play Store Account Deletion.

---

## App Flow & Navigation Architecture

```mermaid
graph TD
    Login["Animated Login Screen<br/>(Telegram Session / Telegram Web / Email)<br/>*No Guest Mode*"] --> AuthCheck{"Authenticated?"}
    
    AuthCheck --> HasBots{"User Has Bots?"}
    
    HasBots -- No (First Time) --> AddBotScreen["Dedicated Add Bot Screen<br/>1. Telegram Auto-Detect<br/>2. BotFather Guide & Token<br/>3. Ready-To-Use Bots Marketplace"]
    HasBots -- Yes --> Dashboard["Dashboard Screen<br/>(TopBar, Analytics, Health)"]
    
    Dashboard --> TopBarAdd["TopBar '+ Add Bot'"] --> AddBotScreen
    
    AddBotScreen --> SelectFree["Deploy Free Bot (1/1)"] --> Dashboard
    AddBotScreen --> SelectPro["Deploy Ready-to-Use Pro Bot"] --> Paywall["Upgrade Plan / Paywall Modal"]
    
    Dashboard --> ModulesHub["Modules Hub (Spaces)"]
    ModulesHub --> ToggleFree["Toggle Free Module"] --> Activated["Module Live on Bot"]
    ModulesHub --> TogglePro["Toggle Pro Module (AI/Payment)"] --> Paywall
    
    Dashboard --> Settings["Settings Screen"]
    Settings --> PlansCard["Current Plan: Free Tier"] --> UpgradePlansScreen["Subscription Plans Screen<br/>(Free vs Pro vs Business)"]
    Settings --> DeleteAccount["Delete Account (Play Store Compliance)"]
```

---

## Subscription Plans Specification

| Feature / Limit | Free Tier (₹0) | Pro Creator (₹499/mo) | Business Agency (₹1,499/mo) |
| :--- | :--- | :--- | :--- |
| **Max Active Bots** | 1 Bot | 5 Bots | Unlimited |
| **Bot User Saturation** | Up to 500 Users | Up to 10,000 Users | Unlimited |
| **Welcome Module** | Included ✅ | Included ✅ | Included ✅ |
| **Force Join Channels** | 1 Channel ✅ | Up to 5 Channels ⭐ | Unlimited ⭐ |
| **Broadcast Campaigns** | Standard (Rate-limited) | High-speed batching ⭐ | Priority instant delivery ⭐ |
| **Ready-to-Use Bots** | Preview only | 1 Free Template ⭐ | All Templates Unlocked ⭐ |
| **AI Smart Responder** | Locked 🔒 | Included ⭐ | Included ⭐ |
| **Payment Gateway (UPI)** | Locked 🔒 | Included ⭐ | Included ⭐ |
| **Redeem Codes System** | Locked 🔒 | Included ⭐ | Included ⭐ |
| **Data Export (CSV)** | Locked 🔒 | Included ⭐ | Included ⭐ |

---

## Ready-to-Use Bots Catalog

```mermaid
classDiagram
    class ReadyToUseBot {
        +String id
        +String title
        +String category
        +String icon
        +String description
        +List~String~ includedModules
        +String priceTag
        +Boolean isPro
    }

    class StoreBot {
        +ProductCatalog
        +CartSystem
        +UPIPayment
    }
    class VipChannelBot {
        +InviteLinkGenerator
        +SubscriptionExpiryTracker
        +AutoKickScheduler
    }
    class AiAssistantBot {
        +GeminiOpenAIContext
        +KnowledgeBaseQA
        +VoiceToText
    }
    class SupportTicketBot {
        +TicketQueue
        +AgentForwarding
        +AutoResponses
    }

    ReadyToUseBot <|-- StoreBot
    ReadyToUseBot <|-- VipChannelBot
    ReadyToUseBot <|-- AiAssistantBot
    ReadyToUseBot <|-- SupportTicketBot
```

---

## Proposed Changes

### Component 1: Core Navigation & Models (`core:ui`, `presentation/tgbot`)

#### [MODIFY] `core/ui/.../navigation/Screen.kt`
- Add:
  - `data object AddBotScreen : Screen()`
  - `data object PlansScreen : Screen()`

#### [MODIFY] `composeApp/.../presentation/tgbot/TgBot.kt`
- Add data classes:
  - `ReadyToUseBotTemplate(id, title, category, description, icon, price, isPro, modules)`
  - `SubscriptionPlan(id, name, priceFormatted, botLimit, userLimit, features, isCurrent)`
  - Update `TgModulesConfig` to include Pro module descriptors (`aiResponder`, `paymentGateway`, `redeemCodes`, `multiForceJoin`).

---

### Component 2: Dedicated Reusable Add Bot Screen (`presentation/tgbot/`)

#### [NEW] `composeApp/.../presentation/tgbot/AddBotScreen.kt`
A full-screen composable containing 3 interactive tabs:
1. **Tab 1: Auto-Detect (Telegram Session)**:
   - Calls `/api/v1/auth/telegram-session/my-bots`.
   - Lists user's Telegram bots fetched from `@BotFather`.
   - 1-tap "Connect This Bot" button.
2. **Tab 2: BotFather Token & Visual Guide**:
   - Visual tutorial with step badges:
     - 1. Open `@BotFather` button (`https://t.me/BotFather`).
     - 2. Send `/newbot` and choose name.
     - 3. Copy HTTP Token banner.
   - Token input field with live `getMe` verification.
3. **Tab 3: Ready-To-Use Bots Marketplace**:
   - Card grid for Store Bot, VIP Access Bot, AI Assistant, and Support Bot.
   - Pro badges, feature chips, and "Deploy Template" action.
   - If user is on Free plan, triggers the Upgrade Paywall modal.

---

### Component 3: Subscription Plans & Pro Paywall (`presentation/plans/`)

#### [NEW] `composeApp/.../presentation/plans/PlansScreen.kt`
- Visual comparison cards for Free (₹0), Pro (₹499), and Business (₹1,499).
- Monthly / Annual toggle.
- "Current Plan" indicator and "Upgrade Plan" checkout button.

#### [NEW] `composeApp/.../presentation/plans/UpgradePlanModal.kt`
- Bottom-sheet dialog appearing whenever a user on Free plan:
  - Tries to add a 2nd bot (limit 1/1).
  - Taps a Pro Ready-to-Use Bot template.
  - Toggles a Pro module (AI Auto-Reply, Payment Gateway, Multi-Channel FSub).

---

### Component 4: Modules Hub Upgrades (`presentation/main/SpacesScreen.kt`)

#### [MODIFY] `SpacesScreen.kt`
- Reorganize Module Library into:
  - **Core Modules (Free)**: Welcome Message, Force Join (Single Channel), Broadcast Sender, Event Logs.
  - **Pro Modules (⭐ PAID)**:
    - 🤖 AI Smart Auto-Responder (OpenAI / Gemini).
    - 💳 UPI & Payment Gateway Integration.
    - 🎟️ Voucher & Redeem Codes Generator.
    - 📢 Multi-Channel Force Join (Up to 5 Channels).
- Toggling a Pro module on Free Tier opens `UpgradePlanModal`.

---

### Component 5: Animated Login & Indian Legal Compliance (`presentation/auth/`)

#### [MODIFY] `LoginRegisterScreen.kt`
- Smooth Compose canvas background animations (gradient breathing waves).
- **Remove Guest login**.
- Telegram Session Login (Phone number + Telegram OTP + 2FA password).
- Telegram Web / Bot Auth.
- Mandatory Indian Legal Consent Checkbox ("Governed by IT Act, 2000 & DPDP Act, 2023").

#### [NEW] `LegalTermsDialog.kt`
- Modal dialog displaying statutory Indian IT disclosures, Grievance Officer details, and Telegram session data safety policy.

---

### Component 6: Backend Synchronization (`TgBotBackendService.kt`, `telegram-saas`)

#### [MODIFY] `TgBotBackendService.kt`
- Add API methods:
  - `getSubscriptionPlans(token)`
  - `getReadyToUseBots(token)`
  - `deployTemplate(token, templateId, botToken)`
  - `verifySessionOtp(phone, code, hash, password)`
  - `discoverSessionBots(token)`

---

## Verification Plan

### 1. Build Verification
```bash
cd /root/MyBrain && ./gradlew :androidApp:assembleDebug
```
- Verify clean compilation with zero routing errors.

### 2. Manual & Functional Testing
1. **Login Flow**:
   - Launch app ➔ Verify animated background and lack of Guest login.
   - Tap Terms & Privacy ➔ Verify Indian IT Act 2000 & DPDP Act 2023 disclosures open.
   - Complete login ➔ If user has 0 bots, redirect immediately to `AddBotScreen`.
2. **Dedicated Add Bot Screen**:
   - Check Tab 1 (Auto-Detect), Tab 2 (Manual Token + BotFather Guide), Tab 3 (Marketplace).
   - Test BotFather deep-link button.
   - Enter token ➔ Connect bot ➔ User enters Dashboard.
3. **Ready-To-Use Bots & Pro Paywall**:
   - Open Add Bot Screen ➔ Navigate to "Ready-to-Use Bots" tab.
   - Tap "Deploy Store Bot" ➔ Verify "Upgrade to Pro" bottom sheet modal opens.
4. **Pro Modules in Spaces Screen**:
   - Open Modules Hub ➔ Check Core vs Pro module sections.
   - Toggle AI Auto-Responder or Payment Gateway ➔ Verify Pro paywall modal triggers.
5. **Subscription Plans Screen**:
   - Open Settings ➔ Tap "Subscription Plans" ➔ Verify Free, Pro (₹499), and Business (₹1,499) cards render.
