How mohanavel15/chatapp works
Project Type and Purpose
• This is a full-stack chat application (PWA) with both real-time (WebSocket) and request/response (REST) interactions.
• Features: user authentication, channels, messages, relationships (friends), file uploads, email notifications, push notifications (future).
File Structure
• Top-level GO files (gateway.go, main.go, middleware.go) bootstrap and wire together the services.
• server/ directory contains:
• config (environment)
• database (MongoDB models & access)
• mail (SMTP integration)
• request/response DTOs
• restapi (HTTP endpoints)
• websocket (real-time event handling)
• utils (authentication, helpers)
• web/ directory contains the React/PWA frontend built with Vite, Tailwind, TypeScript.
• Docker and docker-compose files orchestrate MongoDB, the Go server, and the static frontend.
README
• Confirms use of MongoDB, JWT auth, SMTP mail server.
• Describes build steps and environment variables.
Main Components & Their Interactions
a. Frontend (PWA)
• Hosted as static assets (index.html + JS/CSS) served by the Go server or CDN.
• React app uses HTTP REST for CRUD operations (login, fetch channels, messages, relationships).
• Opens a WebSocket for real-time message delivery and events (user online/offline, new messages).
b. API Gateway / HTTP Server
• gateway.go + middleware.go route incoming HTTP + WS connections to handlers.
• RestAPI handlers under server/restapi/ (auth, channels, messages, invites, pins, files).
• WebSocket handlers under server/websocket/ (connect/disconnect, event dispatch).
• Authentication middleware verifies JWTs on HTTP and WS.
c. Database Layer
• MongoDB (configured via MONGO_URI, MONGO_DATABASE).
• Collections for users, channels, messages, relationships, etc.
• Access layer in server/database/.
d. Mail Service
• SMTP integration to send verification, password reset, invites.
e. External Services
• SMTP server
• (Future) Push Notification service
Relationships & Data Flows
• Frontend → HTTP REST → API Gateway → Business logic → Database
• Frontend → WebSocket → Gateway → Event handlers → Database & back → Frontend
• Backend → SMTP → Mail Server
• Backend → MongoDB → Storage
Architectural Patterns & Design Principles
• Layered architecture:
• API layer (REST + WebSocket)
• Service/handler layer (business logic)
• Repository layer (database access)
• Separation of concerns: config, models, requests, responses isolated.
• JWT-based stateless authentication.
• Event-driven real-time updates via WebSocket channel.
Technologies & Frameworks to Call Out
• Go (Gin‐style router or net/http)
• MongoDB driver
• React + TypeScript + Vite + TailwindCSS
• WebSocket (native Go)
• Docker & Docker-Compose
• SMTP (net/smtp or third-party)