alpha01 filetti: web app, crossword service and tor batch

This commit is contained in:
2026-06-05 16:22:17 +02:00
parent 47d8957e15
commit 9cb8a5aa8f
29 changed files with 8590 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import { notFound } from "next/navigation";
import { CrosswordRuntimePage } from "@/components/crossword-runtime-page";
import { LanguageSwitcher } from "@/components/language-switcher";
import { getDictionary, isLocale } from "@/lib/i18n";
type CrosswordPageProps = {
params: Promise<{ locale: string; id: string }>;
};
export default async function CrosswordPage({ params }: CrosswordPageProps) {
const { locale, id } = await params;
if (!isLocale(locale)) {
notFound();
}
const dict = getDictionary(locale);
return (
<main className="shell stack">
<section className="card play-header">
<div className="hero__topline">
<span className="hero__badge">{dict.play.badge}</span>
<LanguageSwitcher locale={locale} path={`/crosswords/${id}`} />
</div>
<h1 className="page-title">Progetto Enigma</h1>
<p className="page-subtitle">{dict.play.subtitle}</p>
</section>
<CrosswordRuntimePage
id={id}
locale={locale}
labels={{
player: dict.player,
clues: dict.clues,
play: dict.play,
loading: dict.play.loading,
errorPrefix: dict.play.errorPrefix,
}}
/>
</main>
);
}

View File

@@ -0,0 +1,42 @@
import { notFound } from "next/navigation";
import { CrosswordSolutionRuntimePage } from "@/components/crossword-solution-runtime-page";
import { LanguageSwitcher } from "@/components/language-switcher";
import { getDictionary, isLocale } from "@/lib/i18n";
type CrosswordSolutionPageProps = {
params: Promise<{ locale: string; id: string }>;
};
export default async function CrosswordSolutionPage({ params }: CrosswordSolutionPageProps) {
const { locale, id } = await params;
if (!isLocale(locale)) {
notFound();
}
const dict = getDictionary(locale);
return (
<main className="shell stack">
<section className="card play-header">
<div className="hero__topline">
<span className="hero__badge">{dict.solution.badge}</span>
<LanguageSwitcher locale={locale} path={`/crosswords/${id}/solution`} />
</div>
<h1 className="page-title">Progetto Enigma</h1>
<p className="page-subtitle">{dict.solution.subtitle}</p>
</section>
<CrosswordSolutionRuntimePage
id={id}
locale={locale}
labels={{
player: dict.player,
clues: dict.clues,
solution: dict.solution,
loading: dict.play.loading,
errorPrefix: dict.play.errorPrefix,
}}
/>
</main>
);
}

View File

@@ -0,0 +1,34 @@
import { notFound } from "next/navigation";
import { CrosswordConfigForm } from "@/components/crossword-config-form";
import { LanguageSwitcher } from "@/components/language-switcher";
import { getDictionary, isLocale } from "@/lib/i18n";
type NewCrosswordPageProps = {
params: Promise<{ locale: string }>;
};
export default async function NewCrosswordPage({ params }: NewCrosswordPageProps) {
const { locale } = await params;
if (!isLocale(locale)) {
notFound();
}
const dict = getDictionary(locale);
return (
<main className="shell stack">
<section className="hero">
<div className="hero__topline">
<span className="hero__badge">{dict.newPage.badge}</span>
<LanguageSwitcher locale={locale} path="/new" />
</div>
<h1 className="page-title">{dict.newPage.title}</h1>
<p className="page-subtitle">{dict.newPage.subtitle}</p>
</section>
<section className="card panel">
<CrosswordConfigForm locale={locale} dict={dict.form} />
</section>
</main>
);
}

View File

