alexp97 commited on
Commit
68ec720
·
1 Parent(s): 8f7750d

feat(ui): Shiny -> backend/dashboard.py (legacy) + scaffold Astro+Tailwind (Fase 8, SF8.1)

Browse files

- Reubica la UI Shiny a backend/dashboard.py (montable en /shiny, legacy); frontend/
queda para Astro. Ajusta run_ui.ps1 y README al nuevo path.
- Scaffold Astro 5 + Tailwind v4 (plugin @tailwindcss/vite, NO @astrojs /tailwind):
package.json, astro.config.mjs (output static + inlineStylesheets 'always' = Regla de Oro
+ proxy /api y /shiny en dev), tsconfig, src/pages/index.astro, src/styles/global.css.
- pnpm-workspace.yaml (allowBuilds) para que pnpm 11 corra esbuild/sharp; build verificado.

README.md CHANGED
@@ -48,8 +48,9 @@ uv run python -m backend.db.migrate
48
  # 3) Backend (FastAPI) en :8000 — o scripts/run_backend.ps1
49
  uv run python -u -m uvicorn backend.main:app --reload --port 8000 --log-level info
50
 
51
- # 4) UI en :8001 (otra terminal) — o scripts/run_ui.ps1
52
- uv run python -u -m uvicorn frontend.app:app --reload --port 8001
 
53
  # Atajo: ambos en ventanas separadas
54
  .\scripts\dev.ps1
55
  ```
 
48
  # 3) Backend (FastAPI) en :8000 — o scripts/run_backend.ps1
49
  uv run python -u -m uvicorn backend.main:app --reload --port 8000 --log-level info
50
 
51
+ # 4) UI Shiny LEGACY en :8001 (otra terminal) — o scripts/run_ui.ps1
52
+ # (la UI principal Astro se sirve desde el gateway en / cuando está compilada — Fase 8)
53
+ uv run python -u -m uvicorn backend.dashboard:app --reload --port 8001
54
  # Atajo: ambos en ventanas separadas
55
  .\scripts\dev.ps1
56
  ```
frontend/app.py → backend/dashboard.py RENAMED
@@ -1,10 +1,12 @@
1
  """
2
- Archivo: app.py
3
  Fecha de modificación: 03/06/2026
4
  Autor: Equipo AgroVisión
5
 
6
  Descripción:
7
- Interfaz Shiny for Python de la **plataforma** AgroVisión (6 módulos): Resumen de Campo,
 
 
8
  Creación de Parcelas (mapa + dibujo), Teledetección (NDVI 5 años + clima + heatmap),
9
  Conteo por Dron (**en desarrollo**), Asistente Agéntico (RAG) y Credenciales (efímeras).
10
  Consume el backend FastAPI por HTTP, adjuntando las credenciales BYOK como cabeceras
@@ -24,8 +26,8 @@ Entradas / Dependencias:
24
  Salidas / Efectos:
25
  - Estado efímero por sesión; nada se persiste en el cliente.
26
 
27
- Ejecución:
28
- uv run python -m uvicorn frontend.app:app --host 127.0.0.1 --port 8001 --reload
29
  """
30
 
31
  from __future__ import annotations
 
1
  """
2
+ Archivo: dashboard.py
3
  Fecha de modificación: 03/06/2026
4
  Autor: Equipo AgroVisión
5
 
6
  Descripción:
7
+ UI **Shiny for Python (LEGACY)** de AgroVisión. Desde la Fase 8 la UI principal es
8
+ **Astro + Tailwind** (servida por el gateway en `/`); este dashboard Shiny se conserva
9
+ como alternativa montable en `/shiny` y para desarrollo. Mantiene los 6 módulos: Resumen de Campo,
10
  Creación de Parcelas (mapa + dibujo), Teledetección (NDVI 5 años + clima + heatmap),
11
  Conteo por Dron (**en desarrollo**), Asistente Agéntico (RAG) y Credenciales (efímeras).
12
  Consume el backend FastAPI por HTTP, adjuntando las credenciales BYOK como cabeceras
 
26
  Salidas / Efectos:
27
  - Estado efímero por sesión; nada se persiste en el cliente.
28
 
29
+ Ejecución (legacy):
30
+ uv run python -m uvicorn backend.dashboard:app --host 127.0.0.1 --port 8001 --reload
31
  """
32
 
33
  from __future__ import annotations
