diff --git a/README.md b/README.md index e8bf415..de54e05 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,39 @@ -# Historias Incompletas +# Sí, no, o indiferente -Juego de historias de pensamiento lateral (estilo "cuenta un enigma, el resto -adivina la explicación completa haciendo preguntas de sí/no") para 2 o más -jugadores compartiendo un mismo dispositivo. Web + APK (Capacitor). +A lateral-thinking story game (in the style of "tell a puzzle, everyone else +guesses the full explanation by asking yes/no questions") for 2 or more +players sharing a single device. Web + APK (Capacitor). -- Un jugador narra: elige una historia, lee en voz alta el enigma, y - responde preguntas de sí/no del resto del grupo hasta que adivinan (o se - rinden) la solución completa. -- La app trae un mazo de historias por defecto embebido, y además intenta - bajar un mazo "actualizado" desde un backend propio que genera 5 historias - nuevas por día con la API de Gemini. Si no hay conexión o el backend no - tiene nada disponible, se usa el mazo default. +- One player narrates: they pick a story, read the puzzle aloud, and answer + yes/no questions from the rest of the group until they guess (or give up + on) the full solution. +- The app ships with a default deck of stories embedded, and also tries to + download an "updated" deck from its own backend, which generates 5 new + stories a day using the Gemini API. If there's no connection or the + backend has nothing available, the default deck is used. -## Estructura del repo +## Repo structure ``` -backend/ API en Node/Express que sirve /api/stories y genera historias - nuevas con Gemini (backend/README.md) -frontend/ App React + Vite, empaquetable como APK con Capacitor +backend/ Node/Express API that serves /api/stories and generates new + stories with Gemini (backend/README.md) +frontend/ React + Vite app, packageable as an Android APK with Capacitor (frontend/README.md) -deploy/ Unidades systemd + config de nginx de ejemplo para producción -docs/ Guía de deploy paso a paso (docs/DEPLOY.md) +deploy/ Example systemd units + nginx config for production ``` -## Desarrollo local +## Local development ### Backend ```bash cd backend npm install -cp .env.example .env # completa GEMINI_API_KEY y ADMIN_TOKEN +cp .env.example .env # fill in GEMINI_API_KEY and ADMIN_TOKEN npm run dev # http://localhost:8787 ``` -Generar historias manualmente (usa tu GEMINI_API_KEY real): +Generate stories manually (uses your real GEMINI_API_KEY): ```bash npm run generate @@ -45,43 +44,41 @@ npm run generate ```bash cd frontend npm install -cp .env.example .env # VITE_API_URL=http://localhost:8787 en dev +cp .env.example .env # VITE_API_URL=http://localhost:8787 in dev npm run dev # http://localhost:5173 ``` -### Frontend (APK con Capacitor) +### Frontend (APK with Capacitor) -Requiere Android Studio / Android SDK + JDK 17 instalados en tu máquina de -desarrollo (esto no se puede generar en este entorno). Una vez instalados: +Requires Android Studio / Android SDK + JDK 17 installed on your development +machine (this can't be generated in this environment). Once installed: ```bash cd frontend -npm run cap:sync # build web + copia assets a android/ -npm run android:open # abre el proyecto en Android Studio para compilar/firmar el APK +npm run cap:sync # builds the web app + copies assets into android/ +npm run android:open # opens the project in Android Studio to build/sign the APK ``` -También podés compilar por línea de comandos una vez que tengas el SDK: +You can also build it from the command line once you have the SDK: ```bash cd frontend/android ./gradlew assembleDebug -# APK en frontend/android/app/build/outputs/apk/debug/ +# APK at frontend/android/app/build/outputs/apk/debug/ ``` -## Contenido por defecto +## Default content -`frontend/src/data/defaultStories.json` tiene 16 historias originales -escritas para este proyecto (no extraídas de ningún juego comercial de -terceros), usadas como fallback cuando no hay conexión al backend o todavía -no se generó ningún lote. +`frontend/src/data/defaultStories.json` has 16 original stories written for +this project (not extracted from any third-party commercial game), used as +a fallback when there's no connection to the backend or no batch has been +generated yet. -## Producción +## Production -Ver [`docs/DEPLOY.md`](docs/DEPLOY.md) para el paso a paso de deploy en un -LXC de Debian sin Docker, con systemd + nginx + certbot, apuntando a tu -propio dominio. +Example systemd/nginx configs live in the `deploy/` folder. -## API key de Gemini +## Gemini API key -Conseguila en https://aistudio.google.com/apikey y ponela en -`backend/.env` como `GEMINI_API_KEY`. +Get one at https://aistudio.google.com/apikey and put it in `backend/.env` +as `GEMINI_API_KEY`. diff --git a/docs/DEPLOY.md b/docs/DEPLOY.md deleted file mode 100644 index 23b45de..0000000 --- a/docs/DEPLOY.md +++ /dev/null @@ -1,114 +0,0 @@ -# Deploy en un LXC de Debian (sin Docker, sin proveedor externo) - -Esta guia asume un contenedor LXC Debian 12 con acceso root, sin Docker, y -que vas a exponer la app en tu propio dominio con nginx + Let's Encrypt. - -## 1. Preparar el sistema - -```bash -apt update && apt upgrade -y -apt install -y curl git nginx certbot python3-certbot-nginx - -# Node.js 22 LTS via NodeSource -curl -fsSL https://deb.nodesource.com/setup_22.x | bash - -apt install -y nodejs - -node -v # deberia mostrar v22.x -``` - -Crea un usuario de sistema dedicado (sin login) para correr la app: - -```bash -useradd --system --create-home --home-dir /opt/historias --shell /usr/sbin/nologin historias -``` - -## 2. Clonar y preparar el proyecto - -```bash -cd /opt/historias -git clone app -cd app - -# Backend -cd backend -npm ci -cp .env.example .env -# Editar .env: GEMINI_API_KEY, ADMIN_TOKEN, CORS_ORIGIN=https://tu-dominio.com -npm run build - -# Frontend -cd ../frontend -npm ci -cp .env.example .env -# Editar .env: VITE_API_URL=https://tu-dominio.com -npm run build # genera frontend/dist, servido por nginx - -chown -R historias:historias /opt/historias -``` - -> Los paths de los ejemplos en `deploy/*.service` asumen que el repo termina -> viviendo en `/opt/historias/backend` y `/opt/historias/frontend`. Si tu -> checkout usa otra carpeta (por ejemplo `/opt/historias/app/backend`), -> ajusta `WorkingDirectory` y `ExecStart` en los archivos `.service` antes de -> instalarlos. - -## 3. Servicio de la API (systemd) - -```bash -cp deploy/story-api.service /etc/systemd/system/story-api.service -systemctl daemon-reload -systemctl enable --now story-api -systemctl status story-api -curl http://127.0.0.1:8787/api/health # {"ok":true} -``` - -## 4. Generacion diaria de historias (systemd timer) - -```bash -cp deploy/story-generate.service /etc/systemd/system/story-generate.service -cp deploy/story-generate.timer /etc/systemd/system/story-generate.timer -systemctl daemon-reload -systemctl enable --now story-generate.timer - -# Probar la generacion manualmente una vez (usa tu GEMINI_API_KEY real): -systemctl start story-generate.service -journalctl -u story-generate.service -n 50 --no-pager -``` - -El timer corre todos los dias a las 06:00 (hora del sistema del LXC) con -hasta 10 minutos de retraso aleatorio. Ajusta `OnCalendar` en el `.timer` si -preferis otro horario. - -## 5. nginx + TLS - -```bash -cp deploy/nginx.conf.example /etc/nginx/sites-available/historias -# Editar server_name y la ruta de "root" si corresponde -ln -s /etc/nginx/sites-available/historias /etc/nginx/sites-enabled/historias -nginx -t && systemctl reload nginx - -certbot --nginx -d tu-dominio.com -``` - -## 6. Actualizar la app despues de un cambio - -```bash -cd /opt/historias/app -git pull -cd backend && npm ci && npm run build -cd ../frontend && npm ci && npm run build -systemctl restart story-api -``` - -## Notas - -- Las historias generadas se guardan en `backend/data/*.json` (no se versionan - en git). Hace backup de esa carpeta si te importa el historial generado. -- Si Gemini falla un dia (cuota, red, etc.), `story-generate.service` termina - con error y `latest.json` simplemente no se actualiza: la API sigue - sirviendo el ultimo lote bueno, y si nunca hubo ninguno, el cliente cae a - las historias default embebidas en la app. -- `ADMIN_TOKEN` protege `POST /api/admin/generate`, util para forzar una - generacion manual sin esperar al timer: - `curl -X POST https://tu-dominio.com/api/admin/generate -H "x-admin-token: "` -- Revisa logs con `journalctl -u story-api -f` y `journalctl -u story-generate -f`.