a full-stack twitter clone. the back end is flask with sqlalchemy and alembic migrations on postgres, the front end is react/redux, and deployed in docker.

tweets are full crud and you can post one from anywhere on the site. on top of tweets there are comments, likes, bookmarks and follows, each with its own blueprint under /api and its own table. likes and bookmarks are both just join tables between users and tweets, but they show up in different places. bookmarks get their own page, likes show up as a count on the tweet.
class Like(db.Model):
__tablename__ = 'likes'
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey("users.id", ondelete='CASCADE'), nullable=False)
tweet_id = db.Column(db.Integer, db.ForeignKey("tweets.id", ondelete='CASCADE'), nullable=False)
class Follow(db.Model):
__tablename__ = 'follows'
id = db.Column(db.Integer, primary_key=True)
sender = db.Column(db.Integer, db.ForeignKey("users.id", ondelete='CASCADE'), nullable=False)
reciever = db.Column(db.Integer, db.ForeignKey("users.id", ondelete='CASCADE'), nullable=False)every foreign key cascades on delete, so deleting a user takes their tweets, likes, follows and messages with them without any cleanup code. follows are directional, a sender and a receiver, which is what makes "who follows who" a one-table question.
notifications are written by the routes that cause them. following someone inserts two rows in one request: the follow itself, then a notification for the person being followed with a message and a link back to the sender's profile. likes and comments do the same thing against the tweet's author.
@follow_routes.route('/add', methods=['POST'])
@login_required
def post_a_follow():
data = request.json
follow = Follow(sender=data["sender"], reciever=data["reciever"])
db.session.add(follow)
db.session.commit()
the_user = User.query.get(data["sender"]).to_dict()
new_notif = Notification(
reciever=data["reciever"],
sender=data["sender"],
message=f'{the_user["username"]} has started following you.',
link=f'/profile/{data["sender"]}',
)
db.session.add(new_notif)
db.session.commit()
return {"follow": follow.to_dict()}media on tweets gets uploaded to s3. the server takes the file, pushes it to a bucket with a public-read acl and stores the resulting url on the tweet, so the database never holds image data.

if you follow someone you can open a dm channel with them. each channel is a socket room (they make great keys). the client joins the room when it opens the conversation, and sending a message emits to the room with flask-socketio, so both sides see it live instead of polling. the whole socket layer is three handlers.
socketio = SocketIO(cors_allowed_origins=origins)
@socketio.on("message")
def handle_chat(data):
send({'message': data['message'], "sender": data['sender']}, room=data['room'])
@socketio.on('join')
def join(data):
join_room(data['room'])
@socketio.on("leave")
def leave(data):
leave_room(data['room'])