Initial commit

This commit is contained in:
jpgiannetti
2026-01-31 11:45:11 +01:00
commit f99fb3c614
166 changed files with 115155 additions and 0 deletions

44
backend/.air.toml Normal file
View File

@@ -0,0 +1,44 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ./cmd/api"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata", "docs", "migrations", "features", "docker", "scripts"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
main_only = false
time = false
[misc]
clean_on_exit = false
[screen]
clear_on_rebuild = false
keep_scroll = true

51
backend/.env.example Normal file
View File

@@ -0,0 +1,51 @@
# Server
SERVER_PORT=8080
SERVER_ENV=development
# Database
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=roadwave_dev
DATABASE_USER=roadwave
DATABASE_PASSWORD=dev_password
DATABASE_SSL_MODE=disable
DATABASE_MAX_CONNECTIONS=25
DATABASE_MAX_IDLE_CONNECTIONS=5
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0
# Zitadel
ZITADEL_DOMAIN=localhost:8081
ZITADEL_PROJECT_ID=your_project_id
ZITADEL_CLIENT_ID=your_client_id
ZITADEL_CLIENT_SECRET=your_client_secret
ZITADEL_ISSUER=http://localhost:8081
# JWT
JWT_SECRET=your_super_secret_key_change_me
# OVH Object Storage (S3-compatible)
OVH_S3_ENDPOINT=s3.gra.io.cloud.ovh.net
OVH_S3_REGION=gra
OVH_S3_ACCESS_KEY=your_ovh_access_key
OVH_S3_SECRET_KEY=your_ovh_secret_key
OVH_S3_BUCKET=roadwave-dev
# Mangopay
MANGOPAY_CLIENT_ID=your_mangopay_client_id
MANGOPAY_API_KEY=your_mangopay_api_key
MANGOPAY_BASE_URL=https://api.sandbox.mangopay.com
# Logging
LOG_LEVEL=debug
LOG_FORMAT=console
# CORS
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:8080
# Rate Limiting
RATE_LIMIT_REQUESTS_PER_MINUTE=60

33
backend/Dockerfile Normal file
View File

@@ -0,0 +1,33 @@
# Builder stage
FROM golang:1.23-alpine AS builder
RUN apk add --no-cache git ca-certificates
WORKDIR /app
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -o /bin/api ./cmd/api
# Final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates ffmpeg
WORKDIR /root/
# Copy binary from builder
COPY --from=builder /bin/api .
# Copy config files
COPY config/ ./config/
EXPOSE 8080
CMD ["./api"]

25
backend/Dockerfile.dev Normal file
View File

@@ -0,0 +1,25 @@
FROM golang:1.23-alpine
RUN apk add --no-cache git ca-certificates make
# Install Air for hot reload
RUN go install github.com/cosmtrek/air@latest
# Install sqlc
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
# Install migrate
RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
WORKDIR /app
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
EXPOSE 8080
CMD ["air", "-c", ".air.toml"]

77
backend/README.md Normal file
View File

