A terminal-based chat application written in Elixir for learning and demonstration purposes.
-
User Management
- Secure registration with username validation
- Password hashing using SHA256
- Session management
-
Messaging
- Send messages to other users
- View inbox with unread message indicators
- View conversation history between users
- Message timestamps
-
Data Persistence
- Automatic saving to disk
- State maintained between sessions
- Agent-based in-memory storage
-
User Experience
- Interactive CLI with clear prompts
- List all registered users
- Unread message counter
- Command help system
- Elixir 1.14 or higher
- Erlang/OTP 24 or higher
Use the automated setup script:
./scripts/setup.shOr manually:
- Clone the repository:
git clone https://github.com/codeforgood-org/elixir-chat-sim.git
cd elixir-chat-sim- Install dependencies:
mix deps.get- Run tests to verify installation:
mix testmix run -e "ChatSimulator.CLI.main()"mix escript.build
./chat_simulatordocker-compose upOr build manually:
./scripts/docker-build.sh
docker run -it --rm chat-simulator:latestWhen not logged in:
register- Create a new accountlogin- Login to existing accounthelp- Show available commandsquitorexit- Exit the application
When logged in:
send- Send a message to another userinbox- View your messageschat- View conversation with a specific userusers- List all registered userslogout- Logout from your accounthelp- Show available commandsquitorexit- Exit the application
╔═══════════════════════════════════════╗
║ CHAT SIMULATOR v0.1.0 ║
║ Terminal-based Chat System ║
╚═══════════════════════════════════════╝
Welcome to Terminal Chat!
Type 'help' for available commands
[Not logged in]
> register
Choose a username: alice
Choose a password: secret123
✓ Registration successful! You are now logged in as alice.
[alice]
> users
--- Registered Users ---
• alice
1 user(s) registered
[alice]
> send
--- Send Message ---
To (username): bob
✗ User 'bob' not found.
[alice]
> logout
Logged out successfully.
[Not logged in]
> quit
Thank you for using Chat Simulator. Goodbye!
The application is organized into modular components:
lib/
├── chat_simulator.ex # Main module with convenience functions
└── chat_simulator/
├── auth.ex # Authentication and registration
├── cli.ex # Command-line interface
├── message.ex # Message struct and operations
├── storage.ex # Data persistence with Agent
└── user.ex # User struct and validation
- ChatSimulator - Main module providing high-level API
- ChatSimulator.User - User data structure with password hashing
- ChatSimulator.Message - Message data structure with formatting
- ChatSimulator.Auth - Registration and login logic
- ChatSimulator.Storage - Agent-based storage with file persistence
- ChatSimulator.CLI - Interactive command-line interface
Run all tests:
mix testRun tests with coverage:
mix test --coverRun specific test file:
mix test test/chat_simulator/user_test.exsRun all checks at once:
./scripts/test.shOr individually:
Format code:
mix formatRun static analysis:
mix credoRun dialyzer (type checking):
mix dialyzerClean build artifacts:
./scripts/clean.shmix docsThen open doc/index.html in your browser.
elixir-chat-sim/
├── lib/ # Application code
│ ├── chat_simulator.ex
│ └── chat_simulator/
│ ├── auth.ex # Authentication
│ ├── cli.ex # Command-line interface
│ ├── message.ex # Message handling
│ ├── storage.ex # Data persistence
│ └── user.ex # User management
├── test/ # Test suite
│ ├── test_helper.exs
│ ├── integration_test.exs
│ └── chat_simulator/
│ ├── auth_test.exs
│ ├── message_test.exs
│ ├── storage_test.exs
│ └── user_test.exs
├── config/ # Configuration
│ ├── config.exs
│ ├── dev.exs
│ ├── test.exs
│ ├── prod.exs
│ └── runtime.exs
├── scripts/ # Helper scripts
│ ├── setup.sh
│ ├── test.sh
│ ├── clean.sh
│ └── docker-build.sh
├── examples/ # Usage examples
│ ├── api_usage.exs
│ └── automated_chat.exs
├── .github/ # GitHub configs
│ ├── workflows/
│ │ └── ci.yml
│ ├── ISSUE_TEMPLATE/
│ ├── PULL_REQUEST_TEMPLATE.md
│ └── dependabot.yml
├── Dockerfile
├── docker-compose.yml
├── .formatter.exs
├── .credo.exs
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── SECURITY.md
├── LICENSE
├── mix.exs
└── README.md
- Passwords are hashed using SHA256 before storage
- No plain-text passwords are stored
- User input is validated before processing
- Message content is limited to 500 characters
Note: This is an educational project. For production use, consider:
- Using a more robust password hashing algorithm (bcrypt, argon2)
- Adding rate limiting
- Implementing proper session tokens
- Adding encryption for stored data
- Input sanitization for XSS prevention
See CONTRIBUTING.md for guidelines on how to contribute to this project.
Check out the examples/ directory for:
- api_usage.exs - Using the API programmatically
- automated_chat.exs - Simulated multi-user conversations
Run examples:
mix compile
elixir examples/api_usage.exs
elixir examples/automated_chat.exsThis project demonstrates several Elixir concepts:
- Structs - Data structures for Users and Messages
- Pattern Matching - Command parsing and data extraction
- Guards - Function clause selection based on conditions
- Agents - State management for storage
- Configuration - Environment-specific settings
- Logging - Application logging with Logger
- File I/O - Data persistence
- Documentation - Module and function documentation
- Testing - Comprehensive test suite with ExUnit
- CI/CD - Automated testing and deployment
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Elixir
- Created for educational purposes by codeforgood-org
- Inspired by classic terminal chat applications
Potential future enhancements:
- Group chat functionality
- Message encryption
- User blocking/privacy features
- Message editing and deletion
- File attachments
- User profiles and status
- Network-based client-server architecture
- Web interface with Phoenix
- Message search functionality
- Emoji support
For issues, questions, or contributions:
- Open an issue on GitHub
- Submit a pull request
- Contact: codeforgood-org
Happy Chatting! 💬