How kone-net/go-chat works
Project Type and Purpose
• This is a full-stack chat application designed for real-time communication. The backend (written in Go) manages WebSocket connections, HTTP REST API endpoints, database operations (with MySQL via GORM), and distributed messaging via Kafka. The frontend (in a separate repository) is built with React, Redux, and AntDesign.
• Key features include traditional chat (text, images, files), multimedia (voice/video/screen sharing), user management (login, registration, profile update), and distributed deployment.
File Structure to Extract Architectural Components
• Top-level directories and files indicate a clear separation between various architectural layers:
• "api" directory: Contains controller code (HTTP endpoints) for operations like managing users, groups, files, and messages.
• "cmd" directory: Contains the main entry point (main.go) that initializes the service.
• "internal" directory:
• dao – for data access using MySQL.
• model – defining database models for users, groups, messages, etc.
• router – binding Gin routes to controller and WebSocket handlers.
• server – implements the WebSocket server logic with client registration, message broadcasting, and disconnection handling.
• service – contains business logic for users, groups, and messages.
• kafka – for Kafka producer/consumer handling global message distribution.
• "pkg" directory: Houses common utilities (constants, error handling, logging with zap, protocol buffer messages, etc.), which are used across the project.
• "deployments" shows Docker files and docker-compose for containerized and distributed deployment.
• "web" holds static assets (which are also used by the frontend or for file upload operations).
Extract Additional Insights from the README
• The README details both back-end and front-end technology stacks. It describes WebSocket usage for persistent connections, integration of protocol buffers to serialize/deserialize message contents (allowing both text and binary data transfers), and the use of Kafka for distributed messaging.
• It also explains how WebSocket connections are handled (client registration, reading, and writing) and provides sample code from both Go and JavaScript.
• Deployment and build instructions (via Makefile, Docker, docker-compose) emphasize separation of concerns and modularity.
Mapping Out Major Components
a. Back-End Application:
• API Layer: Represent the HTTP controllers (in “api/v1”) that offer endpoints for login, file uploads, friend management, etc.
• WebSocket Server: Show a component responsible for handling WebSocket connections (from “internal/server”, “internal/router/socket.go”). Note how incoming connections are registered and managed.
• Business Logic/Services: Represent “internal/service” components (group_service, user_service, message_service) which process chat logic.
• Data Access Layer: Include “internal/dao” and “internal/model” for MySQL interactions.
• Messaging/Distributed Queue: Show a Kafka component (using “internal/kafka”) that publishes and consumes messages; underline its role in scaling and distributed deployment.
b. Database:
c. File Storage:
• “web/static” folder used for storing uploaded files, screenshots, assets, etc.
d. Front-End Application:
• Even though it is maintained in a separate repository (go-chat-web), include a block for the React application that interacts with the backend over WebSocket and RESTful APIs. Mention its usage of Redux, AntDesign, and protocol buffers.
e. External Services and Deployment:
• Docker & Nginx: Include these as infrastructural components used for containerizing the application, reverse proxying (via deployments/docker/nginx.conf), and load balancing.
• Mention that the system supports distributed deployment where Kafka enables message broadcasting across multiple instances.