# 🎯 Focolari Voting System - Guida Agente ## Panoramica Progetto **Nome:** Sistema Controllo Accessi "Focolari Voting System" **Committente:** Movimento dei Focolari **Scopo:** Gestione dei varchi di accesso per le assemblee di voto del Movimento. ### Contesto d'Uso Il sistema funziona su **tablet Android** (via browser Chrome) posizionati ai varchi d'ingresso delle sale votazione. Ogni tablet Γ¨ collegato a un **lettore RFID USB** che emula tastiera. --- ## πŸ—οΈ Architettura ``` VotoFocolari/ β”œβ”€β”€ ai-prompts/ # Documentazione e piani di sviluppo β”œβ”€β”€ backend-mock/ # Python FastAPI (server mock) β”‚ β”œβ”€β”€ main.py # Entry point con argparse β”‚ β”œβ”€β”€ Pipfile # Dipendenze pipenv β”‚ β”œβ”€β”€ api/ # Routes FastAPI β”‚ β”œβ”€β”€ schemas/ # Modelli Pydantic β”‚ └── data/ # Dataset JSON (default, test) └── frontend/ # React + TypeScript + Vite + Tailwind └── src/ β”œβ”€β”€ App.tsx # State machine principale β”œβ”€β”€ hooks/ # Custom hooks (RFID scanner) β”œβ”€β”€ components/ # UI components β”œβ”€β”€ screens/ # Schermate complete β”œβ”€β”€ services/ # API layer β”œβ”€β”€ types/ # TypeScript definitions └── tests/ # Test automatici use case ``` --- ## πŸ”§ Stack Tecnologico ### Backend Mock - **Python 3.10+** - **FastAPI** - Framework web asincrono - **Uvicorn** - ASGI server - **Pydantic** - Validazione dati - **pipenv** - Gestione ambiente virtuale - **argparse** - Parametri CLI (porta, dataset) ### Frontend - **React 19** - UI Library - **TypeScript 5.9** - Type safety - **Vite 7** - Build tool - **Tailwind CSS 4** - Styling utility-first - **React Router** - Routing (/, /debug) - **Vitest** - Testing framework - **Design:** Ottimizzato per touch tablet --- ## 🎨 Design System | Colore | Hex | Uso | |--------|-----|-----| | Blu Istituzionale | `#0072CE` | Colore primario, brand | | Arancio Accento | `#F5A623` | Azioni secondarie | | Giallo | `#FFD700` | Evidenze | | Verde Success | `#22C55E` | Conferme, ammesso | | Rosso Error | `#EF4444` | Errori, non ammesso | --- ## πŸ“Ÿ Logica RFID (CRITICA) Il lettore RFID simula una tastiera. **Non possiamo distinguerlo dalla digitazione umana** in base alla velocitΓ . ### Protocollo - **Formato:** `` - **Esempio US:** `;00012345?` - **Esempio IT:** `Γ²00012345_` ### Pattern Supportati ```typescript const VALID_PATTERNS = [ { start: ';', end: '?' }, // Layout US { start: 'Γ²', end: '_' }, // Layout IT ]; ``` ### Strategia 1. Ascolto globale `keydown` 2. Se ricevo un carattere `start` β†’ avvio buffer + timeout (2.5s) 3. Accumulo caratteri nel buffer 4. Se ricevo il corretto `end` β†’ emetto codice pulito 5. Se timeout scade β†’ scarto buffer --- ## πŸ”„ State Machine Applicativa ``` LOADING β†’ WAITING_VALIDATOR β†’ [badge validatore] β†’ VALIDATOR_PASSWORD β†’ [password OK] β†’ GATE_ACTIVE β†’ [badge partecipante] β†’ SHOWING_USER β†’ [badge validatore] β†’ SUCCESS_MODAL (5s, carosello multilingua) β†’ GATE_ACTIVE ``` --- ## 🌍 Messaggi Benvenuto (Frontend) Il backend risponde in modo **asettico** (solo `success: true`). Il frontend mostra un **carosello automatico** di messaggi multilingua: - Italiano, English, FranΓ§ais, Deutsch, EspaΓ±ol, PortuguΓͺs, δΈ­ζ–‡, ζ—₯本θͺž Scorrimento ogni ~2 secondi, durata modale 5 secondi. --- ## πŸ“ File Chiave | File | Descrizione | |------|-------------| | `backend-mock/main.py` | Entry point con argparse | | `backend-mock/api/routes.py` | Definizione endpoint | | `backend-mock/schemas/models.py` | Modelli Pydantic | | `backend-mock/data/*.json` | Dataset utenti | | `frontend/src/hooks/useRFIDScanner.ts` | Cuore del sistema - gestione lettore | | `frontend/src/App.tsx` | State machine e orchestrazione | | `frontend/src/components/WelcomeCarousel.tsx` | Carosello multilingua | | `frontend/src/screens/DebugScreen.tsx` | Diagnostica RFID | | `frontend/src/tests/` | Test automatici use case | --- ## πŸš€ Quick Start ### Backend ```bash cd backend-mock pipenv install pipenv run python main.py # Default pipenv run python main.py -p 9000 # Porta custom pipenv run python main.py -d data/test.json # Dataset test ``` ### Frontend ```bash cd frontend npm install npm run dev # Sviluppo npm run test # Test suite npm run test:ui # Test con UI ``` --- ## πŸ§ͺ Test Automatici Suite di test per validazione use case: | Test | Descrizione | |------|-------------| | UC01 | Login validatore | | UC02 | Accesso partecipante ammesso | | UC03 | Accesso negato | | UC04 | Timeout sessione | | UC05 | Cambio rapido badge | | UC06 | Pattern RFID multipli | --- ## πŸ” Debug ### Console Browser Tutti i log sono prefissati: - `[RFID]` - Eventi lettore badge - `[FLOW]` - Transizioni stato - `[API]` - Chiamate HTTP ### Pagina Debug (`/debug`) Accesso: logo cliccabile 5 volte. Mostra in tempo reale: - Ultimi 20 tasti premuti - Stato scanner (idle/scanning) - Buffer corrente - Pattern attivo --- ## ⚠️ Note Importanti 1. **Badge Validatore:** `999999` con password `focolari` 2. **Sessione:** 30 minuti di timeout, salvata in localStorage 3. **Timeout utente:** 60 secondi sulla schermata decisione 4. **Multi-layout:** Il sistema supporta RFID su tastiera US e IT 5. **Backend asettico:** Nessun messaggio multilingua dal server 6. **Git:** Il progetto sfrutta un Repository per versionare e sviluppare, ma solo l'utente puΓ² eseguire comandi git, eccetto se richiesto diversamente, l'agente puΓ² solo chiedere di eseguire o suggerire cosa fare, ma mai prendere iniziative --- ## πŸ“š Documentazione Correlata - `01-backend-plan.md` - Piano sviluppo backend - `02-frontend-plan.md` - Piano sviluppo frontend