frontend/__init__.py DELETED
@@ -1 +0,0 @@
1
- """Paquete frontend del MVP (UI Shiny for Python). Expone `app` como aplicación ASGI."""
 
 
frontend/astro.config.mjs ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @ts-check
2
+ import { defineConfig } from "astro/config";
3
+ import tailwindcss from "@tailwindcss/vite";
4
+
5
+ // Regla de Oro (plan_replication.md): SPA estática de una sola página, CSS inline
6
+ // (evita rutas /_astro/ rotas en ShinyApps.io). En dev, /api se proxea al gateway.
7
+ export default defineConfig({
8
+ output: "static",
9
+ build: { inlineStylesheets: "always" },
10
+ vite: {
11
+ plugins: [tailwindcss()],
12
+ server: {
13
+ proxy: {
14
+ "/api": { target: "http://localhost:8000", changeOrigin: true },
15
+ "/shiny": { target: "http://localhost:8000", changeOrigin: true, ws: true },
16
+ },
17
+ },
18
+ },
19
+ });
frontend/package.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "agrovision-frontend",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "private": true,
6
+ "scripts": {
7
+ "dev": "astro dev",
8
+ "build": "astro build",
9
+ "preview": "astro preview"
10
+ },
11
+ "dependencies": {
12
+ "astro": "^5.6.0"
13
+ },
14
+ "devDependencies": {
15
+ "@tailwindcss/vite": "^4.0.0",
16
+ "tailwindcss": "^4.0.0"
17
+ }
18
+ }
frontend/pnpm-lock.yaml ADDED
The diff for this file is too large to render. See raw diff
 
frontend/pnpm-workspace.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # pnpm 11: permitir los build scripts nativos de estos paquetes (binarios
2
+ # precompilados) para evitar ERR_PNPM_IGNORED_BUILDS al correr `pnpm build`/`pnpm dev`.
3
+ allowBuilds:
4
+ esbuild: true
5
+ sharp: true
6
+ "@tailwindcss/oxide": true
frontend/src/pages/index.astro ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ import "../styles/global.css";
3
+ ---
4
+
5
+ <!doctype html>
6
+ <html lang="es">
7
+ <head>
8
+ <meta charset="utf-8" />
9
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
10
+ <title>AgroVisión</title>
11
+ </head>
12
+ <body class="text-stone-900">
13
+ <main class="p-8">
14
+ <h1 class="flex items-center gap-2 text-2xl font-bold text-emerald-700">
15
+ 🌱 AgroVisión
16
+ </h1>
17
+ <p class="mt-2 text-sm text-stone-600">
18
+ Frontend Astro + Tailwind — scaffold inicial (Fase 8). La UI completa se
19
+ construye en los siguientes pasos.
20
+ </p>
21
+ </main>
22
+ </body>
23
+ </html>
frontend/src/styles/global.css ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "tailwindcss";
2
+
3
+ /* Paleta del mockup: Warm Neutrals & Deep Canopy (stone + emerald de Tailwind). */
4
+ :root {
5
+ color-scheme: light;
6
+ }
7
+
8
+ body {
9
+ background-color: #faf9f6; /* stone-50 cálido del mockup */
10
+ }
frontend/tsconfig.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "extends": "astro/tsconfigs/strict",
3
+ "include": [".astro/types.d.ts", "**/*"],
4
+ "exclude": ["dist"]
5
+ }
scripts/run_ui.ps1 CHANGED
@@ -4,11 +4,10 @@ Set-Location (Split-Path -Parent $PSScriptRoot)
4
  $env:UV_PROJECT_ENVIRONMENT = "$env:LOCALAPPDATA\agrovision-venv"
5
  $env:UV_LINK_MODE = "copy"
6
 
7
- # La app Shiny es ASGI: se sirve con uvicorn (python -u -m) para evitar el shim
8
- # shiny.exe, que OneDrive bloquea. Equivale a `shiny run frontend/app.py`.
9
- # --reload-exclude evita reinicios por cambios fuera del código de la UI (incluye backend/).
10
  $env:PYTHONUNBUFFERED = "1"
11
- uv run python -u -m uvicorn frontend.app:app --host 127.0.0.1 --port 8001 --reload --log-level info `
12
- --reload-exclude ".venv" --reload-exclude "backend" --reload-exclude "docs" `
13
  --reload-exclude "tests" --reload-exclude "scripts" --reload-exclude "supabase" `
14
  --reload-exclude "models" --reload-exclude "sample_data" --reload-exclude "scratch"
 
4
  $env:UV_PROJECT_ENVIRONMENT = "$env:LOCALAPPDATA\agrovision-venv"
5
  $env:UV_LINK_MODE = "copy"
6
 
7
+ # UI Shiny LEGACY (desde Fase 8 la UI principal es Astro servida por el gateway en /).
8
+ # Se sirve con uvicorn (python -u -m) para evitar el shim shiny.exe que OneDrive bloquea.
 
9
  $env:PYTHONUNBUFFERED = "1"
10
+ uv run python -u -m uvicorn backend.dashboard:app --host 127.0.0.1 --port 8001 --reload --log-level info `
11
+ --reload-exclude ".venv" --reload-exclude "frontend" --reload-exclude "docs" `
12
  --reload-exclude "tests" --reload-exclude "scripts" --reload-exclude "supabase" `
13
  --reload-exclude "models" --reload-exclude "sample_data" --reload-exclude "scratch"