- Front end is written in React, which is a Typescript framework. Vite is the front-end build tool.
- Database will be Postgres. Database migrations are managed using Goose.
- Backend is Go with the Echo framework.
- Make sure you have
go(v1.23 preferably). (Mac)brewseems to have issues on Mac with installing go for this project. Downloading it from the official website seems to work. Just download and run the installer. - Install
yarninstalled on your computer usingnpm install --global yarn. Note that you will need to installnpmfirst if you haven't already. - On the terminal, run
chmod +x ./dev.shto modify permissions - On the terminal, run
cd web && yarn && yarn run devto install the React dependencies. Once you see thebuild in <time>msmessage, you can exit out of the command usingCtrl+C - Add the following to
~/.bashrcon Linux or~/.zshrcon Mac.
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
Then, run source ~/.bashrc on Linux or source ~/.zshrc on Mac.
- Install
air(live-reload for go applications) andgoose(database migration tool) by running
go install github.com/air-verse/air@latest
go install github.com/pressly/goose/v3/cmd/goose@latest
- Install postgres and create a database named
autograder. Make sure you postgres is up and running. You can download Beekeeper Studio as a database explorer if you don't already have one. - Run
source .envrcto export the variables of.envrcon your local machine. Rungoose upto run all the required database migrations. - Open http://localhost:8080/ to access the web app.
- Install
goandnodejs - Install
yarnwith the commandnpm install --global yarn - If yarn cannot run because of security restrictions, run the command
Set-ExecutionPolicy -ExecutionPolicy Unrestrictedin PowerShell as an admin. (read this for more info) - With the terminal opened from the project, run
cd webyarnthenyarn run dev. It will show in the terminal "built in ms" after it is finished, during which point you can Ctrl+C to exit out of the command. - With the terminal opened from the main project folder, run
go install github.com/air-verse/air@latestto install air - Install goose with
go install github.com/pressly/goose/v3/cmd/goose@latestand this installer - Install postgres, make sure the password for the postgres user is 'postgres', and create a database named
autograder. Make sure you postgres is up and running. You can download Beekeeper Studio as a database explorer if you don't already have one. - Make sure you have git installed because you need to use Git Bash to run the project
- Open the project in VS code and set the default terminal by entering Ctrl+Shift+p, typing in
Terminal: Set Default Profile, clicking on that, then selecting "Git Bash" - Install direnv in git bash with the command
winget install direnv - Hook direnv to git bash by editing the .bashrc file with the command
code ~/.bashrcand paste ineval "$(direnv hook bash)" - From a git bash terminal in VS code, run
direnv allowto set the environment variables - Run
goose upin Git Bash to migrate the database - Install Postman so you can test the APIs
- In the file
air.toml, changecmd = "go build -o ./tmp/main ."tocmd = "go build -o ./tmp/main.exe - Run the command
./dev.shto run the project
- Download the most recent version of postgres via their installer under the column "Mac OS X"
- Go through the steps in the installer. When it prompts you to set up your database admin make the username
postgresand passwordpostgres. - After the install is finished, open pgAdmin which will prompt you to type in your password (
postgres) to connect to your local server that's been setup via the installation. - On the left column under the dropdown menu for
PosgreSQL [Version #]right clickDatabasesand clickCreate>Database.... - Name it
autograderand click Save.
- Install postgres using
brew install postgresql. - Start postgres using
brew services start postgresql. - Run
psql postgres. - On the postgres command line, run
CREATE USER postgres WITH PASSWORD 'postgres';. Note: If needed, you can runALTER USER postgres WITH SUPERUSER;to give the new user privledges (this might not be required). - Run
CREATE DATABASE autograder;to create the database. - Type
\qto exit.
Note: Before building the binary for deployment, please do the following:
- Set up a Postgres database. Update the credentials in
config.yamlwith the database's credentials. - Chanage the default JWT Secret in
config.yamlto be a long and secure sequence of charaters. - TODO (Setting up Email stuff)
Run go build main.go on the terminal. This will create a new binary file.
You can now run the binary using ./main on the terminal.
Run env GOOS=windows GOARCH=arm64 go build main.go on the terminal.
If the above doesn't generate a binary or generates a binary that doesn't run on your computer, change the GOARCH value from arm64 to the correct one for your CPU. You can find the list for valid GOARCH values here.
You can now run the using main.exe
The backend for this project makes use of a slightly modified version of the Three-Layered Architecture. The incoming requests are parsed into the correspoding entity (defined inside models) by the handler layer. A valid request passes from the handler into the service layer, where all the business logic is performed. The next step after the service layer is the datastore layer, where the necessary database operation is performed.
Such an architecture allows one layer to be modified and tested independently of other operations in addition to providing all the benefits of modularity.
You can use Postman/Bruno or a similar tool to test the APIs.
Register:
POST
URL: 'http://localhost:8080/api/auth/register/<id>?token=<token>'
Raw JSON: {"first_name": "New", "last_name": "User", "password": "Hello123$%"}
From the returned Set-Cookie value, take the token's value and set it as the Bearer Token value inside Authorization.
Create Invite (need token):
POST
URL: 'http://localhost:8080/api/auth/invite'
Raw JSON: {"email": "testing@gmail.com", "user_role": "student"}
Create Classroom (need token):
POST
URL: 'http://localhost:8080/api/classroom'
Raw JSON: {"name":"Joe"}
Add user to classroom / alter the roles of existing users in classroom:
PUT
URL: http://localhost:8080/api/auth/<classroomId>/user
Raw JSON:
{
"users": [{"email": "test@udallas.edu", "role": "student"}]
}
Change the name of a classroom:
PATCH
URL: http://localhost:8080/api/classroom/edit/<classroomId>
Raw JSON: {"name": "New Name"}
Delete a classroom:
DELETE
URL: http://localhost:8080/api/classroom/delete/<classroomId>
Get 'view mode' assignments
GET
URL: http://localhost:8080/api/classroom/<classroomId>/view_assignments
Login:
POST
URL: 'http://localhost:8080/api/auth/login'
Raw JSON: {"email":"test@udallas.edu", "password":"Hello123$%"}
Logout:
POST
URL: 'http://localhost:8080/api/auth/logout/<sessionId>'
Password Reset Request:
POST
URL: 'http://localhost:8080/api/auth/password'
Raw JSON: {"email":"test@udallas.edu"}
Password Reset:
POST
URL: 'http://localhost:8080/api/auth/reset_password/<requestId>?token=<token>'
Raw JSON: {"password":"TryingThis123!"}
Refresh Access Token:
POST
URL: 'http://localhost:8080/api/auth/refresh'
Change User Info:
PUT
URL: 'http://localhost:8080/api/auth/user_info
Raw JSON:
{
"current_email":"current_email@udallas.edu",
"new_email":"new_email@udallas.edu",
"first_name":"First",
"last_name":"Last"
}
Is Login Valid:
GET
URL: 'http://localhost:8080/api/auth/valid_login
Get user's first and last name:
GET
URL: 'http://localhost:8080/api/auth/user_name'