Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Archit404Error authored Sep 30, 2023
0 parents commit 8fcfb57
Show file tree
Hide file tree
Showing 47 changed files with 14,132 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Users who will be automatically be notified & added as reviewers when a PR is made (should be TL)

* @Archit404Error

# Change the user above as necessary
35 changes: 35 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!-- IF A SECTION IS NOT APPLICABLE TO YOU, PLEASE DELETE IT!! -->

<!-- Your title should be able to summarize what changes you've made in one sentence. For example: "Exclude staff from the check for follows". For stacked PRs, please indicate clearly in the title where in the stack you are. For example: "[Eatery Refactor][4/5] Converted all files to MVP model" -->

## Overview

<!-- Summarize your changes here. -->

## Changes Made

<!-- Include details of what your changes actually are and how it is intended to work. -->

## Test Coverage

<!-- Describe how you tested this feature. Manual testing and/or unit testing. Please include repro steps and/or how to turn the feature on if applicable. -->

## Next Steps (delete if not applicable)

<!-- If this is part of a multi-PR change, please describe what changes you plan on addressing in future PRs. -->

## Related PRs or Issues (delete if not applicable)

<!-- List related PRs against other branches/repositories. -->

## Screenshots (delete if not applicable)

<!-- This could include of screenshots of the new feature / proof that the changes work. -->

<details>

<summary>Screen Shot Name</summary>

<!-- Insert file link here. Newlines above and below your link are necessary for this to work. -->

</details>
21 changes: 21 additions & 0 deletions .github/workflows/depend-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Dependabot PR Merge"

on:
workflow_dispatch:

