Skip to content

NakoGH/MyMetroMap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

30 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

My Metro App - Application de Cartographie PersonnalisΓ©e

Application React + TypeScript + Vite permettant de générer des cartes de métro personnalisées selon le profil utilisateur. Intègre un backend Express + PostgreSQL + Prisma pour collecter les retours utilisateurs via un questionnaire de satisfaction.

πŸš€ Stack Technique

Frontend

  • React 19 avec TypeScript
  • Vite pour le build et le dev server
  • TailwindCSS pour le styling
  • D3.js pour le rendu des cartes schΓ©matiques
  • Leaflet pour les cartes gΓ©ographiques
  • Radix UI (shadcn/ui) pour les composants UI

Backend

  • Express - API REST
  • PostgreSQL 16 - Base de donnΓ©es
  • Prisma - ORM avec migrations
  • Zod - Validation des donnΓ©es
  • TypeScript - Type safety cΓ΄tΓ© serveur

Infrastructure

  • Docker & Docker Compose - Containerisation
  • Nginx - Serveur web statique et reverse proxy

πŸ“¦ Installation

PrΓ©requis

  • Node.js 24+
  • npm ou yarn
  • Docker & Docker Compose (pour la production)
  • PostgreSQL 16 (pour le dΓ©veloppement local)

Setup Local

  1. Installer les dΓ©pendances
npm install
  1. Configurer la base de donnΓ©es

CrΓ©ez une base PostgreSQL locale :

# Avec psql
createdb metrodb

# Ou via Docker
docker run -d \
  --name metro-postgres \
  -e POSTGRES_USER=metroadmin \
  -e POSTGRES_PASSWORD=metropassword \
  -e POSTGRES_DB=metrodb \
  -p 5432:5432 \
  postgres:16-alpine
  1. Configurer les variables d'environnement

Le fichier .env est dΓ©jΓ  configurΓ© pour le dΓ©veloppement local :

DATABASE_URL="postgresql://metroadmin:metropassword@localhost:5432/metrodb"
PORT=3001
NODE_ENV=development
CORS_ORIGIN=http://localhost:5173
  1. Initialiser Prisma et crΓ©er les tables
npm run prisma:migrate
  1. GΓ©nΓ©rer le Prisma Client
npm run prisma:generate

πŸ”₯ DΓ©veloppement

Lancer le frontend et le backend en parallèle

Terminal 1 - Backend API :

npm run server:dev

Le serveur dΓ©marre sur http://localhost:3001

Terminal 2 - Frontend Vite :

npm run dev

L'application est accessible sur http://localhost:5173

Le proxy Vite redirige automatiquement /api vers le backend.

Visualiser les donnΓ©es avec Prisma Studio

npm run prisma:studio

Ouvre une interface web sur http://localhost:5555 pour explorer la base de donnΓ©es.

🐳 Production (Docker)

Build et lancement

docker-compose up --build

Services dΓ©marrΓ©s :

  • Frontend (Nginx) : http://localhost:3200
  • Backend (Express) : http://localhost:3001
  • PostgreSQL : localhost:5432

Architecture Docker

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         Frontend (Nginx :80)            β”‚
β”‚  Serve static files + reverse proxy     β”‚
β”‚         Port exposΓ©: 3200               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚ Proxy /api β†’ backend
             ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Backend (Express :3001)            β”‚
β”‚   API REST + Prisma Client              β”‚
β”‚         Port exposΓ©: 3001               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚ Connexion DATABASE_URL
             ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    PostgreSQL 16 (:5432)                β”‚
β”‚   Volume persistant: postgres_data      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š API Endpoints

POST /api/survey

Soumet un questionnaire de satisfaction.

Body:

{
  "question1": 4,
  "question2": 5,
  "question3": 3,
  "question4": 4,
  "question5": 5,
  "openFeedback": "Super application !",
  "userProfile": {
    "profession": "etudiant",
    "domicile": "vieux_lyon",
    "travail": "cordeliers",
    "mapType": "schematisee",
    "geometry": "octilineaire",
    "lineColor": "#e60042",
    "colorMode": "custom",
    "modeAffichage": "mobile",
    "basemap": "cartodb-light"
  },
  "mapConfig": {
    "basemap": "cartodb-light",
    "colorMode": "custom",
    "lineColor": "#e60042",
    "geometry": "octilineaire",
    "mapType": "schematisee"
  }
}

