Skip to main content

Developpement Local

Ce guide explique comment configurer et demarrer Bemba en environnement de developpement local.

Prerequis​

OutilVersionInstallation
PHP8.3+php.net
Composer2.xgetcomposer.org
Node.js20+nodejs.org
PostgreSQL15+postgresql.org
Redis7+ (facultatif en local : le cache de développement est sur disque)redis.io

Structure du projet​

pch-sig/
├── backend/ # API Symfony
│ ├── bin/
│ ├── config/
│ ├── migrations/
│ ├── public/
│ ├── src/
│ └── composer.json
├── frontend/ # Application React
│ ├── public/
│ ├── src/
│ └── package.json
├── documentation/ # Documentation Docusaurus
├── monitoring/ # Grafana/Prometheus du poste d'administration, Loki/Promtail des serveurs
└── CLAUDE.md # Instructions techniques

Configuration Backend​

1. Installer les dependances​

cd backend
composer install

2. Configurer l'environnement​

Copier le fichier .env :

cp .env .env.local

Modifier .env.local :

# Base de donnees
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/pch_sig?serverVersion=15"

# Redis
REDIS_URL="redis://localhost:6379"

# JWT (generer les cles si necessaire)
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
JWT_PASSPHRASE=pch_sig_dev

# Mailer : aucun envoi réel en local (ou Mailpit si vous l'avez démarré : smtp://localhost:1025)
MAILER_DSN=null://null

3. Generer les cles JWT​

mkdir -p config/jwt
openssl genpkey -out config/jwt/private.pem -aes256 -algorithm rsa -pkeyopt rsa_keygen_bits:4096
openssl pkey -in config/jwt/private.pem -out config/jwt/public.pem -pubout

4. Creer la base de donnees​

php bin/console doctrine:database:create
php bin/console doctrine:migrations:migrate

5. Charger les fixtures (optionnel)​

php bin/console doctrine:fixtures:load

Configuration Frontend​

1. Installer les dependances​

cd frontend
npm install --legacy-peer-deps

2. Configurer l'environnement​

Creer .env.development.local :

REACT_APP_API_URL=http://localhost:8000/api
REACT_APP_ENV_NAME=LOCAL
REACT_APP_ENV_COLOR=#f59e0b

Demarrer les Services​

Methode 1 : Commandes separees​

# Terminal 1 - Backend
cd backend
php bin/console cache:clear
php -S localhost:8000 -t public

# Terminal 2 - Frontend
cd frontend
npm start

Methode 2 : Processus Windows independants​

Cette methode permet aux services de persister apres la fermeture du terminal.

# Backend (fenetre minimisee)
powershell -Command "Start-Process -FilePath 'php' -ArgumentList '-S','localhost:8000','-t','public' -WorkingDirectory 'C:/chemin/vers/pch-sig/backend' -WindowStyle Minimized"

# Frontend (fenetre minimisee)
powershell -Command "Start-Process -FilePath 'cmd' -ArgumentList '/c','cd /d C:/chemin/vers/pch-sig/frontend && npm start' -WindowStyle Minimized"

Verifier les services​

# Backend
curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/api
# Attendu: 200 ou 401

# Frontend
curl -s -o /dev/null -w "%{http_code}" http://localhost:3000
# Attendu: 200

URLs de Developpement​

ServiceURLDescription
Frontendhttp://localhost:3000Application React
Backend APIhttp://localhost:8000/apiAPI Symfony
API Dochttp://localhost:8000/api/docsDocumentation OpenAPI
Mailpit (facultatif)http://localhost:8025Interface e-mails, seulement si vous le lancez vous-même

Arret des Services​

Arreter le backend​

# Trouver le PID
netstat -ano | grep ":8000.*LISTENING"

# Tuer le process
taskkill /F /PID <PID>

# Ou tuer tous les processus PHP
taskkill /F /IM php.exe

Arreter le frontend​

# Trouver le PID
netstat -ano | grep ":3000.*LISTENING"

# Tuer le process
taskkill /F /PID <PID>

Indicateur d'Environnement​

En developpement local, un badge orange LOCAL apparait en bas a gauche de l'ecran. Ce badge est configure via les variables d'environnement :

REACT_APP_ENV_NAME=LOCAL
REACT_APP_ENV_COLOR=#f59e0b

En production, aucun badge n'apparait (REACT_APP_ENV_NAME vide ou absent).


Commandes Utiles​

Backend​

# Vider le cache
php bin/console cache:clear

# Voir les routes
php bin/console debug:router

# Voir les services
php bin/console debug:container

# Creer une migration
php bin/console make:migration

# Executer les migrations
php bin/console doctrine:migrations:migrate

# Verifier le schema
php bin/console doctrine:schema:validate

Frontend​

# Demarrer le dev server
npm start

# Build production
npm run build

# Verifier TypeScript
npx tsc --noEmit

# Linter
npm run lint

Diagnostic des Erreurs​

Erreurs TypeScript fantomes​

Si le dev server affiche des erreurs qui n'existent pas :

  1. Verifier avec TypeScript pur :

    npx tsc --noEmit
  2. Si tsc passe, redemarrer le dev server :

    # Tuer le process
    taskkill /F /PID <PID>

    # Relancer
    npm start

Module not found​

  1. Verifier que le fichier existe sur le disque
  2. Verifier le git status
  3. Si le fichier existe, c'est un probleme de cache Webpack

Port deja utilise​

# Voir qui utilise le port
netstat -ano | grep ":<PORT>.*LISTENING"

# Tuer le process
taskkill /F /PID <PID>

Base de Donnees​

Connexion PostgreSQL​

psql -h localhost -U postgres -d pch_sig

Commandes utiles​

-- Voir les tables
\dt

-- Voir la structure d'une table
\d menages

-- Nombre de menages
SELECT COUNT(*) FROM menages;

-- Derniers menages
SELECT id, code_menage, created_at FROM menages ORDER BY created_at DESC LIMIT 10;

Redis​

Connexion Redis​

redis-cli

Commandes utiles​

# Voir les cles
KEYS *

# Vider le cache
FLUSHALL

# Statistiques
INFO

Prochaines Etapes​