This repository acts as the backend API and database setup for a local environment. The architecture is as follows:
┏━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━┓
┃ ┃ -------------------> ┃ ┃ -----------------> ┃ ┃
┃ ┃ [HTTP Requests] ┃ ┃ [DB Requests] ┃ ┃
┃ Frontend ┃ ┃ Backend ┃ ┃ Database ┃
┃ Server ┃ ┃ Server ┃ ┃ Instance ┃
┃ ┃ [HTTP Responses] ┃ ┃ [DB Responses] ┃ ┃
┃ ┃ <------------------- ┃ ┃ <----------------- ┃ ┃
┗━━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━┛
React Express.js MongoDB
Tailwind Mongoose/MongoDB Docker
Next.js Docker
- Technologies
- Contribution Guidelines
- Laptop Setup + Application Installations
- Running the Project
- Troubleshooting
Git / Github Desktop
We use Git for version control. We use Github Desktop as a UI to interface with GitDocker Desktop
We use Docker to containerize our projects, and deploy them in neutral environments that are OS independent.NVM / NPM / Node.js
We use NVM to manage our NPM versions. We use NPM to manage our dependencies for the project.MongoDB Compass
We use MongoDB Compass to view our database instance.Visual Studio Code
We are in favour of using VS Code for web development for its lightweight experience and useful extensions.
Express.js
We use Express.js to build our web server.MongoDB / Mongoose
We use MongoDB for our database, and Mongoose in order to validate data going in and out of the database.Jest + Supertest
We use Jest and Supertest as our testing libraries, to test endpoints on our Express.js server.
: We are not accepting issues or PRs made from outside collaborators at the moment. If you wish to report a bug, or become a collaborator, please send an email to [email protected]
-
Find a 'New Ticket' you find interesting from the Project Board, and ask to be assigned.
-
Once assigned, create a new branch off
main
named with the issue number and the ticket name formatted as follows:- "IssueNumber-name-of-ticket"
- Example:
14-post-request-to-database-for-articles
-
Work on your branch, commit and push when necessary. Be descriptive and clear with your commit messages.
-
Once finished, create a pull request to merge into the
main
branch. The pull request should properly fill out the PR template. -
An admin will review your ticket, and either approve your changes, or request changes. If changes requested, checkout to your branch and make requested changes.
Note: Code will be thoroughly reviewed - we uphold a code quality standard at NU Sci:
- You will be asked to explain your reasoning to be approved.
- You must have proper and clear formatting on all changes in the code.
- You must not have extraneous code / code not relevant to the ticket in the pull request.
- The code must be well-documented and commented.
- The code must conform to the design patterns and choices already existing in the code.
- The code must pass all tests, as well as have new tests defined for new or adjusted functionality.
It often requires multiple rounds of review in order for a pull request to be merged.
- If you're new to web development, please refer to the MacOS Setup or the Windows Setup steps.
- If your laptop is set up, start at the Application Installation section.
- On MacOS you can install Git two ways: Git Installer or Xcode CLT. If you are a developer working on other projects, we recommend installing Xcode CLT for its utilities, but we only need to have Git.
- Required: MacOS v10.9+
- Run the following command, and follow the prompts to install:
git --version
- Run the following command to install Xcode Command Line Tools, which comes prepackaged with Git:
xcode-select --install
- To verify you have Xcode Command Line Tools installed, run the command:
xcode-select --version
- Run the following command to install Homebrew, a Linux/MacOS package manager:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- To verify you have Homebrew installed, run the command:
brew -v
- Run the following command to install NVM, a version manager for Node Package Manager:
brew install nvm
- To verify you have NVM installed, run the command:
nvm -v
- Run the following command to install version 22 of Node.js, a dependency installer for Javascript:
nvm install 22
- Use the installed version of Node.js
nvm use 22
- To verify you have NPM installed, run the command:
npm -v
4. Go to the Application Installation section, and continue following the steps.
- Follow the steps to install Git
- Follow the steps to install version 22.x.x of Node.js, which comes prepackaged with NPM, a dependency installer for Javascript
3. Go to the Application Installation section, and continue following the steps.
- This section defines applications you will need to run / develop the project.
- Follow the steps to install Visual Studio Code
- Launch Visual Studio Code.
- Navigate to the 'Extensions' tab, and download the following:
- Jest
- Prettier
- Live Share
- Follow the steps to install Github Desktop
- Launch Github Desktop, and go to 'Settings'.
- Click the 'Git' tab, and connect to your Github account to the application.
- Follow the steps to install Docker Desktop
- Launch Docker Desktop, no need to sign in or create an account.
- Follow the steps to install MongoDB Compass
- Launch MongoDB Compass.
- To build and run the project locally, refer to the Running the Project section.
- This section defines how to start up the project, and run it on your local machine.
- Navigate to this page, and click the "Code" button. Click the "HTTPS" tab, and copy the repository URL.
- Open Github Desktop, and click the "Add" option, and then "Clone Repository". Select the "URL" option, and paste the URL from Github.
- Open the project directory in Visual Studio Code by either clicking "Open in Visual Studio Code" on Github Desktop, or launching Visual Studio Code, clicking "Open Folder", and navigating to the directory in which you cloned the project.
- Add the
.env
file to the root directory. This will define our important secret keys we use for authentication, and initialization of the project.
- Open the terminal in VS Code and ensure that your current directory is the root of the project.
- Run the following command to install the project dependencies:
npm i
- Run the following Docker Image Command in the terminal at root directory. This command will build the Docker Image defined in your root directory from the Dockerfile, and will pull from the mongo:lastest image from the internet. It will build the compose project using the instructions defined in the
docker-compose.yaml
file.
docker compose up -d
-
Test your environment, verify your docker compose project is running and navigate to localhost:9999 to check your connection to the API. Also, navigate to localhost:9999/db to check your connection to the local database instance.
-
Run the command to initialize database data:
npm run reset
- Run the command to run the project testing suite:
npm run test
- To view the database, launch MongoDB Compass. Go to the
.env
file, and copy the connection string. Paste it into the Compass URI box, and click 'Connect'. You should be able to view all the seeded collections.
- Congrats, you have successfully run the project! Feel free to ask for a ticket assignment so you can get started on development!
- For any futher explanations / help, reach out to the heads of software & web.
- If you cannot successfully connect to the database endpoint, install mongosh.
mongosh
- Then, in the Mongo Shell, run these commands:
use admin
db.createUser({user: "nusci", pwd:"mongodb", roles:[{role:"readWrite", db:"Admin"}]})
- Make sure the Docker Compose Project is running in Docker Desktop, and that you have no other projects running on the following ports:
- 9999
- 27017