How valma-julius/mesa_p2p works
Project Type and Purpose
– Mesa is a full-stack, peer-to-peer messaging application oriented toward complete user privacy.
– It consists of:
• A static front-end client (served by Nginx)
• A Ruby on Rails API & ActionCable server (“mesa”)
• A custom PeerJS signaling/forwarding server
• Supporting services: PostgreSQL database, a job queue (Redis), SSL termination
Main Components
a. Nginx Reverse Proxy (layer 7 gateway)
– Listens on ports 80/443, serves static assets, terminates TLS, and proxies requests.
b. Static Front-end Client
– Files under src/mesa_client/frontend (HTML/CSS/JS pages).
– Fetches REST API under /api/*.
– Connects to WebSocket channels for signaling.
– Uses PeerJS client library for P2P connectivity.
c. Rails Backend (“mesa”)
– REST API controllers (users, conversations, p2p_controller).
– ActionCable channels (p2p_chat_channel, signaling_channel, background_jobs_channel).
– Domain layer (service objects under app/domain/* for conversations and P2P logic).
– ActiveRecord models & migrations (users, conversations, messages, p2p_paths, p2p_transactions, jwt_denylist).
– Background jobs (app/jobs) for asynchronous tasks.
d. PeerJS Signaling/Forwarder Server
– Dockerfile + peerjs-config.json in src/backend/mesa.
– Listens on port 9000, handles WebRTC signaling and ICE candidate exchange.
e. Supporting Services
– PostgreSQL (data persistence).
– Redis (ActionCable pub/sub and job queue adapter).
– Docker Compose orchestrates Rails, DB, Redis, and PeerJS.
Relationships & Data Flows
– HTTP(S) traffic
• Browser → Nginx → Static files (front-end)
• Browser → Nginx → Rails API (/api/*) → PostgreSQL
– WebSocket traffic (ActionCable)
• Browser WebSocket → Nginx → Rails (p2p_chat & signaling channels) → Redis as pub/sub
– PeerJS traffic
• Browser PeerJS client → Nginx → PeerJS server (/forwards)
• PeerJS server coordinates ICE candidates and P2P paths
– Background Jobs
• Rails enqueues jobs → Redis → Worker threads process P2P notifications and forwarding
Architectural Patterns & Principles
– Layered architecture: Presentation (static client), API layer, domain/service layer, persistence layer.
– Service objects (app/domain) encapsulate business rules for P2P path finding, conversation management.
– Event-driven messaging: ActionCable channels and background jobs form asynchronous pipelines.
– Separation of concerns: Web server (Nginx) vs. application server (Rails) vs. signaling server (PeerJS).
– Security: JWT-based authentication, SSL termination, CORS policy, JWT deny list.