How carlinhosarena/ticketz works
Project Type and Purpose
• Ticketz is a full-stack, containerized CRM/helpdesk application using WhatsApp as its messaging channel.
• The backend is a Node.js/TypeScript monolith (Express + Sequelize + Redis + WebSockets + Baileys), and the frontend is a React SPA served via Nginx.
• Persistence is handled by PostgreSQL; caching and real-time pub/sub by Redis; Docker Compose orchestrates services.
File Structure
• Top-level directories “frontend” and “backend” signal separation of concerns.
• “confs” and multiple docker-compose-*.yaml files define deployment modes (local, ACME SSL, Cloudflare).
• Backend follows an MVC-style layout: controllers, services, models, middleware, routes, helpers, and DB migrations/seeds.
• Frontend is a React app with contexts, hooks, components, layout, pages, and asset/public folders.
• Key config files: .env-*-local|acme|cloudflare, Nginx configs under frontend/nginx, Dockerfiles.
Main Components to Render
A. Client Layer
– Web browser (User)
– React SPA served by Nginx (Container: frontend)
B. Edge / Reverse Proxy
– Nginx handles TLS termination (Let’s Encrypt via ACME) and serves static SPA
C. API Layer (Container: backend)
– Express HTTP server
– REST controllers (tickets, contacts, messages, sessions, etc.)
– WebSocket endpoint (socket.io or similar in backend/src/libs/socket.ts)
D. Business Logic Layer
– Service classes implementing domain use-cases (Auth, TicketService, WbotServices)
– Middleware for auth, rate-limiting, compliance checks
E. Data Layer
– PostgreSQL service (Container)
– Sequelize ORM models & migrations/seeds
F. Caching & Pub/Sub
– Redis service (Container) for caching, session store, Pub/Sub to push real-time events
G. External Integrations
– WhatsApp “bridge” using Baileys library (handles sessions under backend/src/services/WbotServices)
– Payment gateways (Efi, Owen) invoked by PaymentGatewayServices
H. DevOps / Deployment
– Docker Compose orchestrates containers
– Nginx configs, ACME cert provisioning, environment variable files
– GitHub workflows build Docker images
Relationships & Data Flows
• User → HTTPS → Nginx → React SPA
• React SPA → REST API → Express controllers → Services → Models → PostgreSQL
• Express uses Redis for session/auth token management and publishes real-time events → Redis Pub/Sub → WebSocket server → React (SocketContext)
• Express invokes Baileys services → WhatsApp Web sessions → WhatsApp cloud network
• Payment flows: React SPA → API → PaymentGatewayServices → External payment provider
• Docker Compose network connects all containers
Architectural Patterns & Principles
• Monolithic container with layered “Controllers → Services → Models” pattern
• Containerized 12-factor app: config via environment, stateless services, logs to stdout, services bound via network
• Event-driven real-time updates via Redis Pub/Sub + WebSockets
• Clear separation between static file serving (Nginx + React) and dynamic API
• Infrastructure as code via Docker Compose, Nginx confs, env files