@@ -0,0 +1,85 @@
import Link from "next/link";
import { notFound } from "next/navigation";
import { CrosswordConfigForm } from "@/components/crossword-config-form";
import { LanguageSwitcher } from "@/components/language-switcher";
import { getDictionary, isLocale } from "@/lib/i18n";
import { getMockCrosswordResponse } from "@/lib/mock-crossword";
type LocalizedHomePageProps = {
params: Promise<{ locale: string }>;
};
export default async function LocalizedHomePage({ params }: LocalizedHomePageProps) {
const { locale } = await params;
if (!isLocale(locale)) {
notFound();
}
const dict = getDictionary(locale);
const crossword = getMockCrosswordResponse(locale);
return (
<main className="shell stack">
<section className="hero">
<div className="hero__topline">
<span className="hero__badge">{dict.home.badge}</span>
<LanguageSwitcher locale={locale} />
</div>
<h1>{dict.home.title}</h1>
<p>{dict.home.subtitle}</p>
</section>
<section className="home-grid">
<div className="card panel">
<h2>{dict.home.requestTitle}</h2>
<p className="muted">{dict.home.requestText}</p>
<CrosswordConfigForm locale={locale} dict={dict.form} />
</div>
<div className="stack">
<div className="card panel">
<h2>{dict.home.structureTitle}</h2>
<div className="chip-row">
{dict.home.structureChips.map((chip) => (
<span className="chip" key={chip}>
{chip}
</span>
))}
</div>
<p className="muted contract-note">{dict.home.structureText}</p>
</div>
<div className="card panel">
<h2>{dict.home.demoTitle}</h2>
<div className="kpi-grid">
<div className="kpi">
<span className="muted">{dict.home.kpis.words}</span>
<strong>{crossword.summary.total_words}</strong>
</div>
<div className="kpi">
<span className="muted">{dict.home.kpis.intersections}</span>
<strong>{crossword.summary.intersections}</strong>
</div>
<div className="kpi">
<span className="muted">{dict.home.kpis.rows}</span>
<strong>{crossword.grid.rows}</strong>
</div>
<div className="kpi">
<span className="muted">{dict.home.kpis.cols}</span>
<strong>{crossword.grid.cols}</strong>
</div>
</div>
<div className="actions" style={{ marginTop: 18 }}>
<Link className="button" href={`/${locale}/crosswords/demo-transport`}>
{dict.home.openDemo}
</Link>
<Link className="button button--secondary" href={`/${locale}/new`}>
{dict.home.openConfig}
</Link>
</div>
</div>
</div>
</section>
</main>
);
}

View File

@@ -0,0 +1,18 @@
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { NextResponse } from "next/server";
const RUNTIME_DIR = join(process.cwd(), ".runtime-crosswords");
export async function GET(
_request: Request,
context: { params: Promise<{ id: string }> },
) {
try {
const { id } = await context.params;
const source = await readFile(join(RUNTIME_DIR, `${id}.json`), "utf-8");
return NextResponse.json(JSON.parse(source));
} catch {
return NextResponse.json({ status: "not_found" }, { status: 404 });
}
}

View File

@@ -0,0 +1,65 @@
import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { spawn } from "node:child_process";
import { NextResponse } from "next/server";
const PYTHON = process.env.PYTHON_EXECUTABLE || "python";
const PROJECT_ROOT = join(process.cwd(), "..");
const RUNTIME_DIR = join(process.cwd(), ".runtime-crosswords");
function runPython(requestPayload: unknown): Promise<string> {
return new Promise((resolve, reject) => {
const child = spawn(PYTHON, ["crossword_service.py"], {
cwd: PROJECT_ROOT,
stdio: ["pipe", "pipe", "pipe"],
});
let stdout = "";
let stderr = "";
child.stdout.on("data", (chunk) => {
stdout += chunk.toString();
});
child.stderr.on("data", (chunk) => {
stderr += chunk.toString();
});
child.on("error", (error) => {
reject(error);
});
child.on("close", (code) => {
if (code !== 0) {
reject(new Error(stderr || `Python process exited with code ${code}`));
return;
}
resolve(stdout);
});
child.stdin.write(JSON.stringify(requestPayload));
child.stdin.end();
});
}
export async function POST(request: Request) {
try {
const payload = await request.json();
const stdout = await runPython(payload);
const responsePayload = JSON.parse(stdout);
await mkdir(RUNTIME_DIR, { recursive: true });
const targetPath = join(RUNTIME_DIR, `${responsePayload.crossword_id}.json`);
await writeFile(targetPath, JSON.stringify(responsePayload, null, 2), "utf-8");
return NextResponse.json(responsePayload);
} catch (error) {
return NextResponse.json(
{
status: "error",
message: error instanceof Error ? error.message : "Unknown error",
},
{ status: 500 },
);
}
}

