Git Product home page Git Product logo

ms-account's Introduction

๐Ÿ‘ฉโ€๐Ÿ’ป ms-account

This project aims to handle an account, by implementing the basic operations, such as sign up, log in, and refresh-token. This is a training project.


๐Ÿ› Architecture

This project was build using Clean Architecture. Basically, the application is broken into layers, each one with its responsibility. The main layers are:

  • controllers: It is responsible to adapt the web interface (by HTTP) into the domain model. Body validations and transformations from client to application and vice-versa should be done here.
  • domain: It is the core of the application. The domain contains all the entities and the protocols (interfaces) to its related operations.
  • usecases: It is the implementation of the business rules related to the operations described on domain.
  • gateways: It is responsible to adapt and uncouple external access, such as databases and third-party APIs.
  • main: It is the single hard-coupled layer responsible to build all the instances and inject the dependencies.

Following the Clean Architecture guide-lines, the most inner layers should not know the most external layers, and it is done by using the Dependency Inversion Principle (DIP). Therefore, the use case layer (for instance) should not know the gateway layer. Instead, the use case layer declares protocols that should be implemented by the gateway layer. Any class that implements that protocol is eligible to be used by use case.

The following diagram shows the dependency graph of the sign-up feature. Note the inter-layer dependency: domain does not depend on any layer, and gateway depends on usecase instead of the contrary.

SignUp Dependency Graph

More diagrams can be found in /docs

Following Interface Segregation Principle (ISP), each interface/protocol defines a single operation. A single class can implement several interfaces if it respects the Single Responsibility Principle (SRP). For instance, BCryptAdapter implements both Hasher and HashComparer interfaces, since both are interconnected and share similar responsibilities.


๐ŸŒŽ Endpoints

This project exposes the following endpoints and contracts.

signup

This endpoint aims to create a new account, given the body information. All the fields are mandatory and email must be valid. When a valid body is provided, the account is persisted and the response has code 201 and the just persisted account as the body.

POST /signup

{
    "name": "any name",
    "email": "[email protected]",
    "password": "any password",
    "passwordConfirmation": "any password",
}

login

This endpoint aims to authenticate an existent user given an email and password. Both fields are mandatory. When credentials are valid, the response has code 200 and the access and refresh tokens as the body.

POST /login

{
    "email": "[email protected]",
    "password": "any password",
}

refresh-token

The provided access token (vide login) expires in short time-intervals, to get a new access-token without the need to authenticate again by email/password, use this endpoint.

Provide the mandatory field refresh-token (from login or last refresh-token request) to get a new pair of access and refresh tokens. The refresh-token will also expire but in a larger time interval.

POST /refresh-token

{
    "refreshToken": "valid-refresh-token"
}

๐Ÿš€ How to run

Before run, you must have a MongoDB database available to be used. Take its URL connection, it will be used later.

โžก from code

  • Export the database connection URL to MONGO_URL.
  • npm start

โžก from docker

  • docker --name ms-account -p 3000:3000 -e MONGO_URL=database_connection pcandido/ms-account

ms-account's People

Contributors

pcandido avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.