Skip to content
@broccoli-cli

broccoli

cli based social media for superusers

๐Ÿฅฆ broccoli

goreport release license

Real-time terminal-based chat application for Mac users

๏ฟฝ๏ฟฝ Features

  • โœ… User registration and login (JWT token)
  • โœ… Real-time WebSocket communication
  • โœ… Terminal-based chat client
  • โœ… Message history stored in database
  • โœ… User join/leave notifications

๐Ÿ“ฆ Quick Setup

# Install dependencies
pip3 install -r requirements.txt

# Create .env file
echo "SECRET_KEY=your_super_secret_key_here" > .env

# Start server
python3 server.py

# Start client in new terminal
python3 terminal_client.py

๐Ÿ’ป Usage

  1. Register or login
  2. Type message and press Enter
  3. Type quit to exit

๏ฟฝ๏ฟฝ API Endpoints

  • POST /register - User registration
  • POST /login - User login and JWT token

๏ฟฝ๏ฟฝ WebSocket Events

  • connect - Connection established
  • join - Join chat room
  • message - Send message
  • leave - Leave room

โœ… Test Results

Successful Tests:

  • โœ… User registration (/register)
  • โœ… User login (/login)
  • โœ… JWT token verification
  • โœ… WebSocket connection
  • โœ… Real-time messaging
  • โœ… Terminal client interface
  • โœ… Message database storage
  • โœ… Multi-user support

๏ฟฝ๏ฟฝ Testing Methods:

1. Basic API Tests:

# Register test
curl -X POST http://localhost:8080/register \
  -H "Content-Type: application/json" \
  -d '{"username": "testuser", "password": "testpass123"}'

# Login test  
curl -X POST http://localhost:8080/login \
  -H "Content-Type: application/json" \
  -d '{"username": "testuser", "password": "testpass123"}'

2. Manual Multi-User Test:

# Terminal 1: Server
python3 server.py

# Terminal 2: Client 1
python3 terminal_client.py

# Terminal 3: Client 2  
python3 terminal_client.py

# Terminal 4: Client 3
python3 terminal_client.py

3. Automated Multi-User Test:

# 3 users automated test (elif, sercan, lordi)
python3 test_multi_user.py

4. Quick Test Script:

# Automatically starts 3 clients
./quick_test.sh

๐Ÿ“Š Test Scenarios:

Scenario 1: Basic Functionality

  • โœ… User registration and login
  • โœ… JWT token acquisition
  • โœ… WebSocket connection
  • โœ… Message sending/receiving

Scenario 2: Multi-User

  • โœ… 3 users connect simultaneously (Elif, Sercan, Lordi)
  • โœ… Elif sends loving messages to Sercan โค๏ธ
  • โœ… Sercan responds romantically ๐Ÿ˜Š
  • โœ… Lordi sends playful messages like a funny kid ๐Ÿ˜„
  • โœ… Real-time communication tested
  • โœ… User join/leave notifications

Scenario 3: Performance Test

  • โœ… WebSocket polling works
  • โœ… Message latency < 1 second
  • โœ… Database records correct
  • โœ… Connection drop/reconnect

๐Ÿ” Test Files:

  • test_multi_user.py - Automated multi-user test
  • quick_test.sh - Quick test script
  • terminal_client.py - Manual test client

๐Ÿ“‹ To-do's:

๐Ÿ”ฅ Priority:

  • Private messaging (DM)
  • Multiple chat rooms
  • File sharing
  • Emoji support
  • Message editing/deletion

๐Ÿš€ Advanced:

  • Friend add/remove
  • User profiles
  • Online status
  • Message search
  • Notification system

๐ŸŽฏ Social Media:

  • Post sharing
  • Homepage (latest/friend posts)
  • Post like/dislike
  • Comment system
  • Hashtag support

๐Ÿ“ Project Structure

broccoli/
โ”œโ”€โ”€ server.py              # Main Flask server
โ”œโ”€โ”€ models.py              # Database models (User, Message)
โ”œโ”€โ”€ routes.py              # API endpoints (/register, /login)
โ”œโ”€โ”€ socket_events.py       # WebSocket event handlers
โ”œโ”€โ”€ terminal_client.py     # Terminal chat client
โ”œโ”€โ”€ test_multi_user.py    # Automated multi-user test
โ”œโ”€โ”€ quick_test.sh         # Quick test script
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”œโ”€โ”€ .env                  # Environment variables (SECRET_KEY)
โ”œโ”€โ”€ proje.db             # SQLite database
โ”œโ”€โ”€ .gitignore           # Git ignore file
โ”œโ”€โ”€ LICENSE              # MIT License
โ”œโ”€โ”€ README.md            # Turkish README
โ”œโ”€โ”€ README_EN.md         # English README
โ””โ”€โ”€ assets/              # Project assets
    โ”œโ”€โ”€ broccoli-logo.png
    โ””โ”€โ”€ database-diagram.png

๐Ÿ”ง Technical Details

Backend Stack:

  • Flask - Web framework
  • Flask-SQLAlchemy - Database ORM
  • Flask-SocketIO - WebSocket support
  • PyJWT - JWT authentication
  • SQLite - Database
  • Eventlet - Async server

Frontend (Terminal):

  • Python - Terminal client
  • SocketIO-client - WebSocket client
  • Requests - HTTP client

Security:

  • JWT tokens for authentication
  • Password hashing with werkzeug
  • CORS enabled for cross-origin requests

๐Ÿš€ Development

Running in Development:

# Install dependencies
pip3 install -r requirements.txt

# Set environment
export FLASK_ENV=development
export SECRET_KEY=your_secret_key

# Run server
python3 server.py

Database Management:

# Database is auto-created on first run
# Location: proje.db (SQLite)

# Tables:
# - users (id, username, password_hash, created_at)
# - messages (id, user_id, content, timestamp)

๐Ÿ“ API Documentation

Authentication Endpoints:

POST /register

Register a new user

{
  "username": "newuser",
  "password": "password123"
}

POST /login

Login and get JWT token

{
  "username": "existinguser", 
  "password": "password123"
}

WebSocket Events:

Client โ†’ Server:

  • join - Join chat room
  • message - Send message
  • leave - Leave room

Server โ†’ Client:

  • user_joined - User joined notification
  • user_left - User left notification
  • message - New message received

๐Ÿ› Troubleshooting

Common Issues:

  1. Port 8080

    • Server uses port 8080 by default
    • Check if port is available
  2. JWT token errors:

    • Ensure SECRET_KEY is set in .env
    • Check token expiration
  3. WebSocket connection failed:

    • Verify server is running
    • Check firewall settings
  4. Database errors:

    • Delete proje.db to reset
    • Check file permissions

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch
  3. Make changes
  4. Test thoroughly
  5. Submit pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details


Made with โค๏ธ for Mac users who love terminal-based applications

Popular repositories Loading

  1. broccoli broccoli Public

    broccoli app source code

    Python 2

  2. .github .github Public

Repositories

Showing 2 of 2 repositories

Top languages

Loadingโ€ฆ

Most used topics

Loadingโ€ฆ