488
webapp/app/globals.css Normal file
View File

@@ -0,0 +1,488 @@
:root {
--bg: #f4efe3;
--paper: #fffaf1;
--ink: #1f2a2a;
--muted: #6f776c;
--line: #d7cdb8;
--accent: #0d6b66;
--accent-2: #d97841;
--shadow: 0 18px 50px rgba(58, 48, 24, 0.12);
--cell: 42px;
}
* {
box-sizing: border-box;
}
html {
min-height: 100%;
}
body {
margin: 0;
min-height: 100%;
overflow-x: hidden;
background:
radial-gradient(circle at top left, rgba(217, 120, 65, 0.16), transparent 28%),
radial-gradient(circle at bottom right, rgba(13, 107, 102, 0.14), transparent 24%),
linear-gradient(180deg, #f8f4ea 0%, var(--bg) 100%);
color: var(--ink);
font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}
a {
color: inherit;
text-decoration: none;
}
button,
input,
select {
font: inherit;
}
.shell {
width: min(1240px, calc(100% - 32px));
margin: 0 auto;
}
.hero {
padding: 32px 0 16px;
}
.hero__topline {
display: flex;
justify-content: space-between;
gap: 12px;
align-items: center;
flex-wrap: wrap;
}
.hero__badge {
display: inline-flex;
gap: 8px;
align-items: center;
padding: 8px 12px;
border-radius: 999px;
background: rgba(13, 107, 102, 0.09);
color: var(--accent);
font-size: 13px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.hero__badge--soft {
background: rgba(217, 120, 65, 0.12);
color: #8d4d2b;
}
.hero h1,
.page-title {
margin: 16px 0 10px;
font-family: "Space Grotesk", "Segoe UI", sans-serif;
font-size: clamp(2.2rem, 4vw, 4.2rem);
line-height: 0.95;
letter-spacing: -0.05em;
}
.hero p,
.page-subtitle {
max-width: 760px;
margin: 0;
color: var(--muted);
font-size: 1.04rem;
line-height: 1.6;
}
.card {
background: rgba(255, 250, 241, 0.9);
border: 1px solid rgba(215, 205, 184, 0.95);
border-radius: 24px;
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.stack {
display: grid;
gap: 24px;
}
.home-grid {
display: grid;
grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
gap: 24px;
padding-bottom: 48px;
}
.panel {
padding: 24px;
}
.panel h2,
.panel h3 {
margin: 0 0 12px;
font-family: "Space Grotesk", "Segoe UI", sans-serif;
}
.muted {
color: var(--muted);
}
.config-form {
display: grid;
gap: 16px;
}
.config-form__grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14px;
}
.field {
display: grid;
gap: 6px;
}
.field label {
font-size: 0.92rem;
font-weight: 700;
}
.field input,
.field select {
width: 100%;
padding: 12px 14px;
border-radius: 14px;
border: 1px solid var(--line);
background: #fffdf8;
}
.form-error {
margin: 0;
color: #b03030;
font-weight: 700;
}
.actions {
display: flex;
gap: 12px;
align-items: center;
flex-wrap: wrap;
}
.button {
border: 0;
border-radius: 16px;
padding: 13px 18px;
background: var(--accent);
color: white;
font-weight: 700;
cursor: pointer;
}
.button--secondary {
background: #ece2cc;
color: var(--ink);
}
.kpi-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 14px;
}
.kpi-grid--play {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.kpi {
padding: 18px;
border-radius: 18px;
background: #fffdf8;
border: 1px solid var(--line);
}
.kpi strong {
display: block;
font-size: 1.7rem;
font-family: "Space Grotesk", "Segoe UI", sans-serif;
}
.play-header,
.play-overview,
.play-stage,
.play-sidebar,
.solution-topbar {
padding: 22px;
}
.play-overview {
display: grid;
gap: 18px;
}
.play-overview__header {
display: flex;
justify-content: space-between;
gap: 18px;
align-items: start;
flex-wrap: wrap;
}
.play-overview__header h2,
.play-stage__header h2 {
margin: 10px 0 8px;
font-family: "Space Grotesk", "Segoe UI", sans-serif;
font-size: 1.45rem;
}
.play-overview__actions {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.play-stage,
.play-sidebar {
display: grid;
gap: 16px;
}
.play-stage__header {
display: grid;
gap: 6px;
}
.play-stage__header--tight h2 {
margin-top: 0;
}
.play-sidebar--bottom {
padding-bottom: 24px;
}
.player-shell {
display: grid;
gap: 16px;
}
.grid-board-wrap {
width: 100%;
display: flex;
justify-content: center;
}
.grid-board {
display: grid;
gap: 2px;
padding: 14px;
border-radius: 22px;
background: #e3d8c1;
align-self: start;
width: 100%;
max-width: 100%;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}
.grid-board--solution {
background: #d7d1bf;
}
.grid-cell {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
min-width: 0;
aspect-ratio: 1 / 1;
border: 0;
padding: 0;
background: #fffefb;
color: var(--ink);
cursor: pointer;
text-transform: uppercase;
font-weight: 800;
font-size: 1.05rem;
}
.grid-cell--block {
background: #273636;
cursor: default;
}
.grid-cell--active {
background: #dff2ef;
}
.grid-cell--filled {
color: var(--accent);
}
.grid-cell--revealed {
color: #273636;
background: #fff8e9;
}
.grid-cell__number {
position: absolute;
top: 3px;
left: 4px;
font-size: 0.58rem;
font-weight: 700;
color: var(--muted);
}
.clue-list {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18px;
}
.clue-section h3 {
margin: 0 0 10px;
font-family: "Space Grotesk", "Segoe UI", sans-serif;
}
.clue-section__list {
margin: 0;
padding-left: 0;
list-style: none;
display: grid;
gap: 10px;
max-height: 420px;
overflow: auto;
padding-right: 8px;
}
.clue-item {
color: var(--ink);
font-size: 0.97rem;
line-height: 1.55;
padding-bottom: 8px;
border-bottom: 1px solid rgba(215, 205, 184, 0.8);
}
.chip-row {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.chip {
padding: 8px 10px;
border-radius: 999px;
background: #f0e7d4;
color: #5f573f;
font-size: 0.86rem;
}
.lang-switcher {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.lang-switcher__link {
padding: 8px 12px;
border-radius: 999px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.66);
color: var(--muted);
font-size: 0.86rem;
font-weight: 700;
}
.lang-switcher__link--active {
background: var(--accent);
color: white;
border-color: var(--accent);
}
.contract-note {
border-left: 4px solid var(--accent-2);
padding-left: 14px;
}
.solution-topbar {
display: flex;
justify-content: flex-end;
}
.answer-key {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18px;
}
.answer-key__section h3 {
margin: 0 0 12px;
font-family: "Space Grotesk", "Segoe UI", sans-serif;
}
.answer-key__list {
margin: 0;
padding-left: 0;
list-style: none;
display: grid;
gap: 12px;
max-height: 420px;
overflow: auto;
padding-right: 8px;
}
.answer-key__item {
line-height: 1.55;
}
.answer-key__heading {
display: flex;
gap: 8px;
align-items: baseline;
flex-wrap: wrap;
margin-bottom: 4px;
}
.answer-key__answer {
font-family: "Space Grotesk", "Segoe UI", sans-serif;
letter-spacing: 0.04em;
}
@media (max-width: 980px) {
.home-grid {
grid-template-columns: 1fr;
}
.kpi-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 640px) {
:root {
--cell: 30px;
}
.shell {
width: min(100% - 20px, 1200px);
}
.config-form__grid,
.kpi-grid,
.kpi-grid--play {
grid-template-columns: 1fr;
}
.play-overview__actions,
.solution-topbar {
justify-content: stretch;
}
.play-overview__actions .button,
.solution-topbar .button {
width: 100%;
text-align: center;
}
}

19
webapp/app/layout.tsx Normal file
View File

@@ -0,0 +1,19 @@
import type { Metadata } from "next";
import "./globals.css";
export const metadata: Metadata = {
title: "Cruciverba Lab",
description: "Backoffice e UI iniziale per la generazione di cruciverba interattivi.",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="it">
<body>{children}</body>
</html>
);
}

5
webapp/app/page.tsx Normal file
View File

@@ -0,0 +1,5 @@
import { redirect } from "next/navigation";
export default function RootPage() {
redirect("/it");
}