Welcome to the GRPC CLI Chat Backend! This monorepo houses a powerful chat application comprised of three main services: auth, chat, and a cli client. With a robust authentication system using access and refresh tokens, and independent databases for each service, this project is built to scale and impress. Let's dive into the details! π
- Monorepo Architecture: Three cohesive applications in one repository.
auth: Handles user authentication and authorization.chat: Manages chat messages and chat rooms.cli: Command-line interface for interacting with the chat service.
- Secure Authentication: Utilizes access and refresh tokens for secure communication.
- Database Independence:
- PostgreSQL for the authentication service.
- MongoDB for the chat service.
- Local file for Token Management: Stores user tokens securely.
- Comprehensive Makefile: Simplifies setup, testing, and deployment.
Ensure you have the following installed on your system:
- Docker & Docker Compose
- Go (1.22.4)
- Make
- Clone the Repository
git clone https://github.com/javascriptizer1/grpc-cli-chat.mono.git
cd grpc-cli-chat.mono- Environment Configuration
cp .env.example .env- Start Services with Docker Compose
docker-compose up -d- Download proto dependencies
make vendor-proto- Install other cli dependencies
make install-depsOur CLI client now supports various commands to interact with the backend services seamlessly using Cobra and Bubbletea. Here are a few:
- Auth Service Commands
gchat register: Register a new user.gchat login: Login with existing credentials.gchat list-user: List all users.
- Chat Service Commands
gchat create-chat: Create a chat with the specified users.gchat list-chat: List all user chats.gchat connect-chat: Connect to a specific chat by chat ID.
Example commands:
- Register a New User
go run main.go register --name "John Doe" --email "john@example.com" --password "password" --password-confirm "password"- Login
go run main.go login --login "john@example.com" --password "password"- List of Users
go run main.go list-user- Create a Chat
go run main.go create-chat --user-ids="<uuid>"- List of Chats
go run main.go list-chat- Connect to a Chat
go run main.go connect-chat --chat-id "chat123"The interaction with our application is now fully integrated with Bubbletea, providing a rich, interactive terminal user interface (TUI). This change enhances user experience and allows for more dynamic and responsive interactions.
-
Login
The login allows users to enter their credentials and access the chat service.
-
Registration
The registration enables users to create a new account by providing their name, email, and password.
-
Create Chat
The create chat allows users to initiate a new chat room by selecting participants and starting conversations.
-
Chat List Screen
The chat list shows a list of chat rooms the user is part of and allows seamless navigation between them.
-
Chat Interaction
The chat interaction provides a real-time chat interface where users can send and receive messages.
Our project is organized as a monorepository containing three main applications:
- Database: PostgreSQL
- Functionality: manages user registration, login, and authentication using access and refresh tokens
- Database: MongoDB
- Functionality: handles chat functionalities, including connecting to a chat and sending messages
- Framework: Cobra and Bubbletea
- Functionality: a command-line interface that allows users to interact with the Auth and Chat services using a rich TUI
-
Access and Refresh Tokens: Secure authentication with token-based access control.
-
PostgreSQL and MongoDB: Two separate databases for different services to ensure scalability and maintainability.
-
Service Provider Pattern: A clean and modular approach to managing dependencies and service interactions.
-
Interceptors: Automatically handle token refresh to ensure seamless user experience.
- Generate Go from Proto
make generate-api- Up migrations
make migrations-up- Generate migration
name=migration_name make migrations-generate- Lint the Code
make lint- Build the Project
make buildThe application is deployed in a Kubernetes cluster, ensuring high availability, scalability, and efficient resource management. The deployment process is automated using GitHub Actions.
In addition to Kubernetes, the application can also be deployed on a Virtual Private Server (VPS). This flexibility allows you to choose the deployment target that best fits your infrastructure and scaling needs. The deployment process, whether to Kubernetes or a VPS, is managed through GitHub Actions workflows.
I use GitHub Actions for continuous integration and deployment. The workflow includes:
- Linting: Code is checked using
golangci-lint. - Building Docker Images: Docker images are built for each service.
- Pushing Docker Images: The built images are pushed to Docker Hub.
- Deploying to Kubernetes: The images are deployed to a Kubernetes cluster using Helm charts.
- Deploying to VPS: The application is built, environment variables are configured, and binaries are transferred and set up on the VPS.
Deployment setup exemplifies modern DevOps practices by:
- Automated CI/CD: Minimizing manual intervention and reducing the risk of errors.
- Environment Configurations: Supporting multiple environments (development, production) with ease.
- Scalability and Reliability: Leveraging Kubernetes for managing and scaling microservices effectively.
- Flexibility: Offering deployment options to both Kubernetes and VPS, catering to different infrastructure needs.
- Security: Storing sensitive information like Docker Hub credentials, Kubernetes config, and VPS SSH keys securely in GitHub Secrets.
Ensure that the following environment variables are set in your GitHub repository secrets:
DOCKER_HUB_USERNAME: Your Docker Hub username.DOCKER_HUB_PASSWORD: Your Docker Hub password.KUBE_CONFIG: Your Kubernetes configuration file content.NAMESPACE: Your Kubernetes namespace.VPS_SSH_KEY: Your VPS SSH private key.VPS_USER: Your VPS user.VPS_HOST: Your VPS host address.
I hope you enjoy using the CLI Chat as much as we enjoyed building it. If you find it useful, give us a β on GitHub!
Happy chatting! ππ




