Skip to content

koodi101/project-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Koodi101 Project Template

Forking and cloning the repository

Start by forking the repository

If you work in a group, only one person needs to fork the repository. The others need to be members of the repository. See collaborating with other users

Then clone the forked repository using SSH

git clone git@github.com:<user>/project-template.git

When you use SSH to clone a repository, you need a private key on your account which is authorized to pull (read) the repository.

Using SSH allows you to push (write) to the repository without providing you username and password! Handy, right?

Running the project

Prerequisites

You need to start the backend and the frontend separately, so open two terminal windows, or use a terminal multiplexer: tmux.

Backend

cd backend
npm install
npm run dev

The backend is now running at http://localhost:9000 and automatically reacts to changes in the source code.

Frontend

Notice that you need to run npm install in both directories backend/ and frontend/

cd frontend
npm install
npm start

The frontend is now running at http://localhost:8000 and also automatically rebuilds when the source code changes.

Clearing the database

The database is stored in a sqlite file in backend/db/chat.sqlite.

If you edit the models, you need to remove the database for the changes to get applied. Sequelize doesn't automatically migrate the database to the new structure defined in the models.

To clear the database, stop the backend and remove the database file:

You can stop a running process using Ctrl-C

rm backend/db/database.sqlite

Project ideas

  • Make the graph look nicer with options from chart.js docs.
  • Add a chat application to the page.
    • Fetch all messages and display them.

      Backend has the same /api/chats endpoint from lesson3 available

    • Add a message input box.
    • Optionally add rooms and nicknames. (requires backend API changes and probably nuking the database)
  • Publish the frontend on Vercel.
  • Add unit tests to make sure the backend works correctly.
  • Come up with more ideas and turn them into features on the page!

Collaborating

The owner of the forked repository in your group needs to add the other members as collaborators

Collaboration is the heart of Open Source software development in GitHub.

After creating/forking a repository, owner may add collaborators to it alternatively in the GitHub repository page by clicking settings -> collaborators or by going to the web page by the following URL where <username> is replaced by a repository owner's username

Collaborators can clone the owner's repository using SSH and push changes to it.

https://github.com/<username>/project-template/settings/access

And, by searching usernames of other members, the owner can invite them to collaborate in the project and allow pushing to the repository.

Upon inviting your group members, they will receive the invitation via email. Only after accepting the invitation are they given access to the repository.

Here is the help page with images

Collaborating example

  • Niklash on is making changes to src/index.jsx, committing them and finally pushing them to GitHub.

computer1

Git commands used:

  • git add
  • git diff
  • git status
  • git commit -m "message"
  • git push
  • Severi is then pulling the changes and viewing them.

computer1

Git commands used:

  • git pull
  • git show

Merge conflicts

Sometimes when multiple collaborators are working on the same Git repository locally at the same time, they make conflicting changes. The conflicts will show up once one of them tries to pull the other's changes and git spits out an error like the following:

CONFLICT (content): Merge conflict in index.js
Automatic merge failed; fix conflicts and then commit the result.

Git tries to resolve merge conflicts automatically, which sometimes works. However, even after automatically resolving conflicts, one should test that the project works as there can be semantic conflicts in the code after the merge.

Some common causes for merge conflicts are:

  • Both change the same part of a file, e.g. even just whitespace and indentation changes can cause a conflict
  • Both move, rename or delete the same file

Here are some resources for dealing with merge conflicts:

Running with Docker (advanced)

Then build the docker images and start the services

docker-compose build
docker-compose up

Or with a single command

docker-compose up --build

Hit Ctrl+C to stop the processes

Optionally you can run the process in the background

Add -d to the docker-compose commands.

docker-compose build
docker-compose up -d

Or with a single command

docker-compose up --build -d

-d comes from the word detached

To see if the project is running

docker-compose ps

To stop the running background processes and remove the built images

docker-compose down --rmi all --remove-orphans

If the processes are not running docker-compose down also removes the containers and images

If you don't want to remove the images, you can just run

docker-compose down