https://github.com/dyzio18/selfcodehero
Engage user with gamification engine. Gamification REST API.
https://github.com/dyzio18/selfcodehero
docker eslint express gamification gamification-platform gamification-service mongodb mongoose nodejs rest-api selfcodehero
Last synced: 5 months ago
JSON representation
Engage user with gamification engine. Gamification REST API.
- Host: GitHub
- URL: https://github.com/dyzio18/selfcodehero
- Owner: Dyzio18
- License: other
- Created: 2022-01-25T20:50:15.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-20T18:21:47.000Z (over 3 years ago)
- Last Synced: 2025-03-31T01:51:22.486Z (7 months ago)
- Topics: docker, eslint, express, gamification, gamification-platform, gamification-service, mongodb, mongoose, nodejs, rest-api, selfcodehero
- Language: JavaScript
- Homepage: https://selfcodehero.com
- Size: 473 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SELFCODEHERO - easy gamification engine
Gamification engine based on REST API. Easy and reusable service to track user progress, badges, missions and other cool things.
## Quick Start
If you would still prefer to do the installation manually, follow these steps:
Clone the repo:
```bash
git clone https://github.com/dyzio18/selfcodehero.git
cd selfcodehero
rm -rf ./.git
```Install the dependencies:
```bash
yarn install
# or
npm install
```Set the environment variables:
```bash
cp .env.example .env# open .env and modify the environment variables (if needed)
```## Table of Contents
- [Features](#features)
- [Commands](#commands)
- [Environment Variables](#environment-variables)
- [Project Structure](#project-structure)
- [API Documentation](#api-documentation)
- [Linting](#linting)
- [Contributing](#contributing)## Features
- **NoSQL database**: [MongoDB](https://www.mongodb.com) object data modeling using [Mongoose](https://mongoosejs.com)
- **Authentication and authorization**: using [passport](http://www.passportjs.org)
- **Validation**: request data validation using [Joi](https://github.com/hapijs/joi)
- **Logging**: using [winston](https://github.com/winstonjs/winston) and [morgan](https://github.com/expressjs/morgan)
- **Testing**: unit and integration tests using [Jest](https://jestjs.io)
- **Error handling**: centralized error handling mechanism
- **API documentation**: with [swagger-jsdoc](https://github.com/Surnet/swagger-jsdoc) and [swagger-ui-express](https://github.com/scottie1984/swagger-ui-express)
- **Process management**: advanced production process management using [PM2](https://pm2.keymetrics.io)
- **Dependency management**: with [Yarn](https://yarnpkg.com)
- **Environment variables**: using [dotenv](https://github.com/motdotla/dotenv) and [cross-env](https://github.com/kentcdodds/cross-env#readme)
- **Security**: set security HTTP headers using [helmet](https://helmetjs.github.io)
- **Santizing**: sanitize request data against xss and query injection
- **CORS**: Cross-Origin Resource-Sharing enabled using [cors](https://github.com/expressjs/cors)
- **Compression**: gzip compression with [compression](https://github.com/expressjs/compression)
- **CI**: continuous integration with [Travis CI](https://travis-ci.org)
- **Docker support**
- **Code coverage**: using [coveralls](https://coveralls.io)
- **Code quality**: with [Codacy](https://www.codacy.com)
- **Git hooks**: with [husky](https://github.com/typicode/husky) and [lint-staged](https://github.com/okonet/lint-staged)
- **Linting**: with [ESLint](https://eslint.org) and [Prettier](https://prettier.io)
- **Editor config**: consistent editor configuration using [EditorConfig](https://editorconfig.org)## Commands
Running locally:
```bash
yarn dev
```Running in production:
```bash
yarn start
```Testing:
```bash
# run all tests
yarn test# run all tests in watch mode
yarn test:watch# run test coverage
yarn coverage
```Docker:
```bash
# run docker container in development mode
yarn docker:dev# run docker container in production mode
yarn docker:prod# run all tests in a docker container
yarn docker:test
```Linting:
```bash
# run ESLint
yarn lint# fix ESLint errors
yarn lint:fix# run prettier
yarn prettier# fix prettier errors
yarn prettier:fix
```## Environment Variables
The environment variables can be found and modified in the `.env` file. They come with these default values:
```bash
# Port number
PORT=3000# URL of the Mongo DB
MONGODB_URL=mongodb://127.0.0.1:27017/node-boilerplate# JWT
# JWT secret key
JWT_SECRET=thisisasamplesecret
# Number of minutes after which an access token expires
JWT_ACCESS_EXPIRATION_MINUTES=30
# Number of days after which a refresh token expires
JWT_REFRESH_EXPIRATION_DAYS=30# SMTP configuration options for the email service
# For testing, you can use a fake SMTP service like Ethereal: https://ethereal.email/create
SMTP_HOST=email-server
SMTP_PORT=587
SMTP_USERNAME=email-server-username
SMTP_PASSWORD=email-server-password
EMAIL_FROM=support@yourapp.com
```## Project Structure
```
src\
|--config\ # Environment variables and configuration related things
|--controllers\ # Route controllers (controller layer)
|--docs\ # Swagger files
|--middlewares\ # Custom express middlewares
|--models\ # Mongoose models (data layer)
|--routes\ # Routes
|--services\ # Business logic (service layer)
|--utils\ # Utility classes and functions
|--validations\ # Request data validation schemas
|--app.js # Express app
|--index.js # App entry point
```## API Documentation
To view the list of available APIs and their specifications, run the server and go to `http://localhost:3000/v1/docs` in your browser. This documentation page is automatically generated using the [swagger](https://swagger.io/) definitions written as comments in the route files.
### API Endpoints
List of available routes:
**Auth routes**:\
`POST /v1/auth/register` - register\
`POST /v1/auth/login` - login\
`POST /v1/auth/refresh-tokens` - refresh auth tokens\
`POST /v1/auth/forgot-password` - send reset password email\
`POST /v1/auth/reset-password` - reset password\
`POST /v1/auth/send-verification-email` - send verification email\
`POST /v1/auth/verify-email` - verify email**User routes**:\
`POST /v1/users` - create a user\
`GET /v1/users` - get all users\
`GET /v1/users/:userId` - get user\
`PATCH /v1/users/:userId` - update user\
`DELETE /v1/users/:userId` - delete user**Game routes**:\
`POST /v1/games` - create a game\
`GET /v1/games` - get all games\
`GET /v1/games/:gameId` - get game\
`PATCH /v1/games/:gameId` - update game\
`DELETE /v1/games/:gameId` - delete game## Linting
Linting is done using [ESLint](https://eslint.org/) and [Prettier](https://prettier.io).
In this app, ESLint is configured to follow the [Airbnb JavaScript style guide](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base) with some modifications. It also extends [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) to turn off all rules that are unnecessary or might conflict with Prettier.
To modify the ESLint configuration, update the `.eslintrc.json` file. To modify the Prettier configuration, update the `.prettierrc.json` file.
To prevent a certain file or directory from being linted, add it to `.eslintignore` and `.prettierignore`.
To maintain a consistent coding style across different IDEs, the project contains `.editorconfig`
## Credits
- [hagopj13/node-express-boilerplate](https://github.com/hagopj13/node-express-boilerplate)
## License
[CC BY-NC-SA 4.0](LICENSE)