A minimal MySQL-based replica of core reddit functionality.
Saiddit is an online community forum that allows accounts to post text and links to a given "subsaiddit", and allows other accounts to upvote, downvote, and comment on the posts.
-
An account has:
- username
- salted hash password
- reputation (upvotes minus downvotes).
-
An account can:
- post to any subsaiddit
- comment on any post
- maintain a friend list of other accounts
- maintain a list of favourite posts
- subscribe to a subsaiddit
- upvote or downvote (not both) once per post or comment
-
A post has:
- author
- date/time published
- date/time edited (if applicable)
- title
- text (if it is a 'text' post)
- URL (if it is a 'link' post)
- upvotes
- downvotes
- subsaiddit it belongs to
-
A comment has:
- author
- date/time published
- text
- the post it belongs to
- upvotes
- downvotes
- the comment it is replying to (if applicable)
-
A subsaiddit has:
- title
- description
- author/creator
- date/time created
- default, or not default (whether it's shown on frontpage for unauthenticated user)
The following instructions are for Ubuntu 16.04 LTS.
Note: The chevrons (β―β―β―) represent the zsh shell command prompt.
β―β―β― git clone https://github.com/stvhwrd/saiddit.git saiddit;
β―β―β― cd saiddit;
2. Install MySQL:
β―β―β― sudo apt update;
β―β―β― sudo apt install mysql-server;
β―β―β― sudo mysql_secure_installation;
β―β―β― sudo mysql_install_db;
3. Launch MySQL and create our user with password secretpassword
:
β―β―β― mysql -u saiddituser -p
mysql> CREATE USER 'saiddituser'@'localhost' IDENTIFIED BY 'secretpassword';
mysql> GRANT ALL PRIVILEGES ON * . * TO 'saiddituser'@'localhost';
β―β―β― cd ./sql;
β―β―β― mysql -h localhost -u saiddituser -p < ./db_schema.sql;
Note: If you are working in a Cloud9 instance, you may simply use the setup script at this point.
β―β―β― sudo apt install python python-pip python-dev build-essential;
β―β―β― sudo apt install libmysqlclient-dev;
β―β―β― pip install flask flask-mysql;
β―β―β― mysql -u saiddituser -p;
β―β―β― use saiddit;
8. Navigate to the app
directory, and fire up the Flask app. These commands assume that your pwd
is saiddit
.
β―β―β― cd ./app
β―β―β― python app.py
9. Now open your browser to the port the app is running on: http://localhost:8080/
"MySQL (officially pronounced as "My S-Q-L") is an open-source relational database management system... the world's second most widely used RDBMS, and the most widely used open-source clientβserver model RDBMS." - Wikipedia
Here's a handy cheat sheet for playing with MySQL: Sven Hofmann's MySQL Cheatsheet
Flask is a Python web framework built with a small core and easy-to-extend philosophy. We use it to interface between the HTML/CSS/JS frontend and the MySQL backend.
- Why is Flask a good web framework choice?
- Flask-MySQLdbβs documentation
- Creating a Web App From Scratch Using Python Flask and MySQL
- Python Web Application Development Using Flask and MySQL
- A Quick Guide to Using MySQL in Python
The basic file structure of a small flask application is:
app/
βββ app.py
βββ static/
βββ style.css
templates/
βββ layout.html
βββ index.html
βββ login.html
...
Set up the database by running bash setup.sh
from the sql
directory.
This runs all commands from db_schema.sql
in MySQL, which creates and populates the saiddit
database.
See the diagram below for an E/R diagram representation of the Saiddit DB.
All contributors are listed on this page.