This project was created for COMP3005: Database Management Systems. It is a web backend that simulates a fitness management system for a gym, and allows members, trainers, and admins to engage with gym amenities.
It is created in Go using GraphQL with the gqlgen tool, JWT, and sqlc.
Watch the video demo here
Warning
This codebase suffers from a deeply-flawed-and-not-very-successful attempt at code organization and trying new things...
server/api/graph: GraphQL related files including schema and resolvers
server/api/middleware: Middleware (related to authentication and authorization in this case)
server/api/rest: REST endpoints for authentication
server/core: the application interfaces and types that the API and DB folders rely on
server/db/connect: Database connection file for Postgres
server/db/migrations: Database migrations (fulfils the DDL requirement in the assignment specification)
server/db/pg: Files related to querying and interacting with Postgres. Any files ending in *.sql.go
are generated by sqlc
. Other files are implementations of the core interfaces for Postgres.
server/db/queries: SQL queries and seed data for the database.
server/services: Various functions that act as the go-between for the interfaces and repositories
(This assumes you have Go setup)
-
Create a
.env
file at the root of the directory. Put your own postgres URI into this .env withDATABASE_URL="your-uri"
and create also insertJWT_SECRET="secret"
-
Setup the database with
golang-migrate
by running the necessaryup
commands and insert the seed data. -
In the command line, run
cd ./server
-
Run
go mod tidy
to install dependencies. -
Run
go run main.go server.go
to compile and run the code in one step. Alternatively, compile the code withgo build
and run the executable.