Node.js Backend Architecture Typescript - Learn to build a backend server for production ready blogging platform like Medium and FreeCodeCamp. Main Features: Role based, Express.js, Mongoose, Redis, Mongodb, Joi, Docker, JWT, Unit Tests, Integration Tests.
Note: This is the latest (version 2) of the project. If you are using version 1 then checkout the branch version-1
This project is designed for a production ready environment. It can handle the scale and complexity of a very demanding application. This project is being used by companies like MindOrks, AfterAcademy, and CuriousJr. Apps/Websites having 10+ million usebase.
It is suitable for Web Apps, Mobile Apps, and other API services.
You can connect with me here:
We will learn and build the backend application for a blogging platform. The main focus will be to create a maintainable and highly testable architecture.
Following are the features of this project:
I have also open source a complete blogging website working on this backend project: Goto Repository
The repository [React.js Isomorphic Web Application Architecture] has a complete React.js web application implemented for a blogging platform which is using this project as its API server.
Install using Docker Compose [Recommended Method]
docker-compose up -d
in terminal from the repo directory.docker exec -t app npm test
Run The Tests
npm install
.npm test
.Install Without Docker [2nd Method]
DB_HOST
to localhost
in .env and tests/.env.test files.npm start
and You will be able to access the API from http://localhost:3000npm test
.Postman APIs Here:
addons/postman
āāā .vscode
ā āāā settings.json
ā āāā tasks.json
ā āāā launch.json
āāā .templates
āāā src
ā āāā server.ts
ā āāā app.ts
ā āāā config.ts
ā āāā auth
ā ā āāā apikey.ts
ā ā āāā authUtils.ts
ā ā āāā authentication.ts
ā ā āāā authorization.ts
ā ā āāā schema.ts
ā āāā core
ā ā āāā ApiError.ts
ā ā āāā ApiResponse.ts
ā ā āāā JWT.ts
ā ā āāā Logger.ts
ā ā āāā utils.ts
ā āāā cache
ā āĀ Ā āāā index.ts
ā āĀ Ā āāā keys.ts
ā āĀ Ā āāā query.ts
ā āĀ Ā āāā repository
ā āĀ Ā āāā BlogCache.ts
ā āĀ Ā āāā BlogsCache.ts
ā āāā database
ā ā āāā index.ts
ā ā āāā model
ā ā ā āāā ApiKey.ts
ā ā ā āāā Blog.ts
ā ā ā āāā Keystore.ts
ā ā ā āāā Role.ts
ā ā ā āāā User.ts
ā ā āāā repository
ā ā āāā ApiKeyRepo.ts
ā ā āāā BlogRepo.ts
ā ā āāā KeystoreRepo.ts
ā ā āāā RoleRepo.ts
ā ā āāā UserRepo.ts
ā āāā helpers
ā ā āāā asyncHandler.ts
ā ā āāā permission.ts
ā ā āāā role.ts
ā ā āāā security.ts
ā ā āāā utils.ts
ā ā āāā validator.ts
ā āāā routes
ā ā āāā access
ā ā ā āāā credential.ts
ā ā ā āāā login.ts
ā ā ā āāā logout.ts
ā ā ā āāā schema.ts
ā ā ā āāā signup.ts
ā ā ā āāā token.ts
ā ā ā āāā utils.ts
ā ā āāā blog
ā ā ā āāā editor.ts
ā ā ā āāā index.ts
ā ā ā āāā schema.ts
ā ā ā āāā writer.ts
ā āĀ Ā āāā blogs
ā āĀ Ā āĀ Ā āāā index.ts
ā āĀ Ā āĀ Ā āāā schema.ts
ā ā āāā index.ts
ā ā āāā profile
ā ā āāā schema.ts
ā ā āāā user.ts
ā āāā types
ā āāā app-request.d.ts
āāā tests
ā āāā auth
ā ā āāā apikey
ā ā ā āāā mock.ts
ā ā ā āāā unit.test.ts
ā ā āāā authUtils
ā ā ā āāā mock.ts
ā ā ā āāā unit.test.ts
ā ā āāā authentication
ā ā ā āāā mock.ts
ā ā ā āāā unit.test.ts
ā ā āāā authorization
ā ā āāā mock.ts
ā ā āāā unit.test.ts
ā āāā core
ā ā āāā jwt
ā ā āāā mock.ts
ā ā āāā unit.test.ts
ā āāā cache
ā ā āāā mock.ts
ā āāā database
ā ā āāā mock.ts
ā āāā routes
ā ā āāā access
ā ā ā āāā login
ā ā ā ā āāā integration.test.ts
ā ā ā ā āāā mock.ts
ā ā ā ā āāā unit.test.ts
ā ā ā āāā signup
ā ā ā āāā mock.ts
ā ā ā āāā unit.test.ts
ā ā āāā blog
ā ā āāā index
ā ā ā āāā mock.ts
ā ā ā āāā unit.test.ts
ā ā āāā writer
ā ā āāā mock.ts
ā ā āāā unit.test.ts
ā āāā .env.test
ā āāā setup.ts
āāā addons
ā āāā init-mongo.js
āāā keys
ā āāā private.pem
ā āāā public.pem
āāā .env
āāā .gitignore
āāā .dockerignore
āāā .eslintrc
āāā .eslintignore
āāā .prettierrc
āāā .prettierignore
āāā .travis.yml
āāā Dockerfile
āāā docker-compose.yml
āāā package-lock.json
āāā package.json
āāā jest.config.js
āāā tsconfig.json
/src ā server.ts ā app.ts ā /routes/index.ts ā /auth/apikey.ts ā schema.ts ā /helpers/validator.ts ā asyncHandler.ts ā /routes/access/signup.ts ā schema.ts ā /helpers/validator.ts ā asyncHandler.ts ā /database/repository/UserRepo.ts ā /database/model/User.ts ā /core/ApiResponses.ts
POST /signup/basic HTTP/1.1
Host: localhost:3000
x-api-key: GCMUDiuY5a7WvyUNt9n3QztToSHzK7Uj
Content-Type: application/json
{
"name" : "Janishar Ali",
"email": "[email protected]",
"password": "changeit",
"profilePicUrl": "https://avatars1.githubusercontent.com/u/11065002?s=460&u=1e8e42bda7e6f579a2b216767b2ed986619bbf78&v=4"
}
{
"statusCode": "10000",
"message": "Signup Successful",
"data": {
"user": {
"_id": "63a19e5ba2730d1599d46c0b",
"name": "Janishar Ali",
"roles": [
{
"_id": "63a197b39e07f859826e6626",
"code": "LEARNER",
"status": true
}
],
"profilePicUrl": "https://avatars1.githubusercontent.com/u/11065002?s=460&u=1e8e42bda7e6f579a2b216767b2ed986619bbf78&v=4"
},
"tokens": {
"accessToken": "some_token",
"refreshToken": "some_token"
}
}
}
{
"statusCode": "10001",
"message": "Bad Parameters"
}
GET /profile/my HTTP/1.1
Host: localhost:3000
x-api-key: GCMUDiuY5a7WvyUNt9n3QztToSHzK7Uj
Content-Type: application/json
Authorization: Bearer <your_token_received_from_signup_or_login>
{
"statusCode": "10000",
"message": "success",
"data": {
"name": "Janishar Ali Anwar",
"profilePicUrl": "https://avatars1.githubusercontent.com/u/11065002?s=460&u=1e8e42bda7e6f579a2b216767b2ed986619bbf78&v=4",
"roles": [
{
"_id": "5e7b8acad7aded2407e078d7",
"code": "LEARNER"
},
{
"_id": "5e7b8c22d347fc2407c564a6",
"code": "WRITER"
},
{
"_id": "5e7b8c2ad347fc2407c564a7",
"code": "EDITOR"
}
]
}
}
Copyright (C) 2024 JANISHAR ALI ANWAR
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.