/evite

Invitation Service

Primary LanguageGo

Evite - App Invitation Service

Requirements

  • The App Admin generates an invitation token (6 - 12 digit alphanumberic string)
  • The invitation token is then used to log in
  • The APIs should be REST-ful
  • The admin endpoints should be authenticated with JWT
  • Invite tokens to expire after 7 days
  • Invite tokens can be recalled (disabled)
  • A public endpoint for validating the invite token
  • Develop the API in Golang
  • Frameworks/Libraries: Gin, Gorm,
  • Use in-memory storage for the tokens (Redis)
  • Use an actual DB
  • Deployment instructions are written in README.md
  • Write tests (unit tests and integration tests)
  • An admin can get an overview of active and inactive tokens
  • Document the APIs in Swagger
  • The invite token validation logic needs to be throttled (limit the requests coming from a specific client)

How to run this project

You need to install Go version >= 1.18 and an IDE/editor such as Goland or VSCode to run the project. All scripts can be found at Makefile.

# create `.env` file
cp .env.template .env
# run docker-compose to create MySQL database and Go server
make start
# down all services
make stop
# run unit test locally
make test

CI/CD

The server uses pre-commit hook. Run these scripts below before creating a commit.

Install requires libraries:

# Run pre-commit install to install pre-commit into your git hooks. pre-commit will now run on every commit.
pre-commit install

Description

Project structure

This project has 5 Domain layers:

  • Model Layer
  • Storage Layer: interacts with databases such as RLDB/NoSQL or File System or Remote API.
  • Repository Layer (optional): provides data for the Business Layer.
  • Business Layer: business logic happened here.
  • Transport Layer: receives HTTP requests from Client, parse data (if needed).

project architecture diagram

API Endpoints

The Go server will run default on port 8000.

  • GET /api/v1/users/invitation: Admin generates an invitation token
  • POST /api/v1/login/invitation: login with an invitation token
  • GET /api/v1/token/validation?invitation_token=: validate an invitation token
  • GET /api/v1/token/invitation?status=: Admin gets invitation token by status
  • PATCH /api/v1/token/invitation/:invitation_token: Admin disable/enable an invitation token
  • POST /api/v1/register: create a new user with email and password
  • POST /api/v1/login: login with email and password

Documentation

TODO: Swagger