@@ -0,0 +1,77 @@
# Backend - RoadWave
Backend Go de l'application RoadWave.
## Structure
```
backend/
├── cmd/ # Points d'entrée de l'application
│ └── api/ # Serveur API REST
├── internal/ # Code interne (non exportable)
│ ├── auth/ # Validation JWT, intégration Zitadel
│ ├── user/ # Profils, centres d'intérêt
│ ├── content/ # CRUD contenus, métadonnées
│ ├── geo/ # Recherche géospatiale, algorithme
│ ├── streaming/ # Génération HLS, transcoding
│ ├── moderation/ # Signalements, workflow
│ ├── payment/ # Intégration Mangopay
│ └── analytics/ # Métriques écoute, jauges
├── pkg/ # Code exportable (bibliothèques réutilisables)
├── migrations/ # Migrations SQL
├── tests/
│ └── bdd/ # Step definitions pour tests Gherkin
├── config/ # Fichiers de configuration (dev, staging, prod)
├── go.mod # Dépendances Go
├── sqlc.yaml # Configuration SQLC
├── .air.toml # Configuration Air (hot reload)
├── Dockerfile # Image production
└── Dockerfile.dev # Image développement
```
## Architecture
Voir [ADR-012 : Architecture Backend](../docs/adr/012-architecture-backend.md) pour les détails de l'architecture modulaire.
## Commandes
Depuis la **racine du monorepo** :
```bash
# Développement
make dev # Démarrer avec hot reload
make docker-up # Lancer tous les services Docker
# Tests
make test # Lancer tous les tests
make test-unit # Tests unitaires uniquement
make test-bdd # Tests BDD Gherkin
# Migrations
make migrate-up # Appliquer les migrations
make migrate-down # Rollback dernière migration
make migrate-create name=add_users # Créer nouvelle migration
# Build
make build # Compiler le binaire production
make lint # Linter le code
make format # Formatter le code
```
## Configuration
1. Copier `.env.example` en `.env` :
```bash
cp backend/.env.example backend/.env
```
2. Ajuster les variables d'environnement si nécessaire
## Dépendances
- **Go** : 1.21+
- **PostgreSQL** : 16+ avec PostGIS
- **Redis** : 7+
- **Zitadel** : dernière version
Toutes les dépendances sont gérées via Docker Compose (voir `docker-compose.yml` à la racine).

77
backend/config/dev.yaml Normal file
View File

@@ -0,0 +1,77 @@
server:
port: 8080
env: development
read_timeout: 10s
write_timeout: 10s
database:
host: localhost
port: 5432
name: roadwave_dev
user: roadwave
password: dev_password
ssl_mode: disable
max_connections: 25
max_idle_connections: 5
max_lifetime: 5m
redis:
host: localhost
port: 6379
password: ""
db: 0
pool_size: 10
min_idle_connections: 3
max_retries: 3
zitadel:
domain: localhost:8081
project_id: ${ZITADEL_PROJECT_ID}
client_id: ${ZITADEL_CLIENT_ID}
client_secret: ${ZITADEL_CLIENT_SECRET}
issuer: http://localhost:8081
jwt:
secret: ${JWT_SECRET}
expiration: 24h
ovh_s3:
endpoint: ${OVH_S3_ENDPOINT}
region: ${OVH_S3_REGION}
access_key: ${OVH_S3_ACCESS_KEY}
secret_key: ${OVH_S3_SECRET_KEY}
bucket: ${OVH_S3_BUCKET}
mangopay:
client_id: ${MANGOPAY_CLIENT_ID}
api_key: ${MANGOPAY_API_KEY}
base_url: https://api.sandbox.mangopay.com
logging:
level: debug
format: console
cors:
allowed_origins:
- http://localhost:3000
- http://localhost:8080
allowed_methods:
- GET
- POST
- PUT
- DELETE
- OPTIONS
allowed_headers:
- Origin
- Content-Type
- Authorization
max_age: 3600
rate_limit:
requests_per_minute: 60
burst: 10
geo:
default_radius_km: 50
max_radius_km: 500
cache_ttl: 5m

77
backend/config/prod.yaml Normal file
View File

@@ -0,0 +1,77 @@
server:
port: 8080
env: production
read_timeout: 20s
write_timeout: 20s
database:
host: ${DATABASE_HOST}
port: ${DATABASE_PORT}
name: ${DATABASE_NAME}
user: ${DATABASE_USER}
password: ${DATABASE_PASSWORD}
ssl_mode: require
max_connections: 100
max_idle_connections: 25
max_lifetime: 15m
redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}
password: ${REDIS_PASSWORD}
db: 0
pool_size: 50
min_idle_connections: 10
max_retries: 3
zitadel:
domain: ${ZITADEL_DOMAIN}
project_id: ${ZITADEL_PROJECT_ID}
client_id: ${ZITADEL_CLIENT_ID}
client_secret: ${ZITADEL_CLIENT_SECRET}
issuer: https://${ZITADEL_DOMAIN}
jwt:
secret: ${JWT_SECRET}
expiration: 24h
ovh_s3:
endpoint: ${OVH_S3_ENDPOINT}
region: ${OVH_S3_REGION}
access_key: ${OVH_S3_ACCESS_KEY}
secret_key: ${OVH_S3_SECRET_KEY}
bucket: ${OVH_S3_BUCKET}
mangopay:
client_id: ${MANGOPAY_CLIENT_ID}
api_key: ${MANGOPAY_API_KEY}
base_url: https://api.mangopay.com
logging:
level: warn
format: json
cors:
allowed_origins:
- https://roadwave.com
- https://www.roadwave.com
allowed_methods:
- GET
- POST
- PUT
- DELETE
- OPTIONS
allowed_headers:
- Origin
- Content-Type
- Authorization
max_age: 3600
rate_limit:
requests_per_minute: 200
burst: 50
geo:
default_radius_km: 50
max_radius_km: 500
cache_ttl: 5m

