-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from brunotot/md-repository-refactor
Md repository refactor
- Loading branch information
Showing
28 changed files
with
682 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
## Features |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
## Installation | ||
|
||
### GitHub repository setup | ||
|
||
1. Create new repository from `@mern-monorepo-starter` template [here](https://github.com/new?template_name=monorepo-mern-railway-starter&template_owner=brunotot). | ||
|
||
2. Navigate to **Repo > Settings > Actions - General** and save the following Workflow-related options: | ||
|
||
1. `Read and write permissions` checked | ||
2. `Allow GitHub Actions to create and approve pull requests` checked | ||
|
||
3. Now GitHub actions are ready for usage. Let's now re-run the autogenerated TypeDoc workflow so it generates the `gh-pages` branch. Navigate to **Repo > Actions > MERN Sample App - TypeDoc** and click on **Run workflow** | ||
|
||
4. After the `gh-pages` branch is generated, navigate to **Repo > Settings > Pages** and save the `gh-pages` branch as the deployment branch. | ||
|
||
5. That's it! Now your GitHub repository is ready to be used for deployment | ||
|
||
### Local installation | ||
|
||
1. Clone the previously created repository to your local machine | ||
|
||
```sh | ||
git clone https://github.com/REPO_USER/REPO_NAME.git | ||
``` | ||
|
||
2. Change directory to the cloned one from Step **#1** | ||
|
||
```sh | ||
cd REPO_NAME | ||
``` | ||
|
||
3. Install local packages and run prepare scripts | ||
|
||
```sh | ||
pnpm install | ||
``` | ||
|
||
4. That's it! Now you may open the project in **VSCode** | ||
```sh | ||
code . | ||
``` | ||
### Railway setup | ||
1. Create an account on Railway [here](https://railway.app/login) | ||
2. Install `@railway/cli` if you don't have it already | ||
|
||
```sh | ||
npm i -g @railway/cli | ||
``` | ||
|
||
3. Now you have access to the **railway** command. See [Railway CLI documentation](https://docs.railway.app/reference/cli-api) | ||
|
||
```sh | ||
railway --help | ||
``` | ||
|
||
4. Login to Railway CLI | ||
|
||
```sh | ||
railway login | ||
``` | ||
|
||
5. Create a new Railway project | ||
|
||
```sh | ||
railway init | ||
``` | ||
|
||
6. Setup created project through Railway's website (the link will be printed to the console) | ||
<!-- > [!WARNING] | ||
> To gain access to Railway Deployments you should upgrade your Railway account to at least a Hobby tier ($5.00 / month). --> | ||
- setup **MongoDB** service | ||
1. create MongoDB service by clicking on **New > Database > Add MongoDB** | ||
2. under **MongoDB Service > Data** create `test` database | ||
3. under **MongoDB Service > Data** create `production` database | ||
4. under **MongoDB Service > Data** create `development` database | ||
5. under **MongoDB Service > Variables** section, find and store the value of `MONGO_URL` locally | ||
- setup **Backend** service - **Express app** | ||
> [!WARNING] | ||
> Incoming steps require at least a `Hobby` plan on the Railway account (lowest priced at $5/month) | ||
1. create Backend service by clicking on **New > GitHub Repo** | ||
2. connect your repository to your Railway project | ||
3. edit service name to `Backend` | ||
- setup **Frontend** service - **React app** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env node | ||
|
||
import "zx/globals"; | ||
import inquirer from "inquirer"; | ||
|
||
const TEMPLATE_REPO = "brunotot/monorepo-mern-railway-starter"; | ||
|
||
const { ownerHandle, repoHandle, repoVisibility, repoDescription } = await inquirer.prompt([ | ||
{ | ||
name: "ownerHandle", | ||
message: "[1/4] Your GitHub username:", | ||
default: "brunotot", | ||
}, | ||
{ | ||
name: "repoHandle", | ||
message: "[2/4] Repository name:", | ||
default: "my-mern-monorepo", | ||
}, | ||
{ | ||
name: "repoVisibility", | ||
message: "[3/4] Repository visibility:", | ||
choices: ["Public", "Private", "Internal"], | ||
type: "list", | ||
}, | ||
{ | ||
name: "repoDescription", | ||
message: "[4/4] Repository description:", | ||
default: "", | ||
}, | ||
]); | ||
|
||
try { | ||
const res = | ||
await $`gh repo create ${repoHandle} --template ${TEMPLATE_REPO} --${repoVisibility.toLowerCase()} --description ${repoDescription ?? " "}`; | ||
console.log(res.stdout); | ||
} catch (error) { | ||
console.log(error); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "create-mern-monorepo", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.mjs", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"bin": { | ||
"create-mern-monorepo": "index.mjs" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"inquirer": "^9.2.21", | ||
"zx": "^8.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
/* @org/backend/config/managers */ | ||
export * from "./managers/InjectorMetadataManager"; | ||
export * from "./managers/JwtManager" | ||
|
||
/* @org/backend/config/singletons */ | ||
export * from "./singletons/ServiceRegistry"; | ||
export * from "./singletons/Environment"; | ||
export * from "./singletons/ServiceRegistry"; | ||
export * from "./singletons/Logger"; | ||
export * from "./singletons/MongoClient"; | ||
export * from "./singletons/RouterCollection"; | ||
|
||
/* @org/backend/config/managers */ | ||
export * from "./managers/InjectorMetadataManager"; | ||
export * from "./managers/JwtManager" | ||
export * from "./managers/DatabaseManager" | ||
|
||
/* @org/backend/config/setup */ | ||
import "./setup"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Environment } from "@org/backend/config/singletons/Environment"; | ||
import { type Db } from "mongodb"; | ||
import { type ZodSchema, type z } from "zod"; | ||
import server from "@org/backend/server"; | ||
|
||
export class DatabaseManager { | ||
private static instance: DatabaseManager; | ||
|
||
static getInstance() { | ||
this.instance ??= new DatabaseManager(); | ||
return this.instance; | ||
} | ||
|
||
#client: Db; | ||
|
||
private constructor() { | ||
// NOOP | ||
} | ||
|
||
get client() { | ||
if (this.#client) return this.#client; | ||
this.#client = server.mongoClient.db(Environment.getInstance().vars.MONGO_DATABASE); | ||
return this.#client; | ||
} | ||
|
||
collection<const T extends ZodSchema>(zodSchema: T) { | ||
const documentName = zodSchema.description; | ||
if (!documentName) throw new Error("No document name provided."); | ||
const lowerCaseName = documentName.toLowerCase(); | ||
const suffix = "s"; | ||
const computedSuffix = lowerCaseName.endsWith(suffix) ? "" : suffix; | ||
const name = lowerCaseName + computedSuffix; | ||
return this.client.collection<z.infer<T>>(name); | ||
} | ||
} |
Oops, something went wrong.