This is a simple chat application built with Flask, Flask-SocketIO, and Flask-SQLAlchemy.
-
Clone the repository:
git clone https://github.com/your-repo/chat-app.git cd chat-app
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate
-
Install the dependencies:
pip install -r requirements.txt
-
Run the application:
python main.py
- Open your web browser and go to
http://127.0.0.1:5000
. - Enter your name and either create a new room or join an existing one using the room code.
- Start chatting!
-
Room: Represents a chat room.
id
: Primary key.code
: Unique code for the room.members
: Number of members in the room.messages
: Relationship to the Message model.
-
Message: Represents a chat message.
id
: Primary key.name
: Name of the user who sent the message.content
: The message content.room_id
: Foreign key to the Room model.
- / (GET, POST): Home route where users can create or join a chat room.
- /room (GET): Room route where users can see the chat interface and messages.
message
: Handles incoming chat messages, saves them to the database, and broadcasts them to the room.connect
: Handles user connection, joins them to the room, and updates the member count.disconnect
: Handles user disconnection, removes them from the room, and updates the member count.
chat-app/
├── app.py
├── templates/
│ ├── home.html
│ └── room.html
├── static/
│ └── style.css
└── requirements.txt