# Fermenty ERP — Contexto del Proyecto

## Descripción
**Fermenty.app** — Guía de fermentos caseros (Kombucha, Kefir, Chucrut, Kimchi y más).
Web app Laravel 13 + Blade + Bootstrap 5 + SCSS. Futura app móvil via API REST.

---

## Stack técnico
| Elemento | Detalle |
|---|---|
| Framework | Laravel 13 |
| PHP | 8.4 (XAMPP-Lite D:\xampp_lite_8_4) |
| CSS | Bootstrap 5 + SCSS + Comfortaa (Google Fonts) |
| JS | Alpine.js + Bootstrap JS |
| Build | Vite |
| Auth | Laravel Breeze + Google OAuth (Socialite) |
| DB | MySQL/MariaDB |
| Control de versiones | Git + Bitbucket (mideya/fermenty-erp) |

---

## Entornos

### Servidor (producción)
- Ubuntu Linux
- Ruta: `/var/www/fermentyapp`
- PHP: sistema
- Deploy: `git pull` + `composer install` + `php artisan migrate` + `npm run build`

### Local (desarrollo)
- Windows + XAMPP-Lite (PHP 8.4) puerto **8084**
- XAMPP original (PHP 8.2) puerto **80** para otros proyectos
- Ruta: `D:\Lirona\ERPs\Fermenty.app`
- URLs: `http://fermenty.local:8084` / `http://erp.fermenty.local:8084`
- Cliente Git: Sourcetree
- PHP para comandos: `D:\xampp_lite_8_4\apps\php\php.exe`
- Composer: `D:\xampp_lite_8_4\apps\php\php.exe C:\ProgramData\ComposerSetup\bin\composer.phar`

---

## Diseño / Identidad visual
- **Colores**: Verde `#3A7A22` (navbar/sidebar) + Naranja `#E8621A` (CTAs/premium)
- **Fuente**: Comfortaa (300/400/600/700)
- **Border radius**: 12px cards, 20px badges/botones
- **SCSS**: `resources/scss/` — variables, typography, layout, components, utilities, landing, auth, pages, catalogue, batches, newsletter, profile, admin

---

## Base de datos
**22 migraciones** en orden correcto (todas con `bigId`, no UUID):

```
001 ferment_types
002 fermentation_guides
003 guide_steps
004 step_actions
005 ferment_options
006 notification_rules
007 recipes
008 batches
009 batch_steps
010 batch_ingredients
011 batch_photos
012 daily_logs
013 measurements
014 batch_events
015 fermenty_notifications
016 batch_reviews
017 flavor_results
018 insights
019 user_social_providers
020 community_posts
021 add_fields_to_users (role, plan, status, avatar, locale)
022 newsletter_subscribers
```

**Seeders**: `FermentTypesSeeder` + `FermentationGuidesSeeder` + `NotificationRulesSeeder`
- 10 tipos de fermento (4 free + 6 premium)
- 4 guías completas con pasos y acciones
- 16 reglas de notificación

---

## Modelos (app/Models/)
User, FermentType, FermentationGuide, GuideStep, StepAction, FermentOption,
NotificationRule, Recipe, Batch, BatchStep, BatchIngredient, BatchPhoto,
DailyLog, Measurement, BatchEvent, FermentyNotification, BatchReview,
FlavorResult, Insight, UserSocialProvider, CommunityPost, NewsletterSubscriber

---

## Controllers (app/Http/Controllers/)
```
DashboardController
FermentTypeController
BatchController
BatchLogController
BatchEventController
BatchReviewController
CommunityController
ProfileController
NewsletterController
Auth/GoogleController
Admin/DashboardController
Admin/FermentTypeController
Admin/GuideController
Admin/NewsletterAdminController
Admin/UserAdminController
```

---

## Servicios (app/Services/)
- **BatchService** — crear lote + copiar pasos + generar notificaciones + gestión de estados

---

## Rutas principales (routes/web.php)
| Zona | Prefix | Middleware |
|---|---|---|
| Pública | `/` | — |
| Auth Breeze | via `auth.php` | — |
| Google OAuth | `/auth/google` | — |
| Privada | `/dashboard`, `/batches`, `/perfil`... | `auth, verified` |
| Admin | `/acp` | `auth, verified, role:admin` |

