Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
backend/test-db-data
backend/db-data
backend/node_modules
backend/build

frontend/node_modules
frontend/.pnp
frontend/.pnp.js

# testing
frontend/coverage

# production
frontend/build

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

frontend/npm-debug.log*
frontend/yarn-debug.log*
frontend/yarn-error.log*
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
### Note: You will find another readme file in each folder with specific instructions about how to run the apps.

# Limbic Fullstack Code Challenge

This is Limbic’s FullStack Challenge that combines bits from the frontend and backend challenges in one.

Jane is a clinical therapist and wants her clients to answer simple questionnaires in order to better understand them. She needs a way to add/delete/edit questions and also see the answers of each client.

## Backend
## Backend

You are tasked with writing an API to create/edit/delete Users, Questions, and Answers. It should be a NodeJS/ExpressJS server with the following endpoints:

Expand Down Expand Up @@ -62,7 +64,6 @@ You are tasked with writing a React/React Native app to consume the backend API.

You can use anything you want for state management. We use MobX and the Context API a lot so it's a big plus if you can also **implement some/all of the state handling with MobX and Context API**.


## Instructions

1. **Submitting Code**
Expand Down
23 changes: 23 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# https://hub.docker.com/_/node
FROM node:18-alpine as build

# Create and change to the app directory.
WORKDIR /usr/src/app

COPY package*.json ./

# Install dependencies
RUN npm install

# Copy local code to the container image.
COPY . ./

# Env variables
ENV PORT=80
ENV TZ=UTC

# Build the application
RUN npm run build

# Run the web service on container startup.
CMD [ "npm", "run", "start:prod" ]
33 changes: 33 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Jane is a clinical therapist and wants her clients to answer simple questionnaires in order to better understand them. She needs a way to add/delete/edit questions and also see the answers of each client.

This is a simple API to create/edit/delete Users, Questions, and Answers.

# Setup

To run the app locally you will first need to create the database. There is a docker-compose.yml file that creates 2 Databases (1 for tests and the other for local development).
If we wanted to deploy to a production DB we would need to connect to a AWS RDS or similar (I skipped that part for this demo).

# Create the Postgres DB container (Check docker-compose to see the details)

docker-compose up -d

# Seed the DB with some users (Keep in mind that it will drop the current DB)

npm run seed:users

# Run the tests

I've written some end to end tests, the tests hit a testing database that is recreated and pre-populated with mock data for each test.
We could also write some unit tests but for this project we did not have much business logic to test so I just went with the end to end ones.

npm run test

# Start the server

npm run start

# Observations

I've tried to structure the code in different folder separating concerns to make it easier to read. I used Sequelize for simplicity but I also like TypeOrm for bigger projects. (requires dependency injection setup)

There is a config file with the DB configurations, ideally we shouldn't commit users and passwords to the repo, we could use AWS Secrets instead, but for this example I just kept it simple.
13 changes: 13 additions & 0 deletions backend/config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"database": {
"name": "limbic",
"dialect": "postgres",
"username": "limbic_user",
"password": "1234",
"port": 5432,
"host": "localhost",
"logEnabled": true,
"forceSync": false
}
}

13 changes: 13 additions & 0 deletions backend/config/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"database": {
"name": "limbic_test",
"dialect": "postgres",
"username": "limbic_test_user",
"password": "1234",
"port": 5433,
"host": "localhost",
"logEnabled": false,
"forceSync": true
}
}

25 changes: 25 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.1'

services:
db:
image: postgres:13
restart: always
volumes:
- ./db-data:/var/lib/postgresql/data
environment:
POSTGRES_DB: limbic
POSTGRES_USER: limbic_user
POSTGRES_PASSWORD: "1234"
ports:
- 5432:5432
testDb:
image: postgres:13
restart: always
volumes:
- ./test-db-data:/var/lib/postgresql/data
environment:
POSTGRES_DB: limbic_test
POSTGRES_USER: limbic_test_user
POSTGRES_PASSWORD: "1234"
ports:
- 5433:5432
5 changes: 5 additions & 0 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
};
Loading