jobs:
combine-prs:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: maadhattah/combine-dependabot-prs@main
with:
branchPrefix: "dependabot"
mustBeGreen: true
combineBranchName: "combined-prs"
includeLabel: ""
ignoreLabel: "nocombine"
baseBranch: "main"
openPR: true
allowSkipped: false
githubToken: ${{ secrets.WORKFLOW_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/jestci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Jest CI

on:
push:
branches: ["main"]
paths: ["backend/**"]
pull_request:
branches: ["main"]
paths: ["backend/**"]

jobs:
test:
runs-on: ubuntu-latest

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

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
cache-dependency-path: ./backend/yarn.lock
node-version: ${{ matrix.node-version }}
cache: "yarn"
- name: Setup Dotenv, Dependencies, and Run Tests
working-directory: ./backend/
run: |
echo 'NODE_ENV = "test"' > .env
echo 'DEV_URI = "${{ secrets.MONGO_DEV }}"' >> .env
yarn install
yarn test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
.env
secrets/
node_modules/
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# MERN Starter

This repository provides an opinionated, pre-configured project setup for a MERN webapp's frontend and backend components.

The frontend and backend both make use of TypeScript, and the repository comes pre-packaged with testing, continuous integration workflows, auto-PR requesting (CODEOWNERS), and a PR template

The frontend and backend repos each have a README to help you get started with the project.

To get started, either fork this repo or clone using `git clone https:/Archit404Error/MERN-webapp`
3 changes: 3 additions & 0 deletions backend/.envtemplate
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE_ENV = "[insert here]"
DEV_URI = "[insert here]"
PROD_URI = "[insert here]"
23 changes: 23 additions & 0 deletions backend/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"singleAttributePerLine": false,
"bracketSameLine": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/Users/archit/Downloads/mern-base/backend/src/index.ts",
"parser": "typescript"
}
12 changes: 12 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:16

RUN mkdir /usr/app
WORKDIR /usr/app

COPY yarn.lock .
COPY package.json .

RUN yarn install
COPY . .
EXPOSE 3000
CMD ["yarn", "start"]
39 changes: 39 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# MERN Starter Backend

Welcome to this MERN boilerplate repo's backend. The backend is centered around the MVC (model-view-controller) design pattern, intended to decouple code and reduce potential errors with the system.

The backend also comes preconfigured with a jest test suite that will execute on PR creation.

## Getting Started

Start off by copying `.envtemplate` and renaming the copy to `.env`. Configure the node env and mongo dev/prod URI's based on your current environment and secrets.

If you don't have yarn and/or node on your system, run `brew install yarn`. Alternatively, if you already have node you can also run `sudo npm i -g yarn`.

Now, run `yarn install` to install all dependencies. Once that finishes, you're all set to run the backend!

Simply use `yarn dev` to begin running the dev server locally, or `yarn build` to create a production build that can be run using `yarn start`

Use `yarn test` to run the jest test suite (will automatically run on PR creation).

## MVC Design Pattern

This backend is centered around the Model-View-Controller design pattern, meaning that each "entity" of your application should have its own folder where necessary models, views, and controllers are specified.

The breakdown of these three types of functions/files is as follows:
- Models -- classes that define our DB schema and structure of our data
- Controllers -- functions that interact with the models to modify specific attributes/pieces of data
- Views -- routes that the user can interact with which make use of controllers to perform a specific action.

Structuring our code in this way decouples the system by introducing modularity. It ensures that we rarely encounter breaking changes and that we have a clean separation of duties for progrmamers. Moreover, it allows us to enforce a predictable design pattern that speeds up onboarding and development on a team.

## Using Docker
This backend can also be easily dockerized. Once you've created your env file, simply run `docker compose up -d` or `docker compose up` to start up the application (make sure the docker daemon is running).

If this fails, try running `docker system prune`. The application should begin running at port 3000 on your local machine.

## Database Structure

This backend makes use of MongoDB, a NoSQL database that heavily emphasizes data nesting as opposed to data references. An examples of this can be seen in `customers/models.ts` with the Customer and Job classes. To read more about this, check out <a href="https://www.mongodb.com/docs/manual/core/data-modeling-introduction/">this page</a> on the MongoDB website about various schema structures.

Generally speaking, embedding documents yields far speedier responses from MongoDB as opposed to traditional id references as used in SQL databases. Therefore, when creating new models it is important to continue using nested data across various collections and documents.
192 changes: 192 additions & 0 deletions backend/api-spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "My API",
"description": "Documentation automatically generated by the <b>swagger-autogen</b> module."
},
"host": "localhost:3000",
"basePath": "/",
"tags": [
{
"name": "User",
"description": "Endpoints"
}
],
"schemes": [
"http",
"https"
],
"securityDefinitions": {
"apiKeyAuth": {
"type": "apiKey",
"in": "header",
"name": "X-API-KEY",
"description": "any description..."
}
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/": {
"get": {
"description": "",
"parameters": [],
"responses": {
"200": {
"description": "OK"
}
}
},
"post": {
"description": "",
"parameters": [],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/users/": {
"get": {
"description": "",
"parameters": [],
"responses": {
"200": {
"description": "OK"
}
}
},
"post": {
"description": "",
"parameters": [],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/customers/": {
"get": {
"tags": [
"Customers"
],
"description": "",
"parameters": [],
"responses": {
"200": {
"description": "OK"
}
}
},
"post": {
"tags": [
"Customers"
],
"description": "",
"parameters": [
{
"name": "body",
"in": "body",
"schema": {
"type": "object",
"properties": {
"name": {
"example": "any"
},
"age": {
"example": "any"
},
"title": {
"example": "any"
},
"company": {
"example": "any"
}
}
}
}
],
"responses": {
"201": {
"description": "Created"
}
}
}
},
"/customers/{id}": {
"get": {
"tags": [
"Customers"
],
"description": "",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/customers/updateName/{id}": {
"put": {
"tags": [
"Customers"
],
"description": "",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"schema": {
"type": "object",
"properties": {
"name": {
"example": "any"
}
}
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/customers/resetAges": {
"post": {
"tags": [
"Customers"
],
"description": "",
"parameters": [],
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
}
Loading

0 comments on commit 8fcfb57

Please sign in to comment.