Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

begin backend migration #1

Merged
merged 3 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,36 @@ DATABASE_URL=''
# Configure auth provider
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=''
CLERK_SECRET_KEY=''

# Port that program will run on
PORT=3000

# The URL at which this application will be running on
BACKEND_URL=http://localhost:3000
FRONTEND_URL=http://localhost:4000

# Long random string for JWT verification
JWT_SECRET=Hello World

# Amount of time before JWT tokens expire
AUTH_TOKEN_EXPIRY=20 days

# Connection string URI for MongoDB database
MONGODB_URI=

# Email configuration details
EMAIL_HOST=
EMAIL_USER=
EMAIL_PASS=
EMAIL_PORT=
EMAIL_TLS=true
EMAIL_CONTACT=TartanHacks Team <tartanhacks@scottylabs.org>
EMAIL_HEADER_IMAGE=https://tartanhacks.com/img/logo.png

# Google Drive credentials
DRIVE_FOLDER_ID=
DRIVE_CLIENT_ID=
DRIVE_CLIENT_SECRET=
DRIVE_ACCESS_TOKEN=
DRIVE_REFRESH_TOKEN=
DRIVE_TOKEN_EXPIRY_DATE=
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ dist/
expo-env.d.ts
apps/expo/.gitignore

# backend
db/
build/
.DS_Store
.python-version
*.Identifier
credentials.json
token.json
.nyc_output/
.tool-versions

# production
build

Expand Down
35 changes: 35 additions & 0 deletions apps/backend/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build & Test

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
env:
EMAIL_PORT: 465
JWT_SECRET: "Hello World"
AUTH_TOKEN_EXPIRY: "20d"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16"
- name: Build project
run: |
npm install
npm run lint:only
npm run build

- name: Run tests with code coverage
uses: paambaati/codeclimate-action@v3.2.0
env:
CC_TEST_REPORTER_ID: 0e1282aa3a3381f8b403add1674c981483766b199d9ee55806bef31596851c7a
with:
coverageCommand: npm run ci
coverageLocations: |
${{github.workspace}}/coverage/lcov.info:lcov
20 changes: 20 additions & 0 deletions apps/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:14-alpine

# Install Doppler
RUN wget -q -t3 'https://packages.doppler.com/public/cli/rsa.8004D9FF50437357.key' -O /etc/apk/keys/cli@doppler-8004D9FF50437357.rsa.pub && \
echo 'https://packages.doppler.com/public/cli/alpine/any-version/main' | tee -a /etc/apk/repositories && \
apk add doppler
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app

# Setup app directory
WORKDIR /home/node/app
COPY package*.json ./
USER node
RUN npm install
COPY --chown=node:node . .

RUN npm run build
ENTRYPOINT ["doppler", "run", "--"]

EXPOSE 3000
CMD ["node", "."]
1 change: 1 addition & 0 deletions apps/backend/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: npm run heroku
59 changes: 59 additions & 0 deletions apps/backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# TartanHacks Backend

