cli-chatapplication
v1.0.2
Published
A real-time CLI Chat Application built with TypeScript and Firebase Realtime Database.
Maintainers
Readme
💬 CLI Chat Application
A real-time command-line chat application built with TypeScript, Node.js, and Firebase Realtime Database.
This project allows multiple users to communicate through a terminal using a shared group chat or private direct messages. It demonstrates real-time communication, user authentication, online presence tracking, and terminal-based interaction without relying on any graphical interface.
✨ Features
🔐 Simple User Authentication
- Login using User ID and Password
- Credentials stored in Firebase Realtime Database
🌐 Real-Time Group Chat
- Multiple users can communicate simultaneously
- Messages are delivered instantly using Firebase listeners
💬 Direct Messaging
- One-to-one conversations between registered users
- Dedicated conversation channel for every pair of users
🟢 Online / Offline Presence
- Users automatically become online after login
- Status changes back to offline when the application exits
⚡ Real-Time Synchronization
- Uses Firebase Realtime Database
- No polling or manual refresh required
💻 Terminal Based Interface
- Lightweight CLI experience
- Built using Node.js readline module
📦 Installation
Install Globally
npm install -g cli-chatapplicationor run it directly without installing
npx cli-chatapplicationVerify Installation
cli-chatIf installed correctly, you'll see:
CLI Chat Application
Enter User ID:
>🚀 Usage
Start the application
cli-chatLogin
Enter your credentials
CLI Chat Application
Enter User ID:
> om-macbook
Enter Password:
> 123456After successful authentication you'll see
Logged in as Om's MacBook
1. Group Chat
2. Direct Message
>Group Chat
Select
1Type your message
> Hello everyone!Every connected user will instantly receive the message.
Direct Message
Select
2Choose a user
Available Users
1. Om's iPad
2. Om's iPhone
Select User:
> 1Now every message you type will be sent only to the selected user.
Exit
Press
Ctrl + CThe application automatically:
- Marks you offline
- Closes the connection
- Exits gracefully
🛠 Tech Stack
| Technology | Purpose | |------------|---------| | TypeScript | Programming Language | | Node.js | Runtime | | Firebase Realtime Database | Real-time backend | | Firebase SDK | Database Communication | | Readline | Terminal Input | | npm | Package Management |
📂 Project Structure
src/
│
├── firebase.ts
│ Firebase configuration and database operations
│
├── index.ts
│ Application entry point
│ Handles authentication and application flow
│
├── groupChat.ts
│ Group chat functionality
│
└── directChat.ts
Direct messaging functionality🔐 User Authentication
Users are stored inside Firebase Realtime Database.
Example
users
│
├── om-macbook
│ username
│ password
│ online
│
├── om-ipad
│ username
│ password
│ online
│
└── om-iphone
username
password
onlineWhen the application starts
CLI Chat Application
Enter User ID:
>
Enter Password:
>If the credentials are valid
- User is marked online
- Chat session starts
If invalid
Invalid User ID or Password🌍 Group Chat
Messages are stored under
groupMessages/Each message contains
{
"senderId": "om-macbook",
"text": "Hello World",
"timestamp": 1751972382
}Messages are synchronized in real time across all connected terminals.
💬 Direct Messaging
Private conversations are stored separately.
Conversation IDs are generated by sorting user IDs alphabetically.
Example
messages/
om-ipad_om-macbook/
om-ipad_om-iphone/
om-macbook_om-iphone/This ensures only one conversation exists between two users.
🟢 Presence System
Each user maintains an online status.
{
"online": true
}Status is updated
- On successful login
- When the application exits
🔥 Firebase Database Structure
users
│
├── userId
│ username
│ password
│ online
│
├── ...
│
groupMessages
│
├── messageId
│ senderId
│ text
│ timestamp
│
└── ...
messages
│
├── conversationId
│ messageId
│ senderId
│ receiverId
│ text
│ timestamp🚀 How It Works
User Login
│
▼
Firebase Authentication Check
│
▼
Mark User Online
│
▼
Select Chat Mode
│
├───────────────┐
▼ ▼
Group Chat Direct Chat
│ │
▼ ▼
Realtime Firebase Listeners
│
▼
Instant Message Delivery📸 Terminal Preview
CLI Chat Application
Enter User ID:
> om-macbook
Enter Password:
> ******
Logged in as Om's MacBook
1. Group Chat
2. Direct Message
> 1
--------------------------------
om-ipad:
Hello
om-macbook:
Hi!
>🎯 Learning Outcomes
This project demonstrates
- Firebase Realtime Database
- Real-time communication
- CLI application development
- TypeScript
- Node.js
- Authentication flow
- Presence management
- Event-driven programming
- npm package development
🚧 Future Improvements
- End-to-end encryption
- Gemini AI integration
- File sharing
- Typing indicators
- Message reactions
- Chat history search
- Custom Firebase project initialization
- Better terminal UI using Ink or Blessed
- User registration from CLI
- Configuration file support
🤝 Contributing
Contributions, ideas and feature requests are always welcome.
Feel free to fork the repository and create a pull request.
📄 License
This project is licensed under the ISC License.
👨💻 Author
Om Sharma
GitHub
https://github.com/Sharma-Ji-21
If you found this project helpful, consider giving it a ⭐ on GitHub.
