This repository is meant to be a the server used for groudstation dashboard.
- Clone repository.
- Run
pnpm install
to install dependancies. - Get .env file from team lead
- Make sure to create a localhost alias for the
HOST_NAME
if needed (Instructions) - Run
pnpm run db
to setup Prisma (also run this script whenever you pull main). - Run scripts below as needed.
There are scripts for running the build process, starting the server, and running tests. The main ones are provided below.
clean:dev
andclean:prod
empty thedev
andprod
directories respectively.clean
clears both.tsc:dev
andtsc:prod
run the Typescript compiler using thetsconfig.json
andtsconfig.prod.json
, respectively. Furthermore, the outputs of the two commands are thedev
andprod
folders, respectively. Prod does not have test files or the prisma seed file.alias:dev
andalias:prod
updates the path aliases in the build output to be correct.build:prod
andbuild:dev
run the Typescript compilation and alias correction at the same time.start:prod
andstart:dev
starts the server with the appropriate environment.prod
anddev
runs the build step and starts the server- All options that have watch at the end run the same command but in watch mode (wil rerun tasks if files change).
test
runs thevitest
tests. Note that it does not build, sobuild:dev
should be called before runningtest
.db:pull
updates the current database schema usingDATABASE_URL
in .envdb:generate
creates the TS lib for the database models (basically sets up Prisma for use in the codebase)db
runs both pull and generatedb:seed
seed runs all seeding scripts to automate mock data creation and storage in dev db branch.db:seed:log
creates and replaces logs in dev db branch.- Note: To add/remove/update users from user table, run
npx prisma studio
. It will start a web client where you can modify user data (and log data as well but managing log data manually is a pain).
- The
.env
file holds enviroment variables. Most team memebers only need the development one. - Folders in the src directory can be imported from by using '@/[folder_name]' (ex. import {a_controller} from '@/controllers/someControllers.js')
- Imports of local Typescript files must have
js
orcjs
endings due to NodeNext module resolution. - Folder structure goes as follows in src
controllers
are responsible for processing a request, composing services and utils to create a response, and sending the response. These files defines the API for each endpoint.middlewares
are used for performing actions on every reqeust that hits the app or route it is attached to. Examples are logging and checking auth status.models
define the shape of entities that are involved in the code.services
are responsible for interfacing with external data providers (ex. database), API's, or other data producing logic that a controller would need. Also, they take care of core logic for the backend.utils
are commonly used functions (key being that it is meant for convenience of the devs, not a core functionality of the dashboard).index.ts
is the main file that is ran when server starts.
- Testing is done using vitest (at the time of decision, it was the only testing lib that supported es6 imports and mocking).