diff --git a/2021-2022-summer/automated-testing-and-ci-pipelines/index.html b/2021-2022-summer/automated-testing-and-ci-pipelines/index.html index a031339..9aa1561 100644 --- a/2021-2022-summer/automated-testing-and-ci-pipelines/index.html +++ b/2021-2022-summer/automated-testing-and-ci-pipelines/index.html @@ -8,7 +8,7 @@ - + Automated Testing and CI Pipelines - Coders for Causes Workshops diff --git a/2021-2022-summer/index.html b/2021-2022-summer/index.html index 3939188..8d26160 100644 --- a/2021-2022-summer/index.html +++ b/2021-2022-summer/index.html @@ -8,7 +8,7 @@ - + Overview - Coders for Causes Workshops diff --git a/2021-2022-summer/introduction-to-backend-development-with-django/index.html b/2021-2022-summer/introduction-to-backend-development-with-django/index.html index 55caee0..889feba 100644 --- a/2021-2022-summer/introduction-to-backend-development-with-django/index.html +++ b/2021-2022-summer/introduction-to-backend-development-with-django/index.html @@ -8,7 +8,7 @@ - + Introduction to Backend Development with Django - Coders for Causes Workshops diff --git a/2021-2022-summer/introduction-to-frontend-frameworks/index.html b/2021-2022-summer/introduction-to-frontend-frameworks/index.html index 0b2e18a..f6f4550 100644 --- a/2021-2022-summer/introduction-to-frontend-frameworks/index.html +++ b/2021-2022-summer/introduction-to-frontend-frameworks/index.html @@ -8,7 +8,7 @@ - + Overview - Coders for Causes Workshops diff --git a/2021-2022-summer/introduction-to-react/index.html b/2021-2022-summer/introduction-to-react/index.html index ff6512f..43182d2 100644 --- a/2021-2022-summer/introduction-to-react/index.html +++ b/2021-2022-summer/introduction-to-react/index.html @@ -8,7 +8,7 @@ - + Introduction to React - Coders for Causes Workshops diff --git a/2021-2022-summer/introduction-to-vue/index.html b/2021-2022-summer/introduction-to-vue/index.html index fe73e10..3de41ab 100644 --- a/2021-2022-summer/introduction-to-vue/index.html +++ b/2021-2022-summer/introduction-to-vue/index.html @@ -8,7 +8,7 @@ - + Introduction to Vue - Coders for Causes Workshops diff --git a/2021-2022-summer/introduction-to-web-development/index.html b/2021-2022-summer/introduction-to-web-development/index.html index e0eda7e..5da4587 100644 --- a/2021-2022-summer/introduction-to-web-development/index.html +++ b/2021-2022-summer/introduction-to-web-development/index.html @@ -8,7 +8,7 @@ - + Introduction to Web Development - Coders for Causes Workshops diff --git a/2021-2022-summer/introduction-web-basics/index.html b/2021-2022-summer/introduction-web-basics/index.html index 8f7cd95..d8eab7a 100644 --- a/2021-2022-summer/introduction-web-basics/index.html +++ b/2021-2022-summer/introduction-web-basics/index.html @@ -8,7 +8,7 @@ - + Introduction to Web Basics - Coders for Causes Workshops diff --git a/2021-2022-summer/mvc-mvmm-architecture-and-communications/index.html b/2021-2022-summer/mvc-mvmm-architecture-and-communications/index.html index c28c0b6..4fa60d2 100644 --- a/2021-2022-summer/mvc-mvmm-architecture-and-communications/index.html +++ b/2021-2022-summer/mvc-mvmm-architecture-and-communications/index.html @@ -8,7 +8,7 @@ - + MVC-MVMM Architecture and Communications - Coders for Causes Workshops diff --git a/2021-2022-summer/package-managers/index.html b/2021-2022-summer/package-managers/index.html index 5a78179..930ae50 100644 --- a/2021-2022-summer/package-managers/index.html +++ b/2021-2022-summer/package-managers/index.html @@ -8,7 +8,7 @@ - + Package Managers - Coders for Causes Workshops diff --git a/2021-2022-summer/practical-software-engineering-practices/index.html b/2021-2022-summer/practical-software-engineering-practices/index.html index d6f82d7..7c7a980 100644 --- a/2021-2022-summer/practical-software-engineering-practices/index.html +++ b/2021-2022-summer/practical-software-engineering-practices/index.html @@ -8,7 +8,7 @@ - + Practical Software Engineering Practices - Coders for Causes Workshops diff --git a/2021-2022-summer/project-and-workshop-structure/index.html b/2021-2022-summer/project-and-workshop-structure/index.html index 0dc4397..4663049 100644 --- a/2021-2022-summer/project-and-workshop-structure/index.html +++ b/2021-2022-summer/project-and-workshop-structure/index.html @@ -8,7 +8,7 @@ - + Project and Workshop Structure - Coders for Causes Workshops diff --git a/2021-2022-summer/setup/index.html b/2021-2022-summer/setup/index.html index 3a79422..3251ce5 100644 --- a/2021-2022-summer/setup/index.html +++ b/2021-2022-summer/setup/index.html @@ -8,7 +8,7 @@ - + Setup - Coders for Causes Workshops diff --git a/2021-2022-summer/typical-codebase-structure/index.html b/2021-2022-summer/typical-codebase-structure/index.html index c9c8e5a..f6b481b 100644 --- a/2021-2022-summer/typical-codebase-structure/index.html +++ b/2021-2022-summer/typical-codebase-structure/index.html @@ -8,7 +8,7 @@ - + Typical Codebase Structure - Coders for Causes Workshops diff --git a/2021-winter/index.html b/2021-winter/index.html index 0562483..86a552b 100644 --- a/2021-winter/index.html +++ b/2021-winter/index.html @@ -7,7 +7,7 @@ - + Overview - Coders for Causes Workshops diff --git a/2022-2023-summer/index.html b/2022-2023-summer/index.html index f4faca2..abb5567 100644 --- a/2022-2023-summer/index.html +++ b/2022-2023-summer/index.html @@ -8,7 +8,7 @@ - + Overview - Coders for Causes Workshops diff --git a/2022-2023-summer/introduction-to-web-development/index.html b/2022-2023-summer/introduction-to-web-development/index.html index f5a28b6..65b2229 100644 --- a/2022-2023-summer/introduction-to-web-development/index.html +++ b/2022-2023-summer/introduction-to-web-development/index.html @@ -8,7 +8,7 @@ - + Introduction to Web Development - Coders for Causes Workshops diff --git a/2022-2023-summer/mvc-mvvm-architecture-and-communications/index.html b/2022-2023-summer/mvc-mvvm-architecture-and-communications/index.html index ad649bc..b804f8f 100644 --- a/2022-2023-summer/mvc-mvvm-architecture-and-communications/index.html +++ b/2022-2023-summer/mvc-mvvm-architecture-and-communications/index.html @@ -8,7 +8,7 @@ - + MVC and MVVM Software Architectural Patterns and Communications - Coders for Causes Workshops diff --git a/2022-2023-summer/practical-software-engineering-workflow/index.html b/2022-2023-summer/practical-software-engineering-workflow/index.html index fc1b43a..ccf83b0 100644 --- a/2022-2023-summer/practical-software-engineering-workflow/index.html +++ b/2022-2023-summer/practical-software-engineering-workflow/index.html @@ -8,7 +8,7 @@ - + Practical Software Engineering Workflow - Coders for Causes Workshops diff --git a/2022-2023-summer/typical-codebase-structure/index.html b/2022-2023-summer/typical-codebase-structure/index.html index 238b46e..68c65a5 100644 --- a/2022-2023-summer/typical-codebase-structure/index.html +++ b/2022-2023-summer/typical-codebase-structure/index.html @@ -6,7 +6,7 @@ - + Typical Codebase Structure - Coders for Causes Workshops diff --git a/2023-winter/introduction-to-backend-development-with-django/index.html b/2023-winter/introduction-to-backend-development-with-django/index.html index 0451d0a..27f05ac 100644 --- a/2023-winter/introduction-to-backend-development-with-django/index.html +++ b/2023-winter/introduction-to-backend-development-with-django/index.html @@ -8,7 +8,7 @@ - + Welcome to the Djangol! - Coders for Causes Workshops diff --git a/2024-winter/introduction-to-docker/index.html b/2024-winter/introduction-to-docker/index.html index e9718fb..9c7818d 100644 --- a/2024-winter/introduction-to-docker/index.html +++ b/2024-winter/introduction-to-docker/index.html @@ -8,7 +8,7 @@ - + Introduction to Docker - Coders for Causes Workshops @@ -598,7 +598,7 @@

What you will be bui

CFC wants to make an app for accepting coffee orders. You will be creating a Dockerfile for CFC's (totally real) new and upcoming rebrand: Coders for Coffee 🐳. The architecture is a simple frontend and backend both made in TypeScript. Below is a diagram of it:

App Architecture

Important information

-

This workshop relies on a certain understanding of terminal commands and a bit of familiarity with Node.js projects.

+

This workshop relies on a certain understanding of terminal commands and a bit of familiarity with Node.js projects. If you're not familiar with these, don't worry! I'll be explaining everything as we go along. If you have any questions, feel free to ask.

What is Docker?

Docker is a platform for developing, shipping, and running applications using containerization. It allows you to package an application and its dependencies into a container that can run on any machine. This makes it easy to deploy applications in a consistent and reproducible way. Simply put, it's like a way of running mini virtual machines inside your computer.

Why use Docker?

@@ -675,7 +675,7 @@

Building and running an image
1
docker build -t docker-workshop-backend ./apps/backend
 
-

This command builds an image from the Dockerfile in the apps/backend directory and tags it (-t) with the name docker-workshop-backend.

+

This command builds an image from the Dockerfile in the apps/backend directory and tags it (-t) with the name docker-workshop-backend. Otherwise, Docker will give it a random name.

Now, let's run the image we've built:

1
docker run -p 3001:3001 docker-workshop-backend
 
@@ -683,7 +683,7 @@

Building and running an imagePort Mapping

But wait, what does -p 3001:3001 do? I mentioned earlier that Docker basically runs mini virtual machines --- so let's visualise what that looks like.

Docker Port Mapping

-

In order for our container to make connect with the outside world, we need to create a little tunnel. This is done by mapping a port on the host machine to a port on the container. In our case, I've configured the backend to run internally on port 3001. Therefore, we need to map that internal port to a port on the host machine so we can access it. I kept it simple and mapped it to the same port, but you can change it to any port you like (given our frontend knows about it). Ports are mapped like this: -p <host-port>:<container-port> This is one of the security goals of Docker.

+

In order for our container to make connect with the outside world, we need to create a little tunnel. This is done by mapping a port on the host machine to a port on the container. In our case, I've configured the backend to run internally on port 3001. Therefore, we need to map that internal port to a port on the host machine so we can access it. I kept it simple and mapped it to the same port, but you can change it to any port you like (given our frontend knows about it). Ports are mapped like this: -p <host-port>:<container-port> This also improves security, as you can run multiple containers on the same host machine without them interfering with each other.

Now, visit http://localhost:3001 to see the backend now running from a Docker container.

Manual build

@@ -692,12 +692,13 @@

Step 1: What are we building?Step 2: Mapping them to commands

-

The frontend is a React app that uses TypeScript. Now let's:

+

The frontend is a React app that uses TypeScript, so we'll follow the template. If you're unsure, you can always Google what you need e.g. "How to install dependenceis React app":

    +
  1. In your terminal, navigate to the frontend directory: cd apps/frontend
  2. Install dependencies: npm install
  3. Build the app: npm run build
  4. Serve the build files: npm run start
  5. @@ -719,11 +720,11 @@

    Step 2: Mapping them to commands // ... } -

    You can run these commands in the terminal and open it up at http://localhost:9876/ to see the optimised production build of the frontend. Notice how the bottom text has changed from "development" to "production".

    +

    You can run these commands in the terminal yourself and open it up at http://localhost:9876/ to see the optimised production build of the frontend. Notice how the bottom text has changed from "development" to "production".

    Creating a Dockerfile

    When creating a Dockerfile, it's essentially the same process as manually doing it. The only difference is that you're automating it in a file.

    Base image

    -

    All Dockerfiles start with a FROM command, which specifies the base image to use. This image is usually a lightweight Linux distribution with the necessary tools and libraries to run the application. For our frontend, we will use the node:20-alpine image.

    +

    All Dockerfiles start with a FROM command, which specifies the base image to use. This image is usually a lightweight Linux distribution with the necessary tools and libraries to run the application. For our frontend, we will use the node:20-alpine image. This specifies the (as of writing) LTS version of Node.js with the Alpine Linux distribution.

    How do I know what image to use?

    There are a number of things to consider when choosing a base image:

    @@ -739,7 +740,7 @@

    Base imageFROM node:20-alpine

    Working directory

    -

    We're in linux land now. We're first going to create a directory to put our production files in. This is done with the WORKDIR command.

    +

    We're in linux land now. First, let's create a directory to put our production files in. This is done with the WORKDIR command.

    1
     2
     3
    @@ -771,7 +772,7 @@ 

    Copying filesThis command copies everything in the same directory where the Dockerfile is (.) from the host machine to the working directory in the container (./). This is the bare minimum we need to build the frontend. i.e. src, public, package.json, etc.

    Installing dependencies and building

    -

    Now that we have our source code in the image, we need to install the dependencies. This is done with the RUN command. Here, we run both npm install and npm run build in succession using &&.

    +

    Now that we have our source code in the image, we need to install the dependencies. This is done with the RUN command. You can execute any supported command from the base image specified. Here, we run both npm install and npm run build in succession using &&.

    1
     2
     3
    @@ -863,7 +864,7 @@ 

    Prune the dependenciesCOPY . ./ -# cleanup in the same layer +# Cleanup in the same layer RUN npm install && npm run build && npm prune --production # Serve the build files diff --git a/404.html b/404.html index c7a54aa..4157db5 100644 --- a/404.html +++ b/404.html @@ -12,7 +12,7 @@ - + diff --git a/contributions/index.html b/contributions/index.html index e3025c9..b8de05c 100644 --- a/contributions/index.html +++ b/contributions/index.html @@ -8,7 +8,7 @@ - + Contributions - Coders for Causes Workshops diff --git a/index.html b/index.html index ad1a5da..6baea99 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ - + Overview - Coders for Causes Workshops diff --git a/search/search_index.json b/search/search_index.json index 8ed1489..5ef67cd 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Coders for Causes Workshops","text":"

    This is where you can see all the materials for workshops that are presented to the volunteers of the project for each year.

    If you would to know more about us, please visit our website at codersforcauses.org

    "},{"location":"contributions/","title":"Contributions","text":"

    Hi! We are happy that you thought of contributing! If you have any suggestions or issues, please raise it here. I would be happy if you could provide pull requests, if you know how to do it here.

    "},{"location":"contributions/#structure","title":"Structure","text":""},{"location":"contributions/#folder-structure","title":"Folder Structure","text":"

    The structure of this repo is as follows:

    \u251c\u2500\u2500 docs                    // Folders for documentation\n\u2502   \u251c\u2500\u2500 CNAME\n\u2502   \u251c\u2500\u2500 contributions.md\n\u2502   \u251c\u2500\u2500 deployment_and_automated_site_deployment.md\n\u2502   \u251c\u2500\u2500 flavoured_markdown.md\n\u2502   \u251c\u2500\u2500 images              // Assets\n\u2502   \u2502   \u2514\u2500\u2500 ...\n\u2502   \u2502   \n\u2502   \u251c\u2500\u2500 index.md\n\u2502   \u2514\u2500\u2500 writing_markdown.md\n\u251c\u2500\u2500 LICENSE\n\u251c\u2500\u2500 mkdocs.yml              // MkDocs Configuration\n\u251c\u2500\u2500 overrides\n\u2502   \u2514\u2500\u2500 partials\n\u2502       \u2514\u2500\u2500 footer.html\n\u251c\u2500\u2500 README.md\n\u2514\u2500\u2500 requirements.txt\n
    "},{"location":"contributions/#installation","title":"Installation","text":""},{"location":"contributions/#python","title":"Python","text":"Prerequisite

    You need to have Python installed to be able to use pip. There are a few ways of installing Python. You can use a package distributor like Anaconda Or you can just install Python.

    Once you have installed Python, install mkdocs requirements by opening a terminal and typing:

    pip install -r requirements.txt\n
    Python Environments (Optional)

    however, it is good practice to use different environments for different purposes, in which case, for Anaconda, you would open a terminal and type:

    conda create -n mkdocstutorial python\nconda activate mkdocstutorial\n
    then enter:

    pip install -r requirements.txt\n
    "},{"location":"contributions/#docker","title":"Docker","text":"

    Just run docker-compose up, it should show the web server running at localhost:8000

    "},{"location":"contributions/#commands","title":"Commands","text":"
    • mkdocs new [dir-name] - Create a new project.
    • mkdocs serve - Start the live-reloading docs server. Very helpful when you want to take a look at the docs before deploying.
    • mkdocs build - Build the documentation site.
    • mkdocs -h - Print help message and exit.
    • mkdocs gh-deploy - Deploy in github pages
    "},{"location":"contributions/#web-documentation-configuration","title":"Web Documentation Configuration","text":"

    For full documentation visit:

    • mkdocs.org for the generic MkDocs
    • PyMdown Extensions for the different extensions that are installed
    • MkDocs Material for the customisation of the web server documentation.
    "},{"location":"2021-2022-summer/","title":"Coders for Causes 2021/22 Summer Workshops","text":"

    This project period continues the two main projects from the winter of 2020 :

    • Foodbank
    • WAIS

    If you have not before seen the existing progress, see this video.

    These two projects have their own corresponding technology stacks being used, hence will dictate the workshops that will be held.

    "},{"location":"2021-2022-summer/#project-technology","title":"Project Technology","text":""},{"location":"2021-2022-summer/#foodbank","title":"Foodbank","text":"

    Foodbank is mainly with frontend with React + NextJS + TypeScript + TailwindCSS with Firebase and Notion CMS.

    "},{"location":"2021-2022-summer/#wais","title":"WAIS","text":"

    WAIS is a full-stack application with Vue and Django. It uses Docker containerisation for both development (and production in the future).

    "},{"location":"2021-2022-summer/#workshop-recordings","title":"Workshop Recordings","text":"

    The workshop recordings will be held on our youtube channel.

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/","title":"Automated Testing and CI Pipelines","text":""},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#what-is-the-problem-with-manual-testing","title":"What is the problem with manual testing?","text":"
    • tedious
    • some scenarious are hard to repeat
      • eg. network issues, database randomly crashes
    • repetitive
    • growning number of scenarios
    • time consuming
    Cost Savings Scenarios that are hard to repeat - Network Requests
    import requests\ndef make_network_request():\ntry:\n    response = requests.get(\"https://www.google.com\")\n    if response.status_code == 200:\n        return response.text\n    else:\n        return None\nexception requests.exceptions.ConnectionError:\n    return None\n

    This is the way to simulate an exception after a network request.

    import pytest\ndef test_make_network_request_exception(mocker):\n    mocker.patch(\"requests.get\", side_effect=requests.exceptions.ConnectionError)\n    assert make_network_request() is None\n

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#importance-of-software","title":"Importance of Software","text":"

    Before you can truly understand why testing is important, we first have to understand the importance of software.

    Importance of software in different parts

    Control Systems

    Healthcare

    Transportations

    Daily life

    Office Work

    Education

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#software-is-fragile","title":"Software is Fragile","text":"Quote

    It only takes a character difference to prevent a software from compiling or running.

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#consequences-of-fault-softwares","title":"Consequences of Fault Softwares","text":"

    Huge Compute Charges

    Embarrassment

    Disruptions

    User Frustations

    Client loss

    Death

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#automated-testing","title":"Automated Testing","text":""},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#what-is-involved-manual-testing-usually","title":"What is involved manual testing usually?","text":"

    To be able to automate testing, we need to understand what is involved in manual testing.

    • Open your own environment and tools
    • Git checkout/pull/fetch
    • Install dependency
    • Setup the environment
      • Do you need to clear the database?
      • Do you need to enter a couple of data?
      • Do you need to disconnect the internet while server is running?
    • Perform the steps to test
    • Assert the test correction?
    • Did you make a mistake? (repeat the entire thing)
    • Now do a different scenario!
    • Hang on a sec? Your coworker forgot to push? Now do all scenarios again
    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#how-does-automated-testing-work","title":"How does automated testing work?","text":"
    • Write scripts to evaluate code
    • Write script to run scripts when certain events happen (more so later)
    • Update Scripts whenever change happens
    Example from the workshop with github actions - Software Engineering Practices
    name: Python package\n\non:\npull_request:\nworkflow_dispatch:\n    inputs:\n    logLevel:\n        description: \"Log level\"\n        required: false\n        default: \"warning\"\n\njobs:\nflake8_py3:\n    name: \"Linting with Flake8\"\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@v2\n\n    - name: \"Set up Python\"\n        uses: actions/setup-python@v2\n        with:\n        python-version: 3.x\n\n    - name: \"Install flake8\"\n        run: pip install flake8\n\n    - name: \"Run flake8\"\n        uses: liskin/gh-problem-matcher-wrap@v1\n        with:\n        linters: flake8\n        run: flake8 --max-line-length 150 .\n\ntest:\n    runs-on: ubuntu-latest\n    strategy:\n    matrix:\n        python-version: [3.8] # you can add more python version to test it in\n\n    steps:\n    - uses: actions/checkout@v2\n    - name: Set up Python ${{ matrix.python-version }}\n    uses: actions/setup-python@v2\n    with:\n        python-version: ${{ matrix.python-version }}\n    - name: Install dependencies\n    run: |\n        python -m pip install --upgrade pip\n        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi\n    - name: Test with pytest\n    run: |\n        pytest --cov-report html --cov=.\n    - uses: actions/upload-artifact@v1\n    if: always()\n    with:\n        name: coverage-report\n        path: htmlcov\n
    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#test-driven-development","title":"Test-Driven Development","text":"

    Define test/specification first, then write functionality. Works best if you know way ahead of time what you want.

    Note: This does not always work (eg. Frontend)

    Simple Example
    def test_add_two_numbers():\nassert add_two_numbers(1, 2) == 3\n
    def add_two_numbers(a, b):\n    return a + b\n
    More complex example, but demonstrates how it can save time

    Let say you have to develop a function that sends email depending on the number of users in the database

    from django.core.mail import send_mail\n# Not guaranteed to work code\ndef send_email_to_admin():\n    number_of_users = User.objects.count()\n    send_mail(\"Number of users\", f\"There are {number_of_users} users in the database\", \"no-reply@system.com\",[\"admin@system.com\"])\n

    from django.core import mail\nfrom module import send_email_to_admin\nclass EmailTest(TestCase):\n    def setup():\n        # Create users\n        User.objects.create(username=\"admin\" ...)\n\n    def test_send_email_to_admin(self):\n        send_email_to_admin()\n\n        # Test that one message has been sent.\n        self.assertEqual(len(mail.outbox), 1)\n\n        self.assertEqual(mail.outbox[0].subject, \"Number of users\")\n        self.assertTrue(\"1 users in the database\" in mail.outbox[0].body)\n        ...\n

    Usual workflow:

    1. Prepare your tools - mail client and smtp server
    2. Prepare your database
    3. Do manual testing + Write code (repeat)
    4. Write Automated testing

    Test Driven development workflow (also known as red-green-refactor):

    1. Write the Automated Testing - when this is run it will fail
    2. Write code until test pass
    3. Refactor + improve code
    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#given-when-then","title":"GIVEN-WHEN-THEN","text":"

    Acceptance of features can be divided into: - GIVEN \u2013 what are the assumptions - WHEN \u2013 occurence - THEN - effect or observation

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#what-is-cicd","title":"What is CI/CD?","text":"

    Scripts that runs for certain events (such as pull request, a commit) to run test or deploy

    Providers
    • Github Actions
    • Circle CI
    • Bitbucket Pipelines
    • Travis CI
    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#whats-usually-in-ci","title":"What's usually in CI?","text":"
    • Linting (code consistency + undefined variables)
    • Tests
    • Builds + Deploy

    Others: - bot to auto tag issue - Security checks - Code Autosuggestion (kinda like linting, but it suggests stuff)

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#testing-artifacts","title":"Testing Artifacts","text":"

    Files given when testing

    Coverage Report

    Cypress Screenshots + Videos

    Long term test reports

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#demo-cypress-integration-test-e2e-test","title":"Demo - Cypress Integration Test / E2E Test","text":"

    Cypress is a tool that simulates user interaction by programatically performing action against a browser.

    Get started at Cypress.

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/","title":"Welcome to the Djangol!","text":"

    We've got puns 'n' data, We\u2019ve got everything you request

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#how-does-an-application-communicate-with-backend-systems","title":"How does an application communicate with backend systems?","text":"

    JavaScript Object Notation

    JSON

    Link

    [\n{\n    \"id\": 1,\n    \"name\": \"Leanne Graham\",\n    \"username\": \"Bret\",\n    \"email\": \"Sincere@april.biz\",\n    \"address\": {\n    \"street\": \"Kulas Light\",\n    \"suite\": \"Apt. 556\",\n    \"city\": \"Gwenborough\",\n    \"zipcode\": \"92998-3874\",\n    \"geo\": {\n        \"lat\": \"-37.3159\",\n        \"lng\": \"81.1496\"\n    }\n    },\n    \"phone\": \"1-770-736-8031 x56442\",\n    \"website\": \"hildegard.org\",\n    \"company\": {\n    \"name\": \"Romaguera-Crona\",\n    \"catchPhrase\": \"Multi-layered client-server neural-net\",\n    \"bs\": \"harness real-time e-markets\"\n    }\n},\n...\n{\n    \"id\": 10,\n    \"name\": \"Clementina DuBuque\",\n    \"username\": \"Moriah.Stanton\",\n    \"email\": \"Rey.Padberg@karina.biz\",\n    \"address\": {\n    \"street\": \"Kattie Turnpike\",\n    \"suite\": \"Suite 198\",\n    \"city\": \"Lebsackbury\",\n    \"zipcode\": \"31428-2261\",\n    \"geo\": {\n        \"lat\": \"-38.2386\",\n        \"lng\": \"57.2232\"\n    }\n    },\n    \"phone\": \"024-648-3804\",\n    \"website\": \"ambrose.net\",\n    \"company\": {\n    \"name\": \"Hoeger LLC\",\n    \"catchPhrase\": \"Centralized empowering task-force\",\n    \"bs\": \"target end-to-end models\"\n    }\n}\n]\n

    Query this endpoint using JavaScript
    fetch(\"https://jsonplaceholder.typicode.com/users\")\n    .then(response => response.json())\n    .then(data => console.log(data))\n
    Other ways

    JSON is not the only way. There are things like SOAP, RPC, but nevermind them for now as you will most likely have to deal with JSON for the most parts.

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#what-are-apis-and-rest-apis","title":"What are APIs and REST-APIs?","text":"

    Application Programming Interface

    Analogy

    Who interacts with the user interface? - the user Who interacts with the application programming interface ? - the application program (eg. the browser)

    Representational State Transfer Application Programming Interface

    • backend architectural pattern that follows the GET/POST/PUT/PATCH/DELETE

    • Can be represented in Swagger/ Open API specification

    Swagger/ Open API specification

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#what-is-django","title":"What is Django?","text":"

    Django

    • Python web framework for creating server-side application

    Follows MVC:

    • Model - database
    • View \u2013 Interface (API or User Interface)
    • Controller \u2013 URLs + routes

    See Documentation

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#what-is-django-rest-framework-drf","title":"What is Django REST Framework (DRF)?","text":"
    • library for creating REST-API
    • just makes it easier develop REST-API

    In:

    • Authentication + Permission
    • Generic API Views
    • Serialisers (payload validation and format)

    See Documentation

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#features-of-django-and-drf","title":"Features of Django and DRF","text":""},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#serializers","title":"Serializers","text":"
    • converter to and from Python Data types to JSON/XML
    • can be used to do validation

    More info here

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#models","title":"Models","text":"

    Models

    • representation of database connection or schema Example: Todo Django + React
    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#models-with-serializers","title":"Models with Serializers","text":"
    • Model already defined the structure of the data
    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#configuration-file-settingspy","title":"Configuration file settings.py","text":"

    One of the most important file - determines the app configurations and default

    Example of Items you can configure
    • timezones
    • start of URL
    • installed Django Apps
    • middlewares
    • usually becomes the \"default\" configs after environment variables
    • database configuration
    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#route-with-urls","title":"Route with URLs","text":"

    Determines the URL route of the API

    • starts with the urls.py in the config (settings.py)
    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#packaging-a-django-app","title":"Packaging a \"Django App\"","text":"

    \"Django Apps\" are plugin system of Django. Django codebase prefers packaging each endpoint feature to a \"Django App\"

    Authenticate with Microsoft

    For example: django-saml2-auth-lw (used for Microsoft SAML SSO)

    More documentation can be seen here

    You can start creating your own Django app by following the steps:

    1. python manage.py startapp <app_name>. This will bootstrap commonly used files for any \"app\".
    2. Add the app in the INSTALLED_APPS in\u00a0 the settings.py
    3. python manage.py makemigrations to create the migration scripts
    4. python manage.py migrate to run the migration script
    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#views","title":"Views","text":"

    The interface at which any application program interacts with to get something done in the backend.

    Use DRF instead of Base Django

    This is where it gets a little tricky. Django accomodates both frontend and backend, but where it shines is with DRF. So always refer to documentation regarding write it from the documentation.

    If you plan to use Django as an entire full-stack option, then you may not need DRF at all. Just use the generic views.

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#function-based-views-and-class-based-views","title":"Function-based Views and Class-based Views","text":"Codes

    Summary: In DRF, there's a lot more advantage to use class-based views. However, if you want the flexibility and writing things on your own, then you might want to use function-based view.

    Function-Based View

    Link:

    from django.shortcuts import render\nfrom django.http import JsonResponse\n\nfrom rest_framework.decorators import api_view\nfrom rest_framework.response import Response\nfrom .serializers import TaskSerializer\n\nfrom .models import Task\n\n@api_view(['GET'])\ndef apiOverview(request):\n    api_urls = {\n        'List':'/task-list/',\n        'Detail View':'/task-detail/<str:pk>/',\n        'Create':'/task-create/',\n        'Update':'/task-update/<str:pk>/',\n        'Delete':'/task-delete/<str:pk>/',\n        }\n\n    return Response(api_urls)\n\n@api_view(['GET'])\ndef taskList(request):\n    tasks = Task.objects.all().order_by('-id')\n    serializer = TaskSerializer(tasks, many=True)\n    return Response(serializer.data)\n\n@api_view(['GET'])\ndef taskDetail(request, pk):\n    tasks = Task.objects.get(id=pk)\n    serializer = TaskSerializer(tasks, many=False)\n    return Response(serializer.data)\n\n\n@api_view(['POST'])\ndef taskCreate(request):\n    serializer = TaskSerializer(data=request.data)\n\n    if serializer.is_valid():\n        serializer.save()\n\n    return Response(serializer.data)\n\n@api_view(['POST'])\ndef taskUpdate(request, pk):\n    task = Task.objects.get(id=pk)\n    serializer = TaskSerializer(instance=task, data=request.data)\n\n    if serializer.is_valid():\n        serializer.save()\n\n    return Response(serializer.data)\n\n\n@api_view(['DELETE'])\ndef taskDelete(request, pk):\n    task = Task.objects.get(id=pk)\n    task.delete()\n\n    return Response('Item succsesfully delete!')\n

    Class-Based View

    To be seen in in the live demos

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#django-admin","title":"Django Admin","text":"

    Django comes with a built-in user-interface for managing \"Django Apps\" with models.py By default it in the path /admin

    Django Admin

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#other-tools","title":"Other Tools","text":""},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#drf-frontend-for-consuming-api","title":"DRF Frontend for Consuming API","text":"

    When you use DRF for developing API, and use the generic API views and serializers, it will automatically create this for you.

    DRF Frontend

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#postman","title":"Postman","text":"

    Development tool for interacting with APIs:

    • environment variables
    • collection of possible endpoints
    • send different JSON body
    Postman

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#python-debugger-pdb","title":"Python Debugger (pdb)","text":"

    When you run the django python manage.py runserver, you can add breakpoint() to anywhere piece of your code. This will stop the terminal line to the breakpoint if it hits it. From here you can do debugging.

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#demo-live-coding","title":"Demo - Live Coding","text":"

    Demonstrate how to create a backend for a Todo app.

    1. Setup Python environment python -m venv venv then activate with source venv/bin/activate
    2. Install Django pip install Django
    3. Setup django codebase django-admin startproject todo
    4. Install DRF

      # As per https://www.django-rest-framework.org/#installation\npip install djangorestframework\npip install markdown       # Markdown support for the browsable API.\npip install django-filter  # Filtering support\npip install pytz           # Timezone support\n

    5. Freeze requirements pip freeze > requirements.txt

    6. Do a python sqlite migration python manage.py migrate to initialise the Django database for the apps
    7. Create a super user python manage.py createsuperuser
    8. Run the django app with python manage.py runserver
    9. Login with the super user and show Django Admin
    10. Setup django app python manage.py startapp api
    11. Create a model models.py

      from django.db import models\n\n# Todo Model\nclass Todo(models.Model):\n    title = models.CharField(max_length=100)\n    description = models.TextField()\n    completed = models.BooleanField(default=False)\n    created_at = models.DateTimeField(auto_now_add=True)\n    updated_at = models.DateTimeField(auto_now=True)\n\n    def __str__(self):\n        return self.title\n

    12. Do a python sqlite migration python manage.py makemigrations and python manage.py migrate

    13. Show sqlite
    14. Create serialiser serializers.py

      from api.models import Todo\nfrom rest_framework import serializers\n\nclass TodoSerializer(serializers.ModelSerializer):\n    \"\"\"\n    Serializer for Todo model\n    \"\"\"\n    class Meta:\n        model = Todo\n        # All fields\n        fields = '__all__'\n

    15. Create Class-based view views.py and link back to the urls.py

      # api/views.py\nfrom django.shortcuts import render\nfrom rest_framework import viewsets, permissions\nfrom api.serializers import TodoSerializer\nfrom api.models import Todo\n\n# Class Model Viewset\nclass TodoModelViewSet(viewsets.ModelViewSet):\n    # Define the serializer class\n    serializer_class = TodoSerializer\n    # Define the queryset\n    queryset = Todo.objects.all()\n\n    # Permissions (left to your own exercise)\n    # permission_classes = [permissions.IsAuthenticated]\n\n    # Define the list of allowed HTTP methods (by default if you didn't define it, it will just enable all)\n    http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']\n
      # api/urls.py\nfrom django.urls import path, include\nfrom rest_framework import routers\nfrom api.views import TodoModelViewSet\n\nrouter = routers.DefaultRouter(trailing_slash=False)\nrouter.register(r'todos', TodoModelViewSet)\n\nurlpatterns = [\n    path('', include(router.urls)),\n]\n
      # urls.py\nfrom django.contrib import admin\nfrom django.urls import path, include\n\nurlpatterns = [\n    path('admin/', admin.site.urls),\n    path('api-auth/', include('rest_framework.urls')),\n    path('api/', include('api.urls')),\n]\n

    16. Manually test with DRF Frontend or postman

    Final code can be seen here.

    Read through the Viewset Documentation

    Viewsets are one of the most powerful feature ever. In just a couple of lines of code, you can create a CRUD API for your models.

    As one of my favourite developer once said,

    Quote

    Frinze, Viewset is the future! - J. Morales

    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/","title":"Introduction to Frontend Frameworks","text":"

    An intuitive explanation of why frontend frameworks are used

    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#frontend-engineering","title":"Frontend Engineering","text":"
    • Frontend Engineering, one of the most important aspect of web dev
    • Feared by lots of developers (ehem ehem CSS)
    Memes"},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#job-market-and-trends","title":"Job Market and Trends","text":"StackOverflow 2020

    Can be seen that there is a huge portion that will needs frontend.

    Note: Developers can identify as many types

    Startups

    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#github-copilot-and-drag-and-drops","title":"Github Copilot and Drag and Drops","text":"
    • Getting replaced by AIs, Drag and drops?
    • Far from reality?
    Github Copilot and Squarespace"},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#problems","title":"Problems","text":""},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#cross-browser-support","title":"Cross-Browser Support","text":"
    • Need to support multiple browsers
    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#html-is-wet","title":"HTML is WET!","text":"

    Not DRY = WET

    D \u2013 Don't

    R \u2013 Repeat

    Y - Yourself

    Github Tags System

    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#inefficiencies-of-reloading","title":"Inefficiencies of Reloading","text":"
    • Most parts of website don't change
    Youtube
    • What about with notifications and realtime updates?
    notifications"},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#state-management-and-rerendering","title":"State Management and Rerendering","text":"
    • How do you handle changes in the state of the application?
    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#example-spotimania","title":"Example \"Spotimania\"","text":"

    Realtime Multiplayer Song Guessing Game https://spotimania.herokuapp.com/

    Information

    • Song picture
    • Notifications when someone joined or scored
    • Song title + artist

    How do we handle when we \"Submit Guess\"?

    HTML Format Submit Approach
    1. Reloads = loses current state
    2. How do you coordinate with players?
    AJAX Calls
    1. From frontend, use JS to do AJAX Calls
    2. After receiving AJAX call, modify everything that needs the data (Find element by DOM, do some janky HTML inject)
    const newData = await fetch(\u2026)\nconst image = document.querySelector('img .music')\nimage.outerText = `<img src={newData.image} / >`\n
    Cross-site Scripting

    Now, you have to implement your own strategy to do this.

    newData = {\u2026 , image: \"<script>hack()</script>\", ...}\n

    When you try to do render by that approach:
    • slower (rerendering things that should not render)
    • tedious (find element and update)
    • security
    • code complexity
    • hard to keep track of states (especially if different portion of the UI relies on a certain data)
    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#how-do-we-fix-it","title":"How do we fix it?","text":""},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#cross-browser-support_1","title":"Cross-Browser Support","text":"

    Babel: Transpiles / Translates New JavaScript to old JavaScript that is supported

    Webpack: Bundles / Packs Bundles the JavaScript modules into a single minified file

    SCSS Compilation

    Translates concise and programatic version of CSS to something that can be understood by the browser

    Minification

    Makes files smaller by removing unnecessary characters

    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#what-if-html-is-not-wet-what-if-html-is-a-programming-language","title":"What if HTML is NOT WET? What if HTML is a programming language?","text":"Memes about HTML as a programming language

    What if HTML has variables?

    • perform computations to be displayed in the interface (solves State Management and Rerendering)

    What if HTML has loops?

    • Eliminate repetitive code (solves wet HTML)

    What if HTML has functions?

    • Divide interface into modular components (solves wet HTML)
      • load only components that are not loaded (solves Inefficiencies of Reloading)
    • interface determined by parameters
    • Maybe we can write a function that will automatically update HTML when data changes? (solves State Management and Rerendering)

    What if HTML has condition?

    • Conditional rendering (solves Reloading to show different view)
    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#whats-next","title":"What's next?","text":"

    The next two workshop content are:

    • React
    • Vue
    "},{"location":"2021-2022-summer/introduction-to-react/","title":"Introduction to React","text":"

    Sparking the REACTion of User Interface and Experience

    "},{"location":"2021-2022-summer/introduction-to-react/#decomposing-the-html-user-interface","title":"Decomposing the HTML User Interface","text":"Complete code
    <!DOCTYPE html>\n<html lang=\"en\">\n\n<head>\n    <meta charset=\"UTF-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n    <link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\"\n        integrity=\"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T\" crossorigin=\"anonymous\" />\n    <link rel=\"stylesheet\" href=\"style.css\" />\n    <title>My Home Page - Frinze Lapuz</title>\n</head>\n\n<body>\n    <nav class=\"navbar sticky-top navbar-dark bg-dark\">\n        <div class=\"container nav\">\n            <a class=\"navbar-brand\" href=\"#\">Royal Homepage</a>\n        </div>\n    </nav>\n    <div class=\"container\">\n        <div class=\"row\">\n            <div class=\"col\">Here Some Dog For You. Cool Stuff right?</div>\n            <div class=\"col\">\n                <!-- <img class=\"img-fluid img-thumbnail\" src=\"dog.jpg\" alt=\"dog\" /> -->\n                <div class=\"carouselWrapper\">\n                    <div id=\"carouselDoggo\" class=\"carousel slide\" data-ride=\"carousel\">\n                        <ol class=\"carousel-indicators\">\n                            <li data-target=\"#carouselDoggo\" data-slide-to=\"0\" class=\"active\"></li>\n                            <li data-target=\"#carouselDoggo\" data-slide-to=\"1\"></li>\n                            <li data-target=\"#carouselDoggo\" data-slide-to=\"2\"></li>\n                        </ol>\n                        <div class=\"carousel-inner\">\n                            <div class=\"carousel-item active\">\n                                <img src=\"dog.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                                <div class=\"carousel-caption d-none d-md-block\">\n                                    <h5>First Dog</h5>\n                                    <p>Cutie :)</p>\n                                </div>\n                            </div>\n                            <div class=\"carousel-item\">\n                                <img src=\"dog2.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                                <div class=\"carousel-caption d-none d-md-block\">\n                                    <h5>Second Dog</h5>\n                                    <p>Good Doggo!</p>\n                                </div>\n                            </div>\n                            <div class=\"carousel-item\">\n                                <img src=\"dog3.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                                <div class=\"carousel-caption d-none d-md-block\">\n                                    <h5>Third Dog</h5>\n                                    <p>Walkie Barkie Cutie!</p>\n                                </div>\n                            </div>\n                        </div>\n                        <a class=\"carousel-control-prev\" href=\"#carouselDoggo\" data-slide=\"prev\">\n                            <span class=\"carousel-control-prev-icon\"></span>\n                            <span class=\"sr-only\">Previous</span>\n                        </a>\n                        <a class=\"carousel-control-next\" href=\"#carouselDoggo\" data-slide=\"next\">\n                            <span class=\"carousel-control-next-icon\"></span>\n                            <span class=\"sr-only\">Next</span>\n                        </a>\n                    </div>\n                </div>\n            </div>\n        </div>\n    </div>\n    <script src=\"https://code.jquery.com/jquery-3.3.1.slim.min.js\"\n        integrity=\"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo\"\n        crossorigin=\"anonymous\"></script>\n    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js\"\n        integrity=\"sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1\"\n        crossorigin=\"anonymous\"></script>\n    <script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js\"\n        integrity=\"sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM\"\n        crossorigin=\"anonymous\"></script>\n</body>\n\n</html>\n
    Relevant Code for Discussion
    <nav class=\"navbar sticky-top navbar-dark bg-dark\"> <!--(1)-->\n    <div class=\"container nav\">\n        <a class=\"navbar-brand\" href=\"#\">Royal Homepage</a>  \n    </div>\n</nav>\n<div class=\"container\">\n    <div class=\"row\">\n        <div class=\"col\">Here Some Dog For You. Cool Stuff right?</div> <!--(2)-->\n        <div class=\"col\">\n            <div class=\"carouselWrapper\"> <!--(3)-->\n                <div id=\"carouselDoggo\" class=\"carousel slide\" data-ride=\"carousel\">\n                    <ol class=\"carousel-indicators\">\n                        <li data-target=\"#carouselDoggo\" data-slide-to=\"0\" class=\"active\"></li>\n                        <li data-target=\"#carouselDoggo\" data-slide-to=\"1\"></li>\n                        <li data-target=\"#carouselDoggo\" data-slide-to=\"2\"></li>\n                    </ol>\n                    <div class=\"carousel-inner\">\n                        <div class=\"carousel-item active\">\n                            <img src=\"dog.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                            <div class=\"carousel-caption d-none d-md-block\">\n                                <h5>First Dog</h5>\n                                <p>Cutie :)</p>\n                            </div>\n                        </div>\n                        <div class=\"carousel-item\">\n                            <img src=\"dog2.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                            <div class=\"carousel-caption d-none d-md-block\">\n                                <h5>Second Dog</h5>\n                                <p>Good Doggo!</p>\n                            </div>\n                        </div>\n                        <div class=\"carousel-item\">\n                            <img src=\"dog3.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                            <div class=\"carousel-caption d-none d-md-block\">\n                                <h5>Third Dog</h5>\n                                <p>Walkie Barkie Cutie!</p>\n                            </div>\n                        </div>\n                    </div>\n                    <a class=\"carousel-control-prev\" href=\"#carouselDoggo\" data-slide=\"prev\">\n                        <span class=\"carousel-control-prev-icon\"></span>\n                        <span class=\"sr-only\">Previous</span>\n                    </a>\n                    <a class=\"carousel-control-next\" href=\"#carouselDoggo\" data-slide=\"next\">\n                        <span class=\"carousel-control-next-icon\"></span>\n                        <span class=\"sr-only\">Next</span>\n                    </a>\n                </div>\n            </div>\n        </div>\n    </div>\n</div>\n
    1. Navigation Bar
    2. Some Text
    3. Carousel
    "},{"location":"2021-2022-summer/introduction-to-react/#html-stored-in-variables","title":"HTML Stored in Variables","text":"
    const Nav = \n    `<nav class=\"navbar sticky-top navbar-dark bg-dark\"> \n        <div class=\"container nav\">\n            <a class=\"navbar-brand\" href=\"#\">Royal Homepage</a>  \n        </div>\n    </nav>\n    `\n
    "},{"location":"2021-2022-summer/introduction-to-react/#html-stored-in-functions","title":"HTML Stored in Functions","text":"
    const Nav = (title) => \n    `\n    <nav class=\"navbar sticky-top navbar-dark bg-dark\"> \n        <div class=\"container nav\">\n            <a class=\"navbar-brand\" href=\"#\">${title}</a>  \n        </div>\n    </nav>\n    `\n
    Carousel Decomposition

    The highlighted ones are the key-distinct data driven elements.

    <div class=\"carouselWrapper\">\n    <div id=\"carouselDoggo\" class=\"carousel slide\" data-ride=\"carousel\">\n        <ol class=\"carousel-indicators\">  <!--(1)-->\n            <li data-target=\"#carouselDoggo\" data-slide-to=\"0\" class=\"active\"></li>\n            <li data-target=\"#carouselDoggo\" data-slide-to=\"1\"></li>\n            <li data-target=\"#carouselDoggo\" data-slide-to=\"2\"></li>\n        </ol>\n        <div class=\"carousel-inner\">\n            <div class=\"carousel-item active\"> <!--(2)-->\n                <img src=\"dog.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                <div class=\"carousel-caption d-none d-md-block\">\n                    <h5>First Dog</h5>\n                    <p>Cutie :)</p>\n                </div>\n            </div>\n            <div class=\"carousel-item\">\n                <img src=\"dog2.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                <div class=\"carousel-caption d-none d-md-block\">\n                    <h5>Second Dog</h5>\n                    <p>Good Doggo!</p>\n                </div>\n            </div>\n            <div class=\"carousel-item\">\n                <img src=\"dog3.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                <div class=\"carousel-caption d-none d-md-block\">\n                    <h5>Third Dog</h5>\n                    <p>Walkie Barkie Cutie!</p>\n                </div>\n            </div>\n        </div>\n        <a class=\"carousel-control-prev\" href=\"#carouselDoggo\" data-slide=\"prev\">\n            <span class=\"carousel-control-prev-icon\"></span>\n            <span class=\"sr-only\">Previous</span>\n        </a>\n        <a class=\"carousel-control-next\" href=\"#carouselDoggo\" data-slide=\"next\">\n            <span class=\"carousel-control-next-icon\"></span>\n            <span class=\"sr-only\">Next</span>\n        </a>\n    </div>\n</div>\n

    1. Carousel Indicators
    2. Carousel Items

    Now, what if we have a variable called dogsData an array of objects (may come from fetch).

    dogsData = [\n    ...\n    {\n        imgSrc: \"dog.jpg\",\n        title: \"First Dog\",\n        caption: \"Cutie :)\"\n    }\n    ...\n]\n

    const Carousel = (dogsData) =>\n    `\n    <div class=\"carouselWrapper\"> <!--(1)-->\n        <div id=\"carouselDoggo\" class=\"carousel slide\" data-ride=\"carousel\">\n            <ol class=\"carousel-indicators\">\n                ${dogsData.map((dog, index) => `<li data-target=\"#carouselDoggo\" data-slide-to=\"${index}\" class=\"${index === 0 ? 'active' : ''}\"></li>`).join('')}\n            </ol>\n            <div class=\"carousel-inner\">\n                ${dogsData.map((dog, index) => `\n                    <div class=\"carousel-item ${index === 0 ? 'active' : ''}\">\n                        <img src=\"${dog.imgSrc}\" class=\"d-block w-100\" alt=\"...\" />\n                        <div class=\"carousel-caption d-none d-md-block\">\n                            <h5>${dog.title}</h5>\n                            <p>${dog.caption}</p>\n                        </div>\n                    </div>\n                `).join('')}\n            </div>\n            <a class=\"carousel-control-prev\" href=\"#carouselDoggo\" data-slide=\"prev\">\n                <span class=\"carousel-control-prev-icon\"></span>\n                <span class=\"sr-only\">Previous</span>\n            </a>\n            <a class=\"carousel-control-next\" href=\"#carouselDoggo\" data-slide=\"next\">\n                <span class=\"carousel-control-next-icon\"></span>\n                <span class=\"sr-only\">Next</span>\n            </a>\n        </div>\n    </div>\n    `\n
    "},{"location":"2021-2022-summer/introduction-to-react/#assemble-the-components","title":"Assemble the Components","text":"

    {Nav(\"Royal Homepage\")}\n<div class=\"container\">\n    <div class=\"row\">\n        <div class=\"col-md-12\">\n            {Carousel(dogsData)}\n        </div>\n    </div>\n
    or with JSX

    <Nav title=\"Royal Homepage\"></Nav>\n<div class=\"container\">\n    <div class=\"row\">\n        <div class=\"col-md-12\">\n            <Carousel dogsData={dogsData}></Carousel>\n        </div>\n    </div>\n
    "},{"location":"2021-2022-summer/introduction-to-react/#intro-to-react","title":"Intro to React","text":"Complete Modularised Code
    const Nav = () => <nav class=\"navbar sticky-top navbar-dark bg-dark\"> \n    <div class=\"container nav\">\n        <a class=\"navbar-brand\" href=\"#\">Royal Homepage</a>  \n    </div>\n</nav>\n\nconst Carousel = (dogsData) =>\n    <div class=\"carouselWrapper\">\n        <div id=\"carouselDoggo\" class=\"carousel slide\" data-ride=\"carousel\">\n            <ol class=\"carousel-indicators\">\n                ${dogsData.map((dog, index) => `<li data-target=\"#carouselDoggo\" data-slide-to=\"${index}\" class=\"${index === 0 ? 'active' : ''}\"></li>`).join('')}\n            </ol>\n            <div class=\"carousel-inner\">\n                ${dogsData.map((dog, index) => `\n                    <div class=\"carousel-item ${index === 0 ? 'active' : ''}\">\n                        <img src=\"${dog.imgSrc}\" class=\"d-block w-100\" alt=\"...\" />\n                        <div class=\"carousel-caption d-none d-md-block\">\n                            <h5>${dog.title}</h5>\n                            <p>${dog.caption}</p>\n                        </div>\n                    </div>\n                `).join('')}\n            </div>\n            <a class=\"carousel-control-prev\" href=\"#carouselDoggo\" data-slide=\"prev\">\n                <span class=\"carousel-control-prev-icon\"></span>\n                <span class=\"sr-only\">Previous</span>\n            </a>\n            <a class=\"carousel-control-next\" href=\"#carouselDoggo\" data-slide=\"next\">\n                <span class=\"carousel-control-next-icon\"></span>\n                <span class=\"sr-only\">Next</span>\n            </a>\n        </div>\n    </div>\n\nconst Homepage = () =>{\n    const dogsData = fetch(...) // Get data from API\n    return (\n        <>\n            <Nav title=\"Royal Homepage\"></Nav>\n            <div class=\"container\">\n                <div class=\"row\">\n                    <div class=\"col-md-12\">\n                        <Carousel dogsData={dogsData}></Carousel>\n                    </div>\n            </div>\n        </>\n    )\n}\n
    "},{"location":"2021-2022-summer/introduction-to-react/#getting-started-with-react","title":"Getting Started with React","text":"

    Getting Started with the app

    To get started with react, use the following commands

    npx create-react-app my-app where my-app is the name of the folder for where the react app is going to be.

    cd my-app

    Notice that it created a couple of folders. In a couple of sentences:

    src/index.js - injects the user interface in the public/index.html (the front part of the build)

    public - folder containing the static assets as well as the index.html

    package.json - dependencies and scripts for the app

    type yarn start to run the development version of React (it will run react-scripts start within the node_modules \u2026 so running react-scripts start will not exactly be the same). This will serve up React in a port

    To be left as a live coding exercise. Live coding demonstration:

    "},{"location":"2021-2022-summer/introduction-to-react/#demo","title":"Demo","text":"
    • Passing Array props
    • show \u201crafce\u201d
    • useState when adding new item
    "},{"location":"2021-2022-summer/introduction-to-vue/","title":"Introduction to Vue","text":"

    A Vuetiful Introduction to VueJS

    Due to time constraints, we had to reuse the previous Winter Materials.

    As always, see the youtube video playlist

    "},{"location":"2021-2022-summer/introduction-to-web-development/","title":"Introduction to Web Development Space","text":"

    Navigating the Deep Dark Space of Web Development

    This workshop covers a brief overview of the most common tools and technologies used in web development.

    "},{"location":"2021-2022-summer/introduction-to-web-development/#content","title":"Content","text":"
    • What and Why Web Development?
    • FAQs about Web Development
    • Basics of Web and Limitation
    • Server-side Applications (Backend)
    • Others
      • Languages of the Web (the usual)
      • Hosting Stuff
      • CSS Frameworks
      • Developer Tools
      • TypeScript
      • Testing
      • Continuous Integration / Continuous Deployment
      • Virtualisation and Containerisation
      • Browsers
      • Firefox Developer Tools
      • Package Managers
      • Version Control
      • Linters and Formatters
      • Teamwork
      • Roadmaps
    • Word of Encouragement
    "},{"location":"2021-2022-summer/introduction-to-web-development/#what-and-why-web-development","title":"What and Why Web Development?","text":""},{"location":"2021-2022-summer/introduction-to-web-development/#what-is-web-development","title":"What is web development?","text":"
    • Websites development
    • Web applications (client-side and server-side) development
    "},{"location":"2021-2022-summer/introduction-to-web-development/#why-web-development","title":"Why Web Development ?","text":"
    • Accessibility and Portability
    • Career and On-demand in job market
    • Huge possibility to combine with other emerging technologies (e.g. IoT, Machine Learning) and industry (e.g. Health, Mining, O&G)
    Career in Web Development

    Source: Insights from Stack Overflow\u2019s 2016 survey of 50,000 developers

    \"Half of Developers are Web Developers\"

    "},{"location":"2021-2022-summer/introduction-to-web-development/#faqs-about-web-development","title":"FAQs about Web Development","text":""},{"location":"2021-2022-summer/introduction-to-web-development/#why-code-websites-why-not-use-drag-and-drops-like-wordpress-wix","title":"Why code websites, why not use drag and drops like Wordpress, WIX?","text":"
    • Content Management System (CMS)
    • Limitations on theme/template used
    • Difficult to extend
    • Cybersecurity
    More information

    CMS are one of the application of web development, but there are plenty more such as - internet of things, custom software for a particular industrial application (eg. using Machine Learning)

    CMS are usually limited to the template or plugin that you use. If those plugin don't exist, then it limits your productivity very much (difficulty to extend).

    CMS are usually built to cater for non-technical users. This means that thye become the subject of hackers. Think about a scenario where a hacker was able to find a vulnerability in WordPress, now every other WordPress site will be vulnerable.

    "},{"location":"2021-2022-summer/introduction-to-web-development/#what-is-the-best-way-to-learn-all-these","title":"What is the best way to learn all these?","text":"

    In summary, the best way to learn:

    • Do personal projects (inspiration + motivation)
    • Do team projects (get peer reviews and correct bad practices straight away)
    • Watch Online Courses (to figure out what is available)
    More Information

    To be told that you have to learn \"this, this, and that\" before you could do things is tiresome.

    Often times, we want to learn to be a developer so that we can create cool things like software where thousands of people can use the app. We don't tend to be a developer for the sake of us needing to watch endless videos on different things.

    "},{"location":"2021-2022-summer/introduction-to-web-development/#why-does-cfc-not-do-mobile-development-as-much-as-web-development","title":"Why does CFC not do mobile development as much as web development?","text":"
    • App stores has a developer cost
    • Easier to deal/teach web technologies
    • Accessibility (mobile, sensors, tablets, laptops and PCs)
    • Bigger open-source community
    "},{"location":"2021-2022-summer/introduction-to-web-development/#if-i-already-know-a-frontend-framework-is-it-better-to-learn-another-frontend-framework-or-to-learn-a-backend-framework","title":"If I already know a frontend framework, is it better to learn another frontend framework or to learn a backend framework?","text":"
    • It is better to learn a backend framework
    Reasoning

    You want to build skills that complement one another rather than be an alternative.

    It is much more valuable for you to learn a backend framework because that helps you build a functional app.

    "},{"location":"2021-2022-summer/introduction-to-web-development/#basics-of-web-and-limitation","title":"Basics of Web and Limitation","text":"HTML

    What is it?

    • Hypertext Markup Language
    • Describes the structure of a web page

    Limitation

    • Doesn\u2019t handle repeated content well
    • No variables or calculation
    HTML Syntax
    <!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Document</title>\n</head>\n<body>\n    Hello World!\n</body>\n</html>\n
    CSS

    What is it?

    • Cascading Style Sheets
    • Describes the presentation of a web page

    Limitation

    • Most css is quite similar (Handled by CSS Libraries)
    • Not very dynamic (Handled by CSS Frameworks)
    CSS Syntax
    body {\n    background-color: #f0f0f0;\n    font-family: sans-serif;\n}\n\n.container{\n    width: 80%;\n    margin: 0 auto;\n}\n
    JS

    What is it?

    • JavaScript
    • Used to program complex features on a web page

    Limitation

    • Has the capability to modify the user interface, but becomes really tedious to modify interface (more about this in another workshop)
    JS Syntax
    const bodySelector = document.querySelector('body');\nconst myFunction = () => {\n    bodySelector.innerHTML = 'Hello World 2!';\n    // Add a container class to space out\n    bodySelector.classList.add('container');\n}\nbodySelector.onclick = myFunction;\n
    "},{"location":"2021-2022-summer/introduction-to-web-development/#modern-frameworks","title":"Modern Frameworks","text":"
    • Websites can be much more\u2026 they can be web applications
    • \u201cApp\u201d in a website (client-side rendering)
    Modern Frameworks React.js
    • More mature and used more in industry
    Vue.js
    • Growing fast in popularity and use.

    General Information

    • Both are good to use and learn.
    • Knowledge is transferable between the two frameworks.
    Comparison between HTML and JSX

    Highlighted portions are starting chunk of distinct code.

    HTML
    <div class=\"row\">\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">devices</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Applications\n            </p>\n            <p class=\"mb-0\">\n            Build custom web and mobile applications to engage with your audience\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">web</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">Websites</p>\n            <p class=\"mb-0\">\n            Build new websites or optimise existing pages to improve online\n            visibility\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">storage</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Data Storage\n            </p>\n            <p class=\"mb-0\">\n            Design and create databases for efficient information storage and\n            retrieval\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">how_to_reg</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Consulting\n            </p>\n            <p class=\"mb-0\">\n            Empower your organisation through technical knowledge and advice\n            </p>\n        </div>\n        </div>\n    </div>\n</div>\n
    JSX
    import { memo } from 'react'\nimport { Row, Col, Card, CardBody } from 'reactstrap'\nimport services from 'data/services.json'\n\nconst Service = (props: {\nicon: string\ntitle: string\ndescription: string\n}) => (\n<Card className='text-center border-0 bg-transparent'>\n    <CardBody className='px-0'>\n    <i className='material-icons-sharp md-lg'>{props.icon}</i>\n    <p className='mt-4 font-weight-bold text-monospace text-larger'>\n        {props.title}\n    </p>\n    <p className='mb-0'>{props.description}</p>\n    </CardBody>\n</Card>\n)\n\nconst Services = () => (\n<Row>\n    {services.map(service => (\n    <Col\n        xs={12}\n        md={6}\n        lg={12 / services.length}\n        className='m-0'\n        key={service.title}\n    >\n        <Service {...service} />\n    </Col>\n    ))}\n</Row>\n)\n\nexport default memo(Services)\n
    "},{"location":"2021-2022-summer/introduction-to-web-development/#server-side-applications-backend","title":"Server-side Applications (Backend)","text":""},{"location":"2021-2022-summer/introduction-to-web-development/#how-do-devices-communicate","title":"How do devices communicate?","text":"
    • HTTP Request - Hypertext Transfer Protocol
    "},{"location":"2021-2022-summer/introduction-to-web-development/#what-do-server-applications-do","title":"What do server applications do?","text":"
    • Serve frontends (server-side rendering)
    • Web API (Application Programming Interface)
      • Serve data (usually from a database)
      • Process Request (Sending emails or SMS, Machine Learning)
    "},{"location":"2021-2022-summer/introduction-to-web-development/#databases","title":"Databases","text":"

    Place to store the data

    Mongodb

    Allows for database design to be modified without complex migration or data loss

    SQL

    Typically faster and better for large amounts of data or systems that need data consistency and reliability

    "},{"location":"2021-2022-summer/introduction-to-web-development/#others","title":"Others","text":""},{"location":"2021-2022-summer/introduction-to-web-development/#languages-of-the-web-the-usual","title":"Languages of the Web (the usual)","text":"
    • Python (Django, Flask)
    • JavaScript (Node.js, Express)
    • Ruby, Go, Rust, C
    "},{"location":"2021-2022-summer/introduction-to-web-development/#hosting-stuff","title":"Hosting Stuff","text":"

    Many ways - Own a server - Use a 3rd party platform

    "},{"location":"2021-2022-summer/introduction-to-web-development/#css-frameworks","title":"CSS Frameworks","text":"

    Frontend (JS)

    • Vue, React
    • Nuxt.js, Next.js

    Frontend (CSS)

    • MaterialUI, Vuetify
    • Bootstrap
    "},{"location":"2021-2022-summer/introduction-to-web-development/#developer-tools","title":"Developer Tools","text":""},{"location":"2021-2022-summer/introduction-to-web-development/#typescript","title":"TypeScript","text":"
    • Type checking is super useful for complex apps
    • Allows for way better javascript developer tooling
    • Can be annoying if you\u2019re new at it
    "},{"location":"2021-2022-summer/introduction-to-web-development/#testing","title":"Testing","text":"
    • Selenium, Cypress
      • End to end automated testing tools
    • Jest, Mocha, Pytest
      • Unit testing
    • Testing is vital to software projects
    "},{"location":"2021-2022-summer/introduction-to-web-development/#continuous-integration-continuous-deployment","title":"Continuous Integration / Continuous Deployment","text":"
    • Automated Testing
    • Event-driven scripts
    • E.g. Github Action, Bitbucket Pipelines
    "},{"location":"2021-2022-summer/introduction-to-web-development/#virtualisation-and-containerisation","title":"Virtualisation and Containerisation","text":"
    • Allows execution of services in a virtual environment
    • eg. Docker (Containerisation), Vagrant (Virtualisation)
    "},{"location":"2021-2022-summer/introduction-to-web-development/#browsers","title":"Browsers","text":"
    • Standard browsers
      • Google Chrome, Firefox, Edge, etc.
    • Backwards compatibility
      • Internet Explorer
    • Other
      • Mobile - Responsive
      • Screen readers - Accessibility
    "},{"location":"2021-2022-summer/introduction-to-web-development/#firefox-developer-tools","title":"Firefox Developer Tools","text":"
    • Page Inspector
      • Visualise page aspects
      • Grid layout
    • Web Console
      • console.log(\u201cHello World\u201d)
    • Responsive Design Mode
      • View from POV of different screen sizes such as mobile, tablets, etc.
    Some more tools
    • JavaScript Debugger
    • Network Monitor
    • Performance Tools
    • Rulers
    • Colour Pickers Learn more at: https://developer.mozilla.org/en-US/docs/Tools
    "},{"location":"2021-2022-summer/introduction-to-web-development/#package-managers","title":"Package Managers","text":"
    • Installs libraries that can be used
    • Also has code shortcuts (e.g. npm run start)

    (More about package.json and poetry.toml in the projects and Package Manager Workshop)

    "},{"location":"2021-2022-summer/introduction-to-web-development/#version-control","title":"Version Control","text":"
    • Essential for developer teams and complex software development
    • Git
    "},{"location":"2021-2022-summer/introduction-to-web-development/#linters-and-formatters","title":"Linters and Formatters","text":"
    • Makes code formatting consistent (following standard)
    • Useful with version controls to avoid pointless change

    eg.ESLint, Prettier

    "},{"location":"2021-2022-summer/introduction-to-web-development/#teamwork","title":"Teamwork","text":"
    • Many tools out there
    • Used to stop teams from stepping on each others toes
    • Github Issues + Pull Requests
    "},{"location":"2021-2022-summer/introduction-to-web-development/#roadmaps","title":"Roadmaps","text":"

    There's an open-source community that maintains a learning roadmap for developers. See https://roadmap.sh/

    Frontend Developer

    Backend Developer

    Dev-Ops

    "},{"location":"2021-2022-summer/introduction-to-web-development/#word-of-encouragement","title":"Word of Encouragement","text":"Encouragement from the Tech Lead

    \"I can admit that this journey of learning will be difficult, and can sometimes be overwhelming and demotivating. Please, if at any point of this project, you feel that you don't know enough, or you're feeling lost, please reach out! We are all in this journey together! Nobody is born talented, skills are honed with determination and willingness to learn.\"

    \"When I was a first year student entering on the CFC winter project, I didn't feel like I was good enough. I couldn't create a good looking interface, I didn't know how to use npm and all sorts of those things. I was just like many of you! if I gave up just because of all those things I didn't know, of all those self-doubts, then I wouldn't be here today. I admit that I was lucky because I was in CFC, I had connections where I can just ask questions instead of feeling lost of not knowing. So please do leverage that opportunity to reach out\"

    \"You being in this project not only gives you the opportunity to raise your talents, but you also unlock one of the biggest factor of the growth of your career, and that is the connections with your fellow software engineers.\"

    "},{"location":"2021-2022-summer/introduction-web-basics/","title":"Introduction to the Web Basics - HTML, CSS & JavaScript","text":"

    The tools of the web

    This workshop will introduce you to the basics of HTML, CSS and JavaScript, the fundamental technologies of web development. This is a very introductory workshop, and there is still so much we can learn, but this will be a good place to start.

    "},{"location":"2021-2022-summer/introduction-web-basics/#content","title":"Content","text":"
    • Key Web Technologies
    • HTML
      • Elements
      • Attributes
      • Images
      • Anchors/Hyperlinks
      • Forms
      • Document Object Model
    • CSS
      • CSS Format
      • Rules of Selection
      • Document and External Style Sheets
      • Flexboxes
    • JavaScript
      • The Basics of JavaScript
      • Arrays
      • Objects
      • Functions
      • Loops
    • Web App Tutorial
    "},{"location":"2021-2022-summer/introduction-web-basics/#key-web-technologies","title":"Key Web Technologies","text":"

    HTML, CSS and JavaScript each have a different job when it comes to creating web pages.

    "},{"location":"2021-2022-summer/introduction-web-basics/#what-do-they-do","title":"What do they do?","text":"
    • HTML: describes the content and structure of the web page
    • CSS: describes the style and appearance of the web page
    • JavaScript: provides funtionality to a web page
    "},{"location":"2021-2022-summer/introduction-web-basics/#html","title":"HTML","text":"

    Hyper Text Markup Language (HTML) is used to structure the webpage. The general structure of a webpage can be seen below.

    My First HTML Page
    <!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <title>You see this text on your browser tab!!!</title>\n    </head>\n    <body>\n        <!-- this is where the content goes! -->\n        <h1>My First Heading</h1>\n        <p>This is a paragraph</p>\n    </body>\n</html>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#elements","title":"Elements","text":"

    A webpage is made of elements, each with their own properties, that contain content to be displayed on the page. Elements are defined by tags, such as h1, div and body. Most elements have an open and close tab. The container and its content, together, are called an element.

    <h1>This is a header element.</h1>\n

    The most notable, and probably the tag you will use most, is the <div> tag. It defines a division or section within the HTML document, and is used as a container that holds other elements.

    The Seperator
    <!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <title>The Web Dev Fairytale</title>\n    </head>\n    <body>\n        <div>\n            <!-- This div concerns itself with the main heading/title of the story -->\n            <h1>The Dev, the Debugger and the Caffiene Addiction</h1>\n        </div>\n        <div>\n            <!-- This div concerns itself with the first chapter it its entirety -->\n            <h1>Chapter 1</h1>\n            <div>\n                <!-- This div concerns itself with the text of the first chapter -->\n                <!-- section within a section. A subsection! -->\n                <p>Once upon a time, in a castle far, far away...</p>\n            </div>\n        </div>\n        <div>\n            <h2>Chapter 2</h2>\n        </div>\n    </body>\n</html>\n

    We will go through the important ones during this workshop, but you can find the full of them here.

    "},{"location":"2021-2022-summer/introduction-web-basics/#attributes","title":"Attributes","text":"

    Most tags have attributes that specify information or change the tag in some way. The most common being class and id.

    "},{"location":"2021-2022-summer/introduction-web-basics/#most-common-attributes","title":"Most Common Attributes","text":"
    • class: used to specify one or more class names for a HTML element.
      • Classes are used to group certain elements in order to give them specific features through CSS and to allow many elements to be manipulated using JavaScript.
    • id: used to specify a unique id for an element and must be unique
      • The id attribute is assigned to an element so that element can be exclusively specified in the style declaration and JavaScript manipulation

    Below is an example of how attributes are assigned in your code.

    Elements and their Attributes
    <!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <title>You see this text on your browser tab!!!</title>\n    </head>\n    <body style=\"background-color: red\">\n        <div class=\"bigSection\">\n            <h1>BIG HEADER!</h1>\n            <p id=\"first\">This is the first paragraph of the webpage</p>\n            <!-- more cool stuff goes here -->\n        </div>\n        <div class=\"smallSection\">\n            <h6>small header</h6>\n        </div>\n    </body>\n</html>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#images","title":"Images","text":"

    Images are added by using the <img> element tag. It can also be used to add gifs!

    Example
    <img src=\"https://i.imgur.com/SjZxZza.jpeg\" alt=\"Three Cute Dog Mermaids\">\n

    Cute, right?

    "},{"location":"2021-2022-summer/introduction-web-basics/#image-attributes","title":"Image Attributes","text":"
    • src: specifies the location of the image to be displayed
      • This can either be a url, as in the example above, or the relative path of an image within the site's directory
    • alt: an optional attribute that contains a text description.
      • Is useful for accessibility or if the image does not load properly
    "},{"location":"2021-2022-summer/introduction-web-basics/#anchors-and-hyperlinks","title":"Anchors and Hyperlinks","text":"

    We can add links to other websites, or even to sections within the same page, using the <a> element, known as an anchor.

    Adding a hyperlink to an HTML page
    <a href=\"https://codersforcauses.org/\" target=\"_blank\">Coders for Causes</a>\n

    They can be adding added by themself, or within text such as here.

    "},{"location":"2021-2022-summer/introduction-web-basics/#anchor-attributes","title":"Anchor Attributes","text":"
    • href: specifies the destination to link to
      • External site: simply include the url you wish to visit
      • Different page within the site: include the path to the new page, usually in the form of \"/.../index.html\"
      • Different section on same page: use #name_of_section where name_of_section is the id of the element you wish to go to
    • target: specifies where to open the link
      • Setting the target attribute to \"_blank\" opens the link in another tab
    • download: specifies that the linked resouces will be downloaded.
      • Only needs to be included in the declaration of the element
      • Optional: if value of download is set, that value will be the name of the file

    Always be careul when clicking links. You never know when there is something you should not click.

    "},{"location":"2021-2022-summer/introduction-web-basics/#images-and-hyperlinks","title":"Images and Hyperlinks","text":"

    Any image, or any element in general, can be turned into a link by enclosing the element within the anchor tabs.

    Hyperlinked image
    <a href=\"https://codersforcauses.org/\" target=\"_blank\">\n    <img src=\"https://www.uwastudentguild.com/assets/clubs/logos/logo---coders-for-causes-1567649329.jpg\">\n</a>\n

    "},{"location":"2021-2022-summer/introduction-web-basics/#forms","title":"Forms","text":"

    Forms are used to collect user input. They are defined by the <form> tags and usually contain form elements such as <input>, <textbox>, etc.

    Inputs can come in many different forms, such as textboxes, radio buttons, checkboxes and drop down menus. Each input field is given a value Once a form is complete and filled out, we need to submit, or POST, it. This can be done through a special input of type submit.

    The only required attribute of <form> is action. The action attribute speicifies the URL of the application that is to be called when the Submit button is pressed. If no action, then the attribute takes the value of an empty string and the current page is the destination.

    Example
    <p>I like:</p>\n<form action=\"\">\n    <input type=\u201dradio\u201d value=\u201dRed\u201d>\n    <input type=\u201dradio\u201d value=\u201dGreen\u201d>\n    <input type=\u201dradio\u201d value=\u201dBlue\u201d>\n    <input type=\u201dsubmit\u201d value=\u201dSubmit\u201d>\n</form>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#input-validation","title":"Input Validation","text":"

    Input validation is a very important aspect to consider when dealing with forms. Remember the famous acronym GIGO, Garbage-in Garbage-Out. To assist you with input validation, HTML forms have in-built validation for different types of data, such as emails, numbers and dates. This can be achieved by changing the input type of a field to the respective data entry type.

    Baseline input validation with HTML
    <input type=\"email\" name=\"email\" value=\"Email\">\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#document-object-model","title":"Document Object Model","text":"

    All the elements of a HTML page make up a document tree, called the Document Object Model (DOM). The DOM is a platform and language-neutral interface that allows programs to dynamically access and update the content, structure and style of the HTML document. Each element in a HTML document is represented by a node on the tree. We can then use things such as JavaScript to access and update the HTML document using the DOM. We will see more of this in the tutorial at the end.

    "},{"location":"2021-2022-summer/introduction-web-basics/#css","title":"CSS","text":"

    Cascading Style Sheets (CSS) provides style to the web. It is used to specify the layout and style of markup languages. CSS tells the browser how to display the elements that are written in HTML.

    We can write the CSS style rules into an element using inline CSS, where the style attribute of an element is modified directly in the HTML.

    Inline style sheets
    <body style=\"background-color: red;\">\n    <!-- rest of body goes here -->\n</body>\n

    However, this gets hard to manage and maintain, especially when the number of elements in a document grows, and when we want to change many elements that have the same style. We use document-level style sheets or external style sheets to combat this issue.

    But first, we must understand how to create these style sheets.

    "},{"location":"2021-2022-summer/introduction-web-basics/#css-format","title":"CSS Format","text":"
    • Selector
      • A value, or list of values, that specify the elements for which the following style will be applied to
      • Rules for specification will be discussed a little later on, see here
    • Attribute
      • The attribute/property of an element you wish you change
      • Some example attributes include background-color, font-size and width
    • Effect
      • The effect is the value you set each attribute to be
      • This includes setting background-color to \"red\", or font-size to \"16px\"

    The following CSS specifies that all img elements are to be centered and have a width of 50 pixels.

    My First CSS
    img{\n    /* attribute: effect; */\n    display: block;\n    margin-left: auto;\n    margin-right: auto;\n    width: 50px;\n}\n
    How do I know what attributes exist, and what do I change to get my desired effect?

    There are two simple answers to this question: 1. Google it. Chances are, someone has already tried to do something similar and your solution already exists. 2. Play around. Learn what attributes exist, and how changing thier effects changes their on screen appearance.

    "},{"location":"2021-2022-summer/introduction-web-basics/#rules-of-selection","title":"Rules of Selection","text":"

    As mentioned earlier, selectors have a set of rules that allow you to apply styles to certain, or even very specific, groups of elements. These can range selecting elements based on the type of element they are, or what class they are in, to selecting all elements of a certain type that are immediately preceded by an element of another type.

    Element

    Element selectors simply apply the defined style to all elements of the same type.

    body{\n    background-color: red;\n}\n

    Class

    Class selectors apply the defined style to all elements belonging to that class. They are similar to element selectors, except that the class name is preceded by a . character.

    .narrow{\n    width: 10%\n}\n

    We can also specify the type of element within a class we wish to apply the style to by including it before the . character. The following code selects all <p> elements that are of the class narrow:

    p.narrow{\n    width:10%;\n}\n

    id

    These selectors apply the style to an element based on its id. The id is preceded by # in the selector definition.

    #bigButton{\n    font-size: 16px;\n}\n

    Psuedo Classes

    Psuedo classes are styles that apply only when a certian action occurs or a condition is met, and not all the time. Some common selectors include hover, focus and active. They are included after the element, class or id has been specified, and are preceded with a colon :.

    button:hover{\n    color: red;\n}\n

    The full list of them can be found here.

    Group

    To specify a group of elements to apply a style to, simply list the elements, ids or classes delimitted by a comma (,).

    h1, h2, div{\n    color: red;\n}\n

    Other

    There exists other selectors that allow you to be more specific as to what elements are to be selected, such as contextual selectors, but we will leave those as self-learning.

    Contextual Selectors

    Contextual selectors group elements based on their position and surroundings in the document tree. Further reading into the topic can be found through searching the web for platforms that teach you all about computer science, such as Geeks for Geeks.

    "},{"location":"2021-2022-summer/introduction-web-basics/#document-and-external-style-sheets","title":"Document and External Style Sheets","text":"

    Now that we know what we are doing, let's create some style sheets! Document and External style sheets help us better organise and manage the styles of the document. They are located in one location, so you do not have to go far to find them and change parts of your document.

    "},{"location":"2021-2022-summer/introduction-web-basics/#document-style-sheets","title":"Document Style Sheets","text":"

    Document style sheets are located within the <head> of a HTML document, under the <style> tag. They work in the same was as mentioned above. See the below example of how document style sheets are implemented within a HTML page.

    Document Style Sheets
    <!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <title>You see this text on your browser tab!!!</title>\n        <style>\n            body{\n                background-color: blue;\n            }\n            p{\n                color: red;\n                font-size: 16px;\n            }\n        </style>\n    </head>\n    <body>\n        <!-- this is where the content goes! -->\n        <h1>My First Heading</h1>\n        <p>This is a paragraph</p>\n    </body>\n</html>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#external-style-sheets","title":"External Style Sheets","text":"

    What happens when our site grows, and the number of HTML pages increases, and suddenly styles have to change, and we have to change every document, but they all have to follow the same styling as the others, and we have to manage that?! Thankfully, we can store our styles in a seperate .css file and then simply reference the stylesheet in our HTML document.

    styles.css
    body{\n    background-color: blue;\n}\np{\n    color: red;\n    font-size: 16px;\n}\n

    Once we have our css file completed, we can reference it in the HTML document, again in the <head>, so that it can apply the styles to our document.

    Applying my CSS files to my HTML document
    <!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <title>You see this text on your browser tab!!!</title>\n        <link rel=\"stylesheet\" href=\"styles.css\">\n    </head>\n    <body>\n        <!-- this is where the content goes! -->\n        <h1>My First Heading</h1>\n        <p>This is a paragraph</p>\n    </body>\n</html>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#flexboxes","title":"Flexboxes","text":"

    Flexboxes are a great way to position your items within a container.

    Learning is best done when having fun and getting your hands dirty (metaphorically). Flexbox Froggy is an interactive website that teaches you all about flexboxes, one step at a time. Your aim is to allign all the frogs to their corresponding lilypads. It is a much better learning tool than sitting and reading about some code I wrote.

    "},{"location":"2021-2022-summer/introduction-web-basics/#javascript","title":"JavaScript","text":"

    JavaScript, also known as JS, gives a web page fucntionality and reactiveness. It allows the user to interact with the web page, and for us to make it to do things that we want it to do. Similar to CSS, all your JS can be implemented into a HTML document by encapsulating it in the <script> tag within the <head> of the document, or even <body> in this case. However, we will be sticking to having our JS stored in external files for ease of managability. See the below example of how to add a script file to your page. To add many files, simply add another <script> element and reference the other file.

    Adding JavaScript to my HTML document
    <script src=\"script.js\"></script>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#the-basics-of-javascript","title":"The Basics of JavaScript","text":"

    We shall discuss the basic syntax of JS, such as variables and functions, just to get you started. Feel free to do some of your own learning, too. There is a lot of cool things you can do and shortcuts you can use when you dive deeper into JavaScript, such as the ternary operator, but we will leave these for now.

    "},{"location":"2021-2022-summer/introduction-web-basics/#variables","title":"Variables","text":"

    Variables are named memory locations that store data. To define a variable, we can use three different keywords, each giving the variable special properties.

    "},{"location":"2021-2022-summer/introduction-web-basics/#variable-declaration","title":"Variable Declaration","text":"
    • var
      • allows the variable to be redeclared later on in the program
      • gives the variable a global scope, meaning they can be accessed anywhere within the file
    • let
      • once a variable has been declared using let, it cannot be redeclared. It's value can still change, however.
      • gives the variable block scope, meaning it can only be accessed within the block of code that it has been declared in. For example, if I declare a variable using the let key word, I cannot access it outside of the function.
    • const
      • Once the variable has been declared and assigned, it cannot be redeclared and the value never changes. It stays constant, sort of.
      • It, too, gives the variable block scope.

    For a full explanation on variable declaration in JS, check out w3schools' page on it.

    Variables can hold different data types, such as numbers, strings, objects, functions and arrays, but JS will cover the type identification for you.

    "},{"location":"2021-2022-summer/introduction-web-basics/#datatypes","title":"Datatypes","text":"
    • There are two groups of data types in JS: primitives and structural.
    • A primitive is data that is not an object and has no methods. There are seven primitive data types:
      • String, Number, BigInt, undefined, null and symbol
    • A structural data type is one where the data is in the form of an object, and that object has its own methods. The main structural data types are:
      • Objects and Functions
    "},{"location":"2021-2022-summer/introduction-web-basics/#math-and-logic","title":"Math and Logic","text":"

    Math and logic works similar in JS to other programming languages.

    "},{"location":"2021-2022-summer/introduction-web-basics/#math","title":"Math","text":"
    • +, -: addition and subtraction
    • *, /: multiplication and division, respectively.
    • %: modulo operator. Returns the remainder left over after division.
      • For example, 8 % 3 returns 2.
    • **: exponent (x to the power of y)
      • base ** power
    "},{"location":"2021-2022-summer/introduction-web-basics/#logic","title":"Logic","text":"
    • &&: AND operation
    • ||: OR operation
    • !: NOT operation
    • >/>=: greater than/greater than or equal to
    • </<=: less than/less than or equal to
    • ==: equal to
    • ===: exactly equal to
      • Works in a similar way to ==, except it also checks that the datatype is the same
    Difference between == and ===
    console.log(\"2\" == 2);  /* true */\nconsole.log(\"2\" === 2); /* false */\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#arrays","title":"Arrays","text":"

    Arrays are an ordered list of values. They can hold values of many datatypes. Their index starts at 0.

    let myArray = [\"a\", \"b\", \"c\", 1, 2 ,3, {name: \"Jared\", age: 19, canRead: false}]\nmyArray[0] // returns \"a\"\nmyArray[4] // returns 2\n

    "},{"location":"2021-2022-summer/introduction-web-basics/#objects","title":"Objects","text":"

    Objects are variables that can hold more than one value. One can be seen in the previous example in Arrays. The different values of an object are called keys. The keys can hold regular primitive values, such as numbers or strings, or can hold other objects, such as functions. Think of Objects as a list of key/value pairs.

    To access a key's value within an object, you must first reference the object in question, then insert a . folllowed by the key you wish to get.

    Objects in JavaScript
    let person = {\n    name: \"Jared\",\n    age: 19,\n    canRead: false\n}\nconsole.log(person.age) // outputs 19\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#functions","title":"Functions","text":"

    Functions are blocks of code designed to execute a particular task. In JS, the syntax for defining a function is as follows:

    Functions in JavaScript
    function func_name(parameter1, parameter2, ...){\n    // your code goes here (optional, but highly recommended)\n}\n

    Functions can be called or stored in variables.

    Calling and Storing Functions
    function hello_world(){\n    console.log(\"Hello, world!\")\n}\n\n// Calling the function\nhelloWorld()\n\n// Storing the function in a variable\nconst func_name = function (param1, param2){\n    // do stuff here\n}\n

    Functions can return a value (after calculation, etc) or simply perform work on existing data/variables. Functions that do not return anything are normally called procedures.

    "},{"location":"2021-2022-summer/introduction-web-basics/#arrow-functions","title":"Arrow Functions","text":"

    Arrow functions are just a compact way of writing normal functions. They work by removing the function key word, and even the return keyword in some cases. Arrows functions lead with their parameters, usually enclosed in normal brackets. An arrow => then follows, preceding the actual block of code to be executed.

    Arrow Functions: Example 1
    // Traditional function\nfunction addXY (x, y){\n    return x + y;\n}\n\n// Arrow function\nlet addXY = (x, y) => x + y;\n

    In single-lined functions, such as the one above, both the { braces } and the return can be omitted. However, when there are extra lines of processing, both must be included.

    Arrow Functions: Example 2
    // Traditional\nfunction add10(x, y){\n    x += 10\n    y += 10\n    return x + y;\n}\n\n// Arrow function\nlet add10 = (x, y) => {\n    x += 10\n    y += 10\n    return x + y;\n}\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#loops","title":"Loops","text":"For

    For loops repeat until a condition is met. That condition is defined in the for loop. For loops have the following structure:

    For Loops
    /*\nfor(int i = start; condition; increment){\n    // code here\n}\n*/\n\n// Loop 10 times\nfor(int i = 0; i < 10; i++){\n    console.log(i)\n}\n// Output: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9\n
    For-in

    For-in loops iterate over the indexes of data in an iterable object, such as an array.

    For-in Loops
    let myArray = [2, 4, 6]\nfor(let j in myArray){\n    console.log(j)\n}\n// Output: 0, 1, 2\n
    For-of

    For-of loops iterate over the data in the iterable object.

    For-of Loops
    let myArray = [2, 4, 6]\nfor(let k of myArray){\n    console.log(j)\n}\n// Output: 2, 4, 6\n
    While

    While loops iterate while a condition is true. They are called a \"pre-test\" loop, where the condition is tested before the loop can run. The condition is included in the brackets.

    While Loops
    let b = 0\nwhile(b < 3){\n    console.log(\"Bon\")\n    b++\n}\n// Output: \"Bon\\n Bon\\n Bon\\n\"\n
    Do-while

    Do-while loops are similar to while loops, except that they let the block of code run once before testing the condition. They are known as \"post-test\" loops, and the loop is guaranteed to execute at least once.

    Do-while Loops
    let b = 0\ndo {\n    console.log(\"Bon\")\n    b++\n} while(b > 10)\n// Output: \"Bon\\n\"\n

    Loops can be broken or stopped using the break or continue statements.

    "},{"location":"2021-2022-summer/introduction-web-basics/#breakin-out","title":"Breakin' out","text":"
    • break: execution leaves the loop completely and continues on with the next lines of code
    • continue: disregards the rest of the code in the loop block and moves on to the next item in the loop
    "},{"location":"2021-2022-summer/introduction-web-basics/#creating-a-pokemon-api-webapp","title":"Creating a Pokemon API Webapp","text":"

    Now that we know a little bit about the tools of the web, let's build a simple web app that uses the skills we have learnt in this workshop, as well as some other skills we will learn along the way, to create an app that can do something cool.

    For this tutorial, we will pay homage to the recent releases of Pokemon Brilliant Diamond and Shining Pearl, of which I have spent an embarrassing number of hours on since they came out about a week ago, and create a web app that uses the PokeAPI to display images and information about any Pokemon we want.

    Watch the tutorial on our YouTube channel by clicking the link, here, or the image below!

    Back to Top

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/","title":"MVC-MVMM Architecture and Communications","text":"

    Separate the concerns with Design Patterns!

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#what-is-mvcmvvm-architecture","title":"What is MVC/MVVM Architecture?","text":"

    MVC (Model-View-Controller)

    • Model \u2013 data representation layer (how app communicates to db \u2013 Raw or ORM)
    • View \u2013 interface representation (with HTML, CSS and JS)
    • Controller \u2013 request relays (processes HTTP requests)
    MVC

    MVVM (Model-ViewModel-View)

    ViewModel \u2013 data-binding relays (processes the HTTP requests)

    MVVM

    Some inaccuracy

    I acknowledge that this may not be correct. If you search MVC/MVMM, you will see lots of conflicting details. This portion of the slide is explained to make frontend-backend integration easier to explain.

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#examples-of-technologies-with-the-architecture","title":"Examples of Technologies with the Architecture","text":"MVC - Django MVVM - Django + React MVC - Flask MVVM - Flask + React MVC - Express MVVM - Express + React"},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#why-is-software-architecture-important","title":"Why is software architecture important?","text":"

    Architecture shows how an entire software works in a high-level.

    Important for:

    • maintainability and extensibility
    • seperation of concerns
    • choosing different pieces of the stack
    Just some architecture diagrams

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#how-do-frontend-communicate-with-backend","title":"How do frontend communicate with backend?","text":"

    Via HTTP Requests responds with:

    • HTML, CSS, JS
    • JSON/XML
    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#server-side-rendering","title":"Server-side Rendering","text":"

    Via - HTML, CSS, JS

    Data Flow

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#client-side-rendering-and-ajax","title":"Client-side Rendering and AJAX","text":"

    Via HTTP Requests responds with: - blank HTML with JS (at first) - JSON/XML

    Data Flow

    CRUD to HTTP Verb Matching for JSON standard communications with REST-APIs

    Matches HTTP verbs with action

    AJAX \u2013 Asynchronous JavaScript and ~~XML~~ JSON

    JSON are strings

    JSON (JavaScript Object Notation) Note: JSONs are String... you have to serialise JSON to become an object

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#demo-react-to-integrate-with-django","title":"Demo - React to integrate with Django","text":"

    This follows up the demo with React to consume a standard REST-API Django Todo App demonstrated in the previous workshop.

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#other-information","title":"Other Information","text":"
    • Traversy Media MVC
    • React Query
    • Axios (a better Fetch?) Travery Media
    • Async/Await JavaScript
    "},{"location":"2021-2022-summer/package-managers/","title":"Package Managers","text":"

    Unlock the power of open source

    "},{"location":"2021-2022-summer/package-managers/#what-are-package-managers","title":"What are package managers?","text":"
    • Developer tools that allows access to libraries
    Examples
    • JavaScript (NPM/Yarn)
    • Python(Pip/Poetry)
    Diagram of the Package Manager Data Flow Modern Infrastructure Dependency"},{"location":"2021-2022-summer/package-managers/#examples-of-actual-libraries-and-their-dependencies","title":"Examples of Actual Libraries and their dependencies","text":"

    See this tool to visualise dependency.

    MUI Dependency

    Express Dependency

    "},{"location":"2021-2022-summer/package-managers/#install-package-managers","title":"Install Package Managers","text":"
    • NPM Download | Node.js (nodejs.org)
    • Yarn Installation | Yarn (yarnpkg.com)

    • Pip Download Python | Python.org

    • Poetry Poetry - Python dependency management and packaging made easy (python-poetry.org)
    "},{"location":"2021-2022-summer/package-managers/#actual-examples-of-real-world-projects-and-their-dependencies","title":"Actual Examples of Real-World Projects and their dependencies","text":"Foodbank package.json
    {\n    \"name\": \"foodbank\", // (1)\n    \"version\": \"0.1.0\",\n    \"private\": true,\n    \"browserslist\": [\n        \">0.3%\",\n        \"not ie 11\",\n        \"not dead\",\n        \"not op_mini all\"\n    ],\n    \"repository\": {\n        \"type\": \"git\",\n        \"url\": \"git+https://github.com/codersforcauses/foodbank.git\"\n    },\n    \"author\": \"Coders for Causes\",\n    \"license\": \"MIT\",\n    \"bugs\": {\n        \"url\": \"https://github.com/codersforcauses/foodbank/issues\"\n    },\n    \"homepage\": \"https://github.com/codersforcauses/foodbank#readme\",\n    \"scripts\": { // (2)\n        \"dev\": \"next dev\",\n        \"build\": \"next build\",\n        \"start\": \"next start\",\n        \"lint\": \"next lint\",\n        \"prepare\": \"husky install\"\n    },\n    \"dependencies\": { // (3)\n        \"@headlessui/react\": \"1.4.2\",\n        \"critters\": \"0.0.15\",\n        \"keen-slider\": \"6.0.5\",\n        \"next\": \"12.0.4\",\n        \"react\": \"17.0.2\",\n        \"react-dom\": \"17.0.2\",\n        \"react-hook-form\": \"7.20.5\"\n    },\n    \"devDependencies\": { // (4)\n        \"@types/react\": \"17.0.37\",\n        \"autoprefixer\": \"10.4.0\",\n        \"eslint\": \"7.29.0\",\n        \"eslint-config-next\": \"12.0.4\",\n        \"eslint-config-prettier\": \"8.3.0\",\n        \"eslint-plugin-jsx-a11y\": \"6.5.1\",\n        \"eslint-plugin-prettier\": \"4.0.0\",\n        \"husky\": \"7.0.4\",\n        \"postcss\": \"8.4.4\",\n        \"prettier\": \"2.5.0\",\n        \"tailwindcss\": \"2.2.19\",\n        \"typescript\": \"4.5.2\"\n    }\n}\n
    1. Package Headers and Meta Information (line 2-20)

      Contains some meta information about the project. Eg. used for publication in npmjs.org

    2. Scripts

      Alias of commands to run using the modules in the dependency

      yarn start // yarn [script-name]\n

      or

      npm run start // npm run [script-name]\n
    3. Dependencies

      Libraries that are used in the project

      To add a dependency, run

      yarn add formik // yarn add [library-name]\n

      or

      npm install formik // npm install [library-name]\n
    4. Dev-Dependencies

      Libraries that are used in the project on development environments Typically: linters, and testers

      yarn add -D prettier // yarn add -D [library-name]\n

      or

      npm install -D prettier // npm install -D [library-name]\n
    "},{"location":"2021-2022-summer/package-managers/#lockfiles","title":"Lockfiles","text":"

    It locks the dependencies and sub dependencies (dependency of dependency) of your application the last time it installed correctly.

    Files: - package-lock.json - Yarn-lock.json - Poetry.lock

    E.g. wais/yarn.lock at main \u00b7 codersforcauses/wais (github.com)

    "},{"location":"2021-2022-summer/package-managers/#when-to-install-globally","title":"When to install globally?","text":"

    Whenever installing package, it is recommended to install it for a specific project The only thing you should really install globally are CLI tools. Even then, you have npx

    yarn global add [dependency]\n
    or
    npm install \u2013g [dependency]\n

    Firebase CLI

    npm install -g firebase-tools\n
    "},{"location":"2021-2022-summer/package-managers/#demo-material-ui","title":"Demo - Material UI","text":"
    1. Create a react-app npx create-react-app mui-demo
    2. Move directory cd mui-demo
    3. Install react-spring yarn add @mui/material @mui/icons-material
    4. Start the app yarn start
    5. Show Bottom Navigation
      import * as React from 'react';\nimport BottomNavigation from '@mui/material/BottomNavigation';\nimport BottomNavigationAction from '@mui/material/BottomNavigationAction';\nimport FolderIcon from '@mui/icons-material/Folder';\nimport RestoreIcon from '@mui/icons-material/Restore';\nimport FavoriteIcon from '@mui/icons-material/Favorite';\nimport LocationOnIcon from '@mui/icons-material/LocationOn';\n\nexport default function LabelBottomNavigation() {\n  const [value, setValue] = React.useState('recents');\n\n  const handleChange = (event, newValue) => {\n    setValue(newValue);\n  };\n\n  return (\n    <BottomNavigation sx={{ width: 500 }} value={value} onChange={handleChange}>\n      <BottomNavigationAction\n        label=\"Recents\"\n        value=\"recents\"\n        icon={<RestoreIcon />}\n      />\n      <BottomNavigationAction\n        label=\"Favorites\"\n        value=\"favorites\"\n        icon={<FavoriteIcon />}\n      />\n      <BottomNavigationAction\n        label=\"Nearby\"\n        value=\"nearby\"\n        icon={<LocationOnIcon />}\n      />\n      <BottomNavigationAction label=\"Folder\" value=\"folder\" icon={<FolderIcon />} />\n    </BottomNavigation>\n  );\n}\n
    "},{"location":"2021-2022-summer/practical-software-engineering-practices/","title":"Practical Software Engineering Practices","text":"

    How software engineer works collaboratively!

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#how-do-software-engineers-work","title":"How do software engineers work?","text":"

    They use issue/ticket management system to track their work.

    Github Issues and Jira

    The examples are Github Issues and Jira.

    Listing of issues can be displayed in kanban boards.

    Kanban Boards

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#why-do-software-engineers-work-like-this","title":"Why do Software Engineers Work like this?","text":"Scrums

    One example of \"agile\" ways of working and it looks like this.

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#what-is-git","title":"What is Git?","text":"

    Git is a

    • version control system
    • tools for coordinating work for different changes
    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#main-parts-of-git","title":"Main Parts of Git","text":"

    Main Parts of git:

    • Change Node (commit node)
    • Branch

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#git-different-versions","title":"Git Different Versions","text":"Software Versions

    Nodes - Representation of a change (commits + merge)

    Main/Master: - Branch usually as production or deployed

    Development Branch - Branch used for development Used for compiling features for a release

    Feature Branch - Branch used for development for a particular issue

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#github-and-code-repositories","title":"GitHub and Code Repositories","text":"

    GitHub - Place to hold code repositories

    Repositories - Place where codes are stored with different versions

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#interactive-workshop-time","title":"INTERACTIVE WORKSHOP TIME !!!!","text":"
    1. Do the following from codersforcauses/software-engineering-practices-demo: Demonstration of software engineering practices (github.com):
    2. Look at the GitHub issues
    3. Assign yourself an issue
    4. Clone repo with git clone https://github.com/codersforcauses/software-engineering-practices-demo-2021-summer.git
    5. Create a branch with the following format s{Issue Number}-{Issue Name}. git checkout -b s{Issue Number}-{Issue Name}
    6. Create the change to satisfy or complete the github issue
    7. Commit (package) the change git commit -m \"{insert message here}\" and push git push.
    8. Create a pull request and request for a reviewer from CFC peeps
    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#other-resources","title":"Other Resources","text":"
    • Git and Github
    "},{"location":"2021-2022-summer/project-and-workshop-structure/","title":"Project and Workshop Structure","text":"

    A mission to empower the next-generation of software engineers and delivering value to the community!

    "},{"location":"2021-2022-summer/project-and-workshop-structure/#ways-of-working","title":"Ways of Working","text":"
    • (November 27 to February 24 excluding December 19 to January 4) = ~ 11 weeks for project
    • 2 meetups every week (1 online mid-week, 1 on Saturday)

    • Each Saturday meeting will have ~2-3 hour workshops. Some workshops will take the whole hour, while some workshops will take 15-30 minutes.

    • The other time allocated is for working on project with supervision
    • Most workshops will be introductory
    "},{"location":"2021-2022-summer/project-and-workshop-structure/#workshop-schedule","title":"Workshop Schedule","text":"

    The following are rough guideline to the workshop schedules. All workshops are optional, you can attend any of them even if you are not on the specific team dedicated to it (be mindful that there may be time conflicts if it is with the other team).

    Most Workshops are introductory

    They will usually cover the following idea:

    • why is it useful to learn it
    • what are the different aspects of it that you will need to learn

    You will still have to put in the effort to learn it thoroughly.

    Date Workshop Name Recommended Team to attend Duration Saturday, 27 November 2021 Introduction to CFC + Web Development Space All ~1 hour Wednesday, 1 December 2021 Introduction to Web Basics All ~1-1.5 hour Saturday, 4 December 2021 Practical Software Engineering Practices All ~1 hour Saturday, 4 December 2021 Introduction to Frontend Frameworks All ~45 minutes - 1 hour Saturday, 4 December 2021 Introduction to React Foodbank ~45 minutes - 1 hour Saturday, 4 December 2021 Introduction to Vue WAIS ~45 minutes - 1 hour Saturday, 11 December 2021 Introduction to Django WAIS ~1 - 1.5 hours Saturday, 11 December 2021 Introduction to Typescript Foodbank ~30 minutes Saturday, 18 December 2021 MVC Codebase Structure / Frontend-Backend Integration All ~1-1.5 hour Saturday, 18 December 2021 Typical Codebase Structure All ~30 minutes - 1 hour Saturday, 18 December 2021 Package Manager - JavaScript and Python All ~1 hour Saturday, 8 January 2022 Introduction to Docker All ~1 hour Saturday, 8 January 2022 Introduction to Unit Testing and CI/CD All ~1 hour Workshops after January 8, 2022

    The workshops right here are still being decided upon. If you have an idea for a workshop that you would like to attend, please let us know either on Discord or at Github.

    The one that are on consideration are:

    • Deployment on Heroku, and Vercel
    • Introduction to End-to-End Testing with Cypress
    • Gitkraken Workshop
    • Introduction to Prototyping with Figma
    • Introduction to Linux and Command-Line Scripting - Bash
    • Increase your productivity in VsCode
    • How to write good documentation
    • Honing your detective skills with Browser Developer Tools
    "},{"location":"2021-2022-summer/project-and-workshop-structure/#who-are-you","title":"Who are you?","text":"

    Before continuing further, answer the following:

    • What\u2019s your name?
    • What\u2019s your background?
    • Why you\u2019re here?
    Who are the Coders for Causes

    The Coders for Causes is an organisation that aims to empower the next-generation of software engineers while delivering value to the wider-community by helping charities and not-for-profit organisations.

    "},{"location":"2021-2022-summer/setup/","title":"Setup","text":"

    This contains everything you need to know about getting setup.

    "},{"location":"2021-2022-summer/setup/#coders-for-causes-project-team","title":"Coders for Causes Project Team","text":"

    The following access you will need to have when working on the project

    • Coders for Causes Official Project Organisation
      • This includes the project repositories and CFC related long-term materials
    • Coders for Causes Learning Organisation
      • This includes the templates for learning as well as the demo workshops
    • Discord Channel for Project and exclusive Workshops
    "},{"location":"2021-2022-summer/setup/#developer-tools","title":"Developer Tools","text":"

    These are the following tools that you need:

    • Code Editor: VS Code
    • Version Control: Git
    • Interpreter: Nodejs
    • Custom Package Manager: Yarn
    • Interpreter (for WAIS): Python
    • Containerisation (for WAIS): Docker
    Optional Tools

    These are tools that you may like to use, but are not required:

    • GUI for Git: Gitkraken / GitHub Desktop

    After these installation, seek at the OS-specific tools.

    "},{"location":"2021-2022-summer/setup/#windows","title":"Windows","text":"

    These are tools specifically for Windows:

    • Virtual Machine: Vbox
      • You need this if you have some trouble with windows
    Warning for Windows Users

    Legit, among all the OS, you will have the most frustrating time as a developer in windows (unless you're doing C#)

    Wanna have a better developer experience

    You have a couple of options:

    • Using WSL
    • Dual Booting
    • Virtual Machines

    The recommended OS to try is Ubuntu-based Linux. My personal favourite is PopOS.

    "},{"location":"2021-2022-summer/setup/#linux","title":"Linux","text":"

    These are installation specific to Linux:

    • Docker Post Installation Steps

      • Lots of users forget this documentation
      • This step is necessary if you intend to use the visual studio code docker extension
      • This will also allow you to run docker without the \"sudo\" command
    • Docker Compose Installation

      • Docker compose is not installed by default with Linux installations of Docker
      • Please follow this documentation
    • Node installation using Node Version Manager (NVM)

      • Installation steps can be found here
      • NVM is useful when dealing with multiple environments that require different versions of Node
      • It allows you to switch between different Node versions and environments easily
      • This tool is also available if you are using Windows Subsystem for Linux
    "},{"location":"2021-2022-summer/typical-codebase-structure/","title":"Typical Codebase Structure","text":"

    Codebase Jigsaw: How it all fits together!

    Info

    This presentation is only intended to be a brief overview of the typical codebase structure

    If you want more information about anything mentioned feel free to reach out to CFC committee and project helpers!

    "},{"location":"2021-2022-summer/typical-codebase-structure/#overview-and-importance","title":"Overview and Importance","text":"
    • Most codebase will follow almost the same pattern (if they change, it will only change with little quirks)
    • Structure helps every software engineer understand codebase and where to put it certain codes (better code readability = better collaboration = better profit!)
    Profit"},{"location":"2021-2022-summer/typical-codebase-structure/#frontend","title":"Frontend","text":"

    Example: About Us - Coders for Causes Website

    "},{"location":"2021-2022-summer/typical-codebase-structure/#different-folders-and-purpose","title":"Different Folders and Purpose","text":""},{"location":"2021-2022-summer/typical-codebase-structure/#components","title":"Components","text":"

    Components are individual parts/pieces of user interfaces

    "},{"location":"2021-2022-summer/typical-codebase-structure/#pages","title":"Pages","text":"

    Pages are the direct components that are related specific to a route or URL

    "},{"location":"2021-2022-summer/typical-codebase-structure/#public-assets","title":"Public / Assets","text":"

    Assets are usually elements that are referenced E.g. Images, Videos

    "},{"location":"2021-2022-summer/typical-codebase-structure/#utilities-helpers","title":"Utilities / Helpers","text":"

    Pieces of code that are used as utilities or helpers to other codes

    "},{"location":"2021-2022-summer/typical-codebase-structure/#tests","title":"Tests","text":"
    • Scripts that tests that code works
    • Usually E2E frontend
    "},{"location":"2021-2022-summer/typical-codebase-structure/#comparison-with-two-codebases","title":"Comparison with Two Codebases","text":"

    Slight difference, look at software documentation or ask other engineers

    "},{"location":"2021-2022-summer/typical-codebase-structure/#backend","title":"Backend","text":"Context - Role and Subject

    In these example, when I mean \"role\", I mean the general role of file. \"subject\" means the feature or group functionality

    "},{"location":"2021-2022-summer/typical-codebase-structure/#method-of-organisation","title":"Method of Organisation","text":""},{"location":"2021-2022-summer/typical-codebase-structure/#subject-oriented-driven-structure","title":"Subject-Oriented Driven Structure","text":"

    As it can be seen here, both different folders will have the same filenames based on its role. App grows, those files can itself become folders as well.

    Example: erdem/DRF-TDD-example: An example Django REST framework project for test driven development. (github.com)

    "},{"location":"2021-2022-summer/typical-codebase-structure/#role-oriented-driven-structure","title":"Role-Oriented Driven Structure","text":"

    As it can be seen here, both both different folders will have the same filenames based on its subject

    Example: our-lab-training/olt-backend: Our Lab Training - Feathers Backend (github.com)

    "},{"location":"2021-2022-summer/typical-codebase-structure/#different-folders-and-purpose_1","title":"Different Folders and Purpose","text":""},{"location":"2021-2022-summer/typical-codebase-structure/#models-database-connection","title":"Models / Database Connection","text":"

    Object-Relational Model (ORM). Links the database into your app into objects

    "},{"location":"2021-2022-summer/typical-codebase-structure/#routing","title":"Routing","text":"

    Determines the rules for the URL pattern

    "},{"location":"2021-2022-summer/typical-codebase-structure/#views","title":"Views","text":"
    • In REST API, Views are your main \u201cview\u201d of the API
    "},{"location":"2021-2022-summer/typical-codebase-structure/#tests_1","title":"Tests","text":"
    • Contains unit testing (+ possibly e2e testing)
    • Most common candidate for transitioning from file to a folder containing more files
    "},{"location":"2021-2022-summer/typical-codebase-structure/#other-resources","title":"Other Resources","text":"
    • Writing your first Django app, part 1 | Django documentation | Django (djangoproject.com)
    • File Structure \u2013 React (reactjs.org)
    • Best practice for Django project working directory structure - Stack Overflow
    "},{"location":"2021-winter/","title":"Coders for Causes 2021 Winter Workshops","text":"

    This project period there are two main projects:

    • Foodbank
    • WAIS

    If you have not before seen the existing progress, see this video.

    These two projects have their own corresponding technology stacks being used, hence will dictate the workshops that will be held.

    "},{"location":"2021-winter/#project-technology","title":"Project Technology","text":""},{"location":"2021-winter/#foodbank","title":"Foodbank","text":"

    Foodbank is mainly with frontend with React + TailwindCSS with Firebase and Notion CMS.

    "},{"location":"2021-winter/#wais","title":"WAIS","text":"

    WAIS is a full-stack application with Vue and Django. It uses Docker containerisation for both development (and production in the future).

    "},{"location":"2021-winter/#where-are-the-materials","title":"Where are the materials?","text":"

    This website has only been created prior to 2021/22 Summer workshops. However, you can find the videos in our Youtube channel, and workshops slides in google drive.

    "},{"location":"2022-2023-summer/","title":"Coders for Causes 2021/22 Summer Workshops","text":"

    This project period continues the two main projects from the winter of 2020 :

    • WADL
    • POOPS

    If you have not before seen the existing progress, see this video.

    These two projects have their own corresponding technology stacks being used, hence will dictate the workshops that will be held.

    "},{"location":"2022-2023-summer/#project-technology","title":"Project Technology","text":""},{"location":"2022-2023-summer/#poops","title":"POOPS","text":"

    POOPS is a web-app built the frontend with React + NextJS + TypeScript + TailwindCSS with Firebase and Notion CMS.

    "},{"location":"2022-2023-summer/#wadl","title":"WADL","text":"

    WADL is a full-stack application with Vue and Firebase. It uses Docker containerisation for both development (and production in the future).

    "},{"location":"2022-2023-summer/#workshop-recordings","title":"Workshop Recordings","text":"

    The workshop recordings will be held on our youtube channel.

    "},{"location":"2022-2023-summer/introduction-to-web-development/","title":"Introduction to Web Development Space","text":"

    Navigating the Deep Dark Space of Web Development

    This workshop covers a brief overview of the most common tools and technologies used in web development.

    "},{"location":"2022-2023-summer/introduction-to-web-development/#content","title":"Content","text":"
    • Introduction to Web Development Space
    • Content
    • What and Why Web Development?
      • What is web development?
      • Why Web Development ?
    • FAQs about Web Development
      • Why code websites, why not use drag and drops like Wordpress, WIX?
      • What is the best way to learn all these?
      • Why does CFC not do mobile development as much as web development?
      • If I already know a frontend framework, is it better to learn another frontend framework or to learn a backend framework?
    • Basics of Web and Limitation
      • Modern Frameworks
    • Server-side Applications (Backend)
      • How do devices communicate?
      • What do server applications do?
      • Databases
    • Others
      • Languages of the Web (the usual)
      • Hosting Stuff
      • CSS Frameworks
      • Developer Tools
      • TypeScript
      • Testing
      • Continuous Integration / Continuous Deployment
      • Virtualisation and Containerisation
      • Browsers
      • Firefox Developer Tools
      • Package Managers
      • Version Control
      • Linters and Formatters
      • Teamwork
      • Roadmaps
    • Word of Encouragement
    "},{"location":"2022-2023-summer/introduction-to-web-development/#what-and-why-web-development","title":"What and Why Web Development?","text":""},{"location":"2022-2023-summer/introduction-to-web-development/#what-is-web-development","title":"What is web development?","text":"
    • Websites development
    • Web applications (client-side and server-side) development
    "},{"location":"2022-2023-summer/introduction-to-web-development/#why-web-development","title":"Why Web Development ?","text":"
    • Accessibility and Portability
    • Career and On-demand in job market
    • Huge possibility to combine with other emerging technologies (e.g. IoT, Machine Learning) and industry (e.g. Health, Mining, O&G)
    Career in Web Development

    Source: Insights from Stack Overflow\u2019s 2016 survey of 50,000 developers

    \"Half of Developers are Web Developers\"

    "},{"location":"2022-2023-summer/introduction-to-web-development/#faqs-about-web-development","title":"FAQs about Web Development","text":""},{"location":"2022-2023-summer/introduction-to-web-development/#why-code-websites-why-not-use-drag-and-drops-like-wordpress-wix","title":"Why code websites, why not use drag and drops like Wordpress, WIX?","text":"
    • Content Management System (CMS)
    • Limitations on theme/template used
    • Difficult to extend
    • Cybersecurity
    More information

    CMS are one of the application of web development, but there are plenty more such as - internet of things, custom software for a particular industrial application (eg. using Machine Learning)

    CMS are usually limited to the template or plugin that you use. If those plugin don't exist, then it limits your productivity very much (difficulty to extend).

    CMS are usually built to cater for non-technical users. This means that thye become the subject of hackers. Think about a scenario where a hacker was able to find a vulnerability in WordPress, now every other WordPress site will be vulnerable.

    "},{"location":"2022-2023-summer/introduction-to-web-development/#what-is-the-best-way-to-learn-all-these","title":"What is the best way to learn all these?","text":"

    In summary, the best way to learn:

    • Do personal projects (inspiration + motivation)
    • Do team projects (get peer reviews and correct bad practices straight away)
    • Watch Online Courses (to figure out what is available)
    More Information

    To be told that you have to learn \"this, this, and that\" before you could do things is tiresome.

    Often times, we want to learn to be a developer so that we can create cool things like software where thousands of people can use the app. We don't tend to be a developer for the sake of us needing to watch endless videos on different things.

    "},{"location":"2022-2023-summer/introduction-to-web-development/#why-does-cfc-not-do-mobile-development-as-much-as-web-development","title":"Why does CFC not do mobile development as much as web development?","text":"
    • App stores has a developer cost
    • Easier to deal/teach web technologies
    • Accessibility (mobile, sensors, tablets, laptops and PCs)
    • Bigger open-source community
    "},{"location":"2022-2023-summer/introduction-to-web-development/#if-i-already-know-a-frontend-framework-is-it-better-to-learn-another-frontend-framework-or-to-learn-a-backend-framework","title":"If I already know a frontend framework, is it better to learn another frontend framework or to learn a backend framework?","text":"
    • It is better to learn a backend framework
    Reasoning

    You want to build skills that complement one another rather than be an alternative.

    It is much more valuable for you to learn a backend framework because that helps you build a functional app.

    "},{"location":"2022-2023-summer/introduction-to-web-development/#basics-of-web-and-limitation","title":"Basics of Web and Limitation","text":"HTML

    What is it?

    • Hypertext Markup Language
    • Describes the structure of a web page

    Limitation

    • Doesn\u2019t handle repeated content well
    • No variables or calculation
    HTML Syntax
    <!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Document</title>\n</head>\n<body>\n    Hello World!\n</body>\n</html>\n
    CSS

    What is it?

    • Cascading Style Sheets
    • Describes the presentation of a web page

    Limitation

    • Most css is quite similar (Handled by CSS Libraries)
    • Not very dynamic (Handled by CSS Frameworks)
    CSS Syntax
    body {\n    background-color: #f0f0f0;\n    font-family: sans-serif;\n}\n\n.container{\n    width: 80%;\n    margin: 0 auto;\n}\n
    JS

    What is it?

    • JavaScript
    • Used to program complex features on a web page

    Limitation

    • Has the capability to modify the user interface, but becomes really tedious to modify interface (more about this in another workshop)
    JS Syntax
    const bodySelector = document.querySelector('body');\nconst myFunction = () => {\n    bodySelector.innerHTML = 'Hello World 2!';\n    // Add a container class to space out\n    bodySelector.classList.add('container');\n}\nbodySelector.onclick = myFunction;\n
    "},{"location":"2022-2023-summer/introduction-to-web-development/#modern-frameworks","title":"Modern Frameworks","text":"
    • Websites can be much more\u2026 they can be web applications
    • \u201cApp\u201d in a website (client-side rendering)
    Modern Frameworks React.js
    • More mature and used more in industry
    Vue.js
    • Growing fast in popularity and use.

    General Information

    • Both are good to use and learn.
    • Knowledge is transferable between the two frameworks.
    Comparison between HTML and JSX

    Highlighted portions are starting chunk of distinct code.

    HTML
    <div class=\"row\">\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">devices</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Applications\n            </p>\n            <p class=\"mb-0\">\n            Build custom web and mobile applications to engage with your audience\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">web</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">Websites</p>\n            <p class=\"mb-0\">\n            Build new websites or optimise existing pages to improve online\n            visibility\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">storage</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Data Storage\n            </p>\n            <p class=\"mb-0\">\n            Design and create databases for efficient information storage and\n            retrieval\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">how_to_reg</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Consulting\n            </p>\n            <p class=\"mb-0\">\n            Empower your organisation through technical knowledge and advice\n            </p>\n        </div>\n        </div>\n    </div>\n</div>\n
    JSX
    import { memo } from 'react'\nimport { Row, Col, Card, CardBody } from 'reactstrap'\nimport services from 'data/services.json'\n\nconst Service = (props: {\nicon: string\ntitle: string\ndescription: string\n}) => (\n<Card className='text-center border-0 bg-transparent'>\n    <CardBody className='px-0'>\n    <i className='material-icons-sharp md-lg'>{props.icon}</i>\n    <p className='mt-4 font-weight-bold text-monospace text-larger'>\n        {props.title}\n    </p>\n    <p className='mb-0'>{props.description}</p>\n    </CardBody>\n</Card>\n)\n\nconst Services = () => (\n<Row>\n    {services.map(service => (\n    <Col\n        xs={12}\n        md={6}\n        lg={12 / services.length}\n        className='m-0'\n        key={service.title}\n    >\n        <Service {...service} />\n    </Col>\n    ))}\n</Row>\n)\n\nexport default memo(Services)\n
    "},{"location":"2022-2023-summer/introduction-to-web-development/#server-side-applications-backend","title":"Server-side Applications (Backend)","text":""},{"location":"2022-2023-summer/introduction-to-web-development/#how-do-devices-communicate","title":"How do devices communicate?","text":"
    • HTTP Request - Hypertext Transfer Protocol
    "},{"location":"2022-2023-summer/introduction-to-web-development/#what-do-server-applications-do","title":"What do server applications do?","text":"
    • Serve frontends (server-side rendering)
    • Web API (Application Programming Interface)
      • Serve data (usually from a database)
      • Process Request (Sending emails or SMS, Machine Learning)
    "},{"location":"2022-2023-summer/introduction-to-web-development/#databases","title":"Databases","text":"

    Place to store the data

    Mongodb

    Allows for database design to be modified without complex migration or data loss

    SQL

    Typically faster and better for large amounts of data or systems that need data consistency and reliability

    "},{"location":"2022-2023-summer/introduction-to-web-development/#others","title":"Others","text":""},{"location":"2022-2023-summer/introduction-to-web-development/#languages-of-the-web-the-usual","title":"Languages of the Web (the usual)","text":"
    • Python (Django, Flask)
    • JavaScript (Node.js, Express)
    • Ruby, Go, Rust, C
    "},{"location":"2022-2023-summer/introduction-to-web-development/#hosting-stuff","title":"Hosting Stuff","text":"

    Many ways - Own a server - Use a 3rd party platform

    "},{"location":"2022-2023-summer/introduction-to-web-development/#css-frameworks","title":"CSS Frameworks","text":"

    Frontend (JS)

    • Vue, React
    • Nuxt.js, Next.js

    Frontend (CSS)

    • MaterialUI, Vuetify
    • Bootstrap
    "},{"location":"2022-2023-summer/introduction-to-web-development/#developer-tools","title":"Developer Tools","text":""},{"location":"2022-2023-summer/introduction-to-web-development/#typescript","title":"TypeScript","text":"
    • Type checking is super useful for complex apps
    • Allows for way better javascript developer tooling
    • Can be annoying if you\u2019re new at it
    "},{"location":"2022-2023-summer/introduction-to-web-development/#testing","title":"Testing","text":"
    • Selenium, Cypress
      • End to end automated testing tools
    • Jest, Mocha, Pytest
      • Unit testing
    • Testing is vital to software projects
    "},{"location":"2022-2023-summer/introduction-to-web-development/#continuous-integration-continuous-deployment","title":"Continuous Integration / Continuous Deployment","text":"
    • Automated Testing
    • Event-driven scripts
    • E.g. Github Action, Bitbucket Pipelines
    "},{"location":"2022-2023-summer/introduction-to-web-development/#virtualisation-and-containerisation","title":"Virtualisation and Containerisation","text":"
    • Allows execution of services in a virtual environment
    • eg. Docker (Containerisation), Vagrant (Virtualisation)
    "},{"location":"2022-2023-summer/introduction-to-web-development/#browsers","title":"Browsers","text":"
    • Standard browsers
      • Google Chrome, Firefox, Edge, etc.
    • Backwards compatibility
      • Internet Explorer
    • Other
      • Mobile - Responsive
      • Screen readers - Accessibility
    "},{"location":"2022-2023-summer/introduction-to-web-development/#firefox-developer-tools","title":"Firefox Developer Tools","text":"
    • Page Inspector
      • Visualise page aspects
      • Grid layout
    • Web Console
      • console.log(\u201cHello World\u201d)
    • Responsive Design Mode
      • View from POV of different screen sizes such as mobile, tablets, etc.
    Some more tools
    • JavaScript Debugger
    • Network Monitor
    • Performance Tools
    • Rulers
    • Colour Pickers Learn more at: https://developer.mozilla.org/en-US/docs/Tools
    "},{"location":"2022-2023-summer/introduction-to-web-development/#package-managers","title":"Package Managers","text":"
    • Installs libraries that can be used
    • Also has code shortcuts (e.g. npm run start)

    (More about package.json and poetry.toml in the projects and Package Manager Workshop)

    "},{"location":"2022-2023-summer/introduction-to-web-development/#version-control","title":"Version Control","text":"
    • Essential for developer teams and complex software development
    • Git
    "},{"location":"2022-2023-summer/introduction-to-web-development/#linters-and-formatters","title":"Linters and Formatters","text":"
    • Makes code formatting consistent (following standard)
    • Useful with version controls to avoid pointless change

    eg.ESLint, Prettier

    "},{"location":"2022-2023-summer/introduction-to-web-development/#teamwork","title":"Teamwork","text":"
    • Many tools out there
    • Used to stop teams from stepping on each others toes
    • Github Issues + Pull Requests
    "},{"location":"2022-2023-summer/introduction-to-web-development/#roadmaps","title":"Roadmaps","text":"

    There's an open-source community that maintains a learning roadmap for developers. See https://roadmap.sh/

    Frontend Developer

    Backend Developer

    Dev-Ops

    "},{"location":"2022-2023-summer/introduction-to-web-development/#word-of-encouragement","title":"Word of Encouragement","text":"Encouragement from the Tech Lead

    \"I can admit that this journey of learning will be difficult, and can sometimes be overwhelming and demotivating. Please, if at any point of this project, you feel that you don't know enough, or you're feeling lost, please reach out! We are all in this journey together! Nobody is born talented, skills are honed with determination and willingness to learn.\"

    \"When I was a first year student entering on the CFC winter project, I didn't feel like I was good enough. I couldn't create a good looking interface, I didn't know how to use npm and all sorts of those things. I was just like many of you! if I gave up just because of all those things I didn't know, of all those self-doubts, then I wouldn't be here today. I admit that I was lucky because I was in CFC, I had connections where I can just ask questions instead of feeling lost of not knowing. So please do leverage that opportunity to reach out\"

    \"You being in this project not only gives you the opportunity to raise your talents, but you also unlock one of the biggest factor of the growth of your career, and that is the connections with your fellow software engineers.\"

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/","title":"MVC and MVVM: Software Architectural Patterns and Communication","text":"

    Don't pull all your eggs in one basket!

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#content","title":"Content","text":"
    • Software Architecture
      • Model-View-Controller (MVC)
      • Model-View-ViewModel (MVVM)
      • MVC or MVVM?
        • Pros and Cons of MVC
        • Pros and Cons of MVVM
    • Communication
      • Application Programming Interfaces (API)
      • REST: Representation State Transfer
        • Why REST APIs?
    • Demo
    • Resources
    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#software-architecture","title":"Software Architecture","text":"

    The main idea behind implementing software architectural patterns is to address the principle of the Separation of Concerns.

    The goal of Separation of Concerns is to establish a well-organised system, where each section has its own specific, designated role, allowing a project to be well managed and easier to grow.

    Software architecture is the high-level structure of a software system, comprising the overall design of the system, the relationships between its components, and the principles that govern its design and evolution. Architecture is important because it provides a blueprint for the design and implementation of a software system, and defines the ways in which the system can be modified and extended over time.

    The architecture of a system is critical to the success of the software as it sets the foundations of the project, providing the basis to ensure quality and maintainability of the system. A well-designed architecture can make it easier to develop and test the system, and can help to ensure that it is flexible, scalable, and reliable.

    By separating concerns, we can use different technologies for each section which will allow us to decide what stack to use during development. These choices can optimise the performance, development, and testing of the system.

    Beware! Poorly designed system inside!

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#model-view-controller-mvc","title":"Model-View-Controller (MVC)","text":"

    MVC, or Model-View-Controller, is a software architecture pattern that divides an application into three main components: the model, the view, and the controller.

    The model represents the data and the business logic of the application. It is responsible for managing the data and ensuring that it is up-to-date and accurate.

    The view is the user interface of the application. It is responsible for displaying the data to the user and providing a way for the user to interact with the application.

    The controller is the component that mediates between the model and the view. It is responsible for handling user input and updating the model and the view accordingly.

    In an MVC architecture, the model, view, and controller are all independent components that communicate with each other through well-defined interfaces. This allows for a clean separation of concerns, making it easier to develop and maintain the application.

    MVC

    Note

    The example above follows the linear implementation of the MVC pattern. You may see examples of the triangular implementation of MVC which is still a completely valid implementation. The only difference, in principle, is how each section communicates with one another.

    Each framework is different!!!

    While the idea is still the same, each framework implements each section of the MVC pattern slightly differently. Get to know your framework!

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#model-view-viewmodel-mvvm","title":"Model-View-ViewModel (MVVM)","text":"

    MVVM, or Model-View-ViewModel, is a software architecture pattern that is similar to MVC, but with some important differences. It is an architectural pattern used for building user interfaces in modern application development frameworks

    In an MVVM architecture, the View and the Controller from the MVC pattern are combined into a single component called the ViewModel. The ViewModel exposes data to the View, and translates user actions, such as button clicks, into commands that are sent to the Model to perform the appropriate business logic.

    The ViewModel and View are binding together in a process called data binding. Data binding is the process of establishing a connection between the user interface (the View) and its underlying data model (the ViewModel). This allows for direct communication between the two, meaning the UI updates as the data changes and actions are processed by the ViewModel as soon as they happen on the View.

    MVVM

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#mvc-or-mvvm","title":"MVC or MVVM?","text":"

    The right architecture has to be used for the right job, and with the right frameworks. And while MVC and MVVM work in similar ways, they each have their on advantages and disadvantages.

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#pros-and-cons-of-mvc","title":"Pros and Cons of MVC","text":"Pros Cons Clear separation of concerns between the application's data model, user interface, and control logic Difficult to implement in some programming languages and frameworks, especially those that do not have built-in support for the pattern Easier to develop and maintain large, complex applications, and allows different aspects of the application to be developed and tested independently Harder to develop modern user interfaces"},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#pros-and-cons-of-mvvm","title":"Pros and Cons of MVVM","text":"Pros Cons Provides a more flexible and powerful architecture for building GUI applications Can be more difficult to implement than MVC in some cases, and it may require a more complex and sophisticated development environment in order to take full advantage of its capabilities Data binding Data binding Data binding automatically synchronises the application's user interface and data model, which can make it easier to implement complex features and interactions Use of data binding can make it harder to debug and troubleshoot applications, since changes to the data model may not always be immediately visible in the user interface"},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#summary","title":"Summary","text":"

    There are plenty of architectural design patterns for all your software needs. Many are far too complicated and extensive to use in our case. MVC and MVVM are simple in design and easy to implement, making them among the most popular design patterns and perfect for developing web applications.

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#communication","title":"Communication","text":"

    Now that we're experts in designing systems, let's talk about how each part of the system actually communicates with each other.

    Disclaimer

    There are many more ways that systems communicate with each. However, we will only cover the basics required in web development.

    If you feel like learning more about the different software communication channels that exist, a good place to start is with sockets or buses!

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#application-programming-interfaces-api","title":"Application Programming Interfaces (API)","text":"

    An API is a mechanism that allows two software components to communicate with other using a set of definitions and protocols. It is a sort of middleman that enables different software programs to communicate and share data in a consistent and predictable manner.

    APIs can act as the \"Controller\" in MVC systems. The API will handle incoming requests from the frontend (the View), perform some logic which may include fetching data from the Model, then return responses to the client. They can also be used in MVVM architecture to allow communication between the ViewModels and the Models, as well as between any other services used.

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#rest-representation-state-transfer","title":"REST: Representation State Transfer","text":"

    RESTful APIs are application programming interfaces that follow the constraints of REST architectural style and allows for interaction with RESTful web services. You can read more about the details of REST, here.

    In terms of using RESTful APIs, there are some naming and implementing conventions used to accurately label the endpoint with what it does.

    CRUD to HTTP Verb Matching for JSON standard communications with REST-APIs

    CRUD stands for Create, Read, Update, and Delete. RESTful APIs use HTTP verbs to specify the CRUD operation an endpoint is performing.

    HTTP Verb CRUD Operation POST Create/Update GET Read PUT Update/Replace PATCH Update/Modify DELETE Delete

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#why-rest-apis","title":"Why REST APIs?","text":"

    There are many advantages to using RESTful APIs compared to other frameworks. These include:

    • Scalability
      • Are able to handle a large number of requests without affecting performance
      • Stateless nature allows each request to be handled independently
    • Flexibility
      • Support a wide range of data formats and content types
      • More resilient to change
    • Interoperability
      • Are able to be used by a wide range of clients
      • Allows developers to build applications that can integrate with a variety of different systems and services
    • Ease of use
      • Follow a simple, standardised protocol (HTTP, HTTPS)
      • To request a resource via a REST API, you just need to provide its URL
    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#demo","title":"Demo","text":"

    We will be doing a demo to build simple MVC and MVVM applications (if time persists).

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#resources","title":"Resources","text":"

    Keep the learning going!

    Find some useful resources below:

    • MVC Framework - Introduction
    • The Model-View-ViewModel Pattern
    • MVC vs MVVM \u2013 Difference Between Them
    • Red Hat: What is an API?
    • \"What is a REST API?\" by Jamie Juviler
    • Talk to an AI! (ChatGPT)
      • DISCLAIMER: May generate incorrect information
    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/","title":"Practical Software Engineering Workflow","text":"

    How software engineer GSD!

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#how-do-software-engineers-work","title":"How do software engineers work?","text":"

    They use issue/ticket management system to track their work.

    Github Issues and Jira

    The examples are Github Issues and Jira.

    Listing of issues can be displayed in kanban boards.

    Kanban Boards

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#why-do-software-engineers-work-like-this","title":"Why do Software Engineers Work like this?","text":"Scrums

    One example of \"agile\" ways of working and it looks like this.

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#what-is-git","title":"What is Git?","text":"

    Git is a

    • version control system
    • tools for coordinating work for different changes
    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#main-parts-of-git","title":"Main Parts of Git","text":"

    Main Parts of git:

    • Change Node (commit node)
    • Branch

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#git-different-versions","title":"Git Different Versions","text":"Software Versions

    Nodes - Representation of a change (commits + merge)

    Main/Master: - Branch usually as production or deployed

    Development Branch - Branch used for development Used for compiling features for a release

    Feature Branch - Branch used for development for a particular issue

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#github-and-code-repositories","title":"GitHub and Code Repositories","text":"

    GitHub - Place to hold code repositories

    Repositories - Place where codes are stored with different versions

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#interactive-workshop-time","title":"INTERACTIVE WORKSHOP TIME !!!!","text":"
    1. Do the following from codersforcauses/software-engineering-practices-demo: Demonstration of software engineering practices (github.com):
    2. Look at the GitHub issues
    3. Assign yourself an issue
    4. Clone repo with git clone https://github.com/codersforcauses/software-engineering-practices-demo-2022-summer.git
    5. Create a branch with the following format s{Issue Number}-{Issue Name}. git checkout -b {Issue Number}-{Issue Name}
    6. Create the change to satisfy or complete the github issue
    7. Commit (package) the change git commit -m \"{insert message here}\" and push git push.
    8. Create a pull request and request for a reviewer from CFC peeps
    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#other-resources","title":"Other Resources","text":"
    • Git and Github
    "},{"location":"2022-2023-summer/typical-codebase-structure/","title":"Typical Codebase Structure","text":"

    Codebase Jigsaw: How it all fits together!

    Info

    This presentation is only intended to be a brief overview of the typical codebase structure

    If you want more information about anything mentioned feel free to reach out to CFC committee and project helpers!

    "},{"location":"2022-2023-summer/typical-codebase-structure/#overview-and-importance","title":"Overview and Importance","text":"
    • Most codebase will follow almost the same pattern (if they change, it will only change with little quirks)
    • Structure helps every software engineer understand codebase and where to put it certain codes (better code readability = better collaboration = better profit!)
    Profit"},{"location":"2022-2023-summer/typical-codebase-structure/#frontend","title":"Frontend","text":"

    Example: About Us - Coders for Causes Website

    "},{"location":"2022-2023-summer/typical-codebase-structure/#different-folders-and-purpose","title":"Different Folders and Purpose","text":""},{"location":"2022-2023-summer/typical-codebase-structure/#components","title":"Components","text":"

    Components are individual parts/pieces of user interfaces

    "},{"location":"2022-2023-summer/typical-codebase-structure/#pages","title":"Pages","text":"

    Pages are the direct components that are related specific to a route or URL

    "},{"location":"2022-2023-summer/typical-codebase-structure/#public-assets","title":"Public / Assets","text":"

    Assets are usually elements that are referenced E.g. Images, Videos

    "},{"location":"2022-2023-summer/typical-codebase-structure/#utilities-helpers","title":"Utilities / Helpers","text":"

    Pieces of code that are used as utilities or helpers to other codes

    "},{"location":"2022-2023-summer/typical-codebase-structure/#tests","title":"Tests","text":"
    • Scripts that tests that code works
    • Usually E2E frontend
    "},{"location":"2022-2023-summer/typical-codebase-structure/#comparison-with-two-codebases","title":"Comparison with Two Codebases","text":"

    Slight difference, look at software documentation or ask other engineers

    "},{"location":"2022-2023-summer/typical-codebase-structure/#backend","title":"Backend","text":"Context - Role and Subject

    In these example, when I mean \"role\", I mean the general role of file. \"subject\" means the feature or group functionality

    "},{"location":"2022-2023-summer/typical-codebase-structure/#method-of-organisation","title":"Method of Organisation","text":""},{"location":"2022-2023-summer/typical-codebase-structure/#subject-oriented-driven-structure","title":"Subject-Oriented Driven Structure","text":"

    As it can be seen here, both different folders will have the same filenames based on its role. App grows, those files can itself become folders as well.

    Example: erdem/DRF-TDD-example: An example Django REST framework project for test driven development. (github.com)

    "},{"location":"2022-2023-summer/typical-codebase-structure/#role-oriented-driven-structure","title":"Role-Oriented Driven Structure","text":"

    As it can be seen here, both both different folders will have the same filenames based on its subject

    Example: our-lab-training/olt-backend: Our Lab Training - Feathers Backend (github.com)

    "},{"location":"2022-2023-summer/typical-codebase-structure/#different-folders-and-purpose_1","title":"Different Folders and Purpose","text":""},{"location":"2022-2023-summer/typical-codebase-structure/#models-database-connection","title":"Models / Database Connection","text":"

    Object-Relational Model (ORM). Links the database into your app into objects

    "},{"location":"2022-2023-summer/typical-codebase-structure/#migrations","title":"Migrations","text":"
    • Stores changes to be applied to our database
    "},{"location":"2022-2023-summer/typical-codebase-structure/#serializers","title":"Serializers","text":"
    • Specifies how your data are formatted across requests

    )

    "},{"location":"2022-2023-summer/typical-codebase-structure/#views","title":"Views","text":"
    • In REST API, Views are your main \u201cview\u201d of the API
    • Handles your business logic
    "},{"location":"2022-2023-summer/typical-codebase-structure/#urls","title":"URLs","text":"
    • Used for routing and determining the rules for the URL pattern.
    "},{"location":"2022-2023-summer/typical-codebase-structure/#tests_1","title":"Tests","text":"
    • Contains unit testing (+ possibly e2e testing)
    • Most common candidate for transitioning from file to a folder containing more files
    "},{"location":"2022-2023-summer/typical-codebase-structure/#other-resources","title":"Other Resources","text":"
    • Writing your first Django app, part 1 | Django documentation | Django (djangoproject.com)
    • File Structure \u2013 React (reactjs.org)
    • Best practice for Django project working directory structure - Stack Overflow
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/","title":"Welcome to the Djangol!","text":"

    Welcome to the (Django)l !: Introduction to Backend Programming with Django

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#prerequisites-to-this-workshop","title":"Prerequisites to this Workshop","text":"

    You need the following installed:

    • Python3
    • Docker
    • Git

    The starting repo for this workshop: https://github.com/CodersforLearning/django-csf

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#what-you-will-be-building-as-part-of-this-workshop","title":"What you will be building as part of this workshop?","text":"

    You will be building a backend for an event management system. Below is the schematics

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#what-are-apis-and-rest-apis","title":"What are APIs and REST-APIs?","text":"

    Application Programming Interface

    Analogy

    Who interacts with the user interface? - the user Who interacts with the application programming interface ? - the application program (eg. the browser)

    Representational State Transfer Application Programming Interface

    • backend architectural pattern that follows the GET/POST/PUT/PATCH/DELETE

    • Can be represented in Swagger/ Open API specification

    Swagger/ Open API specification

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#what-is-django","title":"What is Django?","text":"

    Django

    • Python web framework for creating server-side application

    Follows MVC:

    • Model - database
    • View \u2013 Interface (API or User Interface)
    • Controller \u2013 URLs + routes

    See Documentation

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#what-is-django-rest-framework-drf","title":"What is Django REST Framework (DRF)?","text":"
    • library for creating REST-API
    • just makes it easier develop REST-API

    In:

    • Authentication + Permission
    • Generic API Views
    • Serialisers (payload validation and format)

    See Documentation

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#interactive-workshop-time","title":"Interactive Workshop Time!!!","text":"

    Firstly, open your IDE (VSCode) and open the terminal.

    1. Clone the repo: git clone https://github.com/CodersforLearning/django-csf.git
    2. Go to the directory: cd django-csf
    3. Run the setup script: ./setup.sh
    What does the setup script do?
    #!/bin/bash\n\n# Create a Python virtual environment\npython3 -m venv venv\n\n# Activate Python environment\nsource venv/bin/activate\n\n# Install Django\npip3 install Django\n\n# Bootstraps the django codebase\ndjango-admin startproject csfevents\n\n# As per https://www.django-rest-framework.org/#installation\npip3 install djangorestframework\npip3 install markdown       # Markdown support for the browsable API.\npip3 install django-filter  # Filtering support\npip3 install pytz           # Timezone support\n\n# Freeze the requirements\ncd csfevents\npip3 freeze > requirements.txt\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#initial-files","title":"Initial files","text":"
    • manage.py - the entrypoint of the Django application
    • csfevents - the main Django application
    • csfevents/settings.py - the configuration file of the Django application
    • csfevents/urls.py - the URL routes of the Django application
    • csfevents/wsgi.py and csfevents/asgi.py - used as the script to run production django application
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#lets-start-the-django-application","title":"Let's start the Django application","text":"
    1. Perform the initial migration: python3 manage.py migrate. Notice that when you run this command, it will create a db.sqlite3 file.
    2. Run the Django application: python3 manage.py runserver
    3. Check out the Django application: http://localhost:8000
    4. Check out the Django admin: http://localhost:8000/admin
    5. Create a superuser: python3 manage.py createsuperuser. Login and look around the Django admin.
    Additional info

    Django ships default \"django apps\" defined settings.py file. You can see the list of apps in the INSTALLED_APPS variable.

    Django apps are plugins that can be used to extend the functionality of the Django application. It's the core method of developing with this backend framework.

    For the db.sqlite3 file, it's the default database that Django uses. You can change this to other databases like MySQL, PostgreSQL, etc.

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#lets-create-our-first-django-app-event","title":"Let's create our first Django app: event","text":"

    Run this command python3 manage.py startapp event.

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#what-did-this-command-do","title":"What did this command do?","text":"

    Initial files that it created:

    • event/admin.py - the admin interface
    • event/apps.py - the configuration
    • event/models.py - the database schema
    • event/tests.py - the test cases
    • event/views.py - the views

    Some files you want to create later are:

    • event/serializers.py - the serializers
    • event/urls.py - the URL routes
    • event/permissions.py - the permissions
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#creation-of-the-database-schema","title":"Creation of the database schema","text":"Quick Reference: ERD WIP Answer
    class Event(models.Model):\n    # UUID id\n    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)\n    name = models.CharField(max_length=100)\n    date = models.DateField()\n\n    organizer = models.ForeignKey(\n        User, on_delete=models.SET_NULL, null=True, blank=True\n    )\n\n    def __str__(self):\n        return self.name\n

    After creating this, you'll need to add it in the INSTALLED_APPS variable in the settings.py file.

    Then run python3 manage.py makemigrations and python3 manage.py migrate.

    What did these commands do?

    makemigrations - creates the migration files These are scripts that defines how the database schema changed.

    migrate - applies the migration files to the database Similar to how we performed our initial migration

    When you have created that, check out db.sqlite3 and you'll see that there's a new table called event_event.

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#creation-of-the-admin-interface","title":"Creation of the admin interface","text":"WIP Answer
    from django.contrib import admin\nfrom .models import Event\n\nadmin.site.register(Event)\n

    Now visit the admin interface and you'll see the Event model there.

    A cooler example
    @admin.register(Event)\nclass EventAdmin(admin.ModelAdmin):\n    list_display = (\"name\", \"date\", \"organizer\")\n    list_filter = (\"organizer\",)\n    search_fields = (\"name\",)\n    ordering = (\"date\",)\n    date_hierarchy = \"date\"\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#do-the-same-thing-again-for-attendance","title":"Do the same thing again for Attendance","text":"Quick Reference: ERD WIP Answer
    # models.py\nclass Attendance(models.Model):\n    user = models.ForeignKey(User, on_delete=models.CASCADE)\n    event = models.ForeignKey(\n        Event, on_delete=models.CASCADE, related_name=\"attendances\"\n    )\n    # String field with only the valid choices \"going\", \"maybe\", \"not_going\"\n    status = models.CharField(\n        max_length=10,\n        choices=[(\"Going\", \"going\"), (\"Maybe\", \"maybe\"), (\"Not Going\", \"not_going\")],\n    )\n\n    def __str__(self):\n        return f\"Event '{self.event.name}' - Attendance '{self.user.username}'\"\n\n# admin.py\n@admin.register(Attendance)\nclass AttendanceAdmin(admin.ModelAdmin):\n    list_display = (\"user\", \"event\", \"status\")\n    list_filter = (\"user\", \"event\", \"status\")\n    search_fields = (\"user\", \"event\", \"status\")\n    ordering = (\"user\", \"event\", \"status\")\n    date_hierarchy = \"event__date\"\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#creation-views-the-interface-in-api","title":"Creation Views: the Interface in API","text":""},{"location":"2023-winter/introduction-to-backend-development-with-django/#serializerspy","title":"serializers.py","text":"

    Serialisers are a way to convert Python models to JSON, XML or any other format you wish.

    WIP Answer
    # serializers.py\nclass EventSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = Event\n        fields = (\"id\", \"name\", \"date\", \"organizer\")\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#viewspy-and-urlspy","title":"views.py and urls.py","text":"

    Here's our goal:

    // Class based - programming\nGET events in the system - /events\nPOST create events - /events\nPUT/PATCH update events - /events/<id>\nDELETE delete events - /events/<id>\n\nSpecial actions\nPOST Change attendee status to an event - /events/<id>/change_attendee_status\n

    Firstly, we need to set the urls.py to import the views from event/views.py.

    # urls.py\nfrom django.contrib import admin\nfrom django.urls import path, include\n\nurlpatterns = [\n    path(\"admin/\", admin.site.urls),\n    path(\"api/events/\", include(\"event.urls\")) # --HERE--\n]\n

    There's 2 main ways to create views

    • Functional
    • Class-based
    Class-based Views

    This is the easiest way - full of magic. If you need flexibility, you can override the methods.

    # event/views.py\nclass EventViewSet(viewsets.ModelViewSet):\n    queryset = Event.objects.all()\n    serializer_class = EventSerializer\n\n    def perform_create(self, serializer):\n        # Set whoever is creating the event as the organizer:\n        serializer.save(organizer=self.request.user)\n\n    # Note: This is a way to override the default methods\n    def destroy(self, request, *args, **kwargs):\n        return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)\n\n# event/urls.py\nrouter = DefaultRouter()\nrouter.register(r\"\", EventViewSet, basename=\"events\")\n\nurlpatterns = [\n    path(\"\", include(router.urls)),\n]\n

    Important to note that the basename is used to generate the URL name. In this case, it will be events-list and events-detail. (you will need this automated testing)

    Functional Views

    This is the more flexible way. This is currently the way CSF does it. Example

    # event/views.py\n@api_view([\"GET\"])\ndef event_list(request):\n    events = Event.objects.all()\n    serializer = EventSerializer(events, many=True)\n    return Response(serializer.data)\n\n@api_view([\"GET\"])\ndef event_detail(request, pk):\n    event = get_object_or_404(Event, pk=pk)\n    serializer = EventSerializer(event)\n    return Response(serializer.data)\n\n@api_view([\"POST\"])\ndef event_create(request):\n    # Set whoever is creating the event as the organizer:\n    serializer = EventSerializer(data=request.data)\n    if serializer.is_valid():\n        serializer.save(organizer=request.user)\n        return Response(serializer.data, status=status.HTTP_201_CREATED)\n    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n\n@api_view([\"PUT\"])\ndef event_update(request, pk):\n    event = get_object_or_404(Event, pk=pk)\n    serializer = EventSerializer(event, data=request.data)\n    if serializer.is_valid():\n        serializer.save()\n        return Response(serializer.data)\n    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n\n@api_view([\"DELETE\"])\ndef event_delete(request, pk):\n    return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)\n\n# urls.py\nurlpatterns = [\n    path(\"\", views.event_list),\n    path(\"<int:pk>/\", views.event_detail),\n    path(\"create/\", views.event_create),\n    path(\"<int:pk>/update/\", views.event_update),\n    path(\"<int:pk>/delete/\", views.event_delete),\n]\n
    Reuse Same Path with different HTTP Methods
    @api_view([\"GET\", \"POST\"])\ndef event_list(request):\n    if request.method == \"GET\":\n        queryset = Event.objects.all()\n        serializer = EventSerializer(queryset, many=True)\n        return Response(serializer.data)\n    elif request.method == \"POST\":\n        serializer = EventSerializer(data=request.data)\n        if serializer.is_valid():\n            serializer.save()\n            return Response(serializer.data, status=201)\n        return Response(serializer.errors, status=400)\n\n@api_view([\"GET\", \"PUT\", \"PATCH\", \"DELETE\"])\ndef event_detail(request, pk):\n    try:\n        event = Event.objects.get(pk=pk)\n    except Event.DoesNotExist:\n        return Response(status=404)\n\n    if request.method == \"GET\":\n        serializer = EventSerializer(event)\n        return Response(serializer.data)\n    elif request.method in [\"PUT\", \"PATCH\"]:\n        serializer = EventSerializer(event, data=request.data)\n        if serializer.is_valid():\n            serializer.save()\n            return Response(serializer.data)\n        return Response(serializer.errors, status=400)\n    elif request.method == \"DELETE\":\n        event.delete()\n        return Response(status=204)\n
    Another Example Class-based Views

    This is the easiest way - full of magic. If you need flexibility, you can override the methods.

    # views.py\nclass EventViewSet(viewsets.ModelViewSet):\n    queryset = Event.objects.all()\n    serializer_class = EventSerializer\n\n    def perform_destroy(self, instance):\n        if not instance.is_public:  # Assuming `is_public` is a boolean field in the `Event` model\n            raise serializers.ValidationError(\"Cannot delete a non-public event.\")\n        super().perform_destroy(instance)\n

    After that long discussion, let's create the views and play around.

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#going-back-to-serializer-for-organizer","title":"Going back to Serializer for Organizer","text":"
    + class UserSerializer(serializers.ModelSerializer):\n+     # read only serializer\n+     class Meta:\n+         model = User\n+         fields = (\"id\", \"username\", \"email\")\n\n\nclass EventSerializer(serializers.ModelSerializer):\n+    organizer = UserSerializer(read_only=True)\n\n    class Meta:\n        model = Event\n        fields = (\"id\", \"name\", \"date\", \"organizer\")\n

    What about if we also want to include attendees?

    + class AttendanceSerializer(serializers.ModelSerializer):\n+     user = UserSerializer(read_only=True)\n+ \n+     class Meta:\n+         model = Attendance\n+         fields = (\"user\", \"status\")\n\n\nclass EventSerializerWithAttendees(serializers.ModelSerializer):\n    organizer = UserSerializer(read_only=True)\n+    attendances = AttendanceSerializer(many=True, read_only=True)\n\n    class Meta:\n        model = Event\n-       fields = (\"id\", \"name\", \"date\", \"organizer\")\n+       fields = (\"id\", \"name\", \"date\", \"organizer\", \"attendances\")\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#bonus-filters-and-search-will-not-be-covered-in-this-workshop","title":"Bonus: Filters and Search (Will not be covered in this workshop)","text":"

    https://www.django-rest-framework.org/api-guide/filtering/

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#eventsidchange_attendee_status","title":"/events/<id>/change_attendee_status/","text":"

    Docs: - Viewset Actions

    eg. /events/1/change_attendee_status/ Payload body looks like

    {\n    \"status\": \"Going\"\n}\n

    # serializers.py\nclass AttendanceChangeStatusSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = Attendance\n        fields = (\"status\")\n\n# views.py\nclass EventViewSet(viewsets.ModelViewSet):\n    ...\n    # Attendance\n    @action(detail=True, methods=[\"post\"])\n    def change_attendee_status(self, request, pk=None):\n        event = self.get_object()\n        serializer = AttendanceChangeStatusSerializer(data=request.data)\n        serializer.is_valid(raise_exception=True)\n\n        user = request.user\n        status = serializer.validated_data[\"status\"]\n        Attendance.objects.update_or_create(\n            user=user, event=event, defaults={\"status\": status}\n        )\n        return Response(status=status.HTTP_200_OK)\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#automated-testing","title":"Automated Testing","text":"

    https://www.django-rest-framework.org/api-guide/testing/

    from rest_framework.test import APITestCase\nfrom django.contrib.auth.models import User\nfrom event.models import Event\n\n# Test to test all the HTTP methods of `EventViewSet`\nclass EventTest(APITestCase):\n    def setUp(self):\n        # Create a user\n        self.user = User.objects.create_user(\n            username=\"test_user\", email=\"test@test.com\", password=\"test_password\"\n        )\n\n        # Create an event\n        self.event = Event.objects.create(\n            name=\"test_event\", date=\"2021-01-01\", organizer=self.user\n        )\n\n    def test_get(self):\n        # Test GET method\n        url = reverse(\"events-list\")\n        response = self.client.get(url)\n        self.assertEqual(response.status_code, 200)\n        self.assertEqual(response.data[0][\"name\"], \"test_event\")\n        self.assertEqual(response.data[0][\"date\"], \"2021-01-01\")\n        self.assertEqual(response.data[0][\"organizer\"][\"username\"], \"test_user\")\n\n    def test_post(self):\n        # Test POST method\n        self.client.login(username=\"test_user\", password=\"test_password\")\n        url = reverse(\"events-list\")\n        response = self.client.post(url, {\"name\": \"test_event2\", \"date\": \"2021-01-02\"})\n        self.assertEqual(response.status_code, 201)\n\n        event_data = response.data\n        self.assertEqual(event_data[\"name\"], \"test_event2\")\n        self.assertEqual(event_data[\"date\"], \"2021-01-02\")\n        self.assertEqual(event_data[\"organizer\"][\"username\"], \"test_user\")\n\n        # Make sure the event by checking the database\n        event = Event.objects.get(name=\"test_event2\")\n        self.assertEqual(str(event.id), event_data[\"id\"])\n    # ... All other methods are left to the reader to implement\n

    To run this test, run python manage.py test

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#authentication-and-authorization","title":"Authentication and Authorization","text":"

    What if we only want the PUT/PATCH/DELETE methods to be accessible by the organizer?

    Docs: - Authentication https://www.django-rest-framework.org/api-guide/authentication/ - Authorization/Permissions https://www.django-rest-framework.org/api-guide/permissions/

    # permissions.py\nfrom rest_framework import permissions\n\n# The organizer is the only one allowed to update or delete an event.\nclass IsOrganizerOrReadOnly(permissions.BasePermission):\n    def has_object_permission(self, request, view, obj):\n        # Read permissions are allowed to any request,\n        # so we'll always allow GET, HEAD or OPTIONS POST.\n        if request.method in [permissions.SAFE_METHODS, 'POST']:\n            return True\n\n        # Write permissions are only allowed to the organiser of the event.\n        return obj.organizer == request.user\n\n# views.py\nclass EventViewSet(viewsets.ModelViewSet):\n    ...\n    permission_classes = [IsOrganizerOrReadOnly]\n    ...\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#tdd-test-driven-development-with-multiple-accounts","title":"TDD: Test-Driven Development With Multiple Accounts","text":"

    This is a perfect showcase how it's very difficult to manage manually testing with multiple accounts.

    class EventTest(APITestCase):\n    ...\n    def test_not_organizer_cannot_modify(self):\n        # Test that a user who is not the organizer cannot modify the event\n        # Create another user\n        self.user2 = User.objects.create_user(\n            username=\"test_user2\", email=\"test2@test.com\", password=\"test_password\"\n        )\n        self.client.login(username=\"test_user2\", password=\"test_password\")\n        url = reverse(\"events-detail\", args=[self.event.id])\n        response = self.client.put(url, {\"name\": \"test_event2\", \"date\": \"2021-01-02\"})\n        self.assertEqual(response.status_code, 403)\n
    How to manually test this?
    • Login as the organiser
    • Create an event
    • Create a new user
    • Login as the new user
    • Try to modify the event
    • Check that it returns a 403 Forbidden
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#extra-reading-jwt-authentication","title":"Extra-Reading - JWT Authentication","text":"

    Summary of Django Simple JWT

    The only key bit to know is

    install pip install djangorestframework-simplejwt

    in settings.py

    REST_FRAMEWORK = {\n    ...\n    'DEFAULT_AUTHENTICATION_CLASSES': (\n        ...\n        'rest_framework_simplejwt.authentication.JWTAuthentication',\n    )\n    ...\n}\n

    in urls.py

    from rest_framework_simplejwt.views import (\n    TokenObtainPairView,\n    TokenRefreshView,\n)\n\nurlpatterns = [\n    ...\n    path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'), # Login\n    path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), # Refresh tokens\n    ...\n]\n

    If you login via /api/token , you will send something like this

    {\n    \"username\":\"test_user\",\n    \"password\":\"test_password\"\n}\n

    you're going to get something like this back

    {\n  \"access\":\"eyJh...\",\n  \"refresh\":\"eyJhb...\"\n}\n

    And if you are using an authenticated endpoint, you need to add the Authorization header with the token. \"Authorization: Bearer eyJhbEXAMPLEOFJWTOKEN...\"

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#bonus-sending-emails","title":"Bonus\" Sending Emails","text":"

    Run docker-compose up to start the mail server.

    Your mail server will have this UI at http://localhost:8025/. It communicates via SMTP on port 1025.

    Add these in your settings.py

    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'\nEMAIL_HOST = 'localhost'\nEMAIL_PORT = 1025\nEMAIL_HOST_USER = ''\nEMAIL_HOST_PASSWORD = ''\nEMAIL_USE_TLS = False\n\nEMAIL_ADDRESS_FROM = 'email-tester@test.com;\n

    Where are these values coming from?

    If you check the docker-compose.yml, you will understand that we are just configuring the values to send via SMTP to the mail server.

    In actual production services, you will change this to your actual SMTP server like AWS SES, Sendgrid, Mailgun, etc.

    New file called utils.py

    from django.core.mail import send_mail\nfrom django.conf import settings\n\ndef send_email(subject, message, recipient_list):\n    send_mail(\n        subject=subject,\n        message=message,\n        from_email=settings.EMAIL_ADDRESS_FROM,\n        recipient_list=recipient_list,\n        fail_silently=False,\n    )\n

    Now let's change it so that when a new event is created, an email is sent to the organizer.

    # views.py\nfrom event.utils import send_email\n\nclass EventViewSet(viewsets.ModelViewSet):\n    ...\n    def perform_create(self, serializer):\n        # Set whoever is creating the event as the organizer:\n        serializer.save(organizer=self.request.user)\n        send_email(\n            subject=\"New event created\",\n            message=\"A new event has been created\",\n            recipient_list=[self.request.user.email],\n        )\n
    "},{"location":"2024-winter/introduction-to-docker/","title":"Introduction to Docker","text":""},{"location":"2024-winter/introduction-to-docker/#prerequisites","title":"Prerequisites","text":"

    You need the following installed:

    • Git
    • Node.js
    • Docker
    • VSCode (highly recommended)

    The starting repo for this workshop: https://github.com/codersforcauses/docker-workshop

    "},{"location":"2024-winter/introduction-to-docker/#what-you-will-be-building-as-part-of-this-workshop","title":"What you will be building as part of this workshop?","text":"

    CFC wants to make an app for accepting coffee orders. You will be creating a Dockerfile for CFC's (totally real) new and upcoming rebrand: Coders for Coffee \ud83d\udc33. The architecture is a simple frontend and backend both made in TypeScript. Below is a diagram of it:

    "},{"location":"2024-winter/introduction-to-docker/#important-information","title":"Important information","text":"

    This workshop relies on a certain understanding of terminal commands and a bit of familiarity with Node.js projects.

    "},{"location":"2024-winter/introduction-to-docker/#what-is-docker","title":"What is Docker?","text":"

    Docker is a platform for developing, shipping, and running applications using containerization. It allows you to package an application and its dependencies into a container that can run on any machine. This makes it easy to deploy applications in a consistent and reproducible way. Simply put, it's like a way of running mini virtual machines inside your computer.

    "},{"location":"2024-winter/introduction-to-docker/#why-use-docker","title":"Why use Docker?","text":"
    • Consistency: Docker containers are isolated from the host system and other containers, ensuring that the application runs the same way everywhere.
    • Portability: Containers can be run on any machine that has Docker installed, making it easy to move applications between environments.
    • Efficiency: Containers are lightweight and share the host system's resources, making them more efficient than virtual machines.
    • Scalability: Docker makes it easy to scale applications by running multiple containers on the same host or across multiple hosts.
    • Security: Containers are isolated from each other and the host system, providing an additional layer of security.
    • DevOps: Docker is a key tool in the DevOps toolchain, enabling developers to build, test, and deploy applications more easily. Imagine a software job where instead of writing software for end-users, you write software to make developers' lives easier!
    "},{"location":"2024-winter/introduction-to-docker/#definitions","title":"Definitions","text":"
    • Dockerfile \ud83d\udcdc: A text file that contains instructions for building a Docker image. It specifies the base image, dependencies, environment variables, and commands to run when the container starts. Think like a recipe for baking a cake.
    • Image \ud83d\udcc0: A read-only template with instructions for creating a Docker container. It contains the application code, runtime, libraries, environment variables, and configuration files. Think like a CD with music on it.
    • Container \u25b6\ufe0f: An instance of an image that can be run as a process on the host machine. It is isolated from other containers and the host system. Think like a CD in a CD player.
    "},{"location":"2024-winter/introduction-to-docker/#how-do-i-use-docker","title":"How do I use Docker?","text":"

    This is a high-level overview of how Docker works:

    In action, you'll only need to know a few commands to get started:

    1. docker pull: Pull an image from a registry (like Docker Hub).
    2. docker run <image>: Run a container from an image.
    3. docker build: Build a Dockerfile into an image.
    "},{"location":"2024-winter/introduction-to-docker/#getting-started","title":"Getting started","text":"

    Firstly, open your IDE and open the terminal.

    1. Clone the repository: git clone https://github.com/codersforcauses/docker-workshop.git
    2. Go to the directory: cd docker-workshop
    3. Run the setup script: npm run setup
    4. Run the app: npm run dev. Visit http://localhost:3000 to see it in action.
    What does the setup script do?

    The setup script installs the dependencies for both the frontend and backend. It is located in the package.json in the root. Formatted nicely:

    npm install --prefix apps/frontend -g && # install dependencies for the frontend\nnpm install --prefix apps/backend -g && # install dependencies for the backend\nnpm install # install dependencies for the root (just a little handy package to run both apps with one command)\n
    "},{"location":"2024-winter/introduction-to-docker/#what-does-the-app-do","title":"What does the app do?","text":"

    The frontend is a simple form that takes a user's order and sends it to the backend. The backend then saves the order to a \"database\". Below is a screenshot of the app:

    "},{"location":"2024-winter/introduction-to-docker/#frontend","title":"Frontend","text":"

    The frontend is a single page app that takes orders. It runs at http://localhost:3000.

    Where is the frontend code?

    The frontend code is located in the apps/frontend directory. The main file is src/App.tsx.

    "},{"location":"2024-winter/introduction-to-docker/#backend","title":"Backend","text":"

    The backend is a simple Hono http server that listens for certain requests. It runs at http://localhost:3001. There are 3 important endpoints:

    1. GET / - Show a simple page to check if the server is running
    2. GET /orders - Get all orders
    3. POST /orders - Create an order
    Where is the backend code?

    The backend code is located in the apps/backend directory. The main file is src/index.ts.

    You can view the first two by going to http://localhost:3001 and http://localhost:3001/orders in your browser.

    "},{"location":"2024-winter/introduction-to-docker/#what-do-we-need-to-do","title":"What do we need to do?","text":"

    We need to create a Dockerfile to build the frontend and backend to images, then run them as containers. I have already created a Dockerfile for the backend, which is located in the apps/backend directory. You will need to create a Dockerfile for the frontend.

    Can I cheat?

    Yes... If you choose to look at it, you might find it helpful. However, it comes with a few optimisations which may be confusing.

    "},{"location":"2024-winter/introduction-to-docker/#building-and-running-an-image","title":"Building and running an image","text":"

    Close the app dev server we ran earlier with CTRL+C.

    Let's start by learning how to build and run a Docker image. First, let's build the backend:

    docker build -t docker-workshop-backend ./apps/backend\n

    This command builds an image from the Dockerfile in the apps/backend directory and tags it (-t) with the name docker-workshop-backend.

    Now, let's run the image we've built:

    docker run -p 3001:3001 docker-workshop-backend\n

    Port Mapping

    But wait, what does -p 3001:3001 do? I mentioned earlier that Docker basically runs mini virtual machines --- so let's visualise what that looks like.

    In order for our container to make connect with the outside world, we need to create a little tunnel. This is done by mapping a port on the host machine to a port on the container. In our case, I've configured the backend to run internally on port 3001. Therefore, we need to map that internal port to a port on the host machine so we can access it. I kept it simple and mapped it to the same port, but you can change it to any port you like (given our frontend knows about it). Ports are mapped like this: -p <host-port>:<container-port> This is one of the security goals of Docker.

    Now, visit http://localhost:3001 to see the backend now running from a Docker container.

    "},{"location":"2024-winter/introduction-to-docker/#manual-build","title":"Manual build","text":"

    To get a better idea of what we need to do, let's build the frontend manually.

    "},{"location":"2024-winter/introduction-to-docker/#step-1-what-are-we-building","title":"Step 1: What are we building?","text":"

    Imagine you are a robot that will execute commands to build the app to be production-ready. Regardless of what you're making, it'll usually fall into this pattern:

    1. Install dependencies
    2. Build the app
    3. Serve the build files
    "},{"location":"2024-winter/introduction-to-docker/#step-2-mapping-them-to-commands","title":"Step 2: Mapping them to commands","text":"

    The frontend is a React app that uses TypeScript. Now let's:

    1. Install dependencies: npm install
    2. Build the app: npm run build
    3. Serve the build files: npm run start

    The build and start scripts are located in apps/frontend/package.json.

    {\n    // ...\n    \"scripts\": {\n        \"build\": \"tsc && vite build\",\n        \"start\": \"serve dist -p 9876\"\n    }\n    // ...\n}\n

    You can run these commands in the terminal and open it up at http://localhost:9876/ to see the optimised production build of the frontend. Notice how the bottom text has changed from \"development\" to \"production\".

    "},{"location":"2024-winter/introduction-to-docker/#creating-a-dockerfile","title":"Creating a Dockerfile","text":"

    When creating a Dockerfile, it's essentially the same process as manually doing it. The only difference is that you're automating it in a file.

    "},{"location":"2024-winter/introduction-to-docker/#base-image","title":"Base image","text":"

    All Dockerfiles start with a FROM command, which specifies the base image to use. This image is usually a lightweight Linux distribution with the necessary tools and libraries to run the application. For our frontend, we will use the node:20-alpine image.

    How do I know what image to use?

    There are a number of things to consider when choosing a base image:

    • Application: Because we're running a Node.js app, an image with Node.js already installed is a good choice.
    • Size: Smaller images are faster to download and use less disk space.
    • Security: Official images are more secure and are regularly updated. Most of the time you'll be using images from Docker Hub.
    • Compatibility: Make sure the image is compatible with your application. In this case, the current LTS release for Node.js is 20, so we will use node:20-alpine. Locking the version down is also good practice to prevent images from suddenly breaking.
    # Use the official Node.js image as the base image\nFROM node:20-alpine\n
    "},{"location":"2024-winter/introduction-to-docker/#working-directory","title":"Working directory","text":"

    We're in linux land now. We're first going to create a directory to put our production files in. This is done with the WORKDIR command.

    FROM node:20-alpine\n\n# Set the working directory in the container\nWORKDIR /app\n
    Why do we need a working directory?

    The WORKDIR command sets the working directory for any subsequent commands in the Dockerfile. This is where the application code will be copied to and where the application will run from. It's like changing directories in the terminal. Just like your own computer, you don't want to group important system files with your projects. It can be named anything you like, but the general convention is to name it /app.

    "},{"location":"2024-winter/introduction-to-docker/#copying-files","title":"Copying files","text":"

    Next, we need to copy our source code into the image. This is done with the COPY command.

    # Use the official Node.js image as the base image\nFROM node:20-alpine\nWORKDIR /app\n\n# Copy the important files to the working directory\nCOPY . ./\n
    What are we copying?

    This command copies everything in the same directory where the Dockerfile is (.) from the host machine to the working directory in the container (./). This is the bare minimum we need to build the frontend. i.e. src, public, package.json, etc.

    "},{"location":"2024-winter/introduction-to-docker/#installing-dependencies-and-building","title":"Installing dependencies and building","text":"

    Now that we have our source code in the image, we need to install the dependencies. This is done with the RUN command. Here, we run both npm install and npm run build in succession using &&.

    FROM node:20-alpine\n\nWORKDIR /app\nCOPY . ./\n\n# Install dependencies and build the app\nRUN npm install && npm run build\n
    Why not do it on separate lines?

    The reason we chain install && build is to reduce the number of layers in the image. Each RUN command creates a new layer in the image, which is essentially a snapshot of everything you've RUN up until now. More layers means a larger image size. By chaining commands together, we can reduce the number of layers and make the image smaller. Docker uses this to cache layers, so if you change a file, it will only rebuild the layers that depend on that file, saving time. In our case, our two commands both depend on the same files, so we should group them together.

    "},{"location":"2024-winter/introduction-to-docker/#serving-the-build","title":"Serving the build","text":"

    We're almost there! The last thing we need to do is serve the build files. This is done with the CMD command. This command specifies the command to run when the container starts. In our case, we want to run npm run start.

    FROM node:20-alpine\nWORKDIR /app\n\nCOPY . ./\n\nRUN npm install && npm run build\n\n# Serve the build files, note how it's an array\nCMD [\"npm\", \"run\", \"start\"]\n

    We're done --- not. There's one last thing we need to do: specify the port the server will run on. This is done with the EXPOSE command. Notice how earlier, npm run start actually started the server on port 9876, so let's expose that instead.

    FROM node:20-alpine\nWORKDIR /app\n\nCOPY . ./\n\nRUN npm install && npm run build\n\n# Serve the build files\nEXPOSE 9876\nCMD [\"npm\", \"run\", \"start\"]\n
    "},{"location":"2024-winter/introduction-to-docker/#done","title":"Done","text":"

    You can now build and run the frontend image. We can actually specify a specific port in the CMD, but I'm just going to map it to port 3000 on the host machine when running the container.

    docker build -t docker-workshop-frontend ./apps/frontend\ndocker run -p 3000:9876 docker-workshop-frontend\n

    If we open up Docker desktop, you can even inspect the container's filesystem to see what we've done.

    The frontend is now running at http://localhost:3000!

    "},{"location":"2024-winter/introduction-to-docker/#optimising-the-dockerfile","title":"Optimising the Dockerfile","text":"

    Let's think about what we've done. We've copied the source code, installed dependencies, built the app, and served the build files. But there are a few things we can do to optimise the Dockerfile:

    • Only have production dependencies in the image. Sometimes we developers install dev dependencies that aren't needed in production, but make our lives easier. If you take a look at apps/frontend/package.json, you'll see a bunch of them.
    • Don't have the source code in the image. We only need the built files to run the app. This reduces the image size.
    "},{"location":"2024-winter/introduction-to-docker/#prune-the-dependencies","title":"Prune the dependencies","text":"

    This is the easiest one. For a node app, you can do npm prune --production to remove all dev dependencies.

    FROM node:20-alpine\nWORKDIR /app\n\nCOPY . ./\n\n# cleanup in the same layer\nRUN npm install && npm run build && npm prune --production\n\n# Serve the build files\nEXPOSE 9876\nCMD [\"npm\", \"run\", \"start\"]\n
    "},{"location":"2024-winter/introduction-to-docker/#multi-stage-builds","title":"Multi-Stage builds","text":"

    Now we want to remove the source code from the image. You might think you could build the app outside the image, but that would mean you'd need to have Node.js installed on your machine, which defeats the purpose of containerisation. Additionally, some dependencies are platform-specific, so the app might not even work when put inside the container. This is where multi-stage builds come in.

    A multi-stage build is a feature of Docker that allows you to use multiple FROM commands in a single Dockerfile. Each FROM command starts a new stage in the build process. You can copy files from one stage to another, allowing you to build the app in one stage and copy the built files to another stage.

    # Stage 0: Define a common image for building and running\nFROM node:20-alpine AS base\n\n\n# Stage 1: Build the app\nFROM base AS builder\nWORKDIR /app\n\nCOPY . ./\n\nRUN npm install && npm run build && npm prune --production\n\n# Stage 2: Serve the build files\nFROM base AS runner\nWORKDIR /app\n\n# Copy dependencies\nCOPY --from=builder /app/node_modules ./node_modules\n# Copy built files\nCOPY --from=builder /app/dist ./dist\n# Copy package.json so we can run `npm run start`\nCOPY --from=builder /app/package.json ./package.json\n\nEXPOSE 9876\nCMD [\"npm\", \"run\", \"start\"]\n
    "},{"location":"2024-winter/introduction-to-docker/#final-touches","title":"Final touches","text":"

    So now we know how to build a Dockerfile into an image and run it as a container. But there is one more thing we can do to make our lives easier: Docker Compose.

    Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define the services, networks, and volumes for your application in a single file. This makes it easy to start, stop, and manage your application with a single command.

    I've already created a docker-compose.yml file for you. It defines two services: frontend and backend. Instead of doing docker run ... in two terminals, you can now can run both services with a single command. You don't even have to build the images, as Docker Compose will do that for you!

    docker compose up\n

    You also might find the frontend starting on port 9876 inside the container to be a little confusing. You can change the port mapping in the docker-compose.yml file to map it to port 3000 on the host machine. Don't forget to change the package.json script and the EXPOSE command in the Dockerfile as well.

    "},{"location":"2024-winter/introduction-to-docker/#conclusion","title":"Conclusion","text":"

    This is just a small taste of what Docker can do. You could put your entire dev environment inside, push images to a registry and run them in the cloud, or even run a bunch of them in a Kubernetes cluster. Keep in mind that we only built a Dockerfile for a simple React app, so it'll be a different depending on what you do. Luckily, there are countless resources online to help you out --- just google \"how to dockerise a app\"."}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Coders for Causes Workshops","text":"

    This is where you can see all the materials for workshops that are presented to the volunteers of the project for each year.

    If you would to know more about us, please visit our website at codersforcauses.org

    "},{"location":"contributions/","title":"Contributions","text":"

    Hi! We are happy that you thought of contributing! If you have any suggestions or issues, please raise it here. I would be happy if you could provide pull requests, if you know how to do it here.

    "},{"location":"contributions/#structure","title":"Structure","text":""},{"location":"contributions/#folder-structure","title":"Folder Structure","text":"

    The structure of this repo is as follows:

    \u251c\u2500\u2500 docs                    // Folders for documentation\n\u2502   \u251c\u2500\u2500 CNAME\n\u2502   \u251c\u2500\u2500 contributions.md\n\u2502   \u251c\u2500\u2500 deployment_and_automated_site_deployment.md\n\u2502   \u251c\u2500\u2500 flavoured_markdown.md\n\u2502   \u251c\u2500\u2500 images              // Assets\n\u2502   \u2502   \u2514\u2500\u2500 ...\n\u2502   \u2502   \n\u2502   \u251c\u2500\u2500 index.md\n\u2502   \u2514\u2500\u2500 writing_markdown.md\n\u251c\u2500\u2500 LICENSE\n\u251c\u2500\u2500 mkdocs.yml              // MkDocs Configuration\n\u251c\u2500\u2500 overrides\n\u2502   \u2514\u2500\u2500 partials\n\u2502       \u2514\u2500\u2500 footer.html\n\u251c\u2500\u2500 README.md\n\u2514\u2500\u2500 requirements.txt\n
    "},{"location":"contributions/#installation","title":"Installation","text":""},{"location":"contributions/#python","title":"Python","text":"Prerequisite

    You need to have Python installed to be able to use pip. There are a few ways of installing Python. You can use a package distributor like Anaconda Or you can just install Python.

    Once you have installed Python, install mkdocs requirements by opening a terminal and typing:

    pip install -r requirements.txt\n
    Python Environments (Optional)

    however, it is good practice to use different environments for different purposes, in which case, for Anaconda, you would open a terminal and type:

    conda create -n mkdocstutorial python\nconda activate mkdocstutorial\n
    then enter:

    pip install -r requirements.txt\n
    "},{"location":"contributions/#docker","title":"Docker","text":"

    Just run docker-compose up, it should show the web server running at localhost:8000

    "},{"location":"contributions/#commands","title":"Commands","text":"
    • mkdocs new [dir-name] - Create a new project.
    • mkdocs serve - Start the live-reloading docs server. Very helpful when you want to take a look at the docs before deploying.
    • mkdocs build - Build the documentation site.
    • mkdocs -h - Print help message and exit.
    • mkdocs gh-deploy - Deploy in github pages
    "},{"location":"contributions/#web-documentation-configuration","title":"Web Documentation Configuration","text":"

    For full documentation visit:

    • mkdocs.org for the generic MkDocs
    • PyMdown Extensions for the different extensions that are installed
    • MkDocs Material for the customisation of the web server documentation.
    "},{"location":"2021-2022-summer/","title":"Coders for Causes 2021/22 Summer Workshops","text":"

    This project period continues the two main projects from the winter of 2020 :

    • Foodbank
    • WAIS

    If you have not before seen the existing progress, see this video.

    These two projects have their own corresponding technology stacks being used, hence will dictate the workshops that will be held.

    "},{"location":"2021-2022-summer/#project-technology","title":"Project Technology","text":""},{"location":"2021-2022-summer/#foodbank","title":"Foodbank","text":"

    Foodbank is mainly with frontend with React + NextJS + TypeScript + TailwindCSS with Firebase and Notion CMS.

    "},{"location":"2021-2022-summer/#wais","title":"WAIS","text":"

    WAIS is a full-stack application with Vue and Django. It uses Docker containerisation for both development (and production in the future).

    "},{"location":"2021-2022-summer/#workshop-recordings","title":"Workshop Recordings","text":"

    The workshop recordings will be held on our youtube channel.

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/","title":"Automated Testing and CI Pipelines","text":""},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#what-is-the-problem-with-manual-testing","title":"What is the problem with manual testing?","text":"
    • tedious
    • some scenarious are hard to repeat
      • eg. network issues, database randomly crashes
    • repetitive
    • growning number of scenarios
    • time consuming
    Cost Savings Scenarios that are hard to repeat - Network Requests
    import requests\ndef make_network_request():\ntry:\n    response = requests.get(\"https://www.google.com\")\n    if response.status_code == 200:\n        return response.text\n    else:\n        return None\nexception requests.exceptions.ConnectionError:\n    return None\n

    This is the way to simulate an exception after a network request.

    import pytest\ndef test_make_network_request_exception(mocker):\n    mocker.patch(\"requests.get\", side_effect=requests.exceptions.ConnectionError)\n    assert make_network_request() is None\n

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#importance-of-software","title":"Importance of Software","text":"

    Before you can truly understand why testing is important, we first have to understand the importance of software.

    Importance of software in different parts

    Control Systems

    Healthcare

    Transportations

    Daily life

    Office Work

    Education

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#software-is-fragile","title":"Software is Fragile","text":"Quote

    It only takes a character difference to prevent a software from compiling or running.

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#consequences-of-fault-softwares","title":"Consequences of Fault Softwares","text":"

    Huge Compute Charges

    Embarrassment

    Disruptions

    User Frustations

    Client loss

    Death

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#automated-testing","title":"Automated Testing","text":""},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#what-is-involved-manual-testing-usually","title":"What is involved manual testing usually?","text":"

    To be able to automate testing, we need to understand what is involved in manual testing.

    • Open your own environment and tools
    • Git checkout/pull/fetch
    • Install dependency
    • Setup the environment
      • Do you need to clear the database?
      • Do you need to enter a couple of data?
      • Do you need to disconnect the internet while server is running?
    • Perform the steps to test
    • Assert the test correction?
    • Did you make a mistake? (repeat the entire thing)
    • Now do a different scenario!
    • Hang on a sec? Your coworker forgot to push? Now do all scenarios again
    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#how-does-automated-testing-work","title":"How does automated testing work?","text":"
    • Write scripts to evaluate code
    • Write script to run scripts when certain events happen (more so later)
    • Update Scripts whenever change happens
    Example from the workshop with github actions - Software Engineering Practices
    name: Python package\n\non:\npull_request:\nworkflow_dispatch:\n    inputs:\n    logLevel:\n        description: \"Log level\"\n        required: false\n        default: \"warning\"\n\njobs:\nflake8_py3:\n    name: \"Linting with Flake8\"\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@v2\n\n    - name: \"Set up Python\"\n        uses: actions/setup-python@v2\n        with:\n        python-version: 3.x\n\n    - name: \"Install flake8\"\n        run: pip install flake8\n\n    - name: \"Run flake8\"\n        uses: liskin/gh-problem-matcher-wrap@v1\n        with:\n        linters: flake8\n        run: flake8 --max-line-length 150 .\n\ntest:\n    runs-on: ubuntu-latest\n    strategy:\n    matrix:\n        python-version: [3.8] # you can add more python version to test it in\n\n    steps:\n    - uses: actions/checkout@v2\n    - name: Set up Python ${{ matrix.python-version }}\n    uses: actions/setup-python@v2\n    with:\n        python-version: ${{ matrix.python-version }}\n    - name: Install dependencies\n    run: |\n        python -m pip install --upgrade pip\n        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi\n    - name: Test with pytest\n    run: |\n        pytest --cov-report html --cov=.\n    - uses: actions/upload-artifact@v1\n    if: always()\n    with:\n        name: coverage-report\n        path: htmlcov\n
    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#test-driven-development","title":"Test-Driven Development","text":"

    Define test/specification first, then write functionality. Works best if you know way ahead of time what you want.

    Note: This does not always work (eg. Frontend)

    Simple Example
    def test_add_two_numbers():\nassert add_two_numbers(1, 2) == 3\n
    def add_two_numbers(a, b):\n    return a + b\n
    More complex example, but demonstrates how it can save time

    Let say you have to develop a function that sends email depending on the number of users in the database

    from django.core.mail import send_mail\n# Not guaranteed to work code\ndef send_email_to_admin():\n    number_of_users = User.objects.count()\n    send_mail(\"Number of users\", f\"There are {number_of_users} users in the database\", \"no-reply@system.com\",[\"admin@system.com\"])\n

    from django.core import mail\nfrom module import send_email_to_admin\nclass EmailTest(TestCase):\n    def setup():\n        # Create users\n        User.objects.create(username=\"admin\" ...)\n\n    def test_send_email_to_admin(self):\n        send_email_to_admin()\n\n        # Test that one message has been sent.\n        self.assertEqual(len(mail.outbox), 1)\n\n        self.assertEqual(mail.outbox[0].subject, \"Number of users\")\n        self.assertTrue(\"1 users in the database\" in mail.outbox[0].body)\n        ...\n

    Usual workflow:

    1. Prepare your tools - mail client and smtp server
    2. Prepare your database
    3. Do manual testing + Write code (repeat)
    4. Write Automated testing

    Test Driven development workflow (also known as red-green-refactor):

    1. Write the Automated Testing - when this is run it will fail
    2. Write code until test pass
    3. Refactor + improve code
    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#given-when-then","title":"GIVEN-WHEN-THEN","text":"

    Acceptance of features can be divided into: - GIVEN \u2013 what are the assumptions - WHEN \u2013 occurence - THEN - effect or observation

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#what-is-cicd","title":"What is CI/CD?","text":"

    Scripts that runs for certain events (such as pull request, a commit) to run test or deploy

    Providers
    • Github Actions
    • Circle CI
    • Bitbucket Pipelines
    • Travis CI
    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#whats-usually-in-ci","title":"What's usually in CI?","text":"
    • Linting (code consistency + undefined variables)
    • Tests
    • Builds + Deploy

    Others: - bot to auto tag issue - Security checks - Code Autosuggestion (kinda like linting, but it suggests stuff)

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#testing-artifacts","title":"Testing Artifacts","text":"

    Files given when testing

    Coverage Report

    Cypress Screenshots + Videos

    Long term test reports

    "},{"location":"2021-2022-summer/automated-testing-and-ci-pipelines/#demo-cypress-integration-test-e2e-test","title":"Demo - Cypress Integration Test / E2E Test","text":"

    Cypress is a tool that simulates user interaction by programatically performing action against a browser.

    Get started at Cypress.

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/","title":"Welcome to the Djangol!","text":"

    We've got puns 'n' data, We\u2019ve got everything you request

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#how-does-an-application-communicate-with-backend-systems","title":"How does an application communicate with backend systems?","text":"

    JavaScript Object Notation

    JSON

    Link

    [\n{\n    \"id\": 1,\n    \"name\": \"Leanne Graham\",\n    \"username\": \"Bret\",\n    \"email\": \"Sincere@april.biz\",\n    \"address\": {\n    \"street\": \"Kulas Light\",\n    \"suite\": \"Apt. 556\",\n    \"city\": \"Gwenborough\",\n    \"zipcode\": \"92998-3874\",\n    \"geo\": {\n        \"lat\": \"-37.3159\",\n        \"lng\": \"81.1496\"\n    }\n    },\n    \"phone\": \"1-770-736-8031 x56442\",\n    \"website\": \"hildegard.org\",\n    \"company\": {\n    \"name\": \"Romaguera-Crona\",\n    \"catchPhrase\": \"Multi-layered client-server neural-net\",\n    \"bs\": \"harness real-time e-markets\"\n    }\n},\n...\n{\n    \"id\": 10,\n    \"name\": \"Clementina DuBuque\",\n    \"username\": \"Moriah.Stanton\",\n    \"email\": \"Rey.Padberg@karina.biz\",\n    \"address\": {\n    \"street\": \"Kattie Turnpike\",\n    \"suite\": \"Suite 198\",\n    \"city\": \"Lebsackbury\",\n    \"zipcode\": \"31428-2261\",\n    \"geo\": {\n        \"lat\": \"-38.2386\",\n        \"lng\": \"57.2232\"\n    }\n    },\n    \"phone\": \"024-648-3804\",\n    \"website\": \"ambrose.net\",\n    \"company\": {\n    \"name\": \"Hoeger LLC\",\n    \"catchPhrase\": \"Centralized empowering task-force\",\n    \"bs\": \"target end-to-end models\"\n    }\n}\n]\n

    Query this endpoint using JavaScript
    fetch(\"https://jsonplaceholder.typicode.com/users\")\n    .then(response => response.json())\n    .then(data => console.log(data))\n
    Other ways

    JSON is not the only way. There are things like SOAP, RPC, but nevermind them for now as you will most likely have to deal with JSON for the most parts.

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#what-are-apis-and-rest-apis","title":"What are APIs and REST-APIs?","text":"

    Application Programming Interface

    Analogy

    Who interacts with the user interface? - the user Who interacts with the application programming interface ? - the application program (eg. the browser)

    Representational State Transfer Application Programming Interface

    • backend architectural pattern that follows the GET/POST/PUT/PATCH/DELETE

    • Can be represented in Swagger/ Open API specification

    Swagger/ Open API specification

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#what-is-django","title":"What is Django?","text":"

    Django

    • Python web framework for creating server-side application

    Follows MVC:

    • Model - database
    • View \u2013 Interface (API or User Interface)
    • Controller \u2013 URLs + routes

    See Documentation

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#what-is-django-rest-framework-drf","title":"What is Django REST Framework (DRF)?","text":"
    • library for creating REST-API
    • just makes it easier develop REST-API

    In:

    • Authentication + Permission
    • Generic API Views
    • Serialisers (payload validation and format)

    See Documentation

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#features-of-django-and-drf","title":"Features of Django and DRF","text":""},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#serializers","title":"Serializers","text":"
    • converter to and from Python Data types to JSON/XML
    • can be used to do validation

    More info here

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#models","title":"Models","text":"

    Models

    • representation of database connection or schema Example: Todo Django + React
    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#models-with-serializers","title":"Models with Serializers","text":"
    • Model already defined the structure of the data
    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#configuration-file-settingspy","title":"Configuration file settings.py","text":"

    One of the most important file - determines the app configurations and default

    Example of Items you can configure
    • timezones
    • start of URL
    • installed Django Apps
    • middlewares
    • usually becomes the \"default\" configs after environment variables
    • database configuration
    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#route-with-urls","title":"Route with URLs","text":"

    Determines the URL route of the API

    • starts with the urls.py in the config (settings.py)
    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#packaging-a-django-app","title":"Packaging a \"Django App\"","text":"

    \"Django Apps\" are plugin system of Django. Django codebase prefers packaging each endpoint feature to a \"Django App\"

    Authenticate with Microsoft

    For example: django-saml2-auth-lw (used for Microsoft SAML SSO)

    More documentation can be seen here

    You can start creating your own Django app by following the steps:

    1. python manage.py startapp <app_name>. This will bootstrap commonly used files for any \"app\".
    2. Add the app in the INSTALLED_APPS in\u00a0 the settings.py
    3. python manage.py makemigrations to create the migration scripts
    4. python manage.py migrate to run the migration script
    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#views","title":"Views","text":"

    The interface at which any application program interacts with to get something done in the backend.

    Use DRF instead of Base Django

    This is where it gets a little tricky. Django accomodates both frontend and backend, but where it shines is with DRF. So always refer to documentation regarding write it from the documentation.

    If you plan to use Django as an entire full-stack option, then you may not need DRF at all. Just use the generic views.

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#function-based-views-and-class-based-views","title":"Function-based Views and Class-based Views","text":"Codes

    Summary: In DRF, there's a lot more advantage to use class-based views. However, if you want the flexibility and writing things on your own, then you might want to use function-based view.

    Function-Based View

    Link:

    from django.shortcuts import render\nfrom django.http import JsonResponse\n\nfrom rest_framework.decorators import api_view\nfrom rest_framework.response import Response\nfrom .serializers import TaskSerializer\n\nfrom .models import Task\n\n@api_view(['GET'])\ndef apiOverview(request):\n    api_urls = {\n        'List':'/task-list/',\n        'Detail View':'/task-detail/<str:pk>/',\n        'Create':'/task-create/',\n        'Update':'/task-update/<str:pk>/',\n        'Delete':'/task-delete/<str:pk>/',\n        }\n\n    return Response(api_urls)\n\n@api_view(['GET'])\ndef taskList(request):\n    tasks = Task.objects.all().order_by('-id')\n    serializer = TaskSerializer(tasks, many=True)\n    return Response(serializer.data)\n\n@api_view(['GET'])\ndef taskDetail(request, pk):\n    tasks = Task.objects.get(id=pk)\n    serializer = TaskSerializer(tasks, many=False)\n    return Response(serializer.data)\n\n\n@api_view(['POST'])\ndef taskCreate(request):\n    serializer = TaskSerializer(data=request.data)\n\n    if serializer.is_valid():\n        serializer.save()\n\n    return Response(serializer.data)\n\n@api_view(['POST'])\ndef taskUpdate(request, pk):\n    task = Task.objects.get(id=pk)\n    serializer = TaskSerializer(instance=task, data=request.data)\n\n    if serializer.is_valid():\n        serializer.save()\n\n    return Response(serializer.data)\n\n\n@api_view(['DELETE'])\ndef taskDelete(request, pk):\n    task = Task.objects.get(id=pk)\n    task.delete()\n\n    return Response('Item succsesfully delete!')\n

    Class-Based View

    To be seen in in the live demos

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#django-admin","title":"Django Admin","text":"

    Django comes with a built-in user-interface for managing \"Django Apps\" with models.py By default it in the path /admin

    Django Admin

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#other-tools","title":"Other Tools","text":""},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#drf-frontend-for-consuming-api","title":"DRF Frontend for Consuming API","text":"

    When you use DRF for developing API, and use the generic API views and serializers, it will automatically create this for you.

    DRF Frontend

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#postman","title":"Postman","text":"

    Development tool for interacting with APIs:

    • environment variables
    • collection of possible endpoints
    • send different JSON body
    Postman

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#python-debugger-pdb","title":"Python Debugger (pdb)","text":"

    When you run the django python manage.py runserver, you can add breakpoint() to anywhere piece of your code. This will stop the terminal line to the breakpoint if it hits it. From here you can do debugging.

    "},{"location":"2021-2022-summer/introduction-to-backend-development-with-django/#demo-live-coding","title":"Demo - Live Coding","text":"

    Demonstrate how to create a backend for a Todo app.

    1. Setup Python environment python -m venv venv then activate with source venv/bin/activate
    2. Install Django pip install Django
    3. Setup django codebase django-admin startproject todo
    4. Install DRF

      # As per https://www.django-rest-framework.org/#installation\npip install djangorestframework\npip install markdown       # Markdown support for the browsable API.\npip install django-filter  # Filtering support\npip install pytz           # Timezone support\n

    5. Freeze requirements pip freeze > requirements.txt

    6. Do a python sqlite migration python manage.py migrate to initialise the Django database for the apps
    7. Create a super user python manage.py createsuperuser
    8. Run the django app with python manage.py runserver
    9. Login with the super user and show Django Admin
    10. Setup django app python manage.py startapp api
    11. Create a model models.py

      from django.db import models\n\n# Todo Model\nclass Todo(models.Model):\n    title = models.CharField(max_length=100)\n    description = models.TextField()\n    completed = models.BooleanField(default=False)\n    created_at = models.DateTimeField(auto_now_add=True)\n    updated_at = models.DateTimeField(auto_now=True)\n\n    def __str__(self):\n        return self.title\n

    12. Do a python sqlite migration python manage.py makemigrations and python manage.py migrate

    13. Show sqlite
    14. Create serialiser serializers.py

      from api.models import Todo\nfrom rest_framework import serializers\n\nclass TodoSerializer(serializers.ModelSerializer):\n    \"\"\"\n    Serializer for Todo model\n    \"\"\"\n    class Meta:\n        model = Todo\n        # All fields\n        fields = '__all__'\n

    15. Create Class-based view views.py and link back to the urls.py

      # api/views.py\nfrom django.shortcuts import render\nfrom rest_framework import viewsets, permissions\nfrom api.serializers import TodoSerializer\nfrom api.models import Todo\n\n# Class Model Viewset\nclass TodoModelViewSet(viewsets.ModelViewSet):\n    # Define the serializer class\n    serializer_class = TodoSerializer\n    # Define the queryset\n    queryset = Todo.objects.all()\n\n    # Permissions (left to your own exercise)\n    # permission_classes = [permissions.IsAuthenticated]\n\n    # Define the list of allowed HTTP methods (by default if you didn't define it, it will just enable all)\n    http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']\n
      # api/urls.py\nfrom django.urls import path, include\nfrom rest_framework import routers\nfrom api.views import TodoModelViewSet\n\nrouter = routers.DefaultRouter(trailing_slash=False)\nrouter.register(r'todos', TodoModelViewSet)\n\nurlpatterns = [\n    path('', include(router.urls)),\n]\n
      # urls.py\nfrom django.contrib import admin\nfrom django.urls import path, include\n\nurlpatterns = [\n    path('admin/', admin.site.urls),\n    path('api-auth/', include('rest_framework.urls')),\n    path('api/', include('api.urls')),\n]\n

    16. Manually test with DRF Frontend or postman

    Final code can be seen here.

    Read through the Viewset Documentation

    Viewsets are one of the most powerful feature ever. In just a couple of lines of code, you can create a CRUD API for your models.

    As one of my favourite developer once said,

    Quote

    Frinze, Viewset is the future! - J. Morales

    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/","title":"Introduction to Frontend Frameworks","text":"

    An intuitive explanation of why frontend frameworks are used

    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#frontend-engineering","title":"Frontend Engineering","text":"
    • Frontend Engineering, one of the most important aspect of web dev
    • Feared by lots of developers (ehem ehem CSS)
    Memes"},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#job-market-and-trends","title":"Job Market and Trends","text":"StackOverflow 2020

    Can be seen that there is a huge portion that will needs frontend.

    Note: Developers can identify as many types

    Startups

    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#github-copilot-and-drag-and-drops","title":"Github Copilot and Drag and Drops","text":"
    • Getting replaced by AIs, Drag and drops?
    • Far from reality?
    Github Copilot and Squarespace"},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#problems","title":"Problems","text":""},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#cross-browser-support","title":"Cross-Browser Support","text":"
    • Need to support multiple browsers
    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#html-is-wet","title":"HTML is WET!","text":"

    Not DRY = WET

    D \u2013 Don't

    R \u2013 Repeat

    Y - Yourself

    Github Tags System

    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#inefficiencies-of-reloading","title":"Inefficiencies of Reloading","text":"
    • Most parts of website don't change
    Youtube
    • What about with notifications and realtime updates?
    notifications"},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#state-management-and-rerendering","title":"State Management and Rerendering","text":"
    • How do you handle changes in the state of the application?
    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#example-spotimania","title":"Example \"Spotimania\"","text":"

    Realtime Multiplayer Song Guessing Game https://spotimania.herokuapp.com/

    Information

    • Song picture
    • Notifications when someone joined or scored
    • Song title + artist

    How do we handle when we \"Submit Guess\"?

    HTML Format Submit Approach
    1. Reloads = loses current state
    2. How do you coordinate with players?
    AJAX Calls
    1. From frontend, use JS to do AJAX Calls
    2. After receiving AJAX call, modify everything that needs the data (Find element by DOM, do some janky HTML inject)
    const newData = await fetch(\u2026)\nconst image = document.querySelector('img .music')\nimage.outerText = `<img src={newData.image} / >`\n
    Cross-site Scripting

    Now, you have to implement your own strategy to do this.

    newData = {\u2026 , image: \"<script>hack()</script>\", ...}\n

    When you try to do render by that approach:
    • slower (rerendering things that should not render)
    • tedious (find element and update)
    • security
    • code complexity
    • hard to keep track of states (especially if different portion of the UI relies on a certain data)
    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#how-do-we-fix-it","title":"How do we fix it?","text":""},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#cross-browser-support_1","title":"Cross-Browser Support","text":"

    Babel: Transpiles / Translates New JavaScript to old JavaScript that is supported

    Webpack: Bundles / Packs Bundles the JavaScript modules into a single minified file

    SCSS Compilation

    Translates concise and programatic version of CSS to something that can be understood by the browser

    Minification

    Makes files smaller by removing unnecessary characters

    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#what-if-html-is-not-wet-what-if-html-is-a-programming-language","title":"What if HTML is NOT WET? What if HTML is a programming language?","text":"Memes about HTML as a programming language

    What if HTML has variables?

    • perform computations to be displayed in the interface (solves State Management and Rerendering)

    What if HTML has loops?

    • Eliminate repetitive code (solves wet HTML)

    What if HTML has functions?

    • Divide interface into modular components (solves wet HTML)
      • load only components that are not loaded (solves Inefficiencies of Reloading)
    • interface determined by parameters
    • Maybe we can write a function that will automatically update HTML when data changes? (solves State Management and Rerendering)

    What if HTML has condition?

    • Conditional rendering (solves Reloading to show different view)
    "},{"location":"2021-2022-summer/introduction-to-frontend-frameworks/#whats-next","title":"What's next?","text":"

    The next two workshop content are:

    • React
    • Vue
    "},{"location":"2021-2022-summer/introduction-to-react/","title":"Introduction to React","text":"

    Sparking the REACTion of User Interface and Experience

    "},{"location":"2021-2022-summer/introduction-to-react/#decomposing-the-html-user-interface","title":"Decomposing the HTML User Interface","text":"Complete code
    <!DOCTYPE html>\n<html lang=\"en\">\n\n<head>\n    <meta charset=\"UTF-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n    <link rel=\"stylesheet\" href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css\"\n        integrity=\"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T\" crossorigin=\"anonymous\" />\n    <link rel=\"stylesheet\" href=\"style.css\" />\n    <title>My Home Page - Frinze Lapuz</title>\n</head>\n\n<body>\n    <nav class=\"navbar sticky-top navbar-dark bg-dark\">\n        <div class=\"container nav\">\n            <a class=\"navbar-brand\" href=\"#\">Royal Homepage</a>\n        </div>\n    </nav>\n    <div class=\"container\">\n        <div class=\"row\">\n            <div class=\"col\">Here Some Dog For You. Cool Stuff right?</div>\n            <div class=\"col\">\n                <!-- <img class=\"img-fluid img-thumbnail\" src=\"dog.jpg\" alt=\"dog\" /> -->\n                <div class=\"carouselWrapper\">\n                    <div id=\"carouselDoggo\" class=\"carousel slide\" data-ride=\"carousel\">\n                        <ol class=\"carousel-indicators\">\n                            <li data-target=\"#carouselDoggo\" data-slide-to=\"0\" class=\"active\"></li>\n                            <li data-target=\"#carouselDoggo\" data-slide-to=\"1\"></li>\n                            <li data-target=\"#carouselDoggo\" data-slide-to=\"2\"></li>\n                        </ol>\n                        <div class=\"carousel-inner\">\n                            <div class=\"carousel-item active\">\n                                <img src=\"dog.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                                <div class=\"carousel-caption d-none d-md-block\">\n                                    <h5>First Dog</h5>\n                                    <p>Cutie :)</p>\n                                </div>\n                            </div>\n                            <div class=\"carousel-item\">\n                                <img src=\"dog2.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                                <div class=\"carousel-caption d-none d-md-block\">\n                                    <h5>Second Dog</h5>\n                                    <p>Good Doggo!</p>\n                                </div>\n                            </div>\n                            <div class=\"carousel-item\">\n                                <img src=\"dog3.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                                <div class=\"carousel-caption d-none d-md-block\">\n                                    <h5>Third Dog</h5>\n                                    <p>Walkie Barkie Cutie!</p>\n                                </div>\n                            </div>\n                        </div>\n                        <a class=\"carousel-control-prev\" href=\"#carouselDoggo\" data-slide=\"prev\">\n                            <span class=\"carousel-control-prev-icon\"></span>\n                            <span class=\"sr-only\">Previous</span>\n                        </a>\n                        <a class=\"carousel-control-next\" href=\"#carouselDoggo\" data-slide=\"next\">\n                            <span class=\"carousel-control-next-icon\"></span>\n                            <span class=\"sr-only\">Next</span>\n                        </a>\n                    </div>\n                </div>\n            </div>\n        </div>\n    </div>\n    <script src=\"https://code.jquery.com/jquery-3.3.1.slim.min.js\"\n        integrity=\"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo\"\n        crossorigin=\"anonymous\"></script>\n    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js\"\n        integrity=\"sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1\"\n        crossorigin=\"anonymous\"></script>\n    <script src=\"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js\"\n        integrity=\"sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM\"\n        crossorigin=\"anonymous\"></script>\n</body>\n\n</html>\n
    Relevant Code for Discussion
    <nav class=\"navbar sticky-top navbar-dark bg-dark\"> <!--(1)-->\n    <div class=\"container nav\">\n        <a class=\"navbar-brand\" href=\"#\">Royal Homepage</a>  \n    </div>\n</nav>\n<div class=\"container\">\n    <div class=\"row\">\n        <div class=\"col\">Here Some Dog For You. Cool Stuff right?</div> <!--(2)-->\n        <div class=\"col\">\n            <div class=\"carouselWrapper\"> <!--(3)-->\n                <div id=\"carouselDoggo\" class=\"carousel slide\" data-ride=\"carousel\">\n                    <ol class=\"carousel-indicators\">\n                        <li data-target=\"#carouselDoggo\" data-slide-to=\"0\" class=\"active\"></li>\n                        <li data-target=\"#carouselDoggo\" data-slide-to=\"1\"></li>\n                        <li data-target=\"#carouselDoggo\" data-slide-to=\"2\"></li>\n                    </ol>\n                    <div class=\"carousel-inner\">\n                        <div class=\"carousel-item active\">\n                            <img src=\"dog.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                            <div class=\"carousel-caption d-none d-md-block\">\n                                <h5>First Dog</h5>\n                                <p>Cutie :)</p>\n                            </div>\n                        </div>\n                        <div class=\"carousel-item\">\n                            <img src=\"dog2.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                            <div class=\"carousel-caption d-none d-md-block\">\n                                <h5>Second Dog</h5>\n                                <p>Good Doggo!</p>\n                            </div>\n                        </div>\n                        <div class=\"carousel-item\">\n                            <img src=\"dog3.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                            <div class=\"carousel-caption d-none d-md-block\">\n                                <h5>Third Dog</h5>\n                                <p>Walkie Barkie Cutie!</p>\n                            </div>\n                        </div>\n                    </div>\n                    <a class=\"carousel-control-prev\" href=\"#carouselDoggo\" data-slide=\"prev\">\n                        <span class=\"carousel-control-prev-icon\"></span>\n                        <span class=\"sr-only\">Previous</span>\n                    </a>\n                    <a class=\"carousel-control-next\" href=\"#carouselDoggo\" data-slide=\"next\">\n                        <span class=\"carousel-control-next-icon\"></span>\n                        <span class=\"sr-only\">Next</span>\n                    </a>\n                </div>\n            </div>\n        </div>\n    </div>\n</div>\n
    1. Navigation Bar
    2. Some Text
    3. Carousel
    "},{"location":"2021-2022-summer/introduction-to-react/#html-stored-in-variables","title":"HTML Stored in Variables","text":"
    const Nav = \n    `<nav class=\"navbar sticky-top navbar-dark bg-dark\"> \n        <div class=\"container nav\">\n            <a class=\"navbar-brand\" href=\"#\">Royal Homepage</a>  \n        </div>\n    </nav>\n    `\n
    "},{"location":"2021-2022-summer/introduction-to-react/#html-stored-in-functions","title":"HTML Stored in Functions","text":"
    const Nav = (title) => \n    `\n    <nav class=\"navbar sticky-top navbar-dark bg-dark\"> \n        <div class=\"container nav\">\n            <a class=\"navbar-brand\" href=\"#\">${title}</a>  \n        </div>\n    </nav>\n    `\n
    Carousel Decomposition

    The highlighted ones are the key-distinct data driven elements.

    <div class=\"carouselWrapper\">\n    <div id=\"carouselDoggo\" class=\"carousel slide\" data-ride=\"carousel\">\n        <ol class=\"carousel-indicators\">  <!--(1)-->\n            <li data-target=\"#carouselDoggo\" data-slide-to=\"0\" class=\"active\"></li>\n            <li data-target=\"#carouselDoggo\" data-slide-to=\"1\"></li>\n            <li data-target=\"#carouselDoggo\" data-slide-to=\"2\"></li>\n        </ol>\n        <div class=\"carousel-inner\">\n            <div class=\"carousel-item active\"> <!--(2)-->\n                <img src=\"dog.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                <div class=\"carousel-caption d-none d-md-block\">\n                    <h5>First Dog</h5>\n                    <p>Cutie :)</p>\n                </div>\n            </div>\n            <div class=\"carousel-item\">\n                <img src=\"dog2.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                <div class=\"carousel-caption d-none d-md-block\">\n                    <h5>Second Dog</h5>\n                    <p>Good Doggo!</p>\n                </div>\n            </div>\n            <div class=\"carousel-item\">\n                <img src=\"dog3.jpg\" class=\"d-block w-100\" alt=\"...\" />\n                <div class=\"carousel-caption d-none d-md-block\">\n                    <h5>Third Dog</h5>\n                    <p>Walkie Barkie Cutie!</p>\n                </div>\n            </div>\n        </div>\n        <a class=\"carousel-control-prev\" href=\"#carouselDoggo\" data-slide=\"prev\">\n            <span class=\"carousel-control-prev-icon\"></span>\n            <span class=\"sr-only\">Previous</span>\n        </a>\n        <a class=\"carousel-control-next\" href=\"#carouselDoggo\" data-slide=\"next\">\n            <span class=\"carousel-control-next-icon\"></span>\n            <span class=\"sr-only\">Next</span>\n        </a>\n    </div>\n</div>\n

    1. Carousel Indicators
    2. Carousel Items

    Now, what if we have a variable called dogsData an array of objects (may come from fetch).

    dogsData = [\n    ...\n    {\n        imgSrc: \"dog.jpg\",\n        title: \"First Dog\",\n        caption: \"Cutie :)\"\n    }\n    ...\n]\n

    const Carousel = (dogsData) =>\n    `\n    <div class=\"carouselWrapper\"> <!--(1)-->\n        <div id=\"carouselDoggo\" class=\"carousel slide\" data-ride=\"carousel\">\n            <ol class=\"carousel-indicators\">\n                ${dogsData.map((dog, index) => `<li data-target=\"#carouselDoggo\" data-slide-to=\"${index}\" class=\"${index === 0 ? 'active' : ''}\"></li>`).join('')}\n            </ol>\n            <div class=\"carousel-inner\">\n                ${dogsData.map((dog, index) => `\n                    <div class=\"carousel-item ${index === 0 ? 'active' : ''}\">\n                        <img src=\"${dog.imgSrc}\" class=\"d-block w-100\" alt=\"...\" />\n                        <div class=\"carousel-caption d-none d-md-block\">\n                            <h5>${dog.title}</h5>\n                            <p>${dog.caption}</p>\n                        </div>\n                    </div>\n                `).join('')}\n            </div>\n            <a class=\"carousel-control-prev\" href=\"#carouselDoggo\" data-slide=\"prev\">\n                <span class=\"carousel-control-prev-icon\"></span>\n                <span class=\"sr-only\">Previous</span>\n            </a>\n            <a class=\"carousel-control-next\" href=\"#carouselDoggo\" data-slide=\"next\">\n                <span class=\"carousel-control-next-icon\"></span>\n                <span class=\"sr-only\">Next</span>\n            </a>\n        </div>\n    </div>\n    `\n
    "},{"location":"2021-2022-summer/introduction-to-react/#assemble-the-components","title":"Assemble the Components","text":"

    {Nav(\"Royal Homepage\")}\n<div class=\"container\">\n    <div class=\"row\">\n        <div class=\"col-md-12\">\n            {Carousel(dogsData)}\n        </div>\n    </div>\n
    or with JSX

    <Nav title=\"Royal Homepage\"></Nav>\n<div class=\"container\">\n    <div class=\"row\">\n        <div class=\"col-md-12\">\n            <Carousel dogsData={dogsData}></Carousel>\n        </div>\n    </div>\n
    "},{"location":"2021-2022-summer/introduction-to-react/#intro-to-react","title":"Intro to React","text":"Complete Modularised Code
    const Nav = () => <nav class=\"navbar sticky-top navbar-dark bg-dark\"> \n    <div class=\"container nav\">\n        <a class=\"navbar-brand\" href=\"#\">Royal Homepage</a>  \n    </div>\n</nav>\n\nconst Carousel = (dogsData) =>\n    <div class=\"carouselWrapper\">\n        <div id=\"carouselDoggo\" class=\"carousel slide\" data-ride=\"carousel\">\n            <ol class=\"carousel-indicators\">\n                ${dogsData.map((dog, index) => `<li data-target=\"#carouselDoggo\" data-slide-to=\"${index}\" class=\"${index === 0 ? 'active' : ''}\"></li>`).join('')}\n            </ol>\n            <div class=\"carousel-inner\">\n                ${dogsData.map((dog, index) => `\n                    <div class=\"carousel-item ${index === 0 ? 'active' : ''}\">\n                        <img src=\"${dog.imgSrc}\" class=\"d-block w-100\" alt=\"...\" />\n                        <div class=\"carousel-caption d-none d-md-block\">\n                            <h5>${dog.title}</h5>\n                            <p>${dog.caption}</p>\n                        </div>\n                    </div>\n                `).join('')}\n            </div>\n            <a class=\"carousel-control-prev\" href=\"#carouselDoggo\" data-slide=\"prev\">\n                <span class=\"carousel-control-prev-icon\"></span>\n                <span class=\"sr-only\">Previous</span>\n            </a>\n            <a class=\"carousel-control-next\" href=\"#carouselDoggo\" data-slide=\"next\">\n                <span class=\"carousel-control-next-icon\"></span>\n                <span class=\"sr-only\">Next</span>\n            </a>\n        </div>\n    </div>\n\nconst Homepage = () =>{\n    const dogsData = fetch(...) // Get data from API\n    return (\n        <>\n            <Nav title=\"Royal Homepage\"></Nav>\n            <div class=\"container\">\n                <div class=\"row\">\n                    <div class=\"col-md-12\">\n                        <Carousel dogsData={dogsData}></Carousel>\n                    </div>\n            </div>\n        </>\n    )\n}\n
    "},{"location":"2021-2022-summer/introduction-to-react/#getting-started-with-react","title":"Getting Started with React","text":"

    Getting Started with the app

    To get started with react, use the following commands

    npx create-react-app my-app where my-app is the name of the folder for where the react app is going to be.

    cd my-app

    Notice that it created a couple of folders. In a couple of sentences:

    src/index.js - injects the user interface in the public/index.html (the front part of the build)

    public - folder containing the static assets as well as the index.html

    package.json - dependencies and scripts for the app

    type yarn start to run the development version of React (it will run react-scripts start within the node_modules \u2026 so running react-scripts start will not exactly be the same). This will serve up React in a port

    To be left as a live coding exercise. Live coding demonstration:

    "},{"location":"2021-2022-summer/introduction-to-react/#demo","title":"Demo","text":"
    • Passing Array props
    • show \u201crafce\u201d
    • useState when adding new item
    "},{"location":"2021-2022-summer/introduction-to-vue/","title":"Introduction to Vue","text":"

    A Vuetiful Introduction to VueJS

    Due to time constraints, we had to reuse the previous Winter Materials.

    As always, see the youtube video playlist

    "},{"location":"2021-2022-summer/introduction-to-web-development/","title":"Introduction to Web Development Space","text":"

    Navigating the Deep Dark Space of Web Development

    This workshop covers a brief overview of the most common tools and technologies used in web development.

    "},{"location":"2021-2022-summer/introduction-to-web-development/#content","title":"Content","text":"
    • What and Why Web Development?
    • FAQs about Web Development
    • Basics of Web and Limitation
    • Server-side Applications (Backend)
    • Others
      • Languages of the Web (the usual)
      • Hosting Stuff
      • CSS Frameworks
      • Developer Tools
      • TypeScript
      • Testing
      • Continuous Integration / Continuous Deployment
      • Virtualisation and Containerisation
      • Browsers
      • Firefox Developer Tools
      • Package Managers
      • Version Control
      • Linters and Formatters
      • Teamwork
      • Roadmaps
    • Word of Encouragement
    "},{"location":"2021-2022-summer/introduction-to-web-development/#what-and-why-web-development","title":"What and Why Web Development?","text":""},{"location":"2021-2022-summer/introduction-to-web-development/#what-is-web-development","title":"What is web development?","text":"
    • Websites development
    • Web applications (client-side and server-side) development
    "},{"location":"2021-2022-summer/introduction-to-web-development/#why-web-development","title":"Why Web Development ?","text":"
    • Accessibility and Portability
    • Career and On-demand in job market
    • Huge possibility to combine with other emerging technologies (e.g. IoT, Machine Learning) and industry (e.g. Health, Mining, O&G)
    Career in Web Development

    Source: Insights from Stack Overflow\u2019s 2016 survey of 50,000 developers

    \"Half of Developers are Web Developers\"

    "},{"location":"2021-2022-summer/introduction-to-web-development/#faqs-about-web-development","title":"FAQs about Web Development","text":""},{"location":"2021-2022-summer/introduction-to-web-development/#why-code-websites-why-not-use-drag-and-drops-like-wordpress-wix","title":"Why code websites, why not use drag and drops like Wordpress, WIX?","text":"
    • Content Management System (CMS)
    • Limitations on theme/template used
    • Difficult to extend
    • Cybersecurity
    More information

    CMS are one of the application of web development, but there are plenty more such as - internet of things, custom software for a particular industrial application (eg. using Machine Learning)

    CMS are usually limited to the template or plugin that you use. If those plugin don't exist, then it limits your productivity very much (difficulty to extend).

    CMS are usually built to cater for non-technical users. This means that thye become the subject of hackers. Think about a scenario where a hacker was able to find a vulnerability in WordPress, now every other WordPress site will be vulnerable.

    "},{"location":"2021-2022-summer/introduction-to-web-development/#what-is-the-best-way-to-learn-all-these","title":"What is the best way to learn all these?","text":"

    In summary, the best way to learn:

    • Do personal projects (inspiration + motivation)
    • Do team projects (get peer reviews and correct bad practices straight away)
    • Watch Online Courses (to figure out what is available)
    More Information

    To be told that you have to learn \"this, this, and that\" before you could do things is tiresome.

    Often times, we want to learn to be a developer so that we can create cool things like software where thousands of people can use the app. We don't tend to be a developer for the sake of us needing to watch endless videos on different things.

    "},{"location":"2021-2022-summer/introduction-to-web-development/#why-does-cfc-not-do-mobile-development-as-much-as-web-development","title":"Why does CFC not do mobile development as much as web development?","text":"
    • App stores has a developer cost
    • Easier to deal/teach web technologies
    • Accessibility (mobile, sensors, tablets, laptops and PCs)
    • Bigger open-source community
    "},{"location":"2021-2022-summer/introduction-to-web-development/#if-i-already-know-a-frontend-framework-is-it-better-to-learn-another-frontend-framework-or-to-learn-a-backend-framework","title":"If I already know a frontend framework, is it better to learn another frontend framework or to learn a backend framework?","text":"
    • It is better to learn a backend framework
    Reasoning

    You want to build skills that complement one another rather than be an alternative.

    It is much more valuable for you to learn a backend framework because that helps you build a functional app.

    "},{"location":"2021-2022-summer/introduction-to-web-development/#basics-of-web-and-limitation","title":"Basics of Web and Limitation","text":"HTML

    What is it?

    • Hypertext Markup Language
    • Describes the structure of a web page

    Limitation

    • Doesn\u2019t handle repeated content well
    • No variables or calculation
    HTML Syntax
    <!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Document</title>\n</head>\n<body>\n    Hello World!\n</body>\n</html>\n
    CSS

    What is it?

    • Cascading Style Sheets
    • Describes the presentation of a web page

    Limitation

    • Most css is quite similar (Handled by CSS Libraries)
    • Not very dynamic (Handled by CSS Frameworks)
    CSS Syntax
    body {\n    background-color: #f0f0f0;\n    font-family: sans-serif;\n}\n\n.container{\n    width: 80%;\n    margin: 0 auto;\n}\n
    JS

    What is it?

    • JavaScript
    • Used to program complex features on a web page

    Limitation

    • Has the capability to modify the user interface, but becomes really tedious to modify interface (more about this in another workshop)
    JS Syntax
    const bodySelector = document.querySelector('body');\nconst myFunction = () => {\n    bodySelector.innerHTML = 'Hello World 2!';\n    // Add a container class to space out\n    bodySelector.classList.add('container');\n}\nbodySelector.onclick = myFunction;\n
    "},{"location":"2021-2022-summer/introduction-to-web-development/#modern-frameworks","title":"Modern Frameworks","text":"
    • Websites can be much more\u2026 they can be web applications
    • \u201cApp\u201d in a website (client-side rendering)
    Modern Frameworks React.js
    • More mature and used more in industry
    Vue.js
    • Growing fast in popularity and use.

    General Information

    • Both are good to use and learn.
    • Knowledge is transferable between the two frameworks.
    Comparison between HTML and JSX

    Highlighted portions are starting chunk of distinct code.

    HTML
    <div class=\"row\">\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">devices</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Applications\n            </p>\n            <p class=\"mb-0\">\n            Build custom web and mobile applications to engage with your audience\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">web</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">Websites</p>\n            <p class=\"mb-0\">\n            Build new websites or optimise existing pages to improve online\n            visibility\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">storage</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Data Storage\n            </p>\n            <p class=\"mb-0\">\n            Design and create databases for efficient information storage and\n            retrieval\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">how_to_reg</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Consulting\n            </p>\n            <p class=\"mb-0\">\n            Empower your organisation through technical knowledge and advice\n            </p>\n        </div>\n        </div>\n    </div>\n</div>\n
    JSX
    import { memo } from 'react'\nimport { Row, Col, Card, CardBody } from 'reactstrap'\nimport services from 'data/services.json'\n\nconst Service = (props: {\nicon: string\ntitle: string\ndescription: string\n}) => (\n<Card className='text-center border-0 bg-transparent'>\n    <CardBody className='px-0'>\n    <i className='material-icons-sharp md-lg'>{props.icon}</i>\n    <p className='mt-4 font-weight-bold text-monospace text-larger'>\n        {props.title}\n    </p>\n    <p className='mb-0'>{props.description}</p>\n    </CardBody>\n</Card>\n)\n\nconst Services = () => (\n<Row>\n    {services.map(service => (\n    <Col\n        xs={12}\n        md={6}\n        lg={12 / services.length}\n        className='m-0'\n        key={service.title}\n    >\n        <Service {...service} />\n    </Col>\n    ))}\n</Row>\n)\n\nexport default memo(Services)\n
    "},{"location":"2021-2022-summer/introduction-to-web-development/#server-side-applications-backend","title":"Server-side Applications (Backend)","text":""},{"location":"2021-2022-summer/introduction-to-web-development/#how-do-devices-communicate","title":"How do devices communicate?","text":"
    • HTTP Request - Hypertext Transfer Protocol
    "},{"location":"2021-2022-summer/introduction-to-web-development/#what-do-server-applications-do","title":"What do server applications do?","text":"
    • Serve frontends (server-side rendering)
    • Web API (Application Programming Interface)
      • Serve data (usually from a database)
      • Process Request (Sending emails or SMS, Machine Learning)
    "},{"location":"2021-2022-summer/introduction-to-web-development/#databases","title":"Databases","text":"

    Place to store the data

    Mongodb

    Allows for database design to be modified without complex migration or data loss

    SQL

    Typically faster and better for large amounts of data or systems that need data consistency and reliability

    "},{"location":"2021-2022-summer/introduction-to-web-development/#others","title":"Others","text":""},{"location":"2021-2022-summer/introduction-to-web-development/#languages-of-the-web-the-usual","title":"Languages of the Web (the usual)","text":"
    • Python (Django, Flask)
    • JavaScript (Node.js, Express)
    • Ruby, Go, Rust, C
    "},{"location":"2021-2022-summer/introduction-to-web-development/#hosting-stuff","title":"Hosting Stuff","text":"

    Many ways - Own a server - Use a 3rd party platform

    "},{"location":"2021-2022-summer/introduction-to-web-development/#css-frameworks","title":"CSS Frameworks","text":"

    Frontend (JS)

    • Vue, React
    • Nuxt.js, Next.js

    Frontend (CSS)

    • MaterialUI, Vuetify
    • Bootstrap
    "},{"location":"2021-2022-summer/introduction-to-web-development/#developer-tools","title":"Developer Tools","text":""},{"location":"2021-2022-summer/introduction-to-web-development/#typescript","title":"TypeScript","text":"
    • Type checking is super useful for complex apps
    • Allows for way better javascript developer tooling
    • Can be annoying if you\u2019re new at it
    "},{"location":"2021-2022-summer/introduction-to-web-development/#testing","title":"Testing","text":"
    • Selenium, Cypress
      • End to end automated testing tools
    • Jest, Mocha, Pytest
      • Unit testing
    • Testing is vital to software projects
    "},{"location":"2021-2022-summer/introduction-to-web-development/#continuous-integration-continuous-deployment","title":"Continuous Integration / Continuous Deployment","text":"
    • Automated Testing
    • Event-driven scripts
    • E.g. Github Action, Bitbucket Pipelines
    "},{"location":"2021-2022-summer/introduction-to-web-development/#virtualisation-and-containerisation","title":"Virtualisation and Containerisation","text":"
    • Allows execution of services in a virtual environment
    • eg. Docker (Containerisation), Vagrant (Virtualisation)
    "},{"location":"2021-2022-summer/introduction-to-web-development/#browsers","title":"Browsers","text":"
    • Standard browsers
      • Google Chrome, Firefox, Edge, etc.
    • Backwards compatibility
      • Internet Explorer
    • Other
      • Mobile - Responsive
      • Screen readers - Accessibility
    "},{"location":"2021-2022-summer/introduction-to-web-development/#firefox-developer-tools","title":"Firefox Developer Tools","text":"
    • Page Inspector
      • Visualise page aspects
      • Grid layout
    • Web Console
      • console.log(\u201cHello World\u201d)
    • Responsive Design Mode
      • View from POV of different screen sizes such as mobile, tablets, etc.
    Some more tools
    • JavaScript Debugger
    • Network Monitor
    • Performance Tools
    • Rulers
    • Colour Pickers Learn more at: https://developer.mozilla.org/en-US/docs/Tools
    "},{"location":"2021-2022-summer/introduction-to-web-development/#package-managers","title":"Package Managers","text":"
    • Installs libraries that can be used
    • Also has code shortcuts (e.g. npm run start)

    (More about package.json and poetry.toml in the projects and Package Manager Workshop)

    "},{"location":"2021-2022-summer/introduction-to-web-development/#version-control","title":"Version Control","text":"
    • Essential for developer teams and complex software development
    • Git
    "},{"location":"2021-2022-summer/introduction-to-web-development/#linters-and-formatters","title":"Linters and Formatters","text":"
    • Makes code formatting consistent (following standard)
    • Useful with version controls to avoid pointless change

    eg.ESLint, Prettier

    "},{"location":"2021-2022-summer/introduction-to-web-development/#teamwork","title":"Teamwork","text":"
    • Many tools out there
    • Used to stop teams from stepping on each others toes
    • Github Issues + Pull Requests
    "},{"location":"2021-2022-summer/introduction-to-web-development/#roadmaps","title":"Roadmaps","text":"

    There's an open-source community that maintains a learning roadmap for developers. See https://roadmap.sh/

    Frontend Developer

    Backend Developer

    Dev-Ops

    "},{"location":"2021-2022-summer/introduction-to-web-development/#word-of-encouragement","title":"Word of Encouragement","text":"Encouragement from the Tech Lead

    \"I can admit that this journey of learning will be difficult, and can sometimes be overwhelming and demotivating. Please, if at any point of this project, you feel that you don't know enough, or you're feeling lost, please reach out! We are all in this journey together! Nobody is born talented, skills are honed with determination and willingness to learn.\"

    \"When I was a first year student entering on the CFC winter project, I didn't feel like I was good enough. I couldn't create a good looking interface, I didn't know how to use npm and all sorts of those things. I was just like many of you! if I gave up just because of all those things I didn't know, of all those self-doubts, then I wouldn't be here today. I admit that I was lucky because I was in CFC, I had connections where I can just ask questions instead of feeling lost of not knowing. So please do leverage that opportunity to reach out\"

    \"You being in this project not only gives you the opportunity to raise your talents, but you also unlock one of the biggest factor of the growth of your career, and that is the connections with your fellow software engineers.\"

    "},{"location":"2021-2022-summer/introduction-web-basics/","title":"Introduction to the Web Basics - HTML, CSS & JavaScript","text":"

    The tools of the web

    This workshop will introduce you to the basics of HTML, CSS and JavaScript, the fundamental technologies of web development. This is a very introductory workshop, and there is still so much we can learn, but this will be a good place to start.

    "},{"location":"2021-2022-summer/introduction-web-basics/#content","title":"Content","text":"
    • Key Web Technologies
    • HTML
      • Elements
      • Attributes
      • Images
      • Anchors/Hyperlinks
      • Forms
      • Document Object Model
    • CSS
      • CSS Format
      • Rules of Selection
      • Document and External Style Sheets
      • Flexboxes
    • JavaScript
      • The Basics of JavaScript
      • Arrays
      • Objects
      • Functions
      • Loops
    • Web App Tutorial
    "},{"location":"2021-2022-summer/introduction-web-basics/#key-web-technologies","title":"Key Web Technologies","text":"

    HTML, CSS and JavaScript each have a different job when it comes to creating web pages.

    "},{"location":"2021-2022-summer/introduction-web-basics/#what-do-they-do","title":"What do they do?","text":"
    • HTML: describes the content and structure of the web page
    • CSS: describes the style and appearance of the web page
    • JavaScript: provides funtionality to a web page
    "},{"location":"2021-2022-summer/introduction-web-basics/#html","title":"HTML","text":"

    Hyper Text Markup Language (HTML) is used to structure the webpage. The general structure of a webpage can be seen below.

    My First HTML Page
    <!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <title>You see this text on your browser tab!!!</title>\n    </head>\n    <body>\n        <!-- this is where the content goes! -->\n        <h1>My First Heading</h1>\n        <p>This is a paragraph</p>\n    </body>\n</html>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#elements","title":"Elements","text":"

    A webpage is made of elements, each with their own properties, that contain content to be displayed on the page. Elements are defined by tags, such as h1, div and body. Most elements have an open and close tab. The container and its content, together, are called an element.

    <h1>This is a header element.</h1>\n

    The most notable, and probably the tag you will use most, is the <div> tag. It defines a division or section within the HTML document, and is used as a container that holds other elements.

    The Seperator
    <!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <title>The Web Dev Fairytale</title>\n    </head>\n    <body>\n        <div>\n            <!-- This div concerns itself with the main heading/title of the story -->\n            <h1>The Dev, the Debugger and the Caffiene Addiction</h1>\n        </div>\n        <div>\n            <!-- This div concerns itself with the first chapter it its entirety -->\n            <h1>Chapter 1</h1>\n            <div>\n                <!-- This div concerns itself with the text of the first chapter -->\n                <!-- section within a section. A subsection! -->\n                <p>Once upon a time, in a castle far, far away...</p>\n            </div>\n        </div>\n        <div>\n            <h2>Chapter 2</h2>\n        </div>\n    </body>\n</html>\n

    We will go through the important ones during this workshop, but you can find the full of them here.

    "},{"location":"2021-2022-summer/introduction-web-basics/#attributes","title":"Attributes","text":"

    Most tags have attributes that specify information or change the tag in some way. The most common being class and id.

    "},{"location":"2021-2022-summer/introduction-web-basics/#most-common-attributes","title":"Most Common Attributes","text":"
    • class: used to specify one or more class names for a HTML element.
      • Classes are used to group certain elements in order to give them specific features through CSS and to allow many elements to be manipulated using JavaScript.
    • id: used to specify a unique id for an element and must be unique
      • The id attribute is assigned to an element so that element can be exclusively specified in the style declaration and JavaScript manipulation

    Below is an example of how attributes are assigned in your code.

    Elements and their Attributes
    <!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <title>You see this text on your browser tab!!!</title>\n    </head>\n    <body style=\"background-color: red\">\n        <div class=\"bigSection\">\n            <h1>BIG HEADER!</h1>\n            <p id=\"first\">This is the first paragraph of the webpage</p>\n            <!-- more cool stuff goes here -->\n        </div>\n        <div class=\"smallSection\">\n            <h6>small header</h6>\n        </div>\n    </body>\n</html>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#images","title":"Images","text":"

    Images are added by using the <img> element tag. It can also be used to add gifs!

    Example
    <img src=\"https://i.imgur.com/SjZxZza.jpeg\" alt=\"Three Cute Dog Mermaids\">\n

    Cute, right?

    "},{"location":"2021-2022-summer/introduction-web-basics/#image-attributes","title":"Image Attributes","text":"
    • src: specifies the location of the image to be displayed
      • This can either be a url, as in the example above, or the relative path of an image within the site's directory
    • alt: an optional attribute that contains a text description.
      • Is useful for accessibility or if the image does not load properly
    "},{"location":"2021-2022-summer/introduction-web-basics/#anchors-and-hyperlinks","title":"Anchors and Hyperlinks","text":"

    We can add links to other websites, or even to sections within the same page, using the <a> element, known as an anchor.

    Adding a hyperlink to an HTML page
    <a href=\"https://codersforcauses.org/\" target=\"_blank\">Coders for Causes</a>\n

    They can be adding added by themself, or within text such as here.

    "},{"location":"2021-2022-summer/introduction-web-basics/#anchor-attributes","title":"Anchor Attributes","text":"
    • href: specifies the destination to link to
      • External site: simply include the url you wish to visit
      • Different page within the site: include the path to the new page, usually in the form of \"/.../index.html\"
      • Different section on same page: use #name_of_section where name_of_section is the id of the element you wish to go to
    • target: specifies where to open the link
      • Setting the target attribute to \"_blank\" opens the link in another tab
    • download: specifies that the linked resouces will be downloaded.
      • Only needs to be included in the declaration of the element
      • Optional: if value of download is set, that value will be the name of the file

    Always be careul when clicking links. You never know when there is something you should not click.

    "},{"location":"2021-2022-summer/introduction-web-basics/#images-and-hyperlinks","title":"Images and Hyperlinks","text":"

    Any image, or any element in general, can be turned into a link by enclosing the element within the anchor tabs.

    Hyperlinked image
    <a href=\"https://codersforcauses.org/\" target=\"_blank\">\n    <img src=\"https://www.uwastudentguild.com/assets/clubs/logos/logo---coders-for-causes-1567649329.jpg\">\n</a>\n

    "},{"location":"2021-2022-summer/introduction-web-basics/#forms","title":"Forms","text":"

    Forms are used to collect user input. They are defined by the <form> tags and usually contain form elements such as <input>, <textbox>, etc.

    Inputs can come in many different forms, such as textboxes, radio buttons, checkboxes and drop down menus. Each input field is given a value Once a form is complete and filled out, we need to submit, or POST, it. This can be done through a special input of type submit.

    The only required attribute of <form> is action. The action attribute speicifies the URL of the application that is to be called when the Submit button is pressed. If no action, then the attribute takes the value of an empty string and the current page is the destination.

    Example
    <p>I like:</p>\n<form action=\"\">\n    <input type=\u201dradio\u201d value=\u201dRed\u201d>\n    <input type=\u201dradio\u201d value=\u201dGreen\u201d>\n    <input type=\u201dradio\u201d value=\u201dBlue\u201d>\n    <input type=\u201dsubmit\u201d value=\u201dSubmit\u201d>\n</form>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#input-validation","title":"Input Validation","text":"

    Input validation is a very important aspect to consider when dealing with forms. Remember the famous acronym GIGO, Garbage-in Garbage-Out. To assist you with input validation, HTML forms have in-built validation for different types of data, such as emails, numbers and dates. This can be achieved by changing the input type of a field to the respective data entry type.

    Baseline input validation with HTML
    <input type=\"email\" name=\"email\" value=\"Email\">\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#document-object-model","title":"Document Object Model","text":"

    All the elements of a HTML page make up a document tree, called the Document Object Model (DOM). The DOM is a platform and language-neutral interface that allows programs to dynamically access and update the content, structure and style of the HTML document. Each element in a HTML document is represented by a node on the tree. We can then use things such as JavaScript to access and update the HTML document using the DOM. We will see more of this in the tutorial at the end.

    "},{"location":"2021-2022-summer/introduction-web-basics/#css","title":"CSS","text":"

    Cascading Style Sheets (CSS) provides style to the web. It is used to specify the layout and style of markup languages. CSS tells the browser how to display the elements that are written in HTML.

    We can write the CSS style rules into an element using inline CSS, where the style attribute of an element is modified directly in the HTML.

    Inline style sheets
    <body style=\"background-color: red;\">\n    <!-- rest of body goes here -->\n</body>\n

    However, this gets hard to manage and maintain, especially when the number of elements in a document grows, and when we want to change many elements that have the same style. We use document-level style sheets or external style sheets to combat this issue.

    But first, we must understand how to create these style sheets.

    "},{"location":"2021-2022-summer/introduction-web-basics/#css-format","title":"CSS Format","text":"
    • Selector
      • A value, or list of values, that specify the elements for which the following style will be applied to
      • Rules for specification will be discussed a little later on, see here
    • Attribute
      • The attribute/property of an element you wish you change
      • Some example attributes include background-color, font-size and width
    • Effect
      • The effect is the value you set each attribute to be
      • This includes setting background-color to \"red\", or font-size to \"16px\"

    The following CSS specifies that all img elements are to be centered and have a width of 50 pixels.

    My First CSS
    img{\n    /* attribute: effect; */\n    display: block;\n    margin-left: auto;\n    margin-right: auto;\n    width: 50px;\n}\n
    How do I know what attributes exist, and what do I change to get my desired effect?

    There are two simple answers to this question: 1. Google it. Chances are, someone has already tried to do something similar and your solution already exists. 2. Play around. Learn what attributes exist, and how changing thier effects changes their on screen appearance.

    "},{"location":"2021-2022-summer/introduction-web-basics/#rules-of-selection","title":"Rules of Selection","text":"

    As mentioned earlier, selectors have a set of rules that allow you to apply styles to certain, or even very specific, groups of elements. These can range selecting elements based on the type of element they are, or what class they are in, to selecting all elements of a certain type that are immediately preceded by an element of another type.

    Element

    Element selectors simply apply the defined style to all elements of the same type.

    body{\n    background-color: red;\n}\n

    Class

    Class selectors apply the defined style to all elements belonging to that class. They are similar to element selectors, except that the class name is preceded by a . character.

    .narrow{\n    width: 10%\n}\n

    We can also specify the type of element within a class we wish to apply the style to by including it before the . character. The following code selects all <p> elements that are of the class narrow:

    p.narrow{\n    width:10%;\n}\n

    id

    These selectors apply the style to an element based on its id. The id is preceded by # in the selector definition.

    #bigButton{\n    font-size: 16px;\n}\n

    Psuedo Classes

    Psuedo classes are styles that apply only when a certian action occurs or a condition is met, and not all the time. Some common selectors include hover, focus and active. They are included after the element, class or id has been specified, and are preceded with a colon :.

    button:hover{\n    color: red;\n}\n

    The full list of them can be found here.

    Group

    To specify a group of elements to apply a style to, simply list the elements, ids or classes delimitted by a comma (,).

    h1, h2, div{\n    color: red;\n}\n

    Other

    There exists other selectors that allow you to be more specific as to what elements are to be selected, such as contextual selectors, but we will leave those as self-learning.

    Contextual Selectors

    Contextual selectors group elements based on their position and surroundings in the document tree. Further reading into the topic can be found through searching the web for platforms that teach you all about computer science, such as Geeks for Geeks.

    "},{"location":"2021-2022-summer/introduction-web-basics/#document-and-external-style-sheets","title":"Document and External Style Sheets","text":"

    Now that we know what we are doing, let's create some style sheets! Document and External style sheets help us better organise and manage the styles of the document. They are located in one location, so you do not have to go far to find them and change parts of your document.

    "},{"location":"2021-2022-summer/introduction-web-basics/#document-style-sheets","title":"Document Style Sheets","text":"

    Document style sheets are located within the <head> of a HTML document, under the <style> tag. They work in the same was as mentioned above. See the below example of how document style sheets are implemented within a HTML page.

    Document Style Sheets
    <!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <title>You see this text on your browser tab!!!</title>\n        <style>\n            body{\n                background-color: blue;\n            }\n            p{\n                color: red;\n                font-size: 16px;\n            }\n        </style>\n    </head>\n    <body>\n        <!-- this is where the content goes! -->\n        <h1>My First Heading</h1>\n        <p>This is a paragraph</p>\n    </body>\n</html>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#external-style-sheets","title":"External Style Sheets","text":"

    What happens when our site grows, and the number of HTML pages increases, and suddenly styles have to change, and we have to change every document, but they all have to follow the same styling as the others, and we have to manage that?! Thankfully, we can store our styles in a seperate .css file and then simply reference the stylesheet in our HTML document.

    styles.css
    body{\n    background-color: blue;\n}\np{\n    color: red;\n    font-size: 16px;\n}\n

    Once we have our css file completed, we can reference it in the HTML document, again in the <head>, so that it can apply the styles to our document.

    Applying my CSS files to my HTML document
    <!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <title>You see this text on your browser tab!!!</title>\n        <link rel=\"stylesheet\" href=\"styles.css\">\n    </head>\n    <body>\n        <!-- this is where the content goes! -->\n        <h1>My First Heading</h1>\n        <p>This is a paragraph</p>\n    </body>\n</html>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#flexboxes","title":"Flexboxes","text":"

    Flexboxes are a great way to position your items within a container.

    Learning is best done when having fun and getting your hands dirty (metaphorically). Flexbox Froggy is an interactive website that teaches you all about flexboxes, one step at a time. Your aim is to allign all the frogs to their corresponding lilypads. It is a much better learning tool than sitting and reading about some code I wrote.

    "},{"location":"2021-2022-summer/introduction-web-basics/#javascript","title":"JavaScript","text":"

    JavaScript, also known as JS, gives a web page fucntionality and reactiveness. It allows the user to interact with the web page, and for us to make it to do things that we want it to do. Similar to CSS, all your JS can be implemented into a HTML document by encapsulating it in the <script> tag within the <head> of the document, or even <body> in this case. However, we will be sticking to having our JS stored in external files for ease of managability. See the below example of how to add a script file to your page. To add many files, simply add another <script> element and reference the other file.

    Adding JavaScript to my HTML document
    <script src=\"script.js\"></script>\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#the-basics-of-javascript","title":"The Basics of JavaScript","text":"

    We shall discuss the basic syntax of JS, such as variables and functions, just to get you started. Feel free to do some of your own learning, too. There is a lot of cool things you can do and shortcuts you can use when you dive deeper into JavaScript, such as the ternary operator, but we will leave these for now.

    "},{"location":"2021-2022-summer/introduction-web-basics/#variables","title":"Variables","text":"

    Variables are named memory locations that store data. To define a variable, we can use three different keywords, each giving the variable special properties.

    "},{"location":"2021-2022-summer/introduction-web-basics/#variable-declaration","title":"Variable Declaration","text":"
    • var
      • allows the variable to be redeclared later on in the program
      • gives the variable a global scope, meaning they can be accessed anywhere within the file
    • let
      • once a variable has been declared using let, it cannot be redeclared. It's value can still change, however.
      • gives the variable block scope, meaning it can only be accessed within the block of code that it has been declared in. For example, if I declare a variable using the let key word, I cannot access it outside of the function.
    • const
      • Once the variable has been declared and assigned, it cannot be redeclared and the value never changes. It stays constant, sort of.
      • It, too, gives the variable block scope.

    For a full explanation on variable declaration in JS, check out w3schools' page on it.

    Variables can hold different data types, such as numbers, strings, objects, functions and arrays, but JS will cover the type identification for you.

    "},{"location":"2021-2022-summer/introduction-web-basics/#datatypes","title":"Datatypes","text":"
    • There are two groups of data types in JS: primitives and structural.
    • A primitive is data that is not an object and has no methods. There are seven primitive data types:
      • String, Number, BigInt, undefined, null and symbol
    • A structural data type is one where the data is in the form of an object, and that object has its own methods. The main structural data types are:
      • Objects and Functions
    "},{"location":"2021-2022-summer/introduction-web-basics/#math-and-logic","title":"Math and Logic","text":"

    Math and logic works similar in JS to other programming languages.

    "},{"location":"2021-2022-summer/introduction-web-basics/#math","title":"Math","text":"
    • +, -: addition and subtraction
    • *, /: multiplication and division, respectively.
    • %: modulo operator. Returns the remainder left over after division.
      • For example, 8 % 3 returns 2.
    • **: exponent (x to the power of y)
      • base ** power
    "},{"location":"2021-2022-summer/introduction-web-basics/#logic","title":"Logic","text":"
    • &&: AND operation
    • ||: OR operation
    • !: NOT operation
    • >/>=: greater than/greater than or equal to
    • </<=: less than/less than or equal to
    • ==: equal to
    • ===: exactly equal to
      • Works in a similar way to ==, except it also checks that the datatype is the same
    Difference between == and ===
    console.log(\"2\" == 2);  /* true */\nconsole.log(\"2\" === 2); /* false */\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#arrays","title":"Arrays","text":"

    Arrays are an ordered list of values. They can hold values of many datatypes. Their index starts at 0.

    let myArray = [\"a\", \"b\", \"c\", 1, 2 ,3, {name: \"Jared\", age: 19, canRead: false}]\nmyArray[0] // returns \"a\"\nmyArray[4] // returns 2\n

    "},{"location":"2021-2022-summer/introduction-web-basics/#objects","title":"Objects","text":"

    Objects are variables that can hold more than one value. One can be seen in the previous example in Arrays. The different values of an object are called keys. The keys can hold regular primitive values, such as numbers or strings, or can hold other objects, such as functions. Think of Objects as a list of key/value pairs.

    To access a key's value within an object, you must first reference the object in question, then insert a . folllowed by the key you wish to get.

    Objects in JavaScript
    let person = {\n    name: \"Jared\",\n    age: 19,\n    canRead: false\n}\nconsole.log(person.age) // outputs 19\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#functions","title":"Functions","text":"

    Functions are blocks of code designed to execute a particular task. In JS, the syntax for defining a function is as follows:

    Functions in JavaScript
    function func_name(parameter1, parameter2, ...){\n    // your code goes here (optional, but highly recommended)\n}\n

    Functions can be called or stored in variables.

    Calling and Storing Functions
    function hello_world(){\n    console.log(\"Hello, world!\")\n}\n\n// Calling the function\nhelloWorld()\n\n// Storing the function in a variable\nconst func_name = function (param1, param2){\n    // do stuff here\n}\n

    Functions can return a value (after calculation, etc) or simply perform work on existing data/variables. Functions that do not return anything are normally called procedures.

    "},{"location":"2021-2022-summer/introduction-web-basics/#arrow-functions","title":"Arrow Functions","text":"

    Arrow functions are just a compact way of writing normal functions. They work by removing the function key word, and even the return keyword in some cases. Arrows functions lead with their parameters, usually enclosed in normal brackets. An arrow => then follows, preceding the actual block of code to be executed.

    Arrow Functions: Example 1
    // Traditional function\nfunction addXY (x, y){\n    return x + y;\n}\n\n// Arrow function\nlet addXY = (x, y) => x + y;\n

    In single-lined functions, such as the one above, both the { braces } and the return can be omitted. However, when there are extra lines of processing, both must be included.

    Arrow Functions: Example 2
    // Traditional\nfunction add10(x, y){\n    x += 10\n    y += 10\n    return x + y;\n}\n\n// Arrow function\nlet add10 = (x, y) => {\n    x += 10\n    y += 10\n    return x + y;\n}\n
    "},{"location":"2021-2022-summer/introduction-web-basics/#loops","title":"Loops","text":"For

    For loops repeat until a condition is met. That condition is defined in the for loop. For loops have the following structure:

    For Loops
    /*\nfor(int i = start; condition; increment){\n    // code here\n}\n*/\n\n// Loop 10 times\nfor(int i = 0; i < 10; i++){\n    console.log(i)\n}\n// Output: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9\n
    For-in

    For-in loops iterate over the indexes of data in an iterable object, such as an array.

    For-in Loops
    let myArray = [2, 4, 6]\nfor(let j in myArray){\n    console.log(j)\n}\n// Output: 0, 1, 2\n
    For-of

    For-of loops iterate over the data in the iterable object.

    For-of Loops
    let myArray = [2, 4, 6]\nfor(let k of myArray){\n    console.log(j)\n}\n// Output: 2, 4, 6\n
    While

    While loops iterate while a condition is true. They are called a \"pre-test\" loop, where the condition is tested before the loop can run. The condition is included in the brackets.

    While Loops
    let b = 0\nwhile(b < 3){\n    console.log(\"Bon\")\n    b++\n}\n// Output: \"Bon\\n Bon\\n Bon\\n\"\n
    Do-while

    Do-while loops are similar to while loops, except that they let the block of code run once before testing the condition. They are known as \"post-test\" loops, and the loop is guaranteed to execute at least once.

    Do-while Loops
    let b = 0\ndo {\n    console.log(\"Bon\")\n    b++\n} while(b > 10)\n// Output: \"Bon\\n\"\n

    Loops can be broken or stopped using the break or continue statements.

    "},{"location":"2021-2022-summer/introduction-web-basics/#breakin-out","title":"Breakin' out","text":"
    • break: execution leaves the loop completely and continues on with the next lines of code
    • continue: disregards the rest of the code in the loop block and moves on to the next item in the loop
    "},{"location":"2021-2022-summer/introduction-web-basics/#creating-a-pokemon-api-webapp","title":"Creating a Pokemon API Webapp","text":"

    Now that we know a little bit about the tools of the web, let's build a simple web app that uses the skills we have learnt in this workshop, as well as some other skills we will learn along the way, to create an app that can do something cool.

    For this tutorial, we will pay homage to the recent releases of Pokemon Brilliant Diamond and Shining Pearl, of which I have spent an embarrassing number of hours on since they came out about a week ago, and create a web app that uses the PokeAPI to display images and information about any Pokemon we want.

    Watch the tutorial on our YouTube channel by clicking the link, here, or the image below!

    Back to Top

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/","title":"MVC-MVMM Architecture and Communications","text":"

    Separate the concerns with Design Patterns!

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#what-is-mvcmvvm-architecture","title":"What is MVC/MVVM Architecture?","text":"

    MVC (Model-View-Controller)

    • Model \u2013 data representation layer (how app communicates to db \u2013 Raw or ORM)
    • View \u2013 interface representation (with HTML, CSS and JS)
    • Controller \u2013 request relays (processes HTTP requests)
    MVC

    MVVM (Model-ViewModel-View)

    ViewModel \u2013 data-binding relays (processes the HTTP requests)

    MVVM

    Some inaccuracy

    I acknowledge that this may not be correct. If you search MVC/MVMM, you will see lots of conflicting details. This portion of the slide is explained to make frontend-backend integration easier to explain.

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#examples-of-technologies-with-the-architecture","title":"Examples of Technologies with the Architecture","text":"MVC - Django MVVM - Django + React MVC - Flask MVVM - Flask + React MVC - Express MVVM - Express + React"},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#why-is-software-architecture-important","title":"Why is software architecture important?","text":"

    Architecture shows how an entire software works in a high-level.

    Important for:

    • maintainability and extensibility
    • seperation of concerns
    • choosing different pieces of the stack
    Just some architecture diagrams

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#how-do-frontend-communicate-with-backend","title":"How do frontend communicate with backend?","text":"

    Via HTTP Requests responds with:

    • HTML, CSS, JS
    • JSON/XML
    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#server-side-rendering","title":"Server-side Rendering","text":"

    Via - HTML, CSS, JS

    Data Flow

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#client-side-rendering-and-ajax","title":"Client-side Rendering and AJAX","text":"

    Via HTTP Requests responds with: - blank HTML with JS (at first) - JSON/XML

    Data Flow

    CRUD to HTTP Verb Matching for JSON standard communications with REST-APIs

    Matches HTTP verbs with action

    AJAX \u2013 Asynchronous JavaScript and ~~XML~~ JSON

    JSON are strings

    JSON (JavaScript Object Notation) Note: JSONs are String... you have to serialise JSON to become an object

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#demo-react-to-integrate-with-django","title":"Demo - React to integrate with Django","text":"

    This follows up the demo with React to consume a standard REST-API Django Todo App demonstrated in the previous workshop.

    "},{"location":"2021-2022-summer/mvc-mvmm-architecture-and-communications/#other-information","title":"Other Information","text":"
    • Traversy Media MVC
    • React Query
    • Axios (a better Fetch?) Travery Media
    • Async/Await JavaScript
    "},{"location":"2021-2022-summer/package-managers/","title":"Package Managers","text":"

    Unlock the power of open source

    "},{"location":"2021-2022-summer/package-managers/#what-are-package-managers","title":"What are package managers?","text":"
    • Developer tools that allows access to libraries
    Examples
    • JavaScript (NPM/Yarn)
    • Python(Pip/Poetry)
    Diagram of the Package Manager Data Flow Modern Infrastructure Dependency"},{"location":"2021-2022-summer/package-managers/#examples-of-actual-libraries-and-their-dependencies","title":"Examples of Actual Libraries and their dependencies","text":"

    See this tool to visualise dependency.

    MUI Dependency

    Express Dependency

    "},{"location":"2021-2022-summer/package-managers/#install-package-managers","title":"Install Package Managers","text":"
    • NPM Download | Node.js (nodejs.org)
    • Yarn Installation | Yarn (yarnpkg.com)

    • Pip Download Python | Python.org

    • Poetry Poetry - Python dependency management and packaging made easy (python-poetry.org)
    "},{"location":"2021-2022-summer/package-managers/#actual-examples-of-real-world-projects-and-their-dependencies","title":"Actual Examples of Real-World Projects and their dependencies","text":"Foodbank package.json
    {\n    \"name\": \"foodbank\", // (1)\n    \"version\": \"0.1.0\",\n    \"private\": true,\n    \"browserslist\": [\n        \">0.3%\",\n        \"not ie 11\",\n        \"not dead\",\n        \"not op_mini all\"\n    ],\n    \"repository\": {\n        \"type\": \"git\",\n        \"url\": \"git+https://github.com/codersforcauses/foodbank.git\"\n    },\n    \"author\": \"Coders for Causes\",\n    \"license\": \"MIT\",\n    \"bugs\": {\n        \"url\": \"https://github.com/codersforcauses/foodbank/issues\"\n    },\n    \"homepage\": \"https://github.com/codersforcauses/foodbank#readme\",\n    \"scripts\": { // (2)\n        \"dev\": \"next dev\",\n        \"build\": \"next build\",\n        \"start\": \"next start\",\n        \"lint\": \"next lint\",\n        \"prepare\": \"husky install\"\n    },\n    \"dependencies\": { // (3)\n        \"@headlessui/react\": \"1.4.2\",\n        \"critters\": \"0.0.15\",\n        \"keen-slider\": \"6.0.5\",\n        \"next\": \"12.0.4\",\n        \"react\": \"17.0.2\",\n        \"react-dom\": \"17.0.2\",\n        \"react-hook-form\": \"7.20.5\"\n    },\n    \"devDependencies\": { // (4)\n        \"@types/react\": \"17.0.37\",\n        \"autoprefixer\": \"10.4.0\",\n        \"eslint\": \"7.29.0\",\n        \"eslint-config-next\": \"12.0.4\",\n        \"eslint-config-prettier\": \"8.3.0\",\n        \"eslint-plugin-jsx-a11y\": \"6.5.1\",\n        \"eslint-plugin-prettier\": \"4.0.0\",\n        \"husky\": \"7.0.4\",\n        \"postcss\": \"8.4.4\",\n        \"prettier\": \"2.5.0\",\n        \"tailwindcss\": \"2.2.19\",\n        \"typescript\": \"4.5.2\"\n    }\n}\n
    1. Package Headers and Meta Information (line 2-20)

      Contains some meta information about the project. Eg. used for publication in npmjs.org

    2. Scripts

      Alias of commands to run using the modules in the dependency

      yarn start // yarn [script-name]\n

      or

      npm run start // npm run [script-name]\n
    3. Dependencies

      Libraries that are used in the project

      To add a dependency, run

      yarn add formik // yarn add [library-name]\n

      or

      npm install formik // npm install [library-name]\n
    4. Dev-Dependencies

      Libraries that are used in the project on development environments Typically: linters, and testers

      yarn add -D prettier // yarn add -D [library-name]\n

      or

      npm install -D prettier // npm install -D [library-name]\n
    "},{"location":"2021-2022-summer/package-managers/#lockfiles","title":"Lockfiles","text":"

    It locks the dependencies and sub dependencies (dependency of dependency) of your application the last time it installed correctly.

    Files: - package-lock.json - Yarn-lock.json - Poetry.lock

    E.g. wais/yarn.lock at main \u00b7 codersforcauses/wais (github.com)

    "},{"location":"2021-2022-summer/package-managers/#when-to-install-globally","title":"When to install globally?","text":"

    Whenever installing package, it is recommended to install it for a specific project The only thing you should really install globally are CLI tools. Even then, you have npx

    yarn global add [dependency]\n
    or
    npm install \u2013g [dependency]\n

    Firebase CLI

    npm install -g firebase-tools\n
    "},{"location":"2021-2022-summer/package-managers/#demo-material-ui","title":"Demo - Material UI","text":"
    1. Create a react-app npx create-react-app mui-demo
    2. Move directory cd mui-demo
    3. Install react-spring yarn add @mui/material @mui/icons-material
    4. Start the app yarn start
    5. Show Bottom Navigation
      import * as React from 'react';\nimport BottomNavigation from '@mui/material/BottomNavigation';\nimport BottomNavigationAction from '@mui/material/BottomNavigationAction';\nimport FolderIcon from '@mui/icons-material/Folder';\nimport RestoreIcon from '@mui/icons-material/Restore';\nimport FavoriteIcon from '@mui/icons-material/Favorite';\nimport LocationOnIcon from '@mui/icons-material/LocationOn';\n\nexport default function LabelBottomNavigation() {\n  const [value, setValue] = React.useState('recents');\n\n  const handleChange = (event, newValue) => {\n    setValue(newValue);\n  };\n\n  return (\n    <BottomNavigation sx={{ width: 500 }} value={value} onChange={handleChange}>\n      <BottomNavigationAction\n        label=\"Recents\"\n        value=\"recents\"\n        icon={<RestoreIcon />}\n      />\n      <BottomNavigationAction\n        label=\"Favorites\"\n        value=\"favorites\"\n        icon={<FavoriteIcon />}\n      />\n      <BottomNavigationAction\n        label=\"Nearby\"\n        value=\"nearby\"\n        icon={<LocationOnIcon />}\n      />\n      <BottomNavigationAction label=\"Folder\" value=\"folder\" icon={<FolderIcon />} />\n    </BottomNavigation>\n  );\n}\n
    "},{"location":"2021-2022-summer/practical-software-engineering-practices/","title":"Practical Software Engineering Practices","text":"

    How software engineer works collaboratively!

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#how-do-software-engineers-work","title":"How do software engineers work?","text":"

    They use issue/ticket management system to track their work.

    Github Issues and Jira

    The examples are Github Issues and Jira.

    Listing of issues can be displayed in kanban boards.

    Kanban Boards

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#why-do-software-engineers-work-like-this","title":"Why do Software Engineers Work like this?","text":"Scrums

    One example of \"agile\" ways of working and it looks like this.

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#what-is-git","title":"What is Git?","text":"

    Git is a

    • version control system
    • tools for coordinating work for different changes
    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#main-parts-of-git","title":"Main Parts of Git","text":"

    Main Parts of git:

    • Change Node (commit node)
    • Branch

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#git-different-versions","title":"Git Different Versions","text":"Software Versions

    Nodes - Representation of a change (commits + merge)

    Main/Master: - Branch usually as production or deployed

    Development Branch - Branch used for development Used for compiling features for a release

    Feature Branch - Branch used for development for a particular issue

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#github-and-code-repositories","title":"GitHub and Code Repositories","text":"

    GitHub - Place to hold code repositories

    Repositories - Place where codes are stored with different versions

    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#interactive-workshop-time","title":"INTERACTIVE WORKSHOP TIME !!!!","text":"
    1. Do the following from codersforcauses/software-engineering-practices-demo: Demonstration of software engineering practices (github.com):
    2. Look at the GitHub issues
    3. Assign yourself an issue
    4. Clone repo with git clone https://github.com/codersforcauses/software-engineering-practices-demo-2021-summer.git
    5. Create a branch with the following format s{Issue Number}-{Issue Name}. git checkout -b s{Issue Number}-{Issue Name}
    6. Create the change to satisfy or complete the github issue
    7. Commit (package) the change git commit -m \"{insert message here}\" and push git push.
    8. Create a pull request and request for a reviewer from CFC peeps
    "},{"location":"2021-2022-summer/practical-software-engineering-practices/#other-resources","title":"Other Resources","text":"
    • Git and Github
    "},{"location":"2021-2022-summer/project-and-workshop-structure/","title":"Project and Workshop Structure","text":"

    A mission to empower the next-generation of software engineers and delivering value to the community!

    "},{"location":"2021-2022-summer/project-and-workshop-structure/#ways-of-working","title":"Ways of Working","text":"
    • (November 27 to February 24 excluding December 19 to January 4) = ~ 11 weeks for project
    • 2 meetups every week (1 online mid-week, 1 on Saturday)

    • Each Saturday meeting will have ~2-3 hour workshops. Some workshops will take the whole hour, while some workshops will take 15-30 minutes.

    • The other time allocated is for working on project with supervision
    • Most workshops will be introductory
    "},{"location":"2021-2022-summer/project-and-workshop-structure/#workshop-schedule","title":"Workshop Schedule","text":"

    The following are rough guideline to the workshop schedules. All workshops are optional, you can attend any of them even if you are not on the specific team dedicated to it (be mindful that there may be time conflicts if it is with the other team).

    Most Workshops are introductory

    They will usually cover the following idea:

    • why is it useful to learn it
    • what are the different aspects of it that you will need to learn

    You will still have to put in the effort to learn it thoroughly.

    Date Workshop Name Recommended Team to attend Duration Saturday, 27 November 2021 Introduction to CFC + Web Development Space All ~1 hour Wednesday, 1 December 2021 Introduction to Web Basics All ~1-1.5 hour Saturday, 4 December 2021 Practical Software Engineering Practices All ~1 hour Saturday, 4 December 2021 Introduction to Frontend Frameworks All ~45 minutes - 1 hour Saturday, 4 December 2021 Introduction to React Foodbank ~45 minutes - 1 hour Saturday, 4 December 2021 Introduction to Vue WAIS ~45 minutes - 1 hour Saturday, 11 December 2021 Introduction to Django WAIS ~1 - 1.5 hours Saturday, 11 December 2021 Introduction to Typescript Foodbank ~30 minutes Saturday, 18 December 2021 MVC Codebase Structure / Frontend-Backend Integration All ~1-1.5 hour Saturday, 18 December 2021 Typical Codebase Structure All ~30 minutes - 1 hour Saturday, 18 December 2021 Package Manager - JavaScript and Python All ~1 hour Saturday, 8 January 2022 Introduction to Docker All ~1 hour Saturday, 8 January 2022 Introduction to Unit Testing and CI/CD All ~1 hour Workshops after January 8, 2022

    The workshops right here are still being decided upon. If you have an idea for a workshop that you would like to attend, please let us know either on Discord or at Github.

    The one that are on consideration are:

    • Deployment on Heroku, and Vercel
    • Introduction to End-to-End Testing with Cypress
    • Gitkraken Workshop
    • Introduction to Prototyping with Figma
    • Introduction to Linux and Command-Line Scripting - Bash
    • Increase your productivity in VsCode
    • How to write good documentation
    • Honing your detective skills with Browser Developer Tools
    "},{"location":"2021-2022-summer/project-and-workshop-structure/#who-are-you","title":"Who are you?","text":"

    Before continuing further, answer the following:

    • What\u2019s your name?
    • What\u2019s your background?
    • Why you\u2019re here?
    Who are the Coders for Causes

    The Coders for Causes is an organisation that aims to empower the next-generation of software engineers while delivering value to the wider-community by helping charities and not-for-profit organisations.

    "},{"location":"2021-2022-summer/setup/","title":"Setup","text":"

    This contains everything you need to know about getting setup.

    "},{"location":"2021-2022-summer/setup/#coders-for-causes-project-team","title":"Coders for Causes Project Team","text":"

    The following access you will need to have when working on the project

    • Coders for Causes Official Project Organisation
      • This includes the project repositories and CFC related long-term materials
    • Coders for Causes Learning Organisation
      • This includes the templates for learning as well as the demo workshops
    • Discord Channel for Project and exclusive Workshops
    "},{"location":"2021-2022-summer/setup/#developer-tools","title":"Developer Tools","text":"

    These are the following tools that you need:

    • Code Editor: VS Code
    • Version Control: Git
    • Interpreter: Nodejs
    • Custom Package Manager: Yarn
    • Interpreter (for WAIS): Python
    • Containerisation (for WAIS): Docker
    Optional Tools

    These are tools that you may like to use, but are not required:

    • GUI for Git: Gitkraken / GitHub Desktop

    After these installation, seek at the OS-specific tools.

    "},{"location":"2021-2022-summer/setup/#windows","title":"Windows","text":"

    These are tools specifically for Windows:

    • Virtual Machine: Vbox
      • You need this if you have some trouble with windows
    Warning for Windows Users

    Legit, among all the OS, you will have the most frustrating time as a developer in windows (unless you're doing C#)

    Wanna have a better developer experience

    You have a couple of options:

    • Using WSL
    • Dual Booting
    • Virtual Machines

    The recommended OS to try is Ubuntu-based Linux. My personal favourite is PopOS.

    "},{"location":"2021-2022-summer/setup/#linux","title":"Linux","text":"

    These are installation specific to Linux:

    • Docker Post Installation Steps

      • Lots of users forget this documentation
      • This step is necessary if you intend to use the visual studio code docker extension
      • This will also allow you to run docker without the \"sudo\" command
    • Docker Compose Installation

      • Docker compose is not installed by default with Linux installations of Docker
      • Please follow this documentation
    • Node installation using Node Version Manager (NVM)

      • Installation steps can be found here
      • NVM is useful when dealing with multiple environments that require different versions of Node
      • It allows you to switch between different Node versions and environments easily
      • This tool is also available if you are using Windows Subsystem for Linux
    "},{"location":"2021-2022-summer/typical-codebase-structure/","title":"Typical Codebase Structure","text":"

    Codebase Jigsaw: How it all fits together!

    Info

    This presentation is only intended to be a brief overview of the typical codebase structure

    If you want more information about anything mentioned feel free to reach out to CFC committee and project helpers!

    "},{"location":"2021-2022-summer/typical-codebase-structure/#overview-and-importance","title":"Overview and Importance","text":"
    • Most codebase will follow almost the same pattern (if they change, it will only change with little quirks)
    • Structure helps every software engineer understand codebase and where to put it certain codes (better code readability = better collaboration = better profit!)
    Profit"},{"location":"2021-2022-summer/typical-codebase-structure/#frontend","title":"Frontend","text":"

    Example: About Us - Coders for Causes Website

    "},{"location":"2021-2022-summer/typical-codebase-structure/#different-folders-and-purpose","title":"Different Folders and Purpose","text":""},{"location":"2021-2022-summer/typical-codebase-structure/#components","title":"Components","text":"

    Components are individual parts/pieces of user interfaces

    "},{"location":"2021-2022-summer/typical-codebase-structure/#pages","title":"Pages","text":"

    Pages are the direct components that are related specific to a route or URL

    "},{"location":"2021-2022-summer/typical-codebase-structure/#public-assets","title":"Public / Assets","text":"

    Assets are usually elements that are referenced E.g. Images, Videos

    "},{"location":"2021-2022-summer/typical-codebase-structure/#utilities-helpers","title":"Utilities / Helpers","text":"

    Pieces of code that are used as utilities or helpers to other codes

    "},{"location":"2021-2022-summer/typical-codebase-structure/#tests","title":"Tests","text":"
    • Scripts that tests that code works
    • Usually E2E frontend
    "},{"location":"2021-2022-summer/typical-codebase-structure/#comparison-with-two-codebases","title":"Comparison with Two Codebases","text":"

    Slight difference, look at software documentation or ask other engineers

    "},{"location":"2021-2022-summer/typical-codebase-structure/#backend","title":"Backend","text":"Context - Role and Subject

    In these example, when I mean \"role\", I mean the general role of file. \"subject\" means the feature or group functionality

    "},{"location":"2021-2022-summer/typical-codebase-structure/#method-of-organisation","title":"Method of Organisation","text":""},{"location":"2021-2022-summer/typical-codebase-structure/#subject-oriented-driven-structure","title":"Subject-Oriented Driven Structure","text":"

    As it can be seen here, both different folders will have the same filenames based on its role. App grows, those files can itself become folders as well.

    Example: erdem/DRF-TDD-example: An example Django REST framework project for test driven development. (github.com)

    "},{"location":"2021-2022-summer/typical-codebase-structure/#role-oriented-driven-structure","title":"Role-Oriented Driven Structure","text":"

    As it can be seen here, both both different folders will have the same filenames based on its subject

    Example: our-lab-training/olt-backend: Our Lab Training - Feathers Backend (github.com)

    "},{"location":"2021-2022-summer/typical-codebase-structure/#different-folders-and-purpose_1","title":"Different Folders and Purpose","text":""},{"location":"2021-2022-summer/typical-codebase-structure/#models-database-connection","title":"Models / Database Connection","text":"

    Object-Relational Model (ORM). Links the database into your app into objects

    "},{"location":"2021-2022-summer/typical-codebase-structure/#routing","title":"Routing","text":"

    Determines the rules for the URL pattern

    "},{"location":"2021-2022-summer/typical-codebase-structure/#views","title":"Views","text":"
    • In REST API, Views are your main \u201cview\u201d of the API
    "},{"location":"2021-2022-summer/typical-codebase-structure/#tests_1","title":"Tests","text":"
    • Contains unit testing (+ possibly e2e testing)
    • Most common candidate for transitioning from file to a folder containing more files
    "},{"location":"2021-2022-summer/typical-codebase-structure/#other-resources","title":"Other Resources","text":"
    • Writing your first Django app, part 1 | Django documentation | Django (djangoproject.com)
    • File Structure \u2013 React (reactjs.org)
    • Best practice for Django project working directory structure - Stack Overflow
    "},{"location":"2021-winter/","title":"Coders for Causes 2021 Winter Workshops","text":"

    This project period there are two main projects:

    • Foodbank
    • WAIS

    If you have not before seen the existing progress, see this video.

    These two projects have their own corresponding technology stacks being used, hence will dictate the workshops that will be held.

    "},{"location":"2021-winter/#project-technology","title":"Project Technology","text":""},{"location":"2021-winter/#foodbank","title":"Foodbank","text":"

    Foodbank is mainly with frontend with React + TailwindCSS with Firebase and Notion CMS.

    "},{"location":"2021-winter/#wais","title":"WAIS","text":"

    WAIS is a full-stack application with Vue and Django. It uses Docker containerisation for both development (and production in the future).

    "},{"location":"2021-winter/#where-are-the-materials","title":"Where are the materials?","text":"

    This website has only been created prior to 2021/22 Summer workshops. However, you can find the videos in our Youtube channel, and workshops slides in google drive.

    "},{"location":"2022-2023-summer/","title":"Coders for Causes 2021/22 Summer Workshops","text":"

    This project period continues the two main projects from the winter of 2020 :

    • WADL
    • POOPS

    If you have not before seen the existing progress, see this video.

    These two projects have their own corresponding technology stacks being used, hence will dictate the workshops that will be held.

    "},{"location":"2022-2023-summer/#project-technology","title":"Project Technology","text":""},{"location":"2022-2023-summer/#poops","title":"POOPS","text":"

    POOPS is a web-app built the frontend with React + NextJS + TypeScript + TailwindCSS with Firebase and Notion CMS.

    "},{"location":"2022-2023-summer/#wadl","title":"WADL","text":"

    WADL is a full-stack application with Vue and Firebase. It uses Docker containerisation for both development (and production in the future).

    "},{"location":"2022-2023-summer/#workshop-recordings","title":"Workshop Recordings","text":"

    The workshop recordings will be held on our youtube channel.

    "},{"location":"2022-2023-summer/introduction-to-web-development/","title":"Introduction to Web Development Space","text":"

    Navigating the Deep Dark Space of Web Development

    This workshop covers a brief overview of the most common tools and technologies used in web development.

    "},{"location":"2022-2023-summer/introduction-to-web-development/#content","title":"Content","text":"
    • Introduction to Web Development Space
    • Content
    • What and Why Web Development?
      • What is web development?
      • Why Web Development ?
    • FAQs about Web Development
      • Why code websites, why not use drag and drops like Wordpress, WIX?
      • What is the best way to learn all these?
      • Why does CFC not do mobile development as much as web development?
      • If I already know a frontend framework, is it better to learn another frontend framework or to learn a backend framework?
    • Basics of Web and Limitation
      • Modern Frameworks
    • Server-side Applications (Backend)
      • How do devices communicate?
      • What do server applications do?
      • Databases
    • Others
      • Languages of the Web (the usual)
      • Hosting Stuff
      • CSS Frameworks
      • Developer Tools
      • TypeScript
      • Testing
      • Continuous Integration / Continuous Deployment
      • Virtualisation and Containerisation
      • Browsers
      • Firefox Developer Tools
      • Package Managers
      • Version Control
      • Linters and Formatters
      • Teamwork
      • Roadmaps
    • Word of Encouragement
    "},{"location":"2022-2023-summer/introduction-to-web-development/#what-and-why-web-development","title":"What and Why Web Development?","text":""},{"location":"2022-2023-summer/introduction-to-web-development/#what-is-web-development","title":"What is web development?","text":"
    • Websites development
    • Web applications (client-side and server-side) development
    "},{"location":"2022-2023-summer/introduction-to-web-development/#why-web-development","title":"Why Web Development ?","text":"
    • Accessibility and Portability
    • Career and On-demand in job market
    • Huge possibility to combine with other emerging technologies (e.g. IoT, Machine Learning) and industry (e.g. Health, Mining, O&G)
    Career in Web Development

    Source: Insights from Stack Overflow\u2019s 2016 survey of 50,000 developers

    \"Half of Developers are Web Developers\"

    "},{"location":"2022-2023-summer/introduction-to-web-development/#faqs-about-web-development","title":"FAQs about Web Development","text":""},{"location":"2022-2023-summer/introduction-to-web-development/#why-code-websites-why-not-use-drag-and-drops-like-wordpress-wix","title":"Why code websites, why not use drag and drops like Wordpress, WIX?","text":"
    • Content Management System (CMS)
    • Limitations on theme/template used
    • Difficult to extend
    • Cybersecurity
    More information

    CMS are one of the application of web development, but there are plenty more such as - internet of things, custom software for a particular industrial application (eg. using Machine Learning)

    CMS are usually limited to the template or plugin that you use. If those plugin don't exist, then it limits your productivity very much (difficulty to extend).

    CMS are usually built to cater for non-technical users. This means that thye become the subject of hackers. Think about a scenario where a hacker was able to find a vulnerability in WordPress, now every other WordPress site will be vulnerable.

    "},{"location":"2022-2023-summer/introduction-to-web-development/#what-is-the-best-way-to-learn-all-these","title":"What is the best way to learn all these?","text":"

    In summary, the best way to learn:

    • Do personal projects (inspiration + motivation)
    • Do team projects (get peer reviews and correct bad practices straight away)
    • Watch Online Courses (to figure out what is available)
    More Information

    To be told that you have to learn \"this, this, and that\" before you could do things is tiresome.

    Often times, we want to learn to be a developer so that we can create cool things like software where thousands of people can use the app. We don't tend to be a developer for the sake of us needing to watch endless videos on different things.

    "},{"location":"2022-2023-summer/introduction-to-web-development/#why-does-cfc-not-do-mobile-development-as-much-as-web-development","title":"Why does CFC not do mobile development as much as web development?","text":"
    • App stores has a developer cost
    • Easier to deal/teach web technologies
    • Accessibility (mobile, sensors, tablets, laptops and PCs)
    • Bigger open-source community
    "},{"location":"2022-2023-summer/introduction-to-web-development/#if-i-already-know-a-frontend-framework-is-it-better-to-learn-another-frontend-framework-or-to-learn-a-backend-framework","title":"If I already know a frontend framework, is it better to learn another frontend framework or to learn a backend framework?","text":"
    • It is better to learn a backend framework
    Reasoning

    You want to build skills that complement one another rather than be an alternative.

    It is much more valuable for you to learn a backend framework because that helps you build a functional app.

    "},{"location":"2022-2023-summer/introduction-to-web-development/#basics-of-web-and-limitation","title":"Basics of Web and Limitation","text":"HTML

    What is it?

    • Hypertext Markup Language
    • Describes the structure of a web page

    Limitation

    • Doesn\u2019t handle repeated content well
    • No variables or calculation
    HTML Syntax
    <!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Document</title>\n</head>\n<body>\n    Hello World!\n</body>\n</html>\n
    CSS

    What is it?

    • Cascading Style Sheets
    • Describes the presentation of a web page

    Limitation

    • Most css is quite similar (Handled by CSS Libraries)
    • Not very dynamic (Handled by CSS Frameworks)
    CSS Syntax
    body {\n    background-color: #f0f0f0;\n    font-family: sans-serif;\n}\n\n.container{\n    width: 80%;\n    margin: 0 auto;\n}\n
    JS

    What is it?

    • JavaScript
    • Used to program complex features on a web page

    Limitation

    • Has the capability to modify the user interface, but becomes really tedious to modify interface (more about this in another workshop)
    JS Syntax
    const bodySelector = document.querySelector('body');\nconst myFunction = () => {\n    bodySelector.innerHTML = 'Hello World 2!';\n    // Add a container class to space out\n    bodySelector.classList.add('container');\n}\nbodySelector.onclick = myFunction;\n
    "},{"location":"2022-2023-summer/introduction-to-web-development/#modern-frameworks","title":"Modern Frameworks","text":"
    • Websites can be much more\u2026 they can be web applications
    • \u201cApp\u201d in a website (client-side rendering)
    Modern Frameworks React.js
    • More mature and used more in industry
    Vue.js
    • Growing fast in popularity and use.

    General Information

    • Both are good to use and learn.
    • Knowledge is transferable between the two frameworks.
    Comparison between HTML and JSX

    Highlighted portions are starting chunk of distinct code.

    HTML
    <div class=\"row\">\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">devices</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Applications\n            </p>\n            <p class=\"mb-0\">\n            Build custom web and mobile applications to engage with your audience\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">web</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">Websites</p>\n            <p class=\"mb-0\">\n            Build new websites or optimise existing pages to improve online\n            visibility\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">storage</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Data Storage\n            </p>\n            <p class=\"mb-0\">\n            Design and create databases for efficient information storage and\n            retrieval\n            </p>\n        </div>\n        </div>\n    </div>\n    <div class=\"m-0 col-12 col-md-6 col-lg-3\">\n        <div class=\"text-center border-0 bg-transparent card\">\n        <div class=\"px-0 card-body\">\n            <i class=\"material-icons-sharp md-lg\">how_to_reg</i>\n            <p class=\"mt-4 font-weight-bold text-monospace text-larger\">\n            Consulting\n            </p>\n            <p class=\"mb-0\">\n            Empower your organisation through technical knowledge and advice\n            </p>\n        </div>\n        </div>\n    </div>\n</div>\n
    JSX
    import { memo } from 'react'\nimport { Row, Col, Card, CardBody } from 'reactstrap'\nimport services from 'data/services.json'\n\nconst Service = (props: {\nicon: string\ntitle: string\ndescription: string\n}) => (\n<Card className='text-center border-0 bg-transparent'>\n    <CardBody className='px-0'>\n    <i className='material-icons-sharp md-lg'>{props.icon}</i>\n    <p className='mt-4 font-weight-bold text-monospace text-larger'>\n        {props.title}\n    </p>\n    <p className='mb-0'>{props.description}</p>\n    </CardBody>\n</Card>\n)\n\nconst Services = () => (\n<Row>\n    {services.map(service => (\n    <Col\n        xs={12}\n        md={6}\n        lg={12 / services.length}\n        className='m-0'\n        key={service.title}\n    >\n        <Service {...service} />\n    </Col>\n    ))}\n</Row>\n)\n\nexport default memo(Services)\n
    "},{"location":"2022-2023-summer/introduction-to-web-development/#server-side-applications-backend","title":"Server-side Applications (Backend)","text":""},{"location":"2022-2023-summer/introduction-to-web-development/#how-do-devices-communicate","title":"How do devices communicate?","text":"
    • HTTP Request - Hypertext Transfer Protocol
    "},{"location":"2022-2023-summer/introduction-to-web-development/#what-do-server-applications-do","title":"What do server applications do?","text":"
    • Serve frontends (server-side rendering)
    • Web API (Application Programming Interface)
      • Serve data (usually from a database)
      • Process Request (Sending emails or SMS, Machine Learning)
    "},{"location":"2022-2023-summer/introduction-to-web-development/#databases","title":"Databases","text":"

    Place to store the data

    Mongodb

    Allows for database design to be modified without complex migration or data loss

    SQL

    Typically faster and better for large amounts of data or systems that need data consistency and reliability

    "},{"location":"2022-2023-summer/introduction-to-web-development/#others","title":"Others","text":""},{"location":"2022-2023-summer/introduction-to-web-development/#languages-of-the-web-the-usual","title":"Languages of the Web (the usual)","text":"
    • Python (Django, Flask)
    • JavaScript (Node.js, Express)
    • Ruby, Go, Rust, C
    "},{"location":"2022-2023-summer/introduction-to-web-development/#hosting-stuff","title":"Hosting Stuff","text":"

    Many ways - Own a server - Use a 3rd party platform

    "},{"location":"2022-2023-summer/introduction-to-web-development/#css-frameworks","title":"CSS Frameworks","text":"

    Frontend (JS)

    • Vue, React
    • Nuxt.js, Next.js

    Frontend (CSS)

    • MaterialUI, Vuetify
    • Bootstrap
    "},{"location":"2022-2023-summer/introduction-to-web-development/#developer-tools","title":"Developer Tools","text":""},{"location":"2022-2023-summer/introduction-to-web-development/#typescript","title":"TypeScript","text":"
    • Type checking is super useful for complex apps
    • Allows for way better javascript developer tooling
    • Can be annoying if you\u2019re new at it
    "},{"location":"2022-2023-summer/introduction-to-web-development/#testing","title":"Testing","text":"
    • Selenium, Cypress
      • End to end automated testing tools
    • Jest, Mocha, Pytest
      • Unit testing
    • Testing is vital to software projects
    "},{"location":"2022-2023-summer/introduction-to-web-development/#continuous-integration-continuous-deployment","title":"Continuous Integration / Continuous Deployment","text":"
    • Automated Testing
    • Event-driven scripts
    • E.g. Github Action, Bitbucket Pipelines
    "},{"location":"2022-2023-summer/introduction-to-web-development/#virtualisation-and-containerisation","title":"Virtualisation and Containerisation","text":"
    • Allows execution of services in a virtual environment
    • eg. Docker (Containerisation), Vagrant (Virtualisation)
    "},{"location":"2022-2023-summer/introduction-to-web-development/#browsers","title":"Browsers","text":"
    • Standard browsers
      • Google Chrome, Firefox, Edge, etc.
    • Backwards compatibility
      • Internet Explorer
    • Other
      • Mobile - Responsive
      • Screen readers - Accessibility
    "},{"location":"2022-2023-summer/introduction-to-web-development/#firefox-developer-tools","title":"Firefox Developer Tools","text":"
    • Page Inspector
      • Visualise page aspects
      • Grid layout
    • Web Console
      • console.log(\u201cHello World\u201d)
    • Responsive Design Mode
      • View from POV of different screen sizes such as mobile, tablets, etc.
    Some more tools
    • JavaScript Debugger
    • Network Monitor
    • Performance Tools
    • Rulers
    • Colour Pickers Learn more at: https://developer.mozilla.org/en-US/docs/Tools
    "},{"location":"2022-2023-summer/introduction-to-web-development/#package-managers","title":"Package Managers","text":"
    • Installs libraries that can be used
    • Also has code shortcuts (e.g. npm run start)

    (More about package.json and poetry.toml in the projects and Package Manager Workshop)

    "},{"location":"2022-2023-summer/introduction-to-web-development/#version-control","title":"Version Control","text":"
    • Essential for developer teams and complex software development
    • Git
    "},{"location":"2022-2023-summer/introduction-to-web-development/#linters-and-formatters","title":"Linters and Formatters","text":"
    • Makes code formatting consistent (following standard)
    • Useful with version controls to avoid pointless change

    eg.ESLint, Prettier

    "},{"location":"2022-2023-summer/introduction-to-web-development/#teamwork","title":"Teamwork","text":"
    • Many tools out there
    • Used to stop teams from stepping on each others toes
    • Github Issues + Pull Requests
    "},{"location":"2022-2023-summer/introduction-to-web-development/#roadmaps","title":"Roadmaps","text":"

    There's an open-source community that maintains a learning roadmap for developers. See https://roadmap.sh/

    Frontend Developer

    Backend Developer

    Dev-Ops

    "},{"location":"2022-2023-summer/introduction-to-web-development/#word-of-encouragement","title":"Word of Encouragement","text":"Encouragement from the Tech Lead

    \"I can admit that this journey of learning will be difficult, and can sometimes be overwhelming and demotivating. Please, if at any point of this project, you feel that you don't know enough, or you're feeling lost, please reach out! We are all in this journey together! Nobody is born talented, skills are honed with determination and willingness to learn.\"

    \"When I was a first year student entering on the CFC winter project, I didn't feel like I was good enough. I couldn't create a good looking interface, I didn't know how to use npm and all sorts of those things. I was just like many of you! if I gave up just because of all those things I didn't know, of all those self-doubts, then I wouldn't be here today. I admit that I was lucky because I was in CFC, I had connections where I can just ask questions instead of feeling lost of not knowing. So please do leverage that opportunity to reach out\"

    \"You being in this project not only gives you the opportunity to raise your talents, but you also unlock one of the biggest factor of the growth of your career, and that is the connections with your fellow software engineers.\"

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/","title":"MVC and MVVM: Software Architectural Patterns and Communication","text":"

    Don't pull all your eggs in one basket!

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#content","title":"Content","text":"
    • Software Architecture
      • Model-View-Controller (MVC)
      • Model-View-ViewModel (MVVM)
      • MVC or MVVM?
        • Pros and Cons of MVC
        • Pros and Cons of MVVM
    • Communication
      • Application Programming Interfaces (API)
      • REST: Representation State Transfer
        • Why REST APIs?
    • Demo
    • Resources
    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#software-architecture","title":"Software Architecture","text":"

    The main idea behind implementing software architectural patterns is to address the principle of the Separation of Concerns.

    The goal of Separation of Concerns is to establish a well-organised system, where each section has its own specific, designated role, allowing a project to be well managed and easier to grow.

    Software architecture is the high-level structure of a software system, comprising the overall design of the system, the relationships between its components, and the principles that govern its design and evolution. Architecture is important because it provides a blueprint for the design and implementation of a software system, and defines the ways in which the system can be modified and extended over time.

    The architecture of a system is critical to the success of the software as it sets the foundations of the project, providing the basis to ensure quality and maintainability of the system. A well-designed architecture can make it easier to develop and test the system, and can help to ensure that it is flexible, scalable, and reliable.

    By separating concerns, we can use different technologies for each section which will allow us to decide what stack to use during development. These choices can optimise the performance, development, and testing of the system.

    Beware! Poorly designed system inside!

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#model-view-controller-mvc","title":"Model-View-Controller (MVC)","text":"

    MVC, or Model-View-Controller, is a software architecture pattern that divides an application into three main components: the model, the view, and the controller.

    The model represents the data and the business logic of the application. It is responsible for managing the data and ensuring that it is up-to-date and accurate.

    The view is the user interface of the application. It is responsible for displaying the data to the user and providing a way for the user to interact with the application.

    The controller is the component that mediates between the model and the view. It is responsible for handling user input and updating the model and the view accordingly.

    In an MVC architecture, the model, view, and controller are all independent components that communicate with each other through well-defined interfaces. This allows for a clean separation of concerns, making it easier to develop and maintain the application.

    MVC

    Note

    The example above follows the linear implementation of the MVC pattern. You may see examples of the triangular implementation of MVC which is still a completely valid implementation. The only difference, in principle, is how each section communicates with one another.

    Each framework is different!!!

    While the idea is still the same, each framework implements each section of the MVC pattern slightly differently. Get to know your framework!

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#model-view-viewmodel-mvvm","title":"Model-View-ViewModel (MVVM)","text":"

    MVVM, or Model-View-ViewModel, is a software architecture pattern that is similar to MVC, but with some important differences. It is an architectural pattern used for building user interfaces in modern application development frameworks

    In an MVVM architecture, the View and the Controller from the MVC pattern are combined into a single component called the ViewModel. The ViewModel exposes data to the View, and translates user actions, such as button clicks, into commands that are sent to the Model to perform the appropriate business logic.

    The ViewModel and View are binding together in a process called data binding. Data binding is the process of establishing a connection between the user interface (the View) and its underlying data model (the ViewModel). This allows for direct communication between the two, meaning the UI updates as the data changes and actions are processed by the ViewModel as soon as they happen on the View.

    MVVM

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#mvc-or-mvvm","title":"MVC or MVVM?","text":"

    The right architecture has to be used for the right job, and with the right frameworks. And while MVC and MVVM work in similar ways, they each have their on advantages and disadvantages.

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#pros-and-cons-of-mvc","title":"Pros and Cons of MVC","text":"Pros Cons Clear separation of concerns between the application's data model, user interface, and control logic Difficult to implement in some programming languages and frameworks, especially those that do not have built-in support for the pattern Easier to develop and maintain large, complex applications, and allows different aspects of the application to be developed and tested independently Harder to develop modern user interfaces"},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#pros-and-cons-of-mvvm","title":"Pros and Cons of MVVM","text":"Pros Cons Provides a more flexible and powerful architecture for building GUI applications Can be more difficult to implement than MVC in some cases, and it may require a more complex and sophisticated development environment in order to take full advantage of its capabilities Data binding Data binding Data binding automatically synchronises the application's user interface and data model, which can make it easier to implement complex features and interactions Use of data binding can make it harder to debug and troubleshoot applications, since changes to the data model may not always be immediately visible in the user interface"},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#summary","title":"Summary","text":"

    There are plenty of architectural design patterns for all your software needs. Many are far too complicated and extensive to use in our case. MVC and MVVM are simple in design and easy to implement, making them among the most popular design patterns and perfect for developing web applications.

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#communication","title":"Communication","text":"

    Now that we're experts in designing systems, let's talk about how each part of the system actually communicates with each other.

    Disclaimer

    There are many more ways that systems communicate with each. However, we will only cover the basics required in web development.

    If you feel like learning more about the different software communication channels that exist, a good place to start is with sockets or buses!

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#application-programming-interfaces-api","title":"Application Programming Interfaces (API)","text":"

    An API is a mechanism that allows two software components to communicate with other using a set of definitions and protocols. It is a sort of middleman that enables different software programs to communicate and share data in a consistent and predictable manner.

    APIs can act as the \"Controller\" in MVC systems. The API will handle incoming requests from the frontend (the View), perform some logic which may include fetching data from the Model, then return responses to the client. They can also be used in MVVM architecture to allow communication between the ViewModels and the Models, as well as between any other services used.

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#rest-representation-state-transfer","title":"REST: Representation State Transfer","text":"

    RESTful APIs are application programming interfaces that follow the constraints of REST architectural style and allows for interaction with RESTful web services. You can read more about the details of REST, here.

    In terms of using RESTful APIs, there are some naming and implementing conventions used to accurately label the endpoint with what it does.

    CRUD to HTTP Verb Matching for JSON standard communications with REST-APIs

    CRUD stands for Create, Read, Update, and Delete. RESTful APIs use HTTP verbs to specify the CRUD operation an endpoint is performing.

    HTTP Verb CRUD Operation POST Create/Update GET Read PUT Update/Replace PATCH Update/Modify DELETE Delete

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#why-rest-apis","title":"Why REST APIs?","text":"

    There are many advantages to using RESTful APIs compared to other frameworks. These include:

    • Scalability
      • Are able to handle a large number of requests without affecting performance
      • Stateless nature allows each request to be handled independently
    • Flexibility
      • Support a wide range of data formats and content types
      • More resilient to change
    • Interoperability
      • Are able to be used by a wide range of clients
      • Allows developers to build applications that can integrate with a variety of different systems and services
    • Ease of use
      • Follow a simple, standardised protocol (HTTP, HTTPS)
      • To request a resource via a REST API, you just need to provide its URL
    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#demo","title":"Demo","text":"

    We will be doing a demo to build simple MVC and MVVM applications (if time persists).

    "},{"location":"2022-2023-summer/mvc-mvvm-architecture-and-communications/#resources","title":"Resources","text":"

    Keep the learning going!

    Find some useful resources below:

    • MVC Framework - Introduction
    • The Model-View-ViewModel Pattern
    • MVC vs MVVM \u2013 Difference Between Them
    • Red Hat: What is an API?
    • \"What is a REST API?\" by Jamie Juviler
    • Talk to an AI! (ChatGPT)
      • DISCLAIMER: May generate incorrect information
    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/","title":"Practical Software Engineering Workflow","text":"

    How software engineer GSD!

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#how-do-software-engineers-work","title":"How do software engineers work?","text":"

    They use issue/ticket management system to track their work.

    Github Issues and Jira

    The examples are Github Issues and Jira.

    Listing of issues can be displayed in kanban boards.

    Kanban Boards

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#why-do-software-engineers-work-like-this","title":"Why do Software Engineers Work like this?","text":"Scrums

    One example of \"agile\" ways of working and it looks like this.

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#what-is-git","title":"What is Git?","text":"

    Git is a

    • version control system
    • tools for coordinating work for different changes
    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#main-parts-of-git","title":"Main Parts of Git","text":"

    Main Parts of git:

    • Change Node (commit node)
    • Branch

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#git-different-versions","title":"Git Different Versions","text":"Software Versions

    Nodes - Representation of a change (commits + merge)

    Main/Master: - Branch usually as production or deployed

    Development Branch - Branch used for development Used for compiling features for a release

    Feature Branch - Branch used for development for a particular issue

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#github-and-code-repositories","title":"GitHub and Code Repositories","text":"

    GitHub - Place to hold code repositories

    Repositories - Place where codes are stored with different versions

    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#interactive-workshop-time","title":"INTERACTIVE WORKSHOP TIME !!!!","text":"
    1. Do the following from codersforcauses/software-engineering-practices-demo: Demonstration of software engineering practices (github.com):
    2. Look at the GitHub issues
    3. Assign yourself an issue
    4. Clone repo with git clone https://github.com/codersforcauses/software-engineering-practices-demo-2022-summer.git
    5. Create a branch with the following format s{Issue Number}-{Issue Name}. git checkout -b {Issue Number}-{Issue Name}
    6. Create the change to satisfy or complete the github issue
    7. Commit (package) the change git commit -m \"{insert message here}\" and push git push.
    8. Create a pull request and request for a reviewer from CFC peeps
    "},{"location":"2022-2023-summer/practical-software-engineering-workflow/#other-resources","title":"Other Resources","text":"
    • Git and Github
    "},{"location":"2022-2023-summer/typical-codebase-structure/","title":"Typical Codebase Structure","text":"

    Codebase Jigsaw: How it all fits together!

    Info

    This presentation is only intended to be a brief overview of the typical codebase structure

    If you want more information about anything mentioned feel free to reach out to CFC committee and project helpers!

    "},{"location":"2022-2023-summer/typical-codebase-structure/#overview-and-importance","title":"Overview and Importance","text":"
    • Most codebase will follow almost the same pattern (if they change, it will only change with little quirks)
    • Structure helps every software engineer understand codebase and where to put it certain codes (better code readability = better collaboration = better profit!)
    Profit"},{"location":"2022-2023-summer/typical-codebase-structure/#frontend","title":"Frontend","text":"

    Example: About Us - Coders for Causes Website

    "},{"location":"2022-2023-summer/typical-codebase-structure/#different-folders-and-purpose","title":"Different Folders and Purpose","text":""},{"location":"2022-2023-summer/typical-codebase-structure/#components","title":"Components","text":"

    Components are individual parts/pieces of user interfaces

    "},{"location":"2022-2023-summer/typical-codebase-structure/#pages","title":"Pages","text":"

    Pages are the direct components that are related specific to a route or URL

    "},{"location":"2022-2023-summer/typical-codebase-structure/#public-assets","title":"Public / Assets","text":"

    Assets are usually elements that are referenced E.g. Images, Videos

    "},{"location":"2022-2023-summer/typical-codebase-structure/#utilities-helpers","title":"Utilities / Helpers","text":"

    Pieces of code that are used as utilities or helpers to other codes

    "},{"location":"2022-2023-summer/typical-codebase-structure/#tests","title":"Tests","text":"
    • Scripts that tests that code works
    • Usually E2E frontend
    "},{"location":"2022-2023-summer/typical-codebase-structure/#comparison-with-two-codebases","title":"Comparison with Two Codebases","text":"

    Slight difference, look at software documentation or ask other engineers

    "},{"location":"2022-2023-summer/typical-codebase-structure/#backend","title":"Backend","text":"Context - Role and Subject

    In these example, when I mean \"role\", I mean the general role of file. \"subject\" means the feature or group functionality

    "},{"location":"2022-2023-summer/typical-codebase-structure/#method-of-organisation","title":"Method of Organisation","text":""},{"location":"2022-2023-summer/typical-codebase-structure/#subject-oriented-driven-structure","title":"Subject-Oriented Driven Structure","text":"

    As it can be seen here, both different folders will have the same filenames based on its role. App grows, those files can itself become folders as well.

    Example: erdem/DRF-TDD-example: An example Django REST framework project for test driven development. (github.com)

    "},{"location":"2022-2023-summer/typical-codebase-structure/#role-oriented-driven-structure","title":"Role-Oriented Driven Structure","text":"

    As it can be seen here, both both different folders will have the same filenames based on its subject

    Example: our-lab-training/olt-backend: Our Lab Training - Feathers Backend (github.com)

    "},{"location":"2022-2023-summer/typical-codebase-structure/#different-folders-and-purpose_1","title":"Different Folders and Purpose","text":""},{"location":"2022-2023-summer/typical-codebase-structure/#models-database-connection","title":"Models / Database Connection","text":"

    Object-Relational Model (ORM). Links the database into your app into objects

    "},{"location":"2022-2023-summer/typical-codebase-structure/#migrations","title":"Migrations","text":"
    • Stores changes to be applied to our database
    "},{"location":"2022-2023-summer/typical-codebase-structure/#serializers","title":"Serializers","text":"
    • Specifies how your data are formatted across requests

    )

    "},{"location":"2022-2023-summer/typical-codebase-structure/#views","title":"Views","text":"
    • In REST API, Views are your main \u201cview\u201d of the API
    • Handles your business logic
    "},{"location":"2022-2023-summer/typical-codebase-structure/#urls","title":"URLs","text":"
    • Used for routing and determining the rules for the URL pattern.
    "},{"location":"2022-2023-summer/typical-codebase-structure/#tests_1","title":"Tests","text":"
    • Contains unit testing (+ possibly e2e testing)
    • Most common candidate for transitioning from file to a folder containing more files
    "},{"location":"2022-2023-summer/typical-codebase-structure/#other-resources","title":"Other Resources","text":"
    • Writing your first Django app, part 1 | Django documentation | Django (djangoproject.com)
    • File Structure \u2013 React (reactjs.org)
    • Best practice for Django project working directory structure - Stack Overflow
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/","title":"Welcome to the Djangol!","text":"

    Welcome to the (Django)l !: Introduction to Backend Programming with Django

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#prerequisites-to-this-workshop","title":"Prerequisites to this Workshop","text":"

    You need the following installed:

    • Python3
    • Docker
    • Git

    The starting repo for this workshop: https://github.com/CodersforLearning/django-csf

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#what-you-will-be-building-as-part-of-this-workshop","title":"What you will be building as part of this workshop?","text":"

    You will be building a backend for an event management system. Below is the schematics

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#what-are-apis-and-rest-apis","title":"What are APIs and REST-APIs?","text":"

    Application Programming Interface

    Analogy

    Who interacts with the user interface? - the user Who interacts with the application programming interface ? - the application program (eg. the browser)

    Representational State Transfer Application Programming Interface

    • backend architectural pattern that follows the GET/POST/PUT/PATCH/DELETE

    • Can be represented in Swagger/ Open API specification

    Swagger/ Open API specification

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#what-is-django","title":"What is Django?","text":"

    Django

    • Python web framework for creating server-side application

    Follows MVC:

    • Model - database
    • View \u2013 Interface (API or User Interface)
    • Controller \u2013 URLs + routes

    See Documentation

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#what-is-django-rest-framework-drf","title":"What is Django REST Framework (DRF)?","text":"
    • library for creating REST-API
    • just makes it easier develop REST-API

    In:

    • Authentication + Permission
    • Generic API Views
    • Serialisers (payload validation and format)

    See Documentation

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#interactive-workshop-time","title":"Interactive Workshop Time!!!","text":"

    Firstly, open your IDE (VSCode) and open the terminal.

    1. Clone the repo: git clone https://github.com/CodersforLearning/django-csf.git
    2. Go to the directory: cd django-csf
    3. Run the setup script: ./setup.sh
    What does the setup script do?
    #!/bin/bash\n\n# Create a Python virtual environment\npython3 -m venv venv\n\n# Activate Python environment\nsource venv/bin/activate\n\n# Install Django\npip3 install Django\n\n# Bootstraps the django codebase\ndjango-admin startproject csfevents\n\n# As per https://www.django-rest-framework.org/#installation\npip3 install djangorestframework\npip3 install markdown       # Markdown support for the browsable API.\npip3 install django-filter  # Filtering support\npip3 install pytz           # Timezone support\n\n# Freeze the requirements\ncd csfevents\npip3 freeze > requirements.txt\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#initial-files","title":"Initial files","text":"
    • manage.py - the entrypoint of the Django application
    • csfevents - the main Django application
    • csfevents/settings.py - the configuration file of the Django application
    • csfevents/urls.py - the URL routes of the Django application
    • csfevents/wsgi.py and csfevents/asgi.py - used as the script to run production django application
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#lets-start-the-django-application","title":"Let's start the Django application","text":"
    1. Perform the initial migration: python3 manage.py migrate. Notice that when you run this command, it will create a db.sqlite3 file.
    2. Run the Django application: python3 manage.py runserver
    3. Check out the Django application: http://localhost:8000
    4. Check out the Django admin: http://localhost:8000/admin
    5. Create a superuser: python3 manage.py createsuperuser. Login and look around the Django admin.
    Additional info

    Django ships default \"django apps\" defined settings.py file. You can see the list of apps in the INSTALLED_APPS variable.

    Django apps are plugins that can be used to extend the functionality of the Django application. It's the core method of developing with this backend framework.

    For the db.sqlite3 file, it's the default database that Django uses. You can change this to other databases like MySQL, PostgreSQL, etc.

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#lets-create-our-first-django-app-event","title":"Let's create our first Django app: event","text":"

    Run this command python3 manage.py startapp event.

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#what-did-this-command-do","title":"What did this command do?","text":"

    Initial files that it created:

    • event/admin.py - the admin interface
    • event/apps.py - the configuration
    • event/models.py - the database schema
    • event/tests.py - the test cases
    • event/views.py - the views

    Some files you want to create later are:

    • event/serializers.py - the serializers
    • event/urls.py - the URL routes
    • event/permissions.py - the permissions
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#creation-of-the-database-schema","title":"Creation of the database schema","text":"Quick Reference: ERD WIP Answer
    class Event(models.Model):\n    # UUID id\n    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)\n    name = models.CharField(max_length=100)\n    date = models.DateField()\n\n    organizer = models.ForeignKey(\n        User, on_delete=models.SET_NULL, null=True, blank=True\n    )\n\n    def __str__(self):\n        return self.name\n

    After creating this, you'll need to add it in the INSTALLED_APPS variable in the settings.py file.

    Then run python3 manage.py makemigrations and python3 manage.py migrate.

    What did these commands do?

    makemigrations - creates the migration files These are scripts that defines how the database schema changed.

    migrate - applies the migration files to the database Similar to how we performed our initial migration

    When you have created that, check out db.sqlite3 and you'll see that there's a new table called event_event.

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#creation-of-the-admin-interface","title":"Creation of the admin interface","text":"WIP Answer
    from django.contrib import admin\nfrom .models import Event\n\nadmin.site.register(Event)\n

    Now visit the admin interface and you'll see the Event model there.

    A cooler example
    @admin.register(Event)\nclass EventAdmin(admin.ModelAdmin):\n    list_display = (\"name\", \"date\", \"organizer\")\n    list_filter = (\"organizer\",)\n    search_fields = (\"name\",)\n    ordering = (\"date\",)\n    date_hierarchy = \"date\"\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#do-the-same-thing-again-for-attendance","title":"Do the same thing again for Attendance","text":"Quick Reference: ERD WIP Answer
    # models.py\nclass Attendance(models.Model):\n    user = models.ForeignKey(User, on_delete=models.CASCADE)\n    event = models.ForeignKey(\n        Event, on_delete=models.CASCADE, related_name=\"attendances\"\n    )\n    # String field with only the valid choices \"going\", \"maybe\", \"not_going\"\n    status = models.CharField(\n        max_length=10,\n        choices=[(\"Going\", \"going\"), (\"Maybe\", \"maybe\"), (\"Not Going\", \"not_going\")],\n    )\n\n    def __str__(self):\n        return f\"Event '{self.event.name}' - Attendance '{self.user.username}'\"\n\n# admin.py\n@admin.register(Attendance)\nclass AttendanceAdmin(admin.ModelAdmin):\n    list_display = (\"user\", \"event\", \"status\")\n    list_filter = (\"user\", \"event\", \"status\")\n    search_fields = (\"user\", \"event\", \"status\")\n    ordering = (\"user\", \"event\", \"status\")\n    date_hierarchy = \"event__date\"\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#creation-views-the-interface-in-api","title":"Creation Views: the Interface in API","text":""},{"location":"2023-winter/introduction-to-backend-development-with-django/#serializerspy","title":"serializers.py","text":"

    Serialisers are a way to convert Python models to JSON, XML or any other format you wish.

    WIP Answer
    # serializers.py\nclass EventSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = Event\n        fields = (\"id\", \"name\", \"date\", \"organizer\")\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#viewspy-and-urlspy","title":"views.py and urls.py","text":"

    Here's our goal:

    // Class based - programming\nGET events in the system - /events\nPOST create events - /events\nPUT/PATCH update events - /events/<id>\nDELETE delete events - /events/<id>\n\nSpecial actions\nPOST Change attendee status to an event - /events/<id>/change_attendee_status\n

    Firstly, we need to set the urls.py to import the views from event/views.py.

    # urls.py\nfrom django.contrib import admin\nfrom django.urls import path, include\n\nurlpatterns = [\n    path(\"admin/\", admin.site.urls),\n    path(\"api/events/\", include(\"event.urls\")) # --HERE--\n]\n

    There's 2 main ways to create views

    • Functional
    • Class-based
    Class-based Views

    This is the easiest way - full of magic. If you need flexibility, you can override the methods.

    # event/views.py\nclass EventViewSet(viewsets.ModelViewSet):\n    queryset = Event.objects.all()\n    serializer_class = EventSerializer\n\n    def perform_create(self, serializer):\n        # Set whoever is creating the event as the organizer:\n        serializer.save(organizer=self.request.user)\n\n    # Note: This is a way to override the default methods\n    def destroy(self, request, *args, **kwargs):\n        return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)\n\n# event/urls.py\nrouter = DefaultRouter()\nrouter.register(r\"\", EventViewSet, basename=\"events\")\n\nurlpatterns = [\n    path(\"\", include(router.urls)),\n]\n

    Important to note that the basename is used to generate the URL name. In this case, it will be events-list and events-detail. (you will need this automated testing)

    Functional Views

    This is the more flexible way. This is currently the way CSF does it. Example

    # event/views.py\n@api_view([\"GET\"])\ndef event_list(request):\n    events = Event.objects.all()\n    serializer = EventSerializer(events, many=True)\n    return Response(serializer.data)\n\n@api_view([\"GET\"])\ndef event_detail(request, pk):\n    event = get_object_or_404(Event, pk=pk)\n    serializer = EventSerializer(event)\n    return Response(serializer.data)\n\n@api_view([\"POST\"])\ndef event_create(request):\n    # Set whoever is creating the event as the organizer:\n    serializer = EventSerializer(data=request.data)\n    if serializer.is_valid():\n        serializer.save(organizer=request.user)\n        return Response(serializer.data, status=status.HTTP_201_CREATED)\n    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n\n@api_view([\"PUT\"])\ndef event_update(request, pk):\n    event = get_object_or_404(Event, pk=pk)\n    serializer = EventSerializer(event, data=request.data)\n    if serializer.is_valid():\n        serializer.save()\n        return Response(serializer.data)\n    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n\n@api_view([\"DELETE\"])\ndef event_delete(request, pk):\n    return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)\n\n# urls.py\nurlpatterns = [\n    path(\"\", views.event_list),\n    path(\"<int:pk>/\", views.event_detail),\n    path(\"create/\", views.event_create),\n    path(\"<int:pk>/update/\", views.event_update),\n    path(\"<int:pk>/delete/\", views.event_delete),\n]\n
    Reuse Same Path with different HTTP Methods
    @api_view([\"GET\", \"POST\"])\ndef event_list(request):\n    if request.method == \"GET\":\n        queryset = Event.objects.all()\n        serializer = EventSerializer(queryset, many=True)\n        return Response(serializer.data)\n    elif request.method == \"POST\":\n        serializer = EventSerializer(data=request.data)\n        if serializer.is_valid():\n            serializer.save()\n            return Response(serializer.data, status=201)\n        return Response(serializer.errors, status=400)\n\n@api_view([\"GET\", \"PUT\", \"PATCH\", \"DELETE\"])\ndef event_detail(request, pk):\n    try:\n        event = Event.objects.get(pk=pk)\n    except Event.DoesNotExist:\n        return Response(status=404)\n\n    if request.method == \"GET\":\n        serializer = EventSerializer(event)\n        return Response(serializer.data)\n    elif request.method in [\"PUT\", \"PATCH\"]:\n        serializer = EventSerializer(event, data=request.data)\n        if serializer.is_valid():\n            serializer.save()\n            return Response(serializer.data)\n        return Response(serializer.errors, status=400)\n    elif request.method == \"DELETE\":\n        event.delete()\n        return Response(status=204)\n
    Another Example Class-based Views

    This is the easiest way - full of magic. If you need flexibility, you can override the methods.

    # views.py\nclass EventViewSet(viewsets.ModelViewSet):\n    queryset = Event.objects.all()\n    serializer_class = EventSerializer\n\n    def perform_destroy(self, instance):\n        if not instance.is_public:  # Assuming `is_public` is a boolean field in the `Event` model\n            raise serializers.ValidationError(\"Cannot delete a non-public event.\")\n        super().perform_destroy(instance)\n

    After that long discussion, let's create the views and play around.

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#going-back-to-serializer-for-organizer","title":"Going back to Serializer for Organizer","text":"
    + class UserSerializer(serializers.ModelSerializer):\n+     # read only serializer\n+     class Meta:\n+         model = User\n+         fields = (\"id\", \"username\", \"email\")\n\n\nclass EventSerializer(serializers.ModelSerializer):\n+    organizer = UserSerializer(read_only=True)\n\n    class Meta:\n        model = Event\n        fields = (\"id\", \"name\", \"date\", \"organizer\")\n

    What about if we also want to include attendees?

    + class AttendanceSerializer(serializers.ModelSerializer):\n+     user = UserSerializer(read_only=True)\n+ \n+     class Meta:\n+         model = Attendance\n+         fields = (\"user\", \"status\")\n\n\nclass EventSerializerWithAttendees(serializers.ModelSerializer):\n    organizer = UserSerializer(read_only=True)\n+    attendances = AttendanceSerializer(many=True, read_only=True)\n\n    class Meta:\n        model = Event\n-       fields = (\"id\", \"name\", \"date\", \"organizer\")\n+       fields = (\"id\", \"name\", \"date\", \"organizer\", \"attendances\")\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#bonus-filters-and-search-will-not-be-covered-in-this-workshop","title":"Bonus: Filters and Search (Will not be covered in this workshop)","text":"

    https://www.django-rest-framework.org/api-guide/filtering/

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#eventsidchange_attendee_status","title":"/events/<id>/change_attendee_status/","text":"

    Docs: - Viewset Actions

    eg. /events/1/change_attendee_status/ Payload body looks like

    {\n    \"status\": \"Going\"\n}\n

    # serializers.py\nclass AttendanceChangeStatusSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = Attendance\n        fields = (\"status\")\n\n# views.py\nclass EventViewSet(viewsets.ModelViewSet):\n    ...\n    # Attendance\n    @action(detail=True, methods=[\"post\"])\n    def change_attendee_status(self, request, pk=None):\n        event = self.get_object()\n        serializer = AttendanceChangeStatusSerializer(data=request.data)\n        serializer.is_valid(raise_exception=True)\n\n        user = request.user\n        status = serializer.validated_data[\"status\"]\n        Attendance.objects.update_or_create(\n            user=user, event=event, defaults={\"status\": status}\n        )\n        return Response(status=status.HTTP_200_OK)\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#automated-testing","title":"Automated Testing","text":"

    https://www.django-rest-framework.org/api-guide/testing/

    from rest_framework.test import APITestCase\nfrom django.contrib.auth.models import User\nfrom event.models import Event\n\n# Test to test all the HTTP methods of `EventViewSet`\nclass EventTest(APITestCase):\n    def setUp(self):\n        # Create a user\n        self.user = User.objects.create_user(\n            username=\"test_user\", email=\"test@test.com\", password=\"test_password\"\n        )\n\n        # Create an event\n        self.event = Event.objects.create(\n            name=\"test_event\", date=\"2021-01-01\", organizer=self.user\n        )\n\n    def test_get(self):\n        # Test GET method\n        url = reverse(\"events-list\")\n        response = self.client.get(url)\n        self.assertEqual(response.status_code, 200)\n        self.assertEqual(response.data[0][\"name\"], \"test_event\")\n        self.assertEqual(response.data[0][\"date\"], \"2021-01-01\")\n        self.assertEqual(response.data[0][\"organizer\"][\"username\"], \"test_user\")\n\n    def test_post(self):\n        # Test POST method\n        self.client.login(username=\"test_user\", password=\"test_password\")\n        url = reverse(\"events-list\")\n        response = self.client.post(url, {\"name\": \"test_event2\", \"date\": \"2021-01-02\"})\n        self.assertEqual(response.status_code, 201)\n\n        event_data = response.data\n        self.assertEqual(event_data[\"name\"], \"test_event2\")\n        self.assertEqual(event_data[\"date\"], \"2021-01-02\")\n        self.assertEqual(event_data[\"organizer\"][\"username\"], \"test_user\")\n\n        # Make sure the event by checking the database\n        event = Event.objects.get(name=\"test_event2\")\n        self.assertEqual(str(event.id), event_data[\"id\"])\n    # ... All other methods are left to the reader to implement\n

    To run this test, run python manage.py test

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#authentication-and-authorization","title":"Authentication and Authorization","text":"

    What if we only want the PUT/PATCH/DELETE methods to be accessible by the organizer?

    Docs: - Authentication https://www.django-rest-framework.org/api-guide/authentication/ - Authorization/Permissions https://www.django-rest-framework.org/api-guide/permissions/

    # permissions.py\nfrom rest_framework import permissions\n\n# The organizer is the only one allowed to update or delete an event.\nclass IsOrganizerOrReadOnly(permissions.BasePermission):\n    def has_object_permission(self, request, view, obj):\n        # Read permissions are allowed to any request,\n        # so we'll always allow GET, HEAD or OPTIONS POST.\n        if request.method in [permissions.SAFE_METHODS, 'POST']:\n            return True\n\n        # Write permissions are only allowed to the organiser of the event.\n        return obj.organizer == request.user\n\n# views.py\nclass EventViewSet(viewsets.ModelViewSet):\n    ...\n    permission_classes = [IsOrganizerOrReadOnly]\n    ...\n
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#tdd-test-driven-development-with-multiple-accounts","title":"TDD: Test-Driven Development With Multiple Accounts","text":"

    This is a perfect showcase how it's very difficult to manage manually testing with multiple accounts.

    class EventTest(APITestCase):\n    ...\n    def test_not_organizer_cannot_modify(self):\n        # Test that a user who is not the organizer cannot modify the event\n        # Create another user\n        self.user2 = User.objects.create_user(\n            username=\"test_user2\", email=\"test2@test.com\", password=\"test_password\"\n        )\n        self.client.login(username=\"test_user2\", password=\"test_password\")\n        url = reverse(\"events-detail\", args=[self.event.id])\n        response = self.client.put(url, {\"name\": \"test_event2\", \"date\": \"2021-01-02\"})\n        self.assertEqual(response.status_code, 403)\n
    How to manually test this?
    • Login as the organiser
    • Create an event
    • Create a new user
    • Login as the new user
    • Try to modify the event
    • Check that it returns a 403 Forbidden
    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#extra-reading-jwt-authentication","title":"Extra-Reading - JWT Authentication","text":"

    Summary of Django Simple JWT

    The only key bit to know is

    install pip install djangorestframework-simplejwt

    in settings.py

    REST_FRAMEWORK = {\n    ...\n    'DEFAULT_AUTHENTICATION_CLASSES': (\n        ...\n        'rest_framework_simplejwt.authentication.JWTAuthentication',\n    )\n    ...\n}\n

    in urls.py

    from rest_framework_simplejwt.views import (\n    TokenObtainPairView,\n    TokenRefreshView,\n)\n\nurlpatterns = [\n    ...\n    path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'), # Login\n    path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), # Refresh tokens\n    ...\n]\n

    If you login via /api/token , you will send something like this

    {\n    \"username\":\"test_user\",\n    \"password\":\"test_password\"\n}\n

    you're going to get something like this back

    {\n  \"access\":\"eyJh...\",\n  \"refresh\":\"eyJhb...\"\n}\n

    And if you are using an authenticated endpoint, you need to add the Authorization header with the token. \"Authorization: Bearer eyJhbEXAMPLEOFJWTOKEN...\"

    "},{"location":"2023-winter/introduction-to-backend-development-with-django/#bonus-sending-emails","title":"Bonus\" Sending Emails","text":"

    Run docker-compose up to start the mail server.

    Your mail server will have this UI at http://localhost:8025/. It communicates via SMTP on port 1025.

    Add these in your settings.py

    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'\nEMAIL_HOST = 'localhost'\nEMAIL_PORT = 1025\nEMAIL_HOST_USER = ''\nEMAIL_HOST_PASSWORD = ''\nEMAIL_USE_TLS = False\n\nEMAIL_ADDRESS_FROM = 'email-tester@test.com;\n

    Where are these values coming from?

    If you check the docker-compose.yml, you will understand that we are just configuring the values to send via SMTP to the mail server.

    In actual production services, you will change this to your actual SMTP server like AWS SES, Sendgrid, Mailgun, etc.

    New file called utils.py

    from django.core.mail import send_mail\nfrom django.conf import settings\n\ndef send_email(subject, message, recipient_list):\n    send_mail(\n        subject=subject,\n        message=message,\n        from_email=settings.EMAIL_ADDRESS_FROM,\n        recipient_list=recipient_list,\n        fail_silently=False,\n    )\n

    Now let's change it so that when a new event is created, an email is sent to the organizer.

    # views.py\nfrom event.utils import send_email\n\nclass EventViewSet(viewsets.ModelViewSet):\n    ...\n    def perform_create(self, serializer):\n        # Set whoever is creating the event as the organizer:\n        serializer.save(organizer=self.request.user)\n        send_email(\n            subject=\"New event created\",\n            message=\"A new event has been created\",\n            recipient_list=[self.request.user.email],\n        )\n
    "},{"location":"2024-winter/introduction-to-docker/","title":"Introduction to Docker","text":""},{"location":"2024-winter/introduction-to-docker/#prerequisites","title":"Prerequisites","text":"

    You need the following installed:

    • Git
    • Node.js
    • Docker
    • VSCode (highly recommended)

    The starting repo for this workshop: https://github.com/codersforcauses/docker-workshop

    "},{"location":"2024-winter/introduction-to-docker/#what-you-will-be-building-as-part-of-this-workshop","title":"What you will be building as part of this workshop?","text":"

    CFC wants to make an app for accepting coffee orders. You will be creating a Dockerfile for CFC's (totally real) new and upcoming rebrand: Coders for Coffee \ud83d\udc33. The architecture is a simple frontend and backend both made in TypeScript. Below is a diagram of it:

    "},{"location":"2024-winter/introduction-to-docker/#important-information","title":"Important information","text":"

    This workshop relies on a certain understanding of terminal commands and a bit of familiarity with Node.js projects. If you're not familiar with these, don't worry! I'll be explaining everything as we go along. If you have any questions, feel free to ask.

    "},{"location":"2024-winter/introduction-to-docker/#what-is-docker","title":"What is Docker?","text":"

    Docker is a platform for developing, shipping, and running applications using containerization. It allows you to package an application and its dependencies into a container that can run on any machine. This makes it easy to deploy applications in a consistent and reproducible way. Simply put, it's like a way of running mini virtual machines inside your computer.

    "},{"location":"2024-winter/introduction-to-docker/#why-use-docker","title":"Why use Docker?","text":"
    • Consistency: Docker containers are isolated from the host system and other containers, ensuring that the application runs the same way everywhere.
    • Portability: Containers can be run on any machine that has Docker installed, making it easy to move applications between environments.
    • Efficiency: Containers are lightweight and share the host system's resources, making them more efficient than virtual machines.
    • Scalability: Docker makes it easy to scale applications by running multiple containers on the same host or across multiple hosts.
    • Security: Containers are isolated from each other and the host system, providing an additional layer of security.
    • DevOps: Docker is a key tool in the DevOps toolchain, enabling developers to build, test, and deploy applications more easily. Imagine a software job where instead of writing software for end-users, you write software to make developers' lives easier!
    "},{"location":"2024-winter/introduction-to-docker/#definitions","title":"Definitions","text":"
    • Dockerfile \ud83d\udcdc: A text file that contains instructions for building a Docker image. It specifies the base image, dependencies, environment variables, and commands to run when the container starts. Think like a recipe for baking a cake.
    • Image \ud83d\udcc0: A read-only template with instructions for creating a Docker container. It contains the application code, runtime, libraries, environment variables, and configuration files. Think like a CD with music on it.
    • Container \u25b6\ufe0f: An instance of an image that can be run as a process on the host machine. It is isolated from other containers and the host system. Think like a CD in a CD player.
    "},{"location":"2024-winter/introduction-to-docker/#how-do-i-use-docker","title":"How do I use Docker?","text":"

    This is a high-level overview of how Docker works:

    In action, you'll only need to know a few commands to get started:

    1. docker pull: Pull an image from a registry (like Docker Hub).
    2. docker run <image>: Run a container from an image.
    3. docker build: Build a Dockerfile into an image.
    "},{"location":"2024-winter/introduction-to-docker/#getting-started","title":"Getting started","text":"

    Firstly, open your IDE and open the terminal.

    1. Clone the repository: git clone https://github.com/codersforcauses/docker-workshop.git
    2. Go to the directory: cd docker-workshop
    3. Run the setup script: npm run setup
    4. Run the app: npm run dev. Visit http://localhost:3000 to see it in action.
    What does the setup script do?

    The setup script installs the dependencies for both the frontend and backend. It is located in the package.json in the root. Formatted nicely:

    npm install --prefix apps/frontend -g && # install dependencies for the frontend\nnpm install --prefix apps/backend -g && # install dependencies for the backend\nnpm install # install dependencies for the root (just a little handy package to run both apps with one command)\n
    "},{"location":"2024-winter/introduction-to-docker/#what-does-the-app-do","title":"What does the app do?","text":"

    The frontend is a simple form that takes a user's order and sends it to the backend. The backend then saves the order to a \"database\". Below is a screenshot of the app:

    "},{"location":"2024-winter/introduction-to-docker/#frontend","title":"Frontend","text":"

    The frontend is a single page app that takes orders. It runs at http://localhost:3000.

    Where is the frontend code?

    The frontend code is located in the apps/frontend directory. The main file is src/App.tsx.

    "},{"location":"2024-winter/introduction-to-docker/#backend","title":"Backend","text":"

    The backend is a simple Hono http server that listens for certain requests. It runs at http://localhost:3001. There are 3 important endpoints:

    1. GET / - Show a simple page to check if the server is running
    2. GET /orders - Get all orders
    3. POST /orders - Create an order
    Where is the backend code?

    The backend code is located in the apps/backend directory. The main file is src/index.ts.

    You can view the first two by going to http://localhost:3001 and http://localhost:3001/orders in your browser.

    "},{"location":"2024-winter/introduction-to-docker/#what-do-we-need-to-do","title":"What do we need to do?","text":"

    We need to create a Dockerfile to build the frontend and backend to images, then run them as containers. I have already created a Dockerfile for the backend, which is located in the apps/backend directory. You will need to create a Dockerfile for the frontend.

    Can I cheat?

    Yes... If you choose to look at it, you might find it helpful. However, it comes with a few optimisations which may be confusing.

    "},{"location":"2024-winter/introduction-to-docker/#building-and-running-an-image","title":"Building and running an image","text":"

    Close the app dev server we ran earlier with CTRL+C.

    Let's start by learning how to build and run a Docker image. First, let's build the backend:

    docker build -t docker-workshop-backend ./apps/backend\n

    This command builds an image from the Dockerfile in the apps/backend directory and tags it (-t) with the name docker-workshop-backend. Otherwise, Docker will give it a random name.

    Now, let's run the image we've built:

    docker run -p 3001:3001 docker-workshop-backend\n

    Port Mapping

    But wait, what does -p 3001:3001 do? I mentioned earlier that Docker basically runs mini virtual machines --- so let's visualise what that looks like.

    In order for our container to make connect with the outside world, we need to create a little tunnel. This is done by mapping a port on the host machine to a port on the container. In our case, I've configured the backend to run internally on port 3001. Therefore, we need to map that internal port to a port on the host machine so we can access it. I kept it simple and mapped it to the same port, but you can change it to any port you like (given our frontend knows about it). Ports are mapped like this: -p <host-port>:<container-port> This also improves security, as you can run multiple containers on the same host machine without them interfering with each other.

    Now, visit http://localhost:3001 to see the backend now running from a Docker container.

    "},{"location":"2024-winter/introduction-to-docker/#manual-build","title":"Manual build","text":"

    To get a better idea of what we need to do, let's build the frontend manually.

    "},{"location":"2024-winter/introduction-to-docker/#step-1-what-are-we-building","title":"Step 1: What are we building?","text":"

    Imagine you are a robot that will execute commands to build the app to be production-ready. Regardless of what you're making, it'll usually fall into this pattern:

    1. Install dependencies
    2. Build the app (if needed)
    3. Serve or run the build files
    "},{"location":"2024-winter/introduction-to-docker/#step-2-mapping-them-to-commands","title":"Step 2: Mapping them to commands","text":"

    The frontend is a React app that uses TypeScript, so we'll follow the template. If you're unsure, you can always Google what you need e.g. \"How to install dependenceis React app\":

    1. In your terminal, navigate to the frontend directory: cd apps/frontend
    2. Install dependencies: npm install
    3. Build the app: npm run build
    4. Serve the build files: npm run start

    The build and start scripts are located in apps/frontend/package.json.

    {\n    // ...\n    \"scripts\": {\n        \"build\": \"tsc && vite build\",\n        \"start\": \"serve dist -p 9876\"\n    }\n    // ...\n}\n

    You can run these commands in the terminal yourself and open it up at http://localhost:9876/ to see the optimised production build of the frontend. Notice how the bottom text has changed from \"development\" to \"production\".

    "},{"location":"2024-winter/introduction-to-docker/#creating-a-dockerfile","title":"Creating a Dockerfile","text":"

    When creating a Dockerfile, it's essentially the same process as manually doing it. The only difference is that you're automating it in a file.

    "},{"location":"2024-winter/introduction-to-docker/#base-image","title":"Base image","text":"

    All Dockerfiles start with a FROM command, which specifies the base image to use. This image is usually a lightweight Linux distribution with the necessary tools and libraries to run the application. For our frontend, we will use the node:20-alpine image. This specifies the (as of writing) LTS version of Node.js with the Alpine Linux distribution.

    How do I know what image to use?

    There are a number of things to consider when choosing a base image:

    • Application: Because we're running a Node.js app, an image with Node.js already installed is a good choice.
    • Size: Smaller images are faster to download and use less disk space.
    • Security: Official images are more secure and are regularly updated. Most of the time you'll be using images from Docker Hub.
    • Compatibility: Make sure the image is compatible with your application. In this case, the current LTS release for Node.js is 20, so we will use node:20-alpine. Locking the version down is also good practice to prevent images from suddenly breaking.
    # Use the official Node.js image as the base image\nFROM node:20-alpine\n
    "},{"location":"2024-winter/introduction-to-docker/#working-directory","title":"Working directory","text":"

    We're in linux land now. First, let's create a directory to put our production files in. This is done with the WORKDIR command.

    FROM node:20-alpine\n\n# Set the working directory in the container\nWORKDIR /app\n
    Why do we need a working directory?

    The WORKDIR command sets the working directory for any subsequent commands in the Dockerfile. This is where the application code will be copied to and where the application will run from. It's like changing directories in the terminal. Just like your own computer, you don't want to group important system files with your projects. It can be named anything you like, but the general convention is to name it /app.

    "},{"location":"2024-winter/introduction-to-docker/#copying-files","title":"Copying files","text":"

    Next, we need to copy our source code into the image. This is done with the COPY command.

    # Use the official Node.js image as the base image\nFROM node:20-alpine\nWORKDIR /app\n\n# Copy the important files to the working directory\nCOPY . ./\n
    What are we copying?

    This command copies everything in the same directory where the Dockerfile is (.) from the host machine to the working directory in the container (./). This is the bare minimum we need to build the frontend. i.e. src, public, package.json, etc.

    "},{"location":"2024-winter/introduction-to-docker/#installing-dependencies-and-building","title":"Installing dependencies and building","text":"

    Now that we have our source code in the image, we need to install the dependencies. This is done with the RUN command. You can execute any supported command from the base image specified. Here, we run both npm install and npm run build in succession using &&.

    FROM node:20-alpine\n\nWORKDIR /app\nCOPY . ./\n\n# Install dependencies and build the app\nRUN npm install && npm run build\n
    Why not do it on separate lines?

    The reason we chain install && build is to reduce the number of layers in the image. Each RUN command creates a new layer in the image, which is essentially a snapshot of everything you've RUN up until now. More layers means a larger image size. By chaining commands together, we can reduce the number of layers and make the image smaller. Docker uses this to cache layers, so if you change a file, it will only rebuild the layers that depend on that file, saving time. In our case, our two commands both depend on the same files, so we should group them together.

    "},{"location":"2024-winter/introduction-to-docker/#serving-the-build","title":"Serving the build","text":"

    We're almost there! The last thing we need to do is serve the build files. This is done with the CMD command. This command specifies the command to run when the container starts. In our case, we want to run npm run start.

    FROM node:20-alpine\nWORKDIR /app\n\nCOPY . ./\n\nRUN npm install && npm run build\n\n# Serve the build files, note how it's an array\nCMD [\"npm\", \"run\", \"start\"]\n

    We're done --- not. There's one last thing we need to do: specify the port the server will run on. This is done with the EXPOSE command. Notice how earlier, npm run start actually started the server on port 9876, so let's expose that instead.

    FROM node:20-alpine\nWORKDIR /app\n\nCOPY . ./\n\nRUN npm install && npm run build\n\n# Serve the build files\nEXPOSE 9876\nCMD [\"npm\", \"run\", \"start\"]\n
    "},{"location":"2024-winter/introduction-to-docker/#done","title":"Done","text":"

    You can now build and run the frontend image. We can actually specify a specific port in the CMD, but I'm just going to map it to port 3000 on the host machine when running the container.

    docker build -t docker-workshop-frontend ./apps/frontend\ndocker run -p 3000:9876 docker-workshop-frontend\n

    If we open up Docker desktop, you can even inspect the container's filesystem to see what we've done.

    The frontend is now running at http://localhost:3000!

    "},{"location":"2024-winter/introduction-to-docker/#optimising-the-dockerfile","title":"Optimising the Dockerfile","text":"

    Let's think about what we've done. We've copied the source code, installed dependencies, built the app, and served the build files. But there are a few things we can do to optimise the Dockerfile:

    • Only have production dependencies in the image. Sometimes we developers install dev dependencies that aren't needed in production, but make our lives easier. If you take a look at apps/frontend/package.json, you'll see a bunch of them.
    • Don't have the source code in the image. We only need the built files to run the app. This reduces the image size.
    "},{"location":"2024-winter/introduction-to-docker/#prune-the-dependencies","title":"Prune the dependencies","text":"

    This is the easiest one. For a node app, you can do npm prune --production to remove all dev dependencies.

    FROM node:20-alpine\nWORKDIR /app\n\nCOPY . ./\n\n# Cleanup in the same layer\nRUN npm install && npm run build && npm prune --production\n\n# Serve the build files\nEXPOSE 9876\nCMD [\"npm\", \"run\", \"start\"]\n
    "},{"location":"2024-winter/introduction-to-docker/#multi-stage-builds","title":"Multi-Stage builds","text":"

    Now we want to remove the source code from the image. You might think you could build the app outside the image, but that would mean you'd need to have Node.js installed on your machine, which defeats the purpose of containerisation. Additionally, some dependencies are platform-specific, so the app might not even work when put inside the container. This is where multi-stage builds come in.

    A multi-stage build is a feature of Docker that allows you to use multiple FROM commands in a single Dockerfile. Each FROM command starts a new stage in the build process. You can copy files from one stage to another, allowing you to build the app in one stage and copy the built files to another stage.

    # Stage 0: Define a common image for building and running\nFROM node:20-alpine AS base\n\n\n# Stage 1: Build the app\nFROM base AS builder\nWORKDIR /app\n\nCOPY . ./\n\nRUN npm install && npm run build && npm prune --production\n\n# Stage 2: Serve the build files\nFROM base AS runner\nWORKDIR /app\n\n# Copy dependencies\nCOPY --from=builder /app/node_modules ./node_modules\n# Copy built files\nCOPY --from=builder /app/dist ./dist\n# Copy package.json so we can run `npm run start`\nCOPY --from=builder /app/package.json ./package.json\n\nEXPOSE 9876\nCMD [\"npm\", \"run\", \"start\"]\n
    "},{"location":"2024-winter/introduction-to-docker/#final-touches","title":"Final touches","text":"

    So now we know how to build a Dockerfile into an image and run it as a container. But there is one more thing we can do to make our lives easier: Docker Compose.

    Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define the services, networks, and volumes for your application in a single file. This makes it easy to start, stop, and manage your application with a single command.

    I've already created a docker-compose.yml file for you. It defines two services: frontend and backend. Instead of doing docker run ... in two terminals, you can now can run both services with a single command. You don't even have to build the images, as Docker Compose will do that for you!

    docker compose up\n

    You also might find the frontend starting on port 9876 inside the container to be a little confusing. You can change the port mapping in the docker-compose.yml file to map it to port 3000 on the host machine. Don't forget to change the package.json script and the EXPOSE command in the Dockerfile as well.

    "},{"location":"2024-winter/introduction-to-docker/#conclusion","title":"Conclusion","text":"

    This is just a small taste of what Docker can do. You could put your entire dev environment inside, push images to a registry and run them in the cloud, or even run a bunch of them in a Kubernetes cluster. Keep in mind that we only built a Dockerfile for a simple React app, so it'll be a different depending on what you do. Luckily, there are countless resources online to help you out --- just google \"how to dockerise a app\"."}]} \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 84363dd..182ad93 100644 Binary files a/sitemap.xml.gz and b/sitemap.xml.gz differ