/nodejs-hexagonal-architecture-boilerplate

Hexagonal architecture template (URL shortener) written in Express.js using Cassandra and Redis

Primary LanguageTypeScriptMIT LicenseMIT

Express.js hexagonal architecture boilerplate (URL shortener)

NodeJS TypeScript Express.js JWT

ApacheCassandra Redis Docker

REST API written in Express.js with TypeScript using hexagonal architecture pattern. Project: URL shortener with registration, authorization, URL redirection with caching and URL uses counter

Endpoints:

  1. POST:/users - Registrates new user and returns created row

    Usage:

    "email": "email@gmail.com",
    "password": "AJSFa*Fya97GFAD",
    "username": "Example username"

    Response:

    "email": "email@gmail.com",
    "username": "Example username",
    "createdAt": "2024-08-05T12:44:11.705Z"
  2. POST:/auth - Authorizes user and returns JWT token

    Usage:

    "email": "email@gmail.com",
    "password": "AJSFa*Fya97GFAD"

    Response:

    "token":"afnajkfjoajf87dsf89asuf89asfu89as7f8a7f89asd7fya8d9uf8a9d7fa8d97f89adfd9",
    "expiresIn": "24h"
  3. GET:/users/me (requires JWT in Bearer header) - Returns user profile

    Authorization:

    Bearer afnajkfjoajf87dsf89asuf89asfu89as7f8a7f89asd7fya8d9uf8a9d7fa8d97f89adfd9
    
  4. POST:/urls (optional JWT in Bearer header) - Creates url short-link

    Authorization (optional):

    Bearer afnajkfjoajf87dsf89asuf89asfu89as7f8a7f89asd7fya8d9uf8a9d7fa8d97f89adfd9
    

    Usage:

    "to": "https://github.com/LCcodder/typing-assets"

    Response:

    "id": "Sf531d",
    "to": "https://github.com/LCcodder/typing-assets",
    "createdAt": "2024-08-05T12:44:11.705Z",
    "usesCount": 0
  5. GET:/r/:id - Redirects to initial URL by id param

  6. GET:/urls/:id - Returns URL object Response:

    "id": "Sf531d",
    "to": "https://github.com/LCcodder/typing-assets",
    "createdAt": "2024-08-05T12:44:11.705Z",
    "usesCount": 0
  7. GET:/urls/my (requires JWT in Bearer header) - Returns created URLs

    Authorization:

    Bearer afnajkfjoajf87dsf89asuf89asfu89as7f8a7f89asd7fya8d9uf8a9d7fa8d97f89adfd9
    

    Response:

    [
        "id": "Sf531d",
        "to": "https://github.com/LCcodder/typing-assets",
        "createdAt": "2024-08-05T12:44:11.705Z",
        "ownerEmail": "email@gmail.com",
        "usesCount": 0
    ]

Usage:

  • Make sure that docker and docker compose are installed on your system

To launch application run:

docker compose up --build
  • If app throws cassandra connection error reload app container

  • If you want launch app without docker you can find keyspace creation statements in init_keyspace.cql file


Made by LCcodder