How quentinregnier/nubo-backend works
Project Type & Purpose
• This is a backend microservice written in Go (Golang) that exposes both a REST API and a WebSocket interface.
• It uses Docker Compose to orchestrate four core services: the Go API, Redis, PostgreSQL, and MongoDB.
• Purpose: serve as the server-side for a social-media-style application (“nubo-backend”) supporting authentication, posts, messaging, real-time events, and caching layers.
File Structure Analysis
Top-level artifacts:
• Dockerfile / docker-compose.yml / .env → containerized environment setup
• cmd/main.go → entry point wiring Gin REST handlers, WebSocket hub, DB & cache initialization
• internal/ → Go code split by concern
– internal/api → REST route definitions and middleware (routes.go, middleware.go)
– internal/websocket → WebSocket handler + hub for broadcast (handler.go, hub.go)
– internal/cache → Redis client init + caching strategy (redis.go, redis_caches.go, redis_strategy.go)
– internal/db → MongoDB and PostgreSQL connectors/managers (mongo.go, postgres.go, mongo_manage.go)
– internal/initdata → startup jobs to clean Redis & Mongo (“init.go”)
– internal/tools → shared utilities (collections, parsing)
• sql/ → raw SQL scripts (functions, procedures, tables, views) for PostgreSQL schema
• mongo-data/ & postgres-data-broken/ → local data volumes persisted by Docker
README Insights
• Confirms architecture: Go + Gin for REST, Gorilla WebSocket, Redis for cache & pub/sub, PostgreSQL for “truth,” MongoDB for 30-day ephemeral store.
• Stepwise dev plan: REST → WebSocket → DB connections → JWT auth → deploy.
• Detailed Docker Compose service definitions.
• Future architectural phases: scaling WebSocket via Redis pub/sub, token protection, data cleaning, multi-instance.
1. Clients (mobile & web)
2. API Server (Go/Gin)
3. WebSocket Hub (Gorilla/WebSocket + Redis Pub/Sub)
4. Redis (cache, session store, pub/sub channel)
5. PostgreSQL (relational permanent storage)
6. MongoDB (document store for recent data, TTL)
7. Docker Compose network (overlay of containers)
• HTTP clients →→ Gin REST handlers →→ Postgres/Mongo/Redis
• WebSocket clients ↔ HTTP upgrader → WebSocket handler → Hub
• Hub broadcasts → publishes to Redis Pub/Sub → other hub instances or same instance → WebSocket clients
• Business logic layer within Go orchestrates multi-store writes: Redis → Mongo → PostgreSQL
c. Architectural Patterns & Principles:
• Layered architecture (API, service, data layers)
• CQRS-style read-path: Redis cache → Mongo (recent) → PostgreSQL (history)
• Pub/Sub for real-time scaling via Redis channel
• Module separation: each concern in its own Go package under internal/
• Startup hooks: initdata for one-time cleaning tasks
d. Key Technologies / Frameworks:
• Go + Gin (REST), Gorilla WebSocket (real-time)
• Redis v8 client (cache, pub/sub), custom LRU cache strategy
• go.mongodb.org/mongo-driver (MongoDB TTL collections)
• jackc/pgx (PostgreSQL connection) + SQL scripts (functions, procedures, tables, views)
• Docker + Docker Compose for environment orchestration