As I mentioned in the previous post, DoubleDibz was a craiglist-like community based market place website. I worked on it during my last year at UCLA but haven't maintained it since then. Now I want to open source the code since it could be useful for anyone working on similiar projects! If you are planning on building a social network on Flask, this is the project for you!
A couple highlight for the codebase
- A large and complete Flask application serving purely as API endpoints which powers a complex Backbone application in the frontend.
- A complete marketplace social network. This includes real-time notifications and messaging support.
Come here to check out the entire source code.
What's included in the code?
- SqlALchemy + alembic for db migration
- a bunch of Flask libraries
- Backbone + Marionette js
- fabric for deployment
- Facebook SDK for login
- images stored on S3
- Purely API endpoints.
- Post create. This is pretty straitforward. The highlight here is every single photo will be resized and cropped and saved on s3. See here.
- Comment on posts.
- hashtags on products. So every products could have category/hashtags. Users could explore products for a specific hashtag.
- Notification. DoubleDibz is completely social. User receives notifications when the products they subscribed to are sold or commented.
- celery workers for notification. I may have over-engineered the system. I was originally concerned that if a product has a lot of subscribers and someone comments on that product, it doesn't make sense to send notification to every subscriber in the same web request. So I introduced celery to handle those tasks asynchronously.
- Search. A really tricky part of the app is I have a database with product posts user created on DoubleDibz but I also have a separate server which pulls products from Facebook groups. The search aggregates results from both DBs. Paginations are supported as well.
- caching results with redis. To optimize for read, I cached user notifications, post data, search results, and user data. The code is also setup to invalidate cache upon write.
The frontend is the most fun part of the project. I learned so much about how to structure a semi-large scale Backbone application to support all the features I wanted to make. All the things I mentioned before has a frontend counter part. You can upload photos to create a new product, look at home feed which is an infinite feed, then search for products and categories, look at product details page. You can message the seller for a product you are interested or comment on the product. You can even comment and tag your FB friends and your friends will receive notifications on FB!
The main thing I want to mention is Chat. This is the most complex part of the system. The challenge here is that every x seconds I'm pulling new messages from the system, and given those new messages, I need to update the correct Backbone view components. This includes updating the message count and also the message thread.
- uwsgi configuration for the application server
- production and staging nginx configuration
- celery configuration
- Fabric script for running deployment (push)
Take a look! Maybe there's something you can use right away.