Skip to content

A ground up solution for optimized time tracking that handles faculty-student management

Notifications You must be signed in to change notification settings

dyl10s/TimeTracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Time Tracker

Development Setup

Install Postgres

To start off you will need to download the database for local development. You can do so at the link here. We are using Postgres 13 you can install the latest patch for version 13, at this time it is 13.1. When installing all the defaults should be kept the same. To make the development process as smooth as possible set your default database password to admin. You can also skip the installation for stack builder on the last step.

Install .Net 5

Next up you will need the framework that the backend runs with. You can install the latest .Net 5 version at this moment it is 5.0.2. You can find the SDK download here.

Install Entity Framework Tools

This software is using a code-first approach to database development which means you do not have to worry about writing any SQL. In order to use the tools after installing .Net 5 you can run the command dotnet tool install --global dotnet-ef.

Install NodeJS and Angular

The front end is built off of Angular and node.js so you will need to install the node.js installer. You can find the find the correct installer for your system here. After NodeJS is installed, you can also install the Angular CLI. Run the command npm install -g @angular/cli.

Install node_modules

To get the front end built and ready for local development, you need to install the node_modules. To do this, open up the Frontend folder inside of a terminal and run npm install. This will install all correct packages and you can now run ng serve to get the Angular app running on http://localhost:4200.

Development Tips

Database

EF Core Overview

As stated earlier this project is using a code first approach which means you should never go and modify the database directly. The database is controlled by Migrations. They can be found in /backend/TimeTracker.Database/Migrations. Migrations are auto-generated by .Net and should only be changed in certain circumstances which this readme will not go into. The database "schema" can be found in the /backend/TimeTracker.Database/Models directory. Each file here represents a table in the database.

Updating the database

If you want to add a new item, you can start by creating a new class in the /backend/TimeTracker.Database/Models directory. Below you can find an example:

using System;

namespace TimeTracker.Api.Models
{
    public class TimeEntry
    {
        public int Id { get; set; }
        public DateTime StartTime { get; set;}
        public DateTime EndTime { get; set; }
        public string Message { get; set;}
    }
}

Each model should have an Id property which automatically increments by 1 each time an item is added to the database. In the class you can put any standard datatype or a reference to another class which would automatically create a relationship in the database. After you have finished creating the class with the required values you can run the follow command from the /backend/TimeTracker.Database directory dotnet ef migrations add YOUR_MIGRATION_NAME --startup-project ../TimeTracker.Api. The migration name can just be a small description of your change like AddedTimeEntry.

When making a change to the database simply change the model file and run the same command dotnet ef migrations add YOUR_MIGRATION_NAME --startup-project ../TimeTracker.Api.

The next time the app is run all migrations will be applied automatically to the database.

Discord Bot Secrets

In order to keep the Discord token private, we are using a build in .net solution called user secrets. The application will run without the secret and will just not run the Discord bot. If you would like to additional Discord bot development you will need to add a user secret in vscode. You can install the extension and follow their instructions to edit the user secrets on the TimeTracker.Api.csproj project. You can find the vscode extension here.

After installing the extension, right click on /backend/TimeTracker.Api/TimeTracker.Api.csproj and select Manage User Secrets. The secret should be in the following format.

{
  "BotToken": "BotTokenHere"
}

You can reach out to one of the existing developers to get the bot development token or create your own bot for local development here.

Deployment

NTime has been built to make deployment easy and is built to be run on a single machine using Docker Compose. Below are a few steps to get NTime up and running on a server.

Install Docker

The first thing you will need to do is install Docker and Docker compose. The steps to install Docker can be found here. The steps to install Docker Compose can be found here

Start Up NTime

We have created a simple script that you can modify and run to fit your needs.

wget -N https://raw.githubusercontent.com/dyl10s/TimeTracker/development/docker-compose.yml
sed -i 's/BotTokenHere/${{ secrets.BOT_TOKEN }}/' docker-compose.yml
sed -i 's/SSLEmailHere/${{ secrets.SSL_EMAIL }}/' docker-compose.yml
sed -i 's/Domain1Here/${{ secrets.DOMAIN_1 }}/' docker-compose.yml
sed -i 's/Domain2Here/${{ secrets.DOMAIN_2 }}/' docker-compose.yml
export TIMETRACK_TAG=dev
sudo -E docker-compose pull
sudo -E docker-compose up -d

There are a few things in this script you will want to configure.

wget -N https://raw.githubusercontent.com/dyl10s/TimeTracker/development/docker-compose.yml - This line just downloads the docker-compose.yml file from the github repo. This is the url for the development branch. If you want to run the current production branch you can run wget -N https://raw.githubusercontent.com/dyl10s/TimeTracker/master/docker-compose.yml

${{ secrets.BOT_TOKEN }} - This should be replaced by your Discord bot token. You can find out more about this in the Discord bot section.

${{ secrets.SSL_EMAIL }} - This is the email you want the SSL certificate linked to, you can just use any personal / school email. This line can be removed if you do not want to auto configure SSL.

${{ secrets.DOMAIN_1 }} and ${{ secrets.DOMAIN_2 }} - This will be replaced by the domain name of your website. Most of the time you would use the main domain as well as the domain starting with www. For example www.timetrack.ml and timetrack.ml. If you want to configure SSL automatically both values must be filled. However if you only have 1 domain name you can just set them both to the same value. If you want to skip automatic SSL configuration you can remove these lines.

If you want the Docker images to be pulled from the development branch you can use export TIMETRACK_TAG=dev. If you want them to be from master you can just remove this command or use export TIMETRACK_TAG=latest.

CI/CD

For development we have been using github actions to automate testing and deployment of NTime. When development or master are updated, the Docker images are automatically built and pushed to the Docker repository which means all you need to do to update the application is run the following commands once the build is complete.

sudo -E docker-compose pull
sudo -E docker-compose up -d

We have configured github actions to automatically run these commands on our development server.

All of this is configured with github secrets which can be found here. The github action itself is located here.