Skip to content

Commit

Permalink
Updating with main (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
celinelumqr authored Nov 26, 2023
2 parents 27b9972 + 7154693 commit 37f068e
Show file tree
Hide file tree
Showing 24 changed files with 1,970 additions and 33 deletions.
3 changes: 3 additions & 0 deletions Topics/Development_Process.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ This is only a simplification of what "Clean Architecture" is; the topic is so v
- A very detailed explanation of Clean Architecture by Robert C. Martin or Uncle Bob and his book
- https://www.youtube.com/watch?v=2dKZ-dWaCiU
- https://github.com/ropalma/ICMC-USP/blob/master/Book%20-%20Clean%20Architecture%20-%20Robert%20Cecil%20Martin.pdf

## Code Smells
### [Code Smells](./Development_Process/Code_Smells.md)
37 changes: 37 additions & 0 deletions Topics/Development_Process/Code_Smells.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Code Smells
Code smells refer to certain types of code that, while functional, will require increasing accommodation as more code begins to rely on the "smelly" code. While it is possible to ignore these types of code, the longer that they remain, the harder it becomes to fix issues they directly or indirectly cause in the future. Therefore, it's in a developer's best interest to be familiar with a broad spectrum of code smells so that they may identify and eliminate them as soon as possible.


## A Motivating Example
Consider the following snippet of code:

```
class Something:
temp_field: int
def do_something(self) -> int | None:
if self.temp_field == None:
return None
else:
return self.temp_field + 1
```
On its own, this code is functional, but it raises a number of questions. For example: when exactly is `temp_field` equal to `None`? When does it actually store relevant data? This answer is largely dependant on how the class `Something` is used, but the specifics may not be clear to someone reading this code.

This code smell is known as a "Temporary Field", which is when classes are given attributes to be used in some of their methods, but in some cases the attribute stores null values. While adding null checks easily allows code using these attributes to function, it decreases code readability, and if the technique is abused it can easily lead to unnecessarily long code. To fix this, refactoring is required.

## Refactoring
Refactoring is a software development practice in which code is rewritten such that no new functionality is actually provided, but the code becomes cleaner and better accommodates future extensions of features. While it is generally recommended in software development that code should not be rewritten, but extended (see the [Open/Closed Principle of SOLID](../Development_Process.md#solid-principles), refactoring typically prevents more significant amounts of code rewriting that may be required in the future.

Many refactoring solutions to code smells are well-established and should be drawn upon once relevant code smells are identified. One such solution for the previous example is known as "Introduce Null Object", in which attributes that may be null should be defined over a new "Null" class, which can provide default values when the aforementioned attribute would have previously been null. This contains any null checks to the new class, allowing for the removal of if-statements in other code that may cause confusion or excessive code length. Furthermore, future code that may deal with the previously temporary field will also no longer need any null checks, as the new class does it for them. Thus, refactoring improved both the readability and extendability of the former code.

## Categories
While there may be many different types of code smells, all of them fall into one of five categories that can more easily be identified when writing code. The categories are as follows:
- Bloaters
- Object-Oriented Abusers
- Change Preventers
- Dispensables
- Couplers

## More Info
For further insight into all the different types of code smells including explanations, examples, and solutions, the following resource is highly recommended:
https://refactoring.guru/refactoring/smells
205 changes: 184 additions & 21 deletions Topics/Development_Process/Docker.md

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions Topics/Development_Process/kubernetes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Introduction to Kubernetes

## What is Kubernetes?

Kubernetes, also known as K8s, is an open-source platform that automates the management process for application containers. It was developed by Google and is now maintained by the Cloud Native Computing Foundation.

## Key Features

- **Auto Scaling:** Kubernetes automatically scales its resources dynamically to meet application's demand.
- **Container Orchestration:** Kubernetes efficiently manages containers across multiple hosts.
- **Self-healing:** It automatically restarts containers that fail, replaces them, and kills containers that don't respond to user-defined health checks.
- **Load Balancing:** Kubernetes can distribute network traffic to ensure stability.
- **Automated Rollouts and Rollbacks:** Allows changes to the application or its configuration while monitoring application health.

## Components

1. **Pods:** The smallest deployable units that can be created, scheduled, and managed.
2. **Services:** An abstraction to expose an application running on a set of Pods.
3. **Volumes:** Provides a way to store data and stateful applications.
4. **Namespaces:** Enable multiple virtual clusters on the same physical cluster.

## Why Use Kubernetes?

- **Portability:** Works across various cloud and on-premises environments.
- **Scalability:** Easily scales applications up or down based on demand.
- **Community Support:** Strong community and ecosystem with numerous resources for learning and troubleshooting.

## Kubernetes Use Cases

### Real life Example - Reddit's Infrastructure Modernization
- **Challenge**: Overcoming limitations of traditional provisioning and configuration.
- **Solution**: Adopted Kubernetes as the core of their internal infrastructure.
- **Outcome**: Addressed drawbacks and failures of the old system, enhancing site reliability​``【oaicite:1】``​.

### Large Scale App Deployment
- **Automation and Scaling:** Ideal for large applications, offering features like horizontal pod scaling and load balancing.
- **Handling Traffic Surges:** Efficient during high-traffic periods and hardware issues.

### Managing Microservices
- **Efficient Communication:** Facilitates communication between smaller, independent services in a microservice architecture.
- **Complex Scenario Management:** Aids in managing complex communications and resource distribution.

### CI/CD Software Development
- **Automation in Pipelines:** Enhances CI/CD processes with automation, improving resource management.
- **Integration with DevOps Tools:** Often used alongside Jenkins, Docker, and other DevOps tools.


## Set-up Kubernetes
The Kubernetes command-line tool, [kubectl](https://kubernetes.io/docs/reference/kubectl/kubectl/), allows you to run commands against Kubernetes clusters.

You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs. For more information including a complete list of kubectl operations, see the kubectl reference documentation.

- [Install kubectl on Linux](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/)

- [Install kubectl on macOS](https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/)

- [Install kubectl on Windows](https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/)


Visit [here](https://kubernetes.io/docs/setup/) for more general guide

## Conclusion

Kubernetes is a powerful tool for managing containerized applications, providing efficiency and flexibility in application deployment and management.

---

For more detailed information, visit the official Kubernetes website: [kubernetes.io](https://kubernetes.io).
6 changes: 4 additions & 2 deletions Topics/Software_Engineering.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ Potential topics--

1. Methodologies & Frameworks
1. Agile
1. Scrum
1. [Scrum](./Software_Engineering/Scrum.md)
1. [User Stories](./Software_Engineering/User_Stories.md)
2. Kanban
3. XP
2. [Waterfall](./Software_Engineering/Waterfall.md)
2. [Waterfall](./Software_Engineering/Waterfall.md)

#### [Deploying Your Personal Website](./Software_Engineering/Deploying_Personal_Website.md)
94 changes: 94 additions & 0 deletions Topics/Software_Engineering/Deploying_Personal_Website.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Deploying your personal website using GitHub

### Why should you create a personal website?

A personal website can be a great way to build a more personalized portfolio to showcase your experience, projects, and achievements to potential employers. They give you more flexibility to present your authentic self and personality, and help you establish a personal brand, as opposed to traditional resumes and CVs. As a student, you might want to build a personal website to not only display your achievements, but also to demonstrate your web development skills and gain some practical learning experience.

If you want to display the same content to every visitor of your site, and you’re looking for a cost-effective solution with lower hosting costs, you might want to opt for a static personal website. However, if you would like to add interactive features like allowing visitors to leave comments on your blog posts that require backend processing, or if you want to experiment with external APIs and databases, a dynamic personal website would be a better choice.

For your reference, here is an example of a [static](https://maruan.alshedivat.com/) personal website. Here is an example of a [dynamic](https://bruno-simon.com/) personal website

## Deploying Static Websites

**Prerequisite:**
Create a [GitHub](https://github.com/) account

**Step 1: Develop your website**

Locally develop your website on your computer. You can use static site generators like [Hugo](https://gohugo.io/), [Jekyll](https://jekyllrb.com/), [Next.js](https://nextjs.org/), or build a simple website using HTML, CSS, and Javascript. Locally test your website and view it using a development server to visualize your website before deployment.

**Step 2: Create a GitHub repository**

Login to GitHub and [create a new repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-new-repository) for your website. [Push](https://docs.github.com/en/migrations/importing-source-code/using-the-command-line-to-import-source-code/adding-locally-hosted-code-to-github) your files from your local machine to your new GitHub repository.

**Step 3: Deploy to Netlify**

- Login to [Netlify](https://app.netlify.com/login) with your GitHub account. Authorize Netlify to access your GitHub account.

<img width="1494" alt="Screenshot 2023-11-22 at 11 19 06 AM" src="https://github.com/learning-software-engineering/learning-software-engineering.github.io/assets/52506101/4949b73e-3e81-459e-8e6d-7c8b43d197d5">

- Click `Add new site` from the Netlify dashboard. Click `Import an existing project` and select `Deploy with GitHub.`

<img width="1206" alt="Screenshot 2023-11-22 at 11 20 55 AM" src="https://github.com/learning-software-engineering/learning-software-engineering.github.io/assets/52506101/91bab809-3e24-4c11-80d6-fac1006800fd">

- Select the repository that you pushed your website code to. Click `Deploy Site` and Netlify will deploy your site for you.

After you’ve deployed, Netlify provides a URL, but you can buy a custom domain and use that instead. You may also benefit from setting up continuous deployment so every time you push changes to your GitHub repository, they will be automatically deployed.

## Deploying Dynamic Websites

**Prerequisites:**
Create a [GitHub](https://github.com/) account

**Step 1: Develop your website**

Build your dynamic website using a backend framework (e.g. Flask, Node.js) and a frontend framework (e.g. React) and thoroughly test your website locally using a development server.

**Step 2: Create a GitHub repository**

Login to GitHub and [create a new repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-new-repository) for your website. [Push](https://docs.github.com/en/migrations/importing-source-code/using-the-command-line-to-import-source-code/adding-locally-hosted-code-to-github) your files from your local machine to your new GitHub repository.

**Step 3: Choose appropriate hosting services**

For dynamic websites, there are hosting services that can deploy both frontend and backend components of your website. Some examples include [Heroku](https://www.heroku.com/), [Amazon Web Services](https://aws.amazon.com/), [Google Cloud Platform](https://cloud.google.com/), and others. However, choosing a separate hosting service for the backend and frontend can offer flexibility and provide you with options for your specific tech stack.

For this tutorial, consider the following tech stack: Python to handle backend logic, Flask to serve JSON responses to be used by the frontend as well as to interact with MySQL, React for creating the frontend, and MySQL to store data.

**Hosting the React frontend:**
- Run `npm run build` or `yarn build` to compile your React app for production
- You can use services like [Netlify](https://www.netlify.com/) or [Vercel](https://vercel.com/) (and many others) to deploy the frontend, but for the purposes of this tutorial, we will use Vercel

1. Login to Vercel with your GitHub account.

<img width="1486" alt="Screenshot 2023-11-22 at 11 25 07 AM" src="https://github.com/learning-software-engineering/learning-software-engineering.github.io/assets/52506101/0ac82ca6-953d-4995-8d42-55f45c3bd1c2">

2. Click `Import Project` on the Vercel dashboard and authorize Vercel to access your GitHub repositories. Choose the repository that you pushed your project to.

<img width="1299" alt="Screenshot 2023-11-22 at 11 26 28 AM" src="https://github.com/learning-software-engineering/learning-software-engineering.github.io/assets/52506101/c1e4ba4e-bf6a-4b37-84dc-b0cd84cc3aa6">


3. Vercel will automatically detect the build settings — all you have to do is click Deploy. Vercel will also automatically deploy your changes pushed to your GitHub repository. Note that Vercel provides a URL to access your website, but you can configure it with a custom domain if you have one.

**Hosting the Python and Flask backend and MySQL server:**

For hosting the backend, we will use [Railway](https://railway.app/). Note that Railway provides a $5 credit to use their services but you may need to sign up for a usage-based subscription to host your Flask backend and MySQL server.

**Python and Flask backend:**
- Login with GitHub.
- In your dashboard, create a new project and choose the option to ‘Deploy from GitHub repo.’ Connect your GitHub repo that has your project.
<img width="1430" alt="Screenshot 2023-11-22 at 11 29 36 AM" src="https://github.com/learning-software-engineering/learning-software-engineering.github.io/assets/52506101/020f270d-5cc7-4367-9a24-6a8aa8fc9b06">
- Specify the root directory to be the directory that has your Flask app (usually a backend folder).
<img width="700" alt="Screenshot 2023-11-22 at 11 30 57 AM" src="https://github.com/learning-software-engineering/learning-software-engineering.github.io/assets/52506101/b6080193-93f5-4659-9aa8-ad4330e42825">
- Specify the language to build the service as Python.
<img width="700" alt="Screenshot 2023-11-22 at 11 31 14 AM" src="https://github.com/learning-software-engineering/learning-software-engineering.github.io/assets/52506101/57ffb91a-5fde-4089-99d4-6c608df319b6">

**MySQL server:**
- Go to the dashboard and create a new project. Choose the option to `Provision MySQL.`
<img width="980" alt="Screenshot 2023-11-22 at 11 35 23 AM" src="https://github.com/learning-software-engineering/learning-software-engineering.github.io/assets/52506101/8e8edbaf-4912-4b32-aa32-1914d89a67d4">
- This automatically sets up a MySQL database for you.
<img width="921" alt="Screenshot 2023-11-22 at 11 35 04 AM" src="https://github.com/learning-software-engineering/learning-software-engineering.github.io/assets/52506101/798378db-3eb5-43a5-b67b-0cd0f3de601a">
- Railway will provide you with all the necessary credentials to use your server (e.g. Host, port, root username and password, etc). You can then configure your backend project settings to use the necessary environment variables that the Flask app will use to connect to the database (as it is generally not good practice to hardcode them in your backend).
<img width="837" alt="Screenshot 2023-11-22 at 11 36 06 AM" src="https://github.com/learning-software-engineering/learning-software-engineering.github.io/assets/52506101/f65ea32c-110c-4875-9ae4-b18c41f586ae">

**Troubleshooting on Vercel and Railway**
A convenient benefit of using services like Vercel and Railway for deployment is that you can review the deployment logs in their respective dashboards to view error messages. In Railway, you can view both build logs and deployment logs for your backend to trace where your issue may be.
Loading

0 comments on commit 37f068e

Please sign in to comment.