**Nota**: El panel admin usa `/acp` (no `/admin`) porque XAMPP-Lite tiene ese alias reservado.

---

## Vistas (resources/views/)
```
layouts/
  app.blade.php         ← layout principal (con sidebar)
  auth.blade.php        → renombrado como guest.blade.php para Breeze
welcome.blade.php       ← landing pública
dashboard.blade.php
auth/
  login.blade.php
  register.blade.php
pages/
  faq.blade.php
  privacidad.blade.php
  terminos.blade.php
fermentos/
  index.blade.php
  show.blade.php
batches/
  index.blade.php
  create.blade.php
  show.blade.php
  logs/
    index.blade.php
    create.blade.php
    show.blade.php
  review/
    create.blade.php
    show.blade.php
perfil/
  show.blade.php
  edit.blade.php
comunidad/
  index.blade.php
  create.blade.php
  show.blade.php
newsletter/
  index.blade.php
  confirmed.blade.php
  unsubscribed.blade.php
admin/
  layouts/admin.blade.php
  dashboard.blade.php
  fermentos/
    index.blade.php
    form.blade.php
    create.blade.php
    edit.blade.php
  guias/
    index.blade.php
    show.blade.php
    form.blade.php
    create.blade.php
    edit.blade.php
  usuarios/
    index.blade.php
    show.blade.php
  newsletter/
    index.blade.php
```

---

## Traducciones (lang/es/)
- `general.php` — navbar, footer, botones, estados
- `landing.php` — textos landing
- `batches.php` — textos de lotes
- `ferments.php` — catálogo
- `auth.php` — login/registro

**Para añadir inglés**: crear `lang/en/` con los mismos archivos.

---

## Políticas (app/Policies/)
- `BatchPolicy` — solo el dueño puede ver/editar/borrar su lote
- `CommunityPostPolicy` — solo el autor puede borrar su post
- Admins tienen acceso total via `before()` en ambas policies

---

## Middleware
- `CheckRole` — protege rutas por rol (`role:admin`)
- Registrado en `bootstrap/app.php` como alias `role`

---

## Pendiente (próximas sesiones)
- [ ] Jobs de notificaciones inteligentes (Laravel Queue)
- [ ] API REST para app móvil (`routes/api.php`)
- [x] Google OAuth — configurar credenciales reales en Google Cloud Console
- [x] Configurar envío de correo — local (Mailpit) funcionando, producción pendiente Resend + DNS
- [ ] Tests automatizados (Feature tests)
- [ ] Stripe/PayPal para plan Premium
- [ ] Panel admin — gestión de pasos de guías
- [ ] Comunidad — sistema de comentarios
- [ ] Recetas propias del usuario
- [ ] Deploy CI/CD desde Bitbucket

---

## Comandos útiles

### Local
```bash
# Arrancar Vite (desarrollo)
npm run dev

# Compilar para producción
npm run build

# Migraciones
D:\xampp_lite_8_4\apps\php\php.exe artisan migrate
D:\xampp_lite_8_4\apps\php\php.exe artisan migrate:fresh --seed

# Tinker
D:\xampp_lite_8_4\apps\php\php.exe artisan tinker

# Dar rol admin a usuario
App\Models\User::where('email', 'tu@email.com')->update(['role' => 'admin']);
```

### Servidor
```bash
cd /var/www/fermentyapp
git pull origin main
composer install --no-dev --optimize-autoloader
php artisan migrate
npm run build
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

---

## Notas importantes
- `.env` **nunca** se sube a Bitbucket — cada entorno tiene el suyo
- `vendor/` y `node_modules/` están en `.gitignore`
- `public/build/` está en `.gitignore` — cada entorno hace su propio build
- La tabla de notificaciones se llama `fermenty_notifications` (no `notifications`) para evitar conflicto con Laravel
- Breeze usa `x-guest-layout` → apunta a `resources/views/layouts/guest.blade.php` (nuestro auth layout)
