# BookDash - Quick Start Guide

## 🚀 Getting Started

### Step 1: Initial Setup

1. **Copy Environment File**
```bash
cp .env.example .env
```

2. **Generate Application Key**
```bash
php artisan key:generate
```

3. **Configure Database**
Edit `.env` file and update database credentials:
```env
DB_DATABASE=bookdash
DB_USERNAME=root
DB_PASSWORD=your_password
```

4. **Create Database**
```sql
CREATE DATABASE bookdash;
```

5. **Run Migrations**
```bash
php artisan migrate
```

6. **Create Storage Link**
```bash
php artisan storage:link
```

7. **Install Dependencies**
```bash
composer install
npm install
npm run build
```

### Step 2: Create Admin User

Run in `php artisan tinker`:
```php
$user = new App\Models\User();
$user->name = 'Admin User';
$user->email = 'admin@bookdash.app';
$user->password = bcrypt('password');
$user->role = 'admin';
$user->credit_balance = 100;
$user->save();
```

Or create via database seeder:
```bash
php artisan db:seed --class=AdminSeeder
```

### Step 3: Start the Application

```bash
php artisan serve
```

Visit: http://localhost:8000

## 📝 First Steps After Login

### As a Regular User:

1. **Purchase Credits**
   - Navigate to Credits page
   - Select a package
   - Complete purchase (simulated in development)

2. **Create Your First Book**
   - Click "Create New Book"
   - Enter title and description
   - Upload cover image (optional)

3. **Add a Chapter**
   - Open your book
   - Click "Add Chapter"
   - Choose your preferred method:
     - Type in the editor
     - Send via email
     - Record via phone call

### As an Admin:

1. **Access Admin Panel**
   - Navigate to `/admin` or click "Admin" in navigation

2. **Manage Users**
   - View all registered users
   - Adjust credit balances
   - Monitor activity

3. **Monitor System**
   - Check analytics
   - Review calls and transcriptions
   - View payments

## 🔧 Configuration Options

### Email Integration

To enable email-to-chapter feature:

1. Set up email service (Mailgun, SendGrid, etc.)
2. Configure webhook in email service to point to:
   ```
   POST https://yourdomain.com/webhook/email
   ```
3. Update mail settings in `.env`

### Bird API (Call Feature)

To enable phone call feature:

1. Sign up at Bird API
2. Get API credentials
3. Update `.env`:
   ```env
   BIRD_API_KEY=your_key
   BIRD_API_URL=https://api.bird.com/v1
   BIRD_PHONE_NUMBER=+1234567890
   ```
4. Configure webhook in Bird dashboard:
   ```
   POST https://yourdomain.com/webhook/call
   ```

### Payment Gateway

To enable real payments:

1. Choose provider (Stripe recommended)
2. Get API keys
3. Update `.env`:
   ```env
   STRIPE_KEY=pk_test_...
   STRIPE_SECRET=sk_test_...
   ```
4. Update `CreditController@processPurchase` with Stripe integration

## 🧪 Testing

### Quick Test Workflow:

1. **Create Test User**
   ```bash
   php artisan tinker
   ```
   ```php
   $user = App\Models\User::factory()->create([
       'credit_balance' => 10
   ]);
   ```

2. **Test Book Creation**
   - Login with test user
   - Create a book
   - Add chapters using different methods

3. **Test Email Integration**
   - Generate unique email for user
   - Send test email
   - Check email_logs table for processing

4. **Test Credit System**
   - Create chapter (should deduct credit)
   - Purchase credits
   - Check credits table for transactions

## 📊 Database Structure

Key tables created:
- `users` - User accounts
- `books` - Book records
- `chapters` - Chapter content
- `credits` - Credit transactions
- `payments` - Payment records
- `calls` - Phone call logs
- `transcriptions` - Transcription data
- `email_logs` - Email processing logs

## 🔍 Troubleshooting

### Common Issues:

**Migration errors:**
```bash
php artisan migrate:fresh  # Warning: Deletes all data!
```

**Permission issues:**
```bash
chmod -R 775 storage bootstrap/cache
```

**Clear cache:**
```bash
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
```

**Queue not processing:**
```bash
php artisan queue:work
```

## 📁 Important Files

### Controllers:
- `app/Http/Controllers/BookController.php`
- `app/Http/Controllers/ChapterController.php`
- `app/Http/Controllers/CreditController.php`
- `app/Http/Controllers/CallController.php`
- `app/Http/Controllers/EmailWebhookController.php`
- `app/Http/Controllers/Admin/AdminController.php`

### Models:
- `app/Models/Book.php`
- `app/Models/Chapter.php`
- `app/Models/Credit.php`
- `app/Models/Payment.php`
- `app/Models/Call.php`
- `app/Models/Transcription.php`
- `app/Models/EmailLog.php`

### Views:
- `resources/views/dashboard.blade.php`
- `resources/views/books/*.blade.php`
- `resources/views/chapters/*.blade.php`
- `resources/views/credits/*.blade.php`

### Routes:
- `routes/web.php` - All application routes

## 🎯 Next Steps

1. **Customize Design**
   - Edit Tailwind classes in views
   - Add your branding

2. **Implement Export**
   - Integrate PDF library (e.g., DomPDF, Snappy)
   - Add DOCX export (PHPWord)
   - Add EPUB export

3. **Add Real Payments**
   - Integrate Stripe/PayPal
   - Add invoice generation

4. **Deploy to Production**
   - Set up on server (DigitalOcean, AWS, etc.)
   - Configure domain and SSL
   - Set up queue workers
   - Configure backup system

## 📚 Resources

- [Laravel Documentation](https://laravel.com/docs)
- [Tailwind CSS](https://tailwindcss.com)
- [Bird API Docs](https://bird.com/docs)

## 🆘 Need Help?

- Check `storage/logs/laravel.log` for errors
- Review SETUP.md for detailed documentation
- Enable debug mode in `.env`: `APP_DEBUG=true`

---

**Happy Writing! 📖**
