Wall Street Trader Project Walkthrough

September - November 2020

Source Code

About

Homework from Harvard's Introduction to Computer Science CS50 hosted on eDX Web Track: Finance. Web application via which you can manage portfolios of stocks. This tool allows you to check real stocks’ actual prices and portfolios’ values, it will also let you buy (okay, “buy”) and sell (okay, “sell”) stocks by querying IEX Stock Quote API for stocks’ prices. I wrote all the code in the templates directory. I wrote most of the code in application.py. Some of the code in helpers.py was provided by instructor. I styled the application myself, with illustrations provided by Freepik. The core of the application was built from September - November 2020, with sporadic updates up until April 2022.

Product Features and Specifications

Technologies

Front-End

  • Jinja
  • HTML5
  • Boostrap
  • CSS3

Back-End

  • Python
  • Flask
  • Flask SQL Alchemy

Testing

  • Pytest
  • Google Lighthouse

Database

  • MySQL

Development

  • Git
  • GitHub
  • Codacy

Production

  • AWS EC2
  • Ubuntu
  • Gunicorn
  • Nginx
  • TravisCI
  • Google Domains
  • Google Analytics

UX/UI Mocks and Graphic Design

Heavily relied on open-source assests to make use of the high quality material created or curated by the open-source community. For the full list, please refer to the attribute section of this GitHub repo.

Design and Architecture

Code Architecture

Used a Model-View-Controller (MVC) Monolithic Architecture since it's the most simple architecture to gain an introduction to full-stack web development. Building a MVC Monolith allows one to gain a perspective on the range of achitectures, particularly the lower-end of the range. The Monolith Architecture falls short in scalability and separation of front-end and back-end. The MVC Architecture falls short when the application begins to grow in complexity with the addition of services that could stand on thier own. The MVC Architecture is perhaps best used for simple proof-of-concept projects, like this one. However, for any projects that serve real business needs, I would opt to use an event-driven serverless architecture.

Wall Street Trader Code Architecture Diagram

Model:

View: Chose Jinja as the front-end templating language for more DRY code compared to plain HTML and for dynamic user-experiences. This is a simple templating language, similar to express for Node.js. Both however fall short on front-end scalability, modularity, and performance compared to a framework like React. Working with simple templating languges helps to remind me the benefits of working with a framework like React. Chose Bootstrap 5 as the CSS framework to keep the UI simple and quick to build. Since the website takes a performance hit for loading Bootstrap, took full advantage of advanced Bootstrap features such as custom validation for all forms and animated form input for the login and register pages.

Controller: Chose Python as the backend programming language for its rich ecosystem and community support. For example,leveraged Werkzeug for the authentication and authorization since it's a common out-of-the-box solution. Chose Flask as the Python application framework since it's a lightweight framework, which is ideal for gaining an understanding of how to build the backend from scratch. Compared to a framework like Django, Flask doesn't have many as features out of the box.

Database Schema

Wall Street Trader Database Schema

Tests

Production System Architecture

I used Ubuntu as the OS on EC2 since it's the most popular operating system for web servers, Gunicorn as the WSGI since it's fast, and Nginx as the reverse proxy since it was made with this optimization in mind.

Wall Street Trader EC2 Server Architecture

Initially hosted application on AWS Elastic Beanstalk for a gradual introduction to AWS. Prior to this, I had only used Heroku to host full-stack web applications, so I chose a similar Infrastructure as a Service (IaaS) offered by AWS. After numerous Elastic Beanstalk policy changes and disconnections, I decided to go to the next level down in AWS, which is hosting this application on an EC2 instance. This offered a lot of experience and opportunities for learning about web servers.

Initially stored user sessions in a tmp folder with mkdtemp, however Nginx had trouble accessing it in production. Therefore refactored application to store user sessions in a Redis database and hosted the Redis database on AWS Elasticache

Wall Street Trader Production System Architecture Diagram

Production Scalability and Load limitations

The production server is hosted on an AWS EC2 server on the t2.small tier, which has a limit of 1 vCPU and 2 GB of RAM. If I needed to scale up due to an overloaded server, I could scale horizontally and add an elastic load balancer or I have the option to scale vertically by upgrading the server to the next tier, t2.medium, which would double the vCPU and RAM.

Production System Cost

Production Metrics

Lessons Learned