![TartanHacks Backend](https://github.com/ScottyLabs/tartanhacks-backend/actions/workflows/main.yml/badge.svg)
[![Test Coverage](https://api.codeclimate.com/v1/badges/c33b0b2952c311738215/test_coverage)](https://codeclimate.com/github/ScottyLabs/tartanhacks-backend/test_coverage)

This is the backend system for the TartanHacks software suite.

## Getting Started

1. Create a Doppler Account [here.](https://www.doppler.com/)
2. Get an invite to the ScottyLabs Doppler workspace by reaching out to David Hwang
3. Install the Doppler CLI by following the installation instructions [here.](https://docs.doppler.com/docs/enclave-installation)
4. Login to doppler with the CLI by running `doppler login --scope ~/project-dir`
5. Run `npm install` to install packages
6. Run `npm run build`
7. Run `npm run dev` to run the project in dev mode.
8. See the swagger endpoint documentation by visiting `/docs`

## Database Model

https://www.figma.com/file/TXPqZa0vUg3BNw9fHGn9vT/TartanHacks-Model?node-id=1%3A6

## Style

Please install [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
in your VS Code workspace. The workspace has configuration files for helping
you adhere to the project style guidelines. Before commits, please make sure
that your code is formatted correctly by running `npm run lint`

## Testing

We are using Jest for testing.

For any functions or endpoints you write, please write the appropriate tests
in the `tests` folder. Before committing, please make sure that all tests
pass.

We also have CI configured through GitHub actions. These will show you if your
commit builds and passes all tests.

## Environment

If you need to create any new environment variables, add an example to `.env.template`
and make sure to add it as well to `.github/workflows/main.yml` so that CI
passes

## Code coverage

To view code coverage, run `npm run coverage`

## Emails

In order to configure a new email template, create a folder under `email-templates`.
In that folder, create your [mjml](https://documentation.mjml.io/) templates. Also,
create a file called `index.ts` which exports the rendered html by calling
[mjml2html](https://documentation.mjml.io/#inside-node-js) on your template file
and indexing on the `html` field. See `email-templates/verification` for an example.
In `email-templates/index.ts`, make sure to include your folder in the default
export so that the email service can detect your newly added template.
3 changes: 3 additions & 0 deletions apps/backend/globalConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"mongoUri": "mongodb://127.0.0.1:40799/9ea9b497-0c98-4eed-b246-8f69e4963861?"
}
11 changes: 11 additions & 0 deletions apps/backend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testTimeout: 10000,
moduleNameMapper: {
"^src/(.*)$": "<rootDir>/src/$1",
},
coverageReporters: ["lcov"],
roots: [".", "./tests/"],
};
5 changes: 5 additions & 0 deletions apps/backend/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"restartable": "rs",
"ignore": [".git", "dist", ".vscode", "node_modules"],
"ext": "ts mjml"
}
103 changes: 103 additions & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"name": "@scottylabs/backend",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"scripts": {
"build": "rm -rf dist && tsc --build && copyfiles -u 1 **/*.mjml dist",
"start": "doppler setup -p tartanhacks-backend -c prd && doppler run -- node . || echo \"Did you run 'npm run build'?\"",
"start-stg": "doppler setup -p tartanhacks-backend -c stg && doppler run -- node . || echo \"Did you run 'npm run build'?\"",
"start-dev": "doppler setup -p tartanhacks-backend -c dev && doppler run -- node . || echo \"Did you run 'npm run build'?\"",
"dev": "doppler setup -p tartanhacks-backend -c dev && doppler run -- nodemon --exec ts-node -r tsconfig-paths/register --files src/index.ts",
"stg": "doppler setup -p tartanhacks-backend -c stg && doppler run -- nodemon --exec ts-node -r tsconfig-paths/register --files src/index.ts",
"prd": "doppler setup -p tartanhacks-backend -c prd && doppler run -- nodemon --exec ts-node -r tsconfig-paths/register --files src/index.ts",
"lint": "npm run lint:pretty && npm run lint:only",
"lint:only": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
"lint:pretty": "prettier --write .",
"test": "NODE_OPTIONS=--trace-warnings doppler setup -p tartanhacks-backend -c dev_test && doppler run -- jest tests --detectOpenHandles",
"test:coverage": "npm test -- --coverage",
"test:solo": "NODE_OPTIONS=--trace-warnings doppler setup -p tartanhacks-backend -c dev && doppler run -- jest --detectOpenHandles",
"test:nodoppler": "NODE_OPTIONS=--trace-warnings && jest tests --detectOpenHandles --watchAll=false",
"ci": "NODE_OPTIONS=--trace-warnings && jest tests --ci --coverage --forceExit --watchAll=false",
"build:swagger": "swagger-jsdoc -d src/swagger.js src/routes/*.ts -o swagger.json",
"heroku": "node ."
},
"author": "gramliu",
"license": "ISC",
"dependencies": {
"@google-cloud/storage": "^5.16.0",
"@types/cors": "^2.8.12",
"@types/multer": "^1.4.6",
"@types/swagger-jsdoc": "^6.0.0",
"@types/swagger-ui-express": "^4.1.2",
"@zerollup/ts-transform-paths": "^1.7.18",
"axios": "^1.6.7",
"bcrypt": "^5.0.1",
"cors": "^2.8.5",
"crypto": "^1.0.1",
"dotenv": "^10.0.0",
"email-templates": "^8.0.7",
"express": "^4.17.1",
"googleapis": "^77.0.0",
"jest-coverage-badges": "^1.1.2",
"jimp": "^0.16.2",
"jsonwebtoken": "^8.5.1",
"luxon": "^1.27.0",
"mjml": "^4.9.3",
"mongoose": "^5.13.13",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"mustache": "^4.2.0",
"node-fetch": "^3.3.2",
"nodemailer": "^6.6.1",
"nodemailer-mock": "^1.5.11",
"swagger-jsdoc": "^6.1.0",
"swagger-ui-express": "^4.1.6",
"unique-names-generator": "^4.5.0"
},
"devDependencies": {
"@scottylabs/eslint-config": "workspace:^0.2.0",
"@scottylabs/prettier-config": "workspace:^0.1.0",
"@scottylabs/tsconfig": "workspace:^0.1.0",
"@jest/types": "^27.0.2",
"@shelf/jest-mongodb": "^1.2.5",
"@swc/cli": "^0.1.57",
"@swc/core": "^1.3.19",
"@swc/helpers": "^0.4.14",
"@types/bcrypt": "^5.0.0",
"@types/express": "^4.17.11",
"@types/jest": "^27.0.2",
"@types/jsonwebtoken": "^8.5.1",
"@types/luxon": "^1.27.0",
"@types/mjml": "^4.7.0",
"@types/morgan": "^1.9.2",
"@types/mustache": "^4.1.1",
"@types/node": "^20.11.13",
"@types/nodemailer": "^6.4.2",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"copyfiles": "^2.4.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-promise": "^4.3.1",
"jest": "^27.0.4",
"mongodb-memory-server": "^6.9.6",
"nodemon": "^2.0.7",
"nyc": "^15.1.0",
"prettier": "^3.2.5",
"supertest": "^6.1.3",
"ts-jest": "^27.0.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^3.9.0",
"ttypescript": "^1.5.12",
"typescript": "^5.3.3"
},
"optionalDependencies": {
"fsevents": "^2.3.2"
}
}
4 changes: 4 additions & 0 deletions apps/backend/src/_enums/BookmarkType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum BookmarkType {
PARTICIPANT = "PARTICIPANT",
PROJECT = "PROJECT",
}
9 changes: 9 additions & 0 deletions apps/backend/src/_enums/CheckinItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Fine-grained access control for checkin items
*/
export enum CheckinAccessLevel {
ALL = "ALL",
SPONSORS_ONLY = "SPONSORS_ONLY",
PARTICIPANTS_ONLY = "PARTICIPANTS_ONLY",
ADMINS_ONLY = "ADMINS_ONLY",
}
14 changes: 14 additions & 0 deletions apps/backend/src/_enums/Email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export enum EmailGroup {
PARTICIPANTS_VERIFIED = "PARTICIPANTS_VERIFIED",
PARTICIPANTS_COMPLETED = "PARTICIPANTS_COMPLETED",
PARTICIPANTS_CONFIRMED = "PARTICIPANTS_CONFIRMED",
SPONSORS = "SPONSORS",
ADMINS = "ADMINS",
}

export enum EmailStatus {
QUEUED = "QUEUED",
SENT = "SENT",
ERROR = "ERROR",
DELETED = "DELETED",
}
Loading
Loading