# Moro - Kirei Rental Platform

E-commerce platform for Japanese kimono rental and sales, featuring AI-powered virtual try-on (face swap), identity verification, and multi-gateway payment processing.

## Tech Stack

| Layer | Technology |
|-------|-----------|
| Backend | Laravel 8.0 (PHP 8.1) |
| Frontend | Vue.js 2.6.10 + Element UI 2.15.10 |
| Database | MySQL 8.0 |
| Cache/Queue/Session | Redis 7 |
| Auth | Laravel Sanctum |
| Payment | PayJP (Japan) + Stripe (International) |
| AI Service | Python Face Swap (port 5000) |
| Build | Laravel Mix 5.0.5 (Webpack 4) |

## Key Features

- Online kimono rental & purchase
- AI face swap (virtual try-on)
- Identity verification (driver's license, My Number card)
- Provisional reservation system
- PayJP / Stripe payment processing
- Comprehensive admin dashboard

---

## Docker Installation (Recommended)

### Prerequisites

- [Docker](https://docs.docker.com/get-docker/) >= 20.0
- [Docker Compose](https://docs.docker.com/compose/install/) >= 2.0

### Install & Run

Single command setup:

```bash
docker compose up -d --wait
```

On first run, the following steps are performed automatically:
1. Pull images (MySQL 8.0, Redis 7)
2. Build PHP 8.1 + Node.js 14 image
3. Import database from `moro.sql`
4. Install Composer dependencies
5. Install npm dependencies
6. Start Laravel server

When the terminal returns the `$` prompt, everything is ready.

### Access

| Service | URL | Note |
|---------|-----|------|
| Site | http://localhost:8000 | Main website |
| Admin | http://localhost:8000/admin | Admin dashboard |
| phpMyAdmin | http://localhost:8080 | Requires `--profile tools` |
| Mailpit | http://localhost:8025 | Requires `--profile tools` |

### Test Accounts

| Role | Email | Password | 2FA Code |
|------|-------|----------|----------|
| Admin | *(see .env or database)* | *(see .env)* | *(see AuthController)* |

### Docker Services

| Service | Description | Port |
|---------|-------------|------|
| laravel | Laravel app server | 8000 |
| mysql | MySQL 8.0 database | 33061 |
| redis | Redis 7 (cache/queue/session) | 63790 |
| queue | Queue worker (background jobs) | - |
| scheduler | Task scheduler (cron) | - |

### Common Docker Commands

```bash
# Install & run (single command)
docker compose up -d --wait

# Run with phpMyAdmin + Mailpit
docker compose --profile tools up -d --wait

# View logs
docker compose logs -f laravel

# Enter Laravel container
docker compose exec laravel bash

# Stop (keep data for next run)
docker compose down

# Stop + remove data (reset DB, vendor, node_modules)
docker compose down -v

# Full cleanup (must reinstall from scratch)
docker compose down -v --rmi all

# Rebuild after modifying Dockerfile
docker compose up -d --build --wait
```

---

## Manual Installation (without Docker)

### Prerequisites

- PHP >= 7.3 / 8.0 / 8.1
- Node.js 14.x
- MySQL 8.0
- Redis
- Composer 2

### Setup

```bash
# Install PHP dependencies
composer install

# Copy and configure .env
cp .env.example .env
php artisan key:generate

# Import database
mysql -u root -p moro < docker/moro.sql

# Run pending migrations
php artisan migrate

# Install npm dependencies
npm install

# Build frontend (site + admin)
npm run dev-all

# Start server
php artisan serve
```

### Background Services

```bash
# Queue worker (required for face swap, email, etc.)
php artisan queue:work --queue=high,default

# Use Supervisor for production environments
```

---

## Project Structure

```
├── app/                    # Laravel models, controllers, services
│   ├── Http/Controllers/
│   │   ├── Admin/          # Admin controllers (82 total)
│   │   ├── PublicControllers/  # Site controllers
│   │   └── Api/            # API controllers
│   ├── Services/           # FaceSwapService, IdentityVerificationService
│   └── Jobs/               # Background jobs
├── resources/js/
│   ├── frontend/           # Vue.js site (135 components)
│   └── backend/            # Vue.js admin dashboard (214 components)
├── database/migrations/    # 92 migrations
├── docker/                 # Docker configuration
│   ├── entrypoint.sh       # Auto-setup script
│   ├── docker.env          # Docker environment variables
│   └── moro.sql            # Database dump
├── python-service/         # AI face swap service
├── Dockerfile
├── docker-compose.yml
└── Dockerfile
```

## Production Server Configuration

### Cron Job (Laravel Scheduler)

```bash
# Add to crontab
* * * * * cd /var/www/html/moro && php artisan schedule:run >> /dev/null 2>&1
```

| Command | Frequency | Description |
|---------|-----------|-------------|
| `orders:cancel-expired-provisional --sync` | Hourly | Auto-cancel provisional orders expired after 3 days |

### Identity Verification System

| Parameter | Value | Description |
|-----------|-------|-------------|
| `PROVISIONAL_EXPIRATION_DAYS` | 3 | Days before provisional order expires |
| `RESUBMISSION_EXPIRATION_DAYS` | 2 | Days allowed to resubmit after rejection |
| `MAX_REJECTION_COUNT` | 2 | Maximum rejections before auto-cancel |

**Flow:**
1. User places order → Creates provisional order (expires in 3 days)
2. No identity submitted after 3 days → Auto-cancel
3. Rejected once → Extended 2 more days to resubmit
4. Rejected twice → Auto-cancel immediately
