Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kr-arunp authored Sep 19, 2024
0 parents commit 20a3567
Show file tree
Hide file tree
Showing 78 changed files with 17,831 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.vscode
**/node_modules/
/dist
logs/
.git
*.md
.cache
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SECRET=xyz #helpul when you add authentication with your API but currently we are not using decodeToken Middleware
PORT=8000
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_USERNAME=default
REDIS_HOST=127.0.0.1
DATABASE_URI=mongodb://127.0.0.1:27017
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

dist/*
build/*
**/*.d.ts
/src/types/
node_modules
**/**/node_modules
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parser": "@typescript-eslint/parser",
"extends": ["plugin:@typescript-eslint/recommended"],
"parserOptions": { "ecmaVersion": 2018, "sourceType": "module" },
"rules": {}
}
18 changes: 18 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Docker Image CI

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

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
28 changes: 28 additions & 0 deletions .github/workflows/webpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: NodeJS with Webpack

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

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Build
run: |
npm install
npx webpack
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.env
dist
sample.txt
logs
log*
5 changes: 5 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
yarn commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint:fix && yarn format && npx lint-staged
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20
14 changes: 14 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules
build
.yarn
.husky
**/**/node_modules
*.lock
*.log
.gitignore
.npmignore
.prettierignore
.DS_Store
.eslintignore
.npmrc
.nvmrc
30 changes: 30 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"bracketSpacing": true,
"printWidth": 80,
"proseWrap": "preserve",
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 4,
"useTabs": true,
"parser": "typescript",
"arrowParens": "always",
"requirePragma": true,
"insertPragma": true,
"endOfLine": "lf",
"overrides": [
{
"files": "*.json",
"options": {
"singleQuote": false
}
},
{
"files": ".*rc",
"options": {
"singleQuote": false,
"parser": "json"
}
}
]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"editor.suggest.snippetsPreventQuickSuggestions": false,
"aiXcoder.showTrayIcon": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": ["source.fixAll.format", "source.fixAll.eslint"],
"editor.tabSize": 2,
"cSpell.words": ["Parens", "plusplus"]
}
Binary file added .yarn/install-state.gz
Binary file not shown.
925 changes: 925 additions & 0 deletions .yarn/releases/yarn-4.4.1.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.4.1.cjs
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ubuntu


RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get upgrade -y
RUN apt-get install -y nodejs

COPY package.json package.json
COPY package-lock.json package-lock.json
COPY src src
COPY tsconfig.json tsconfig.json
COPY .env .env

COPY nodemon.json nodemon.json

RUN npm install -g ts-node nodemon
RUN npm install ts-node --save-dev
RUN npm install typescript -g
RUN npm install typescript --save-dev
ENV PORT 8000
ENV SECRET 123
ENV ADMIN_EMAIL [email protected]

EXPOSE 8000:8000

CMD ["nodemon", "src/server.ts"]
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Ultimate Backend API Starter Kit
### A robust and production-ready backend API starter kit built with TypeScript, Express.js,Zod and Mongoose.

## Features
- Type-safe API development with TypeScript,Zod for schema validation.
- Caching Layer using Redis.
- Seamless data modeling and interaction with MongoDB using Mongoose.
- TypeSafe Environment configuration.
- Auth using JWT Strategy or passport.
- Helmet middleware for Strong security headers.
- Cors middleware for Cross-Origin Resource Sharing.
- Rate limiting middleware for enhanced security using express-rate-limit with redis for centralized storage.
- Streamlined error handling and logging using custom httpResponse ,Global Error Handler and httpError.
- Logging (With Colorful Terminal) with winston for better debugging and monitoring.
- Linting,Husky,eslint,prettier,commitlint for code quality.
- Server Health Monitoring using Custom API endpoint.
- Github Actions for CI/CD.
- Docker support for containerized deployment
- MVC Architecture.
- WebSocket Support using ws package (optional).


## Prerequisites

- Node.js (version 18 or higher)
- yarn
- Redis
- MongoDB

## Installation

1. Clone the repository:
```
git clone https://github.com/arunkumar201/rest-api-using-ts.git
```
2. Navigate to the project directory:
```
cd rest-api-using-ts
```
3. Install dependencies:
```
yarn install
```

## Configuration
- Create a `.env` file in the root of the project according to `.env.example` and add the following environment variables:

## Running the Application

To start the server in development mode:
```
yarn dev
```
For production:

```
yarn build
yarn start:prod
```
## Contributing
- Fork the repository
- Create a new branch
- Make your changes
- Create a pull request
7 changes: 7 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
ignores: [message => message.includes('WIP')],
rules: {
'header-max-length': [0, 'always', 200], // [!code focus]
}
};
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'
services:
rest-api-ts:
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:8000"
depends_on:
- mongo

mongo:
image: mongo:latest
ports:
- "27017:27017"
58 changes: 58 additions & 0 deletions example-tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"lib": [
"DOM",
"ES2015"
],
"baseUrl": ".",
"outDir": "./build",
"rootDir": ".",
"strict": true,
"noImplicitAny": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"moduleResolution": "node",
"esModuleInterop": true,
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"pretty": true,
"resolveJsonModule": true,
"plugins": [
{
"transform": "typescript-transform-paths"
},
{
"transform": "typescript-transform-paths",
"afterDeclarations": true
}
],
"paths": {
"@auth/*": [
"src/features/auth/*"
],
"@user/*": [
"src/features/user/*"
],
"@global/*": [
"src/shared/globals/*"
],
"@service/*": [
"src/shared/services/*"
],
"@socket/*": [
"src/shared/sockets/*"
],
"@worker/*": [
"src/shared/workers/*"
],
"@root/*": [
"src/*"
]
}
}
}
5 changes: 5 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"watch":["src"],
"ext":".ts,.js",
"exec":"ts-node ./src/index.ts"
}
Loading

0 comments on commit 20a3567

Please sign in to comment.