You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-17Lines changed: 52 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,24 @@
1
1
# Auth Backend
2
-
> Typescript RESTful backend application for User Authentication and Authorization.
2
+
> Typescript RESTful backend application template for User Authentication and Authorization.
3
3
4
4
## Table of Contents
5
5
- Auth Backend
6
6
-[Table of Contents](#table-of-contents)
7
7
-[General Information](#general-information)
8
8
-[Features](#features)
9
-
-[Technologies and Techniques used](#technologies-and-techniques-used)
9
+
-[Technologies and Techniques](#technologies-and-techniques)
10
+
-[Project configuration](#project-configuration)
11
+
-[Main application](#main-application)
12
+
-[Security](#security)
13
+
-[Testing](#testing)
10
14
-[Setup](#setup)
11
15
-[Project Status](#project-status)
12
16
-[Room for Improvement](#room-for-improvement)
13
17
14
18
15
19
## General Information
16
20
- This project was created to fullfil the need several Software Engineers have when trying to create a Fullstack Web project from scratch.
17
-
- It provides the source code backend template to authenticate and authorize users by exposing RESTful APIs to do so.
21
+
- It provides the source code backend template to authenticate and authorize users by exposing RESTful APIs. It also secures the APIs with techniques such as Limiting the number of calls pero IP and delaying the calls reponse.
18
22
19
23
## Features
20
24
- Username and password signup ✔
@@ -31,19 +35,11 @@
31
35
- Account verification via SMS 🔜
32
36
- Authentication with Google 🔜
33
37
34
-
## Technologies and Techniques used
38
+
## Technologies and Techniques
35
39
36
-
- This project was implenmented 100% with Typescript, Nodejs and Express.
37
-
- Authentication is implemented with the [bcryptjs](https://github.com/kelektiv/node.bcrypt.js) library for password encryption and the Local stategy from the [Passport](https://www.passportjs.org/) library.
38
-
- Authorization is done with JWT strategy from the Passport library.
39
-
- Tokenization is done with [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken).
40
-
-```MongoDB``` and the ```mongoose``` ORM were used for the databse.
41
-
- Email service is handled with [nodemailer](https://github.com/nodemailer/nodemailer/) and using gmail as Email server for testing purposes.
42
-
-[Cors](https://github.com/expressjs/cors) and [Helmet](https://github.com/helmetjs/helmet) were used to avoid well-known web vulnerabilities.
43
-
-[Compression](https://github.com/expressjs/compression) is being used for performance.
44
-
- The ```.env``` file is handeled with [dotenv](https://github.com/motdotla/dotenv) and managed by a configurator module to facilitate its usage across the other application modules.
40
+
### Project configuration
41
+
- The configuration variables are stored in a ```.env``` file. This file is managed by a configurator module to facilitate its usage across the other application modules by using the [dotenv](https://github.com/motdotla/dotenv) library.
45
42
- The project architecture was implemented by enhancing the concepts of [MVC](https://developer.mozilla.org/en-US/docs/Glossary/MVC) to get a more robust architecture with clear separation of concerns:
46
-
47
43
<divstyle="margin-left: 3rem;" >
48
44
49
45
```
@@ -52,16 +48,42 @@
52
48
┃ ┣ 📂controllers => Orchestrators that use Services and Middlewares to provide a response.
53
49
┃ ┣ 📂interfaces => Typescript Interface and Type definitions to be used in the project.
54
50
┃ ┣ 📂middlewares => Functions to be executed before the Router's main controllers.
55
-
┃ ┣ 📂models => Entity definitions that encapsulate Database and ORM services.
51
+
┃ ┣ 📂models => Entity definitions that encapsulate Database and ORM apis.
56
52
┃ ┣ 📂routers => Routers of the application.
53
+
┃ ┃ ┗📂__tests__ => Jest test files.
57
54
┃ ┣ 📂services => Functions containing the all the Business Logic of the application.
58
-
┃ ┗ 📂util => Functions used in across the folders in multiple times.
55
+
┃ ┗ 📂util => Functions used multiple times across the folders in the project.
59
56
┣ 📂config => Configuration for the different components of the application.
57
+
┃ ┗ 📂tests => Test configuration files.
60
58
┣ 📂public => Publicly available resources.
61
59
┗ 📜index.ts => Main file that starts the database and the main application.
62
60
```
63
61
</div>
64
62
63
+
### Main application
64
+
- This project was implenmented 100% with Typescript, Nodejs and Express.
65
+
- Authentication is implemented with the [bcryptjs](https://github.com/kelektiv/node.bcrypt.js) library for password encryption and the Local stategy from the [Passport](https://www.passportjs.org/) library.
66
+
- Authorization is done with JWT strategy from the Passport library.
67
+
- Tokenization is done with [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken).
68
+
-```MongoDB``` and the ```mongoose``` ORM were used for the databse.
69
+
- Email service is handled with [nodemailer](https://github.com/nodemailer/nodemailer/) and using gmail as Email server for testing purposes.
70
+
-[Compression](https://github.com/expressjs/compression) is being used for performance.
71
+
72
+
### Security
73
+
-[Cors](https://github.com/expressjs/cors) and [Helmet](https://github.com/helmetjs/helmet) were used to avoid well-known web vulnerabilities.
74
+
- The number of calls to the SignUp route is limited to avoid infinite calls that may block the internal resources, this was implemented with [express-rate-limit](https://github.com/express-rate-limit/express-rate-limit)
75
+
- Every SignUp route call from the same IP will have a delayed response to avoid bruteforce attacks. This is implemented with [express-slow-down](https://github.com/express-rate-limit/express-slow-down)
76
+
77
+
78
+
### Testing
79
+
- Unite Testing code coverage is 100%
80
+
- The unit testing is done with [Jest](https://github.com/facebook/jest).
81
+
-[SuperTest](https://github.com/visionmedia/supertest) library is used to test the HTTP server.
82
+
- A MongoDB in memory server was used to perform a complete test with database interaction, this was possible with the [mongodb-memory-server](https://github.com/nodkz/mongodb-memory-server) library.
83
+
-[MailSlurp](https://github.com/mailslurp/mailslurp-client) with a free account configuration was used to perform the Account email verification:
#Secret key to perform Email Verification testing with Jest and Supertest. You can get one free at: https://mailslurp.com/
135
+
EMAIL_MAILSLURP_KEY="YOUR KEY HERE"
136
+
137
+
#API SECURE SETTINGS
138
+
#Establishes the time in milliseconds in wich an IP can make a certain number of calls
139
+
RATE_LIMIT_TIME_IN_MS="60000"
140
+
#Establishes the number of calls that can be made in the time set by RATE_LIMIT_TIME_IN_MS
141
+
RATE_LIMIT_MAX_CALLS="2"
142
+
#How long to keep records of requests in memory.
143
+
SPEED_LIMIT_TIME_WINDOW_IN_MS="30000"
144
+
#Max number of connections during SPEED_LIMIT_TIME_WINDOW_IN_MS before starting to delay responses. Defaults to 1. Set to 0 to disable delaying.
145
+
SPEED_LIMIT_DELAY_AFTER="1"
146
+
#How long to delay the response, multiplied by (number recent hits - SPEED_LIMIT_DELAY_AFTER). Defaults to 1000 (1 second). Set to 0 to disable delaying.
147
+
SPEE_LIMIT_DELAYING_TIME_IN_MS="500"
112
148
113
149
```
114
150
@@ -117,5 +153,4 @@ Project is: _in progress_
117
153
118
154
## Room for Improvement
119
155
There are always room for improvement, in this project so far the thinkgs that can be improved are:
120
-
- Unit testing coverage.
121
156
- A separate web page for the Docs containing the API catalogs.
0 commit comments