View on GitHub

Saiddit

A minimal MySQL-based replica of core reddit functionality.

Download this project as a .zip file Download this project as a tar.gz file

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.


Table of Contents

  1. Installation & Setup
  2. MySQL
  3. Flask
  4. Saiddit Database
  5. Contributors

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 is saiddit.

❯❯❯ 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:


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.