# Quick Reference - Common Commands

A quick cheat sheet for the most common development commands.

> **Backend API-Only Project:** This reference covers Laravel/PHP backend commands only.

## 🚀 Getting Started

```bash
# First time setup
git clone https://github.com/yourusername/web-dolphin-japan.git
cd web-dolphin-japan
composer run setup

# OR manual setup
composer install
cp .env.example .env
php artisan key:generate
php artisan migrate
```

## 🛠️ Development

```bash
# Start everything at once
composer run dev

# Individual services
php artisan serve                      # Laravel (port 8000)
php artisan queue:listen              # Process jobs
php artisan pail                      # View logs
```

## 🗄️ Database

```bash
# Create and run migrations
php artisan make:migration create_table_name
php artisan migrate

# Reset database (destructive!)
php artisan migrate:fresh

# Rollback last migration
php artisan migrate:rollback

# Interactive database shell
php artisan tinker
```

## 🧪 Testing & Quality

```bash
# Run tests
composer run test
php artisan test tests/Feature/ExampleTest.php

# Code formatting
./vendor/bin/pint              # Fix style issues
./vendor/bin/pint --test       # Check without fixing

# View routes
php artisan route:list
```

## 📦 Dependencies

```bash
# PHP packages (Composer)
composer install               # Install dependencies
composer require vendor/package # Add new package
composer remove vendor/package # Remove package
composer update               # Update packages
```

## 🔧 Artisan Commands

```bash
# Configuration
php artisan config:show        # View current config
php artisan env               # Show environment (local/production)

# Cache
php artisan config:clear      # Clear config cache
php artisan cache:clear       # Clear application cache
php artisan view:clear        # Clear compiled views

# Generate
php artisan key:generate      # Generate app key
php artisan migrate           # Run migrations

# Tinker (interactive shell)
php artisan tinker            # Start interactive shell
>>> Brand::all()              # Example: view all brands
>>> exit                      # Exit tinker
```

## 📝 Creating New Features

### 1. Create Model & Migration
```bash
php artisan make:migration create_categories_table
php artisan make:model Category
```

### 2. Create Files
```
app/Models/Category.php                           # Model
app/Http/Repository/CategoryRepository.php       # Data access
app/Http/Service/CategoryService.php             # Business logic
app/Http/Requests/CategoryRequest.php            # Validation
app/Http/Resources/CategoryResource.php          # JSON response
app/Http/Controllers/Admin/CategoryController.php # HTTP handler
```

### 3. Add Routes
Edit `routes/web.php`:
```php
Route::group(['prefix' => 'api/v1'], function () {
    Route::group(['prefix' => 'category'], function () {
        Route::get('/', [CategoryController::class, 'index']);
        Route::post('/add', [CategoryController::class, 'add']);
    });
});
```

### 4. Run & Test
```bash
php artisan migrate
composer run test
php artisan serve
```

## 🐛 Debugging

```bash
# Check logs in real-time
php artisan pail

# View logs file
tail -f storage/logs/laravel.log

# Use Tinker for exploration
php artisan tinker
>>> app('config')['app.name']     # Access config
>>> Route::getRoutes()            # View routes
>>> DB::table('users')->all()     # Query database

# Database inspection (SQLite)
sqlite3 database/database.sqlite
```

## 📂 Project Structure Quick Lookup

| Directory | Purpose |
|-----------|---------|
| `app/Models/` | Eloquent models |
| `app/Http/Controllers/` | HTTP request handlers |
| `app/Http/Service/` | Business logic |
| `app/Http/Repository/` | Data access layer |
| `app/Http/Requests/` | Request validation |
| `app/Http/Resources/` | JSON responses |
| `app/Traits/` | Reusable code |
| `routes/` | API endpoints definition |
| `database/migrations/` | Database schemas |
| `database/seeders/` | Sample data |
| `resources/views/` | Blade templates |
| `tests/Feature/` | API tests |
| `tests/Unit/` | Unit tests |

## 🔗 Useful Links

- **Documentation**: [README.md](README.md)
- **Setup Guide**: [SETUP.md](SETUP.md)
- **Contributing**: [CONTRIBUTING.md](CONTRIBUTING.md)
- **Architecture**: [AGENTS.md](AGENTS.md)
- **Laravel Docs**: https://laravel.com/docs/12
- **Eloquent ORM**: https://laravel.com/docs/12/eloquent

## 💾 Git Workflow

```bash
# Create feature branch
git checkout -b feature/your-feature

# Make changes, then
git add .
git commit -m "feat: Add your feature"

# Push to GitHub
git push origin feature/your-feature

# Create Pull Request on GitHub website
```

## ⚡ Pro Tips

- Use `php artisan tinker` to test code interactively
- Use `composer run dev` to start everything at once
- Check `routes/web.php` to understand existing endpoints
- Use Brand as a reference for new features (AGENTS.md)
- Run `./vendor/bin/pint` before committing code
- Always write tests before creating PR

---

**Need more details?** Check [README.md](README.md) or [SETUP.md](SETUP.md)

Last Updated: May 5, 2026