View File

@@ -0,0 +1,76 @@
server:
port: 8080
env: staging
read_timeout: 15s
write_timeout: 15s
database:
host: ${DATABASE_HOST}
port: ${DATABASE_PORT}
name: ${DATABASE_NAME}
user: ${DATABASE_USER}
password: ${DATABASE_PASSWORD}
ssl_mode: require
max_connections: 50
max_idle_connections: 10
max_lifetime: 10m
redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}
password: ${REDIS_PASSWORD}
db: 0
pool_size: 20
min_idle_connections: 5
max_retries: 3
zitadel:
domain: ${ZITADEL_DOMAIN}
project_id: ${ZITADEL_PROJECT_ID}
client_id: ${ZITADEL_CLIENT_ID}
client_secret: ${ZITADEL_CLIENT_SECRET}
issuer: https://${ZITADEL_DOMAIN}
jwt:
secret: ${JWT_SECRET}
expiration: 24h
ovh_s3:
endpoint: ${OVH_S3_ENDPOINT}
region: ${OVH_S3_REGION}
access_key: ${OVH_S3_ACCESS_KEY}
secret_key: ${OVH_S3_SECRET_KEY}
bucket: ${OVH_S3_BUCKET}
mangopay:
client_id: ${MANGOPAY_CLIENT_ID}
api_key: ${MANGOPAY_API_KEY}
base_url: https://api.sandbox.mangopay.com
logging:
level: info
format: json
cors:
allowed_origins:
- https://staging.roadwave.com
allowed_methods:
- GET
- POST
- PUT
- DELETE
- OPTIONS
allowed_headers:
- Origin
- Content-Type
- Authorization
max_age: 3600
rate_limit:
requests_per_minute: 100
burst: 20
geo:
default_radius_km: 50
max_radius_km: 500
cache_ttl: 5m

20
backend/go.mod Normal file
View File

@@ -0,0 +1,20 @@
module github.com/roadwave/roadwave
go 1.23
require (
github.com/gofiber/fiber/v2 v2.52.0
github.com/redis/go-redis/v9 v9.4.0
github.com/rs/zerolog v1.31.0
github.com/spf13/viper v1.18.2
github.com/joho/godotenv v1.5.1
github.com/go-playground/validator/v10 v10.19.0
github.com/golang-migrate/migrate/v4 v4.17.0
github.com/stretchr/testify v1.8.4
github.com/cucumber/godog v0.14.0
github.com/testcontainers/testcontainers-go v0.28.0
github.com/go-resty/resty/v2 v2.11.0
go.opentelemetry.io/otel v1.22.0
go.opentelemetry.io/otel/trace v1.22.0
github.com/prometheus/client_golang v1.18.0
)

22
backend/sqlc.yaml Normal file
View File

@@ -0,0 +1,22 @@
version: "2"
sql:
- engine: "postgresql"
queries: "internal/database/queries"
schema: "migrations"
gen:
go:
package: "sqlc"
out: "internal/database/sqlc"
sql_package: "pgx/v5"
emit_json_tags: true
emit_prepared_queries: false
emit_interface: true
emit_exact_table_names: false
emit_empty_slices: true
overrides:
- db_type: "pg_catalog.uuid"
go_type: "github.com/google/uuid.UUID"
- db_type: "geography"
go_type: "string"
- db_type: "geometry"
go_type: "string"

View File