Response 201:

{
  "success": true,
  "id": 1,
  "message": "Merci pour votre retour !"
}

GET /api/survey/stats

Récupère les statistiques agrégées des réponses.

Response 200:

{
  "success": true,
  "totalResponses": 42,
  "averageRatings": {
    "question1": 4.2,
    "question2": 4.5,
    "question3": 3.8,
    "question4": 4.1,
    "question5": 4.3
  }
}

GET /health

Health check endpoint.

πŸ—„οΈ SchΓ©ma Prisma

model SurveyResponse {
  id           Int      @id @default(autoincrement())
  createdAt    DateTime @default(now())
  question1    Int      // 1-5
  question2    Int      // 1-5
  question3    Int      // 1-5
  question4    Int      // 1-5
  question5    Int      // 1-5
  openFeedback String   @db.Text
  userProfile  Json
  mapConfig    Json
  
  @@map("survey_responses")
}

πŸ› οΈ Scripts NPM

Script Description
npm run dev DΓ©marre Vite dev server (frontend)
npm run build Build production du frontend
npm run server:dev DΓ©marre le serveur Express en mode dev
npm run server:build Compile le backend TypeScript
npm run server:start Lance le serveur compilΓ©
npm run prisma:generate Génère le Prisma Client
npm run prisma:migrate CrΓ©e une nouvelle migration
npm run prisma:migrate:deploy Applique les migrations en production
npm run prisma:studio Ouvre Prisma Studio

πŸ“ Structure du Projet

my-metro-app/
β”œβ”€β”€ server/                 # Backend Express
β”‚   β”œβ”€β”€ index.ts           # Point d'entrΓ©e serveur
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── survey.ts      # Routes API questionnaire
β”‚   β”œβ”€β”€ types.ts           # Types TypeScript backend
β”‚   └── prisma/
β”‚       └── schema.prisma  # SchΓ©ma base de donnΓ©es
β”œβ”€β”€ src/                   # Frontend React
β”‚   β”œβ”€β”€ components/        # Composants React
β”‚   β”‚   β”œβ”€β”€ Header.tsx     # Formulaire questionnaire
β”‚   β”‚   β”œβ”€β”€ RatingSlider.tsx
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ data/             # DonnΓ©es JSON des rΓ©seaux
β”‚   β”œβ”€β”€ types.ts          # Types TypeScript frontend
β”‚   └── App.tsx
β”œβ”€β”€ Dockerfile            # Build frontend (Nginx)
β”œβ”€β”€ Dockerfile.backend    # Build backend (Node)
β”œβ”€β”€ docker-compose.yml    # Orchestration services
β”œβ”€β”€ nginx.conf            # Config reverse proxy
β”œβ”€β”€ vite.config.ts        # Config Vite avec proxy
β”œβ”€β”€ tsconfig.server.json  # Config TypeScript backend
└── package.json

πŸ”’ Variables d'Environnement

Backend (.env)

DATABASE_URL=postgresql://user:password@host:port/db
PORT=3001
NODE_ENV=development|production
CORS_ORIGIN=http://localhost:5173

Frontend (.env.development)

VITE_API_URL=/api

🚧 Migrations Prisma

CrΓ©er une nouvelle migration

npm run prisma:migrate
# Nom suggΓ©rΓ©: add_new_field, rename_table, etc.

Réinitialiser la base (⚠️ perte de données)

npx prisma migrate reset --schema=./server/prisma/schema.prisma

πŸ“ˆ Monitoring & Debug

  • Logs backend : AffichΓ©s dans le terminal npm run server:dev
  • Logs Docker : docker-compose logs -f backend
  • Connexion PostgreSQL :
    docker exec -it metro-postgres psql -U metroadmin -d metrodb
  • Inspect tables :
    SELECT * FROM survey_responses ORDER BY "createdAt" DESC LIMIT 10;

πŸ§ͺ Tests

Γ€ implΓ©menter : tests unitaires avec Vitest, tests d'intΓ©gration avec Playwright

πŸ“„ Licence

Projet acadΓ©mique - Tous droits rΓ©servΓ©s

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors