Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5e89ca2
first commit
jadogeri Jan 6, 2025
5ba5ae1
Added index.ts template
jadogeri Jan 6, 2025
e468532
Added test route in server.ts
jadogeri Jan 6, 2025
6691cf3
Added User.ts
jadogeri Jan 6, 2025
e446d66
Fixed bugs in User.ts
jadogeri Jan 7, 2025
6733d51
converted constants.js to constants.ts
jadogeri Jan 7, 2025
55d8e40
Create node.js.yml
jadogeri Jan 7, 2025
3bf3369
Updated node.js.yml
jadogeri Jan 7, 2025
bbf3eb8
Update node.js.yml
jadogeri Jan 8, 2025
0ea8e70
Updated node.js.yml
jadogeri Jan 8, 2025
7e57455
Updated node.js.yml
jadogeri Jan 8, 2025
bf8cc50
Added global.d.ts
jadogeri Jan 8, 2025
ca65a39
updated helpful tips
jadogeri Jan 8, 2025
a1f021a
Added controller modules to userController directorys
jadogeri Jan 8, 2025
06a75ac
Added modules to userRoutes
jadogeri Jan 8, 2025
1f475e9
updated endpoint methods
jadogeri Jan 9, 2025
811895b
fixed bugs in loginUser.ts
jadogeri Jan 10, 2025
822d340
implemented currentUser.ts
jadogeri Jan 10, 2025
86332d5
updated contact routes
jadogeri Jan 10, 2025
ce65ec0
added api doc template
jadogeri Jan 12, 2025
9c6e823
Added APIManager class
jadogeri Jan 13, 2025
de4d657
Added helpers in APIManager.ts
jadogeri Jan 13, 2025
8565340
updated key in authService.ts
jadogeri Jan 13, 2025
5a226fa
Fixed bugs in authService.ts
jadogeri Jan 14, 2025
34acd01
Implemented reset user
jadogeri Jan 14, 2025
97d560a
added cors.ts
jadogeri Jan 14, 2025
6e96121
Added errorHandler.ts
jadogeri Jan 14, 2025
8bf170f
import interfaces from express
jadogeri Jan 14, 2025
41f6798
Fixed bugs in index.ts
jadogeri Jan 15, 2025
f2a4327
Fixed bugs in contactRoutes.ts
jadogeri Jan 15, 2025
003e325
fixed bugs in createContact.ts
jadogeri Jan 16, 2025
d9fe814
Deleted validateTokenHandler.js
jadogeri Jan 16, 2025
77393ff
fixed bugs in createContact.ts
jadogeri Jan 16, 2025
2bfdd3e
removed contactController.js
jadogeri Jan 17, 2025
beb8dca
removed template.js
jadogeri Jan 17, 2025
539f0ae
implemented get Contact by Id
jadogeri Jan 17, 2025
5228172
implemented update a contact
jadogeri Jan 17, 2025
961a788
removed temp file
jadogeri Jan 18, 2025
0433f79
Added interfaces to Request body
jadogeri Jan 21, 2025
4202ca1
Updated docs
jadogeri Jan 23, 2025
30504c1
Added deleteContactTest.ts
jadogeri Jan 23, 2025
2ec1c3d
completed tests
jadogeri Jan 24, 2025
3e63b8d
Update node.js.yml
jadogeri Jan 24, 2025
8ca16e8
Update node.js.yml
jadogeri Jan 24, 2025
5be2f4b
changed userController.test.ts to controllers.ts
jadogeri Jan 24, 2025
a19f51a
updated test
jadogeri Jan 24, 2025
c11e713
Merge branch 'main' of https://github.com/jadogeri/Contact_Management…
jadogeri Jan 24, 2025
3baa1ea
Added Dockerfile
jadogeri Jan 26, 2025
8b671dc
Updated README.MD
jadogeri Jan 26, 2025
258518c
removed output file
jadogeri Jan 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
tests
Dockerfile
.git
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CONNECTION_STRING=[YOUR MONGODB CONNECTION STRING]
ACCESS_TOKEN_SECRET=[JWT SECRET ]
PORT=[YOUR PORT NUMBER use 4000]
SALT_ROUNDS=[SALT ROUNDS AN INTEGER]
NANOID_SIZE=[NANOID SIZE AS INTEGER]
BASE_URL=[YOUR BASE URL]
2 changes: 0 additions & 2 deletions .github/FUNDING.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]
# 18.x, 20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
#- run: npm test
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.env

npm-debug.log*
yarn-debug.log*
yarn-error.log*
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:lts-alpine
WORKDIR /app
COPY package*.json /app
RUN npm install
COPY . /app
EXPOSE 4000
CMD npm run dev
205 changes: 203 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,203 @@
# Express_MongoDB_Rest_API_Tutorial
This is express & mongodb rest api tutorial for contact management app

# **System Design Document (SDD)**
## **Contact Management App**
**Version:** 1.1
**Date:** January 22, 2025

---

## Description
This is a Backend Application (Express + Node + Mongoose) which stores user information and contacts.


## Authors

- [@jadogeri](https://www.github.com/jadogeri)

## Screenshots

| ![Screenshot 1](assets/images/screenshot1.png) | ![screenshot 2](assets/images/screenshot2.png) |
| --------------------------------------- | --------------------------------------- |
| | |
![Screenshot 1](assets/images/screenshot3.png) | ![screenshot 2](assets/images/screenshot4.png) |
| --------------------------------------- | --------------------------------------- |
| | |
## Table of Contents

<ul>
<li><a href="#1-introduction">1. Introduction</a>
<ul>
<li><a href="#11-purpose">1.1 Purpose</a> </li>
<li><a href="#12-scope">1.2 Scope</a> </li>
<li><a href="#13-intended-audience">1.3 Intended Audience</a> </li>
</ul>
</li>
</ul>
<ul>
<li><a href="#2-api-reference">2. API Reference</a>
</li>
</ul>
<ul>
<li><a href="#3-system-architecture">3. System Architecture</a>
<ul>
<li><a href="#31-high-level-architecture">3.1 High Level Architecture</a> </li>
<li><a href="#32-technology-stack">3.2 Technology Stack</a> </li>
<li><a href="#33-deployment-artifacts">3.3 Deployment Artifacts</a> </li>
</ul>
</li>
</ul>
<ul>
<li><a href="#4-data-design">4. Data Design</a>
<ul>
<li><a href="#41-data-entities-and-relationships">4.1 Entities and Relationships</a> </li>
<li><a href="#42-database-conceptual-schema">4.2 Database Conceptual Schema</a> </li>
<li><a href="#33-deployment-artifacts">3.3 Deployment Artifacts</a> </li>
</ul>
</li>
</ul>
<ul>
<li><a href="#5-installation">5. Installation</a>
</li>
</ul>
<ul>
<li><a href="#6-usage">6. Usage</a>
<ul>
<li><a href="#61-run-locally">6.1 Run Locally</a> </li>
<ul>
<li><a href="#611-run-server-flask-application">6.1.1 Server (Flask Application)</a> </li>
</ul>
</ul>
</li>
</ul>
<ul>
<li><a href="#7-tests">7. Tests</a>
</li>
</ul>
<ul>
<li><a href="#8-license">8. License</a>
</li>
</ul>
<ul>
<li><a href="#9-references">9. References</a>
</li>
<ul>


## **1. Introduction**
### **1.1 Purpose**
This document outlines the system architecture, components, and design considerations for Unit Converter System. The goal is to provide a robust platform for individuals and businesses to calculate and convert to preferred units.

### **1.2 Scope**
The system will allow users to:
- Submit personal property declarations online.
- Integrate seamlessly with the parish tax collection system for calculations and payments.

### **1.3 Intended Audience**
- End Users (Individuals and Businesses)
- Junior or Senior backend developers.

---

## **2. API Reference**
* [Link to Documentation ](https://documenter.getpostman.com/view/40822092/2sAYQdkAQe#8e614d40-ca8d-4038-95ed-66c932ce2d5e)


## **3. System Architecture**
### **3.1 High-Level Architecture**
The system follows a **three-tier architecture**:
1. **Presentation Layer**: This layer directly interacts with incoming HTTP requests, defines routes using Express's routing mechanism, and sends back the final response to the client.
2. **Application Layer**: This layer encapsulates the core business logic, performing operations like data validation, calculations, and complex data manipulation, typically called by the route handlers in the presentation layer.
3. **Data Layer**: This layer handles communication with the database, performing CRUD operations to retrieve and store data.

![Architecture](assets/images/architecture.png)

### **3.2 Technology Stack**
- **Programming Languages**: Typescript, NOSQL, YAML
- **IDE**: Visual Studio Code (VSCode)
- **Backend Frameworks**: Node and Express
- **Database**: MongoDB
- **Test**: Jest, MockingGoose and Supertest
- **Container**: Docker
- **Security**: JSON Web Token (JWT), Bcrypt and Nanoid
- **Hosting**: Render.com
- **Source Control**: Git and GitHub
- **CI/CD**: GitHub Actions

### **3.3 Deployment Artifacts**
- **Database**: Collection of SQL scripts that are executed on a Sqlite3 database instance.
- **Backend Application**: Appllicationcontains everyting to build and run Express application instance on Render.com or build a Docker image, and run a Docker container on Render.com

---

## **4. Data Design**
### **4.1 Data Entities and Relationships**
|Entity|Description|
|-|-|
|USER|User account information used to authenticate users.|
|CONTACT|A person name and contactinformation.|
|AUTH|Saves authenticationinformation of Users.|

### **4.2 Database Conceptual Schema**
![Unit Converter Conceptual Diagram](<designs/conceptualdiagram.png>)

---
## **5. Installation**
* [Download and install NodeJS](https://nodejs.org/en/download)

---

## **6. Usage**
### **6.1 Run Locally**

1 Open command prompt or terminal.

2 Type command git clone https://github.com/jadogeri/Contact_Management_App.git then press enter.

```bash
git clone https://github.com/jadogeri/Contact_Management_App.git
```

3 Enter command cd Contact_Management_App then press enter.

```bash
cd Contact_Management_App
```

#### **6.1.1 Run Server (Express Application)**

1 Type npm install to install dependencies.

```bash
npm install
```
3 Type npm run dev to run server

```bash
npm run dev
```


---
## **7. Tests**

1. run test command below.

```bash
npm run tests
```
![tests](assets/images/tests.png)

---
## **8. License**

[LICENSE](/LICENSE)

---

## **9. References**

* FreeCodeCamp : [Frontend Web Development: (HTML, CSS, JavaScript, TypeScript, React)](https://www.youtube.com/watch?v=MsnQ5uepIa).
* Dipesh Malvia : [Learn Node.js & Express with Project in 2 Hours](https://www.youtube.com/watch?v=H9M02of22z4&t=140s).
* AweSome Open Source : [Awesome Readme Templates](https://awesomeopensource.com/project/elangosundar/awesome-README-templates)
* Readme.so : [The easiest way to create a README](https://readme.so/)
* Swagger : [Swagger API Documentation](https://swagger.io/docs/)
46 changes: 46 additions & 0 deletions api/APIManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { AxiosResponse } from "axios"
import api from "../configs/axios"
import { IAuth } from "../interfaces/IAuth"

export class APIManager{

static async addAuth(authData : Object, token : string) : Promise<AxiosResponse<any, any>>{
console.log("add auth from api manager.........................................")
return await api.post(process.env.BASE_URL+"/api/auths/add",authData,
{
headers:{
Authorization : `Bearer ${token}`
}
}
)
}

static async updateAuth(authData : Object, token : string) : Promise<AxiosResponse<any, any>>{
console.log("update auth from api manager.........................................")

return await api.put(process.env.BASE_URL+"/api/auths/update",authData,
{
headers:{
Authorization : `Bearer ${token}`
},

}
)
}

static async removeAuth(authData : IAuth, token : string) : Promise<AxiosResponse<any, any>>{
console.log("update auth from api manager.........................................")

return await api.delete(process.env.BASE_URL+"/api/auths/delete",
{
headers:{
Authorization : `Bearer ${token}`
},
data: authData
}
)
}


}

Loading