Skip to content

aip956/SpringBoot_StockPortfolio

Repository files navigation

TASK
StockPortfolio is a CRUD application built in Spring Boot Java.

The home view summarized each investment, with a calculator that
shows how much of a $10M investment remains. The user can add a fund,
and filter buttons allow sorting by dollar amount (increasing / decreasing)
or alphabetical order. The user can also edit the amount invested via
an update button.

TECHNOLOGY STACK

  • Java
  • Spring Boot
  • Maven
  • Thymeleaf
  • Bootstrap
  • MySQL (and MySQL Workbench)

USER REQUIREMENTS
The user should be able to:

  • Edit the Investment Limit Maximum
  • See their total amount invested, and the remaining amount
  • Add, Edit, and Delete a stock line (stock, amount)
  • Sort stock lexicographically or by amount, ascending or descending
  • Make edits/additions through an interface
  • Data persistence; see stock after logging out and in

DESIGN
To create an application with CRUD capability, I used:

IntelliJ Integrated Development Environment:

  • Integration to Git, built-in tools, strong adoption and community

Spring Boot

  • Sensible defaults and auto-configuration
  • Embedded web server (Tomcat) eliminating need for deploying apps to external servers for simpler deployment
  • Dependency Injection and Auto-configuration: For ease-of-use
  • Create dependency management and build automation

Maven for simplified dependency management and IDE integration * Maven build: maven clean install command * Maven dependencies: pom.xml

In the application:
Define routes => Achieved with the stockController class.

  • Get Method
  • Get Method with Sorting
  • Get Method to Add Stock
  • Post Method for Added Stock
  • Get Method to Edit Stock
  • Post Method for Updated Stock
  • Get Method to Delete Stock
  • Get Method to Edit Total Investment
  • Post Method for Edited Total Investment

Define variables/model methods => Achieved with Stock (model)

  • Stock
  • ID
  • Amount Invested

Manage persistence of Stock entities => Achieved with StockRepository.

  • Interface class acts as an interface between the application code and the underlying database.

Make calculations (e.g. total investments vs. investment limits) => Achieved with StockService.

  • This class’ methods act as intermediaries between the controller and the database; the methods calculate the total investments, managing investment limits, etc.
  • getAllStock method
  • findStockById method
  • saveStock method
  • deleteStockById method
  • getTotalAmtInv (get total amount invested) method
  • @autowired for automatic dependency injection

Have an entry point for the user => Achieved through the StockPortfolioApplication.java:

  • Checks if there’s an environment variable ‘PORT’
  • Creates a SpringApplication instance, the entry point, and is annotated @SpringBootApplication
  • Sets Default Property ‘server.port’ and server address
  • Runs the application, starts the Tomcat server and initialized the Spring application context
  • Prints a message to indicate application has started successfully

For the interface, the user needs to view pages for home, edit, and add.

  • Used Thymeleaf to create html templates to integrate dynamic data and logic
  • Server-side Java template for web for server-side rendering / improved performance
  • Integration with Spring Framework Java Backend
  • Used Bootstrap in Thymeleaf to style pages
    • addStock.html
    • editStock.html
    • editTotalInvLimit.html
    • showStocks.html
    • stockNotFound.html

Data Persistence:

  • Integrated MySQL database
  • Scalability: Designed for large-scale applications with high volumes of data
  • Performance: MySQL is optimized for fast read and write performance, with efficient indexing
  • Industry standard and large adoption: Very popular relations database, widely used across various industries
  • Tested with MySQL workbench

Railway for Deployment:

  • I first attempted to deploy my app on AWS, but started incurring significant charges before I was able to complete the deployment. I switch to the simpler Railway Platform as a Service
  • Simple deployment and hosting for web applications
  • Intuitive platform for deployment; integrated with git
  • Cost-effective
  • I did run into an issue with deployment, and my colleague helped diagnose I was missing a “Host” variable.

TO RUN
Locally

  • In IntelliJ IDEA
    • In the StockPortfolioApplication, right click for the menu, then click run
    • Run from file menu


* * Or run from icon * *

Run from file menu



Web Application



* Stock can be sorted by Name, ascending or descending * *

Run from file menu



* Stock can be added/edited * *

Run from file menu


* If investment exceeds limit, there will be an error * *

Run from file menu



C The team: Written primarily by me. However, I did consult with a colleague well-versed in deployment in order to deploy to Railway.

About

StockPortfolio is a CRUD application, deployed on Railway, of a Stock tracker.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages