docs: Add comprehensive documentation (PROJECT_STRUCTURE, QUICK_START) and cleanup

- Remove old STATUS.md and STRUCTURE_NOTES.md
- Add detailed PROJECT_STRUCTURE.md with full architecture documentation
- Add QUICK_START.md with quick reference guide
- Documentation covers: project overview, file structure, database models, API routes, Docker setup, authentication flow, security, and deployment
This commit is contained in:
E-Voting Developer 2025-11-06 01:20:57 +01:00
parent 839ca5461c
commit 4b3da56c40
4 changed files with 457 additions and 291 deletions

View File

@ -0,0 +1,324 @@
# E-Voting System - Architecture & Structure
## 📋 Vue d'ensemble
Système de vote électronique sécurisé utilisant la **cryptographie post-quantique** et **le vote chiffré**.
**Stack technique:**
- **Backend:** Python FastAPI + SQLAlchemy + MariaDB
- **Frontend:** React 19 + React Router + Axios
- **Cryptographie:** ElGamal + Preuve Zero-Knowledge + PQC Hybrid
- **Déploiement:** Docker Compose
---
## 📁 Structure du projet
```
e-voting-system/
├── backend/ # API FastAPI
│ ├── main.py # Point d'entrée FastAPI
│ ├── config.py # Configuration (DB, JWT, etc)
│ ├── database.py # Setup SQLAlchemy
│ ├── models.py # Tables SQLAlchemy (Voter, Election, Vote, Candidate)
│ ├── schemas.py # Schémas Pydantic (validation)
│ ├── services.py # Logique métier (VoterService, ElectionService, VoteService)
│ ├── auth.py # JWT et hashing (bcrypt)
│ ├── dependencies.py # Dépendances FastAPI
│ ├── crypto/ # Modules cryptographie
│ │ ├── encryption.py # ElGamal encryption
│ │ ├── hashing.py # Key derivation (PBKDF2, bcrypt)
│ │ ├── signatures.py # Digital signatures
│ │ ├── zk_proofs.py # Zero-Knowledge proofs
│ │ └── pqc_hybrid.py # PQC Hybrid approach
│ ├── routes/ # Endpoints
│ │ ├── auth.py # Login, Register, Profile
│ │ ├── elections.py # Élections CRUD
│ │ └── votes.py # Soumission/Récupération votes
│ └── scripts/
│ └── seed_db.py # Script initialisation DB
├── frontend/ # Application React
│ ├── public/
│ │ ├── index.html # HTML root
│ │ └── config.js # Config runtime (API_BASE_URL)
│ ├── src/
│ │ ├── App.js # Routeur principal
│ │ ├── index.js # Entry point React
│ │ ├── components/ # Composants réutilisables
│ │ │ ├── Header.jsx # Navigation
│ │ │ ├── Footer.jsx # Footer
│ │ │ ├── Alert.jsx # Messages d'erreur/succès
│ │ │ ├── Modal.jsx # Modals
│ │ │ ├── LoadingSpinner.jsx
│ │ │ └── VoteCard.jsx # Carte candidat
│ │ ├── pages/ # Pages/routes
│ │ │ ├── LoginPage.js # Page de connexion (FIXED)
│ │ │ ├── HomePage.jsx # Accueil
│ │ │ ├── RegisterPage.jsx
│ │ │ ├── DashboardPage.js # Tableau de bord
│ │ │ ├── VotingPage.jsx # Page de vote
│ │ │ ├── ArchivesPage.jsx
│ │ │ └── ProfilePage.jsx
│ │ ├── config/
│ │ │ ├── api.js # Configuration API endpoints
│ │ │ └── theme.js # Thème UI
│ │ ├── hooks/
│ │ │ └── useApi.js # Hook pour appels API
│ │ ├── styles/
│ │ │ ├── globals.css
│ │ │ └── components.css
│ │ └── utils/
│ │ └── api.js # Utilitaires API
│ ├── package.json # Dépendances npm
│ ├── build/ # Compilation production
│ └── Dockerfile # Containerisation
├── docker/
│ ├── Dockerfile.backend # Image FastAPI
│ ├── Dockerfile.frontend # Image React
│ └── init.sql # Script init DB
├── docker-compose.yml # Orchestration (mariadb + backend + frontend)
├── Makefile # Commandes utiles
├── README.md # Documentation principale
└── .claude/ # Documentation développeur
├── PROJECT_STRUCTURE.md # Ce fichier
├── DEPLOYMENT.md # Guide déploiement
└── POSTQUANTUM_CRYPTO.md # Infos PQC
```
---
## 🔑 Composants clés
### Backend - Routes principales
#### `/api/auth/`
- **POST /register** → Créer compte votant
- **POST /login** → Authentification, retourne JWT
- **GET /profile** → Profil votant actuel
#### `/api/elections/`
- **GET /active** → Élection en cours
- **GET /completed** → Élections terminées
- **GET /active/results** → Résultats
#### `/api/votes/`
- **POST /** → Soumettre un vote chiffré
- **GET /history** → Historique votes votant
### Frontend - Pages principales
| Page | Route | Description |
|------|-------|-------------|
| **LoginPage.js** | `/login` | Connexion votant |
| **HomePage.jsx** | `/` | Accueil |
| **DashboardPage.js** | `/dashboard` | Elections actives |
| **VotingPage.jsx** | `/vote/:id` | Interface vote |
| **ArchivesPage.jsx** | `/archives` | Elections passées |
---
## 🔐 Flux d'authentification
```
1. Utilisateur → LoginPage.js
2. POST /api/auth/login (email + password)
3. Backend vérifie credentials (bcrypt.checkpw)
4. ✅ JWT token retourné
5. Token + voter data → localStorage
6. Redirection → /dashboard
```
### Important: LoginPage.js
**Corrigé le 5 nov 2025:**
- ✅ Utilise `API_ENDPOINTS.LOGIN` (au lieu de URL hardcodée)
- ✅ Prop correct: `onLogin` (au lieu de `onLoginSuccess`)
- ✅ Structure données correcte: `email`, `first_name`, `last_name`
---
## 🗄️ Modèles Base de données
### `voters`
```
id (PK)
email (UNIQUE)
password_hash (bcrypt)
first_name
last_name
citizen_id (UNIQUE)
public_key (ElGamal)
has_voted (bool)
created_at
updated_at
```
### `elections`
```
id (PK)
name
description
start_date
end_date
elgamal_p (nombre premier)
elgamal_g (générateur)
public_key (clé publique)
is_active (bool)
results_published (bool)
```
### `candidates`
```
id (PK)
election_id (FK)
name
description
order
```
### `votes`
```
id (PK)
voter_id (FK)
election_id (FK)
candidate_id (FK)
encrypted_vote (ElGamal ciphertext)
zero_knowledge_proof
ballot_hash
timestamp
ip_address
```
---
## 🐳 Docker Compose
3 services:
### `mariadb` (port 3306)
- Image: `mariadb:latest`
- Init script: `docker/init.sql`
- Volume: `evoting_data`
### `backend` (port 8000)
- Build: `docker/Dockerfile.backend`
- CMD: `uvicorn backend.main:app --host 0.0.0.0 --port 8000`
- Dépend de: `mariadb` (healthcheck)
### `frontend` (port 3000)
- Build: `docker/Dockerfile.frontend`
- CMD: `serve -s build -l 3000`
- Dépend de: `backend`
---
## 🚀 Démarrage
### Local (développement)
```bash
# Backend
cd backend
uvicorn main:app --reload
# Frontend (autre terminal)
cd frontend
npm start
```
### Docker
```bash
docker-compose up -d
# Frontend: http://localhost:3000
# Backend: http://localhost:8000
```
### Makefile
```bash
make up # docker-compose up -d
make down # docker-compose down
make logs # docker-compose logs -f backend
make test # pytest tests/ -v
```
---
## 🔒 Sécurité
### Authentification
- Passwords: **bcrypt** (salt + hash)
- Tokens: **JWT** (HS256, 30min expiration)
### Votes
- **Chiffrement:** ElGamal
- **Preuve:** Zero-Knowledge
- **Traçabilité:** ballot_hash
### Post-Quantum
- Hybride PQC/Classique pour transition future
- Module: `backend/crypto/pqc_hybrid.py`
---
## 📝 Variables d'environnement
### Backend (`.env`)
```
DB_HOST=mariadb
DB_PORT=3306
DB_NAME=evoting_db
DB_USER=evoting_user
DB_PASSWORD=evoting_pass123
SECRET_KEY=your-secret-key-change-in-production
DEBUG=false
```
### Frontend (`public/config.js`)
```javascript
window.API_CONFIG = {
API_BASE_URL: 'http://localhost:8000'
};
```
---
## ✅ Tests
```bash
# Tous les tests
pytest tests/ -v
# Tests spécifiques
pytest tests/test_backend.py -v
pytest tests/test_crypto.py -v
pytest tests/test_pqc.py -v
```
---
## 🎯 Statut (5 nov 2025)
✅ **Système fonctionnel**
- [x] Login/Register
- [x] Dashboard
- [x] JWT authentication
- [x] Docker deployment
- [x] API endpoints
- [ ] Vote submission (en cours)
- [ ] Results display (planifié)
---
## 📚 Références
- **FastAPI:** https://fastapi.tiangolo.com/
- **React Router:** https://reactrouter.com/
- **SQLAlchemy:** https://www.sqlalchemy.org/
- **ElGamal:** Crypto asymétrique probabiliste
- **Zero-Knowledge Proofs:** Preuve sans révéler info
---
**Dernière mise à jour:** 5 novembre 2025

View File

@ -0,0 +1,133 @@
# Quick Start & Notes
## 🚀 Démarrage rapide
```bash
# Docker (recommandé)
cd /home/paul/CIA/e-voting-system
docker-compose up -d
# Frontend: http://localhost:3000
# Backend API: http://localhost:8000
# Database: localhost:3306
```
## 🔧 Fixes récentes (5 nov 2025)
### LoginPage.js
- ✅ Utilise `API_ENDPOINTS.LOGIN` au lieu de URL hardcodée
- ✅ Prop correct: `onLogin` (était `onLoginSuccess`)
- ✅ Mapping données correct: `email`, `first_name`, `last_name`
- ✅ Teste les identifiants: `paul.roost@epita.fr` / `tennis16`
### DashboardPage.js
- ✅ Utilise `API_ENDPOINTS.ELECTIONS_ACTIVE`
### Docker
- ✅ Dockerfile.backend: suppression du double CMD
- ✅ Frontend build inclus dans docker-compose
### Nettoyage
- ✅ Suppression du dossier `src/` (doublon)
- ✅ Installation de `lucide-react`
- ✅ Suppression des console.log de debug
---
## 📋 Fichiers à connaître
| Fichier | Rôle |
|---------|------|
| `backend/main.py` | Point d'entrée FastAPI |
| `backend/routes/auth.py` | Routes login/register |
| `frontend/src/pages/LoginPage.js` | **Page de login** |
| `frontend/src/config/api.js` | Configuration API endpoints |
| `docker-compose.yml` | Orchestration services |
| `.env.example` | Variables d'environnement |
---
## 🧪 Test login
```bash
# Via curl
curl -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "paul.roost@epita.fr", "password": "tennis16"}'
# Réponse attendue
{
"access_token": "eyJ...",
"token_type": "bearer",
"expires_in": 1800,
"id": 1,
"email": "paul.roost@epita.fr",
"first_name": "Paul",
"last_name": "Roost"
}
```
---
## 🔑 Points clés
### API Base URL
- **Local dev:** `http://localhost:8000`
- **Docker:** Configuration dans `frontend/public/config.js`
### JWT Token
- Stocké dans `localStorage` sous clé `token`
- Utilisé dans header `Authorization: Bearer <token>`
- Expiration: 30 minutes
### Voter Data
- Stocké dans `localStorage` sous clé `voter`
- Structure: `{ id, email, name, first_name, last_name }`
---
## ⚠️ Erreurs courantes
| Erreur | Cause | Solution |
|--------|-------|----------|
| `CORS error` | Frontend cherche localhost depuis Docker | Utiliser `API_ENDPOINTS` |
| `onLoginSuccess is not a function` | Prop nommé incorrectement | Utiliser `onLogin` |
| `t is not a function` | Composant pas reçu le bon prop | Vérifier noms props parent/enfant |
| Build cache | Ancien JS chargé | Force refresh: `Ctrl+Shift+R` |
---
## 📊 Architecture réseau Docker
```
User Browser (localhost:3000)
Frontend Container (nginx serve)
Backend Container (:8000)
MariaDB Container (:3306)
```
**Important:** Du navigateur, utiliser `localhost:8000`. Du container, utiliser `evoting_backend:8000`.
---
## 🔐 Credentials de test
- **Email:** `paul.roost@epita.fr`
- **Password:** `tennis16`
- **DB User:** `evoting_user`
- **DB Pass:** `evoting_pass123`
---
## 📚 Autres fichiers .claude
- **PROJECT_STRUCTURE.md** - Architecture complète (ce répertoire)
- **DEPLOYMENT.md** - Guide déploiement production
- **POSTQUANTUM_CRYPTO.md** - Détails cryptographie
---
**Dernière mise à jour:** 5 novembre 2025

View File

@ -1,268 +0,0 @@
# 🗳️ E-Voting System - Status Final
**Date:** 5 novembre 2025
**Status:** ✅ **PRODUCTION READY**
**Branch:** `paul/evoting` on gitea.vidoks.fr
---
## 📊 Architecture
```
┌─────────────────────────────────────────────────────────────┐
│ DOCKER NETWORK │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ FRONTEND │ │ BACKEND │ │
│ │ React 18 CRA │ │ FastAPI (3.12) │ │
│ │ :3000 │ │ :8000 │ │
│ └──────────────────┘ └────────┬─────────┘ │
│ │ │
│ ┌────────▼─────────┐ │
│ │ MariaDB │ │
│ │ :3306 │ │
│ └──────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
```
---
## 📁 Structure du Projet
```
/home/paul/CIA/e-voting-system/
├── frontend/ # React Create React App (18.x)
│ ├── public/ # Static files
│ ├── src/ # React components
│ ├── package.json
│ └── build/ # Production build
├── backend/ # FastAPI application
│ ├── main.py # Entry point
│ ├── models.py # SQLAlchemy ORM
│ ├── schemas.py # Pydantic models
│ ├── routes/ # API endpoints
│ │ ├── elections.py
│ │ ├── votes.py
│ │ └── auth.py
│ ├── crypto/ # Cryptography modules
│ │ ├── hashing.py # SHA-256
│ │ ├── encryption.py # ElGamal
│ │ ├── signatures.py # RSA-PSS
│ │ └── pqc_hybrid.py # Post-Quantum (ML-DSA-65, ML-KEM-768)
│ ├── pyproject.toml # Poetry dependencies
│ └── poetry.lock
├── docker/ # Docker configuration
│ ├── Dockerfile.backend
│ ├── Dockerfile.frontend
│ ├── init.sql # Database initialization
├── docs/ # Documentation
│ ├── DEPLOYMENT.md
│ └── POSTQUANTUM_CRYPTO.md
├── docker-compose.yml # Service orchestration
├── .env # Environment variables
└── README.md # Main readme
```
---
## 🚀 Démarrage Rapide
### Lancer les services
```bash
cd /home/paul/CIA/e-voting-system
docker-compose up -d
```
### Accès
- **Frontend:** http://localhost:3000
- **API:** http://localhost:8000
- **API Docs:** http://localhost:8000/docs (Swagger UI)
- **Database:** localhost:3306
### Arrêter
```bash
docker-compose down
```
---
## 🔐 Fonctionnalités
### ✅ Frontend (React)
- SPA responsive avec pages multiples
- Enregistrement de votant
- Interface de vote
- Affichage des résultats
- Gestion d'état avec Context API
- Communication API avec Axios
### ✅ Backend (FastAPI)
- 7 endpoints REST (/elections, /votes, /voters)
- Authentification JWT
- Validation Pydantic
- ORM SQLAlchemy
- Logs structurés
- CORS activé
### ✅ Cryptographie
- **Classique:** RSA-PSS, ElGamal, SHA-256, PBKDF2
- **Post-Quantum:** ML-DSA-65 (Dilithium), ML-KEM-768 (Kyber) - FIPS 203/204
- **Hybrid:** Approche défense-en-profondeur (classique + PQC)
### ✅ Base de Données
- 5 tables normalisées (voters, elections, candidates, votes, audit_logs)
- 1 élection active pré-chargée avec 4 candidats
- Intégrité référentielle
- Timestamps
---
## 📊 Services Docker
```
✅ evoting-frontend Node 20 Alpine → port 3000
✅ evoting-backend Python 3.12 → port 8000
✅ evoting_db MariaDB 12 → port 3306
```
**Vérifier le statut:**
```bash
docker ps
docker logs evoting_backend # Backend logs
docker logs evoting_frontend # Frontend logs
docker logs evoting_db # Database logs
```
---
## 🧪 Tests
```bash
# Unit tests
cd /home/paul/CIA/e-voting-system
pytest
# Coverage
pytest --cov=backend tests/
```
---
## 📝 Git History
```
Commit 4a6c595 (HEAD paul/evoting)
├─ Restructure: React CRA frontend + FastAPI backend in separate dirs
│ └─ 48 files changed, 20243 insertions
Commit 94939d2
├─ Move DEPLOYMENT.md to .claude/ directory
Commit 15a52af
├─ Remove liboqs-python: use optional import for PQC compatibility
Commit 6df490a
└─ Add post-quantum cryptography (FIPS 203/204)
└─ 798 insertions, 2173 deletions
```
---
## ⚙️ Configuration
### `.env` (Production - À mettre à jour)
```env
# Database
DB_HOST=mariadb
DB_PORT=3306
DB_NAME=evoting_db
DB_USER=evoting_user
DB_PASSWORD=CHANGE_THIS_PASSWORD_IN_PRODUCTION
# Backend
SECRET_KEY=CHANGE_THIS_SECRET_KEY_IN_PRODUCTION
DEBUG=false
# Frontend
REACT_APP_API_URL=http://your-production-domain.com/api
```
---
## 🔗 Endpoints API
### Elections
```
GET /api/elections/active → Current election + candidates
GET /api/elections/{id}/results → Election results
```
### Votes
```
POST /api/votes/submit → Submit a vote
GET /api/votes/verify/{id} → Verify vote signature
```
### Voters
```
POST /api/voters/register → Register voter (generates keys)
GET /api/voters/check?email=... → Check voter existence
```
---
## 🛡️ Security Features
- ✅ JWT authentication
- ✅ Password hashing (bcrypt)
- ✅ CORS configuration
- ✅ SQL injection protection (ORM)
- ✅ Rate limiting ready
- ✅ Vote encryption with hybrid PQC
- ✅ Digital signatures (RSA + Dilithium)
- ✅ Audit logging
---
## 📚 Documentation
- `docs/DEPLOYMENT.md` - Deployment guide & troubleshooting
- `docs/POSTQUANTUM_CRYPTO.md` - PQC implementation details
- `README.md` - Main project readme
---
## 🎯 Prochaines Étapes
1. ✅ **Frontend React fonctionnel** - COMPLÉTÉ
2. ✅ **Backend API fonctionnel** - COMPLÉTÉ
3. ✅ **Base de données intégrée** - COMPLÉTÉ
4. ✅ **Cryptographie PQC prête** - COMPLÉTÉ
5. ⏳ **Intégrer PQC dans les endpoints** - À faire
6. ⏳ **Tests E2E complets** - À faire
7. ⏳ **Déployer en production** - À faire
---
## 📞 Support
Pour des questions sur:
- **PQC:** Voir `docs/POSTQUANTUM_CRYPTO.md`
- **Déploiement:** Voir `docs/DEPLOYMENT.md`
- **API:** Accéder à http://localhost:8000/docs
---
**Last Updated:** 2025-11-05
**Project Status:** ✅ Ready for Testing & Development

View File

@ -1,23 +0,0 @@
# 📝 IMPORTANT - Structure des Documentation
## ✅ RÈGLE : Tous les .md (SAUF README.md) doivent être dans `.claude/`
**Raison:** Garder la racine minimale et propre.
### Fichiers à TOUJOURS garder dans `.claude/`:
- ✅ `POSTQUANTUM_CRYPTO.md` - Documentation PQC
- ✅ `DEPLOYMENT.md` - Guide de déploiement
- ✅ `STATUS.md` - Status du projet (MOVE HERE!)
- ✅ Tout autre .md technique
### Fichiers à la RACINE:
- ✅ `README.md` SEULEMENT
### À FAIRE:
```bash
# Déplacer STATUS.md vers .claude/
mv STATUS.md .claude/STATUS.md
git add -A && git commit -m "Move STATUS.md to .claude/"
```
**Ne plus oublier ceci!**