How youngyangyang04/kamachat works
The KamaChat project is a full-stack instant messaging application—a chatroom system similar to WeChat. The backend is implemented in Go (with Gin, GORM, WebSocket, Kafka, Redis, and more) while the frontend is built using Vue3 (with Vue Router, Vuex, Element-UI, etc.). The system supports features such as one-on-one and group chats, contacts management, offline messages, audio/video calling (with WebRTC and TURN servers), and backend administrative functions.
Main Components
• Backend Server:
• API Layer: The “api/v1” folder contains various controllers (chatroom, session, message, group info, user info, etc.) that handle HTTP requests and serve as entry points for client communication.
• Business Logic & Service Layer: The “internal/service” package encapsulates logic for chat operations (including Kafka integration for messaging), GORM-based DB operations, Redis caching, SMS authentication, and AES encryption.
• Data Access Layer: Under “internal/dao” and “internal/model”, you have the database-related code that uses GORM to interface with a MySQL backend.
• Configuration Management: Located in the “internal/config” directory, which processes TOML config files found under “configs/”.
• HTTPS & TLS Support: See “internal/https_server” and the “pkg/ssl” that handle secure communications.
• Logging: Integration of Zap logs is used to record system events (found in “pkg/zlog”).
• Frontend Application:
• This is housed within the “web/chat-server” directory and includes Vue components, asset files (CSS, images, JavaScript), routing (Vue Router), and state management (Vuex).
• The frontend interacts with the backend primarily over HTTP/HTTPS and WebSocket channels (for real-time messaging).
• Supporting Infrastructure:
• Database: MySQL, with persistence and connection setup through GORM.
• Cache: Redis is used for fast data retrieval and user session management.
• Message Queue: Kafka handles efficient message distribution between services.
• SMS Service: For secure login and registration, SMS validation services are present.
• TURN/WebRTC: For facilitating reliable, NAT-traversal audio/video communication.
• Web/SSL Servers: The deployment scripts outline configuring Apache, SSL certificates, and TURN server for secure, external communications.
Defining the Relationships and Interactions
• The Frontend uses HTTP/HTTPS to interact with the Backend’s API endpoints and WebSocket connections for real-time message push notifications.
• The Backend communicates with the MySQL database (using GORM) for persistent storage of user information, messages, and chat records.
• Redis is integrated for caching sessions, offline message states, and to improve response times.
• Kafka acts as a message queue, handling message routing between chat services and ensuring reliability.
• External services such as SMS providers (via Alibaba Cloud) support user registration and verification.
• The TURN server is used for audio/video sessions, configured with SSL/TLS to secure media traffic.
• Logs, configuration, and certificate management are maintained separately in dedicated packages/ files for clarity.
Highlighting Architectural Patterns and Design Principles
• Modular design: Separation of concerns is achieved through distinct folders for controllers (API layer), models (data structures), daos (data access), and services (business logic).
• Full-stack separation: Clear division between frontend (Vue based) and backend (Go based on Gin).
• Service-Oriented Architecture: Independent modules for message handling, database operations, caching, authentication, and media (WebRTC) communication ensure scalability and maintainability.
• Secure Communication: Emphasis on HTTPS, SSL certificate management, and secure WebSocket communications.
• Configuration Driven: External config files (in TOML) drive deployment, making the system adapt to different environments easily.
Final Recommendations to the Principal Software Engineer
• Stay detailed but organized—with components clearly separated according to the project's layered architecture.