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)
Table of Contents
Installation and Setup
The following instructions are for Ubuntu 16.04 LTS.
Note: The chevrons (❯❯❯) represent the zsh prompt
1. Clone this repository:
❯❯❯ 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:
The password we’re using is
secretpassword
❯❯❯ mysql -u saiddituser -p
mysql> CREATE USER 'saiddituser'@'localhost' IDENTIFIED BY 'secretpassword';
mysql> GRANT ALL PRIVILEGES ON * . * TO 'saiddituser'@'localhost';
4. Create the database (you will be required to enter the sudo
password):
❯❯❯ 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.
5. Install Python 2.x and pip:
❯❯❯ sudo apt install python python-pip python-dev build-essential;
6. Then install python dependencies:
❯❯❯ sudo apt install libmysqlclient-dev;
❯❯❯ pip install flask flask-mysql;
7. Now start up your MySQL server, and use the saiddit
database:
❯❯❯ mysql -u saiddituser -p;
❯❯❯ use saiddit;
8. Navigate to the app
directory, and fire up the Flask app:
These commands assume that your
pwd
issaiddit
.
❯❯❯ cd ./app
❯❯❯ python app.py
9. Now open your browser to the port the app is running on: http://localhost:8080/
MySQL
“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
Cheat Sheet
Here’s a handy cheat sheet for playing with MySQL: Sven Hofmann’s MySQL Cheatsheet
Flask
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.
Resources:
- 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
Structure
The basic file structure of a small flask application is:
app/
├── app.py
└── static/
└── style.css
templates/
├── layout.html
├── index.html
└── login.html
...
Saiddit Database
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.
Credit
All contributors are listed on this page.