- Login: Secured hashed passowrd in db using bcrypt
- See comments without login
- Login to post comment
- Login to upvote/downvote on comments posted by other but not on their own.
- Can get to add only one upvote or downvote on a particular comment. To change vote one can remove previous vote and click on other type of vote.
- Can remove their own upvotes/downvotes.
- Logged in user can view their own votes highlighted.
- Logout
- Responsive
- express.js
- passport.js for authentication (server side sessions and cookies used)
- bcrypt for hashing
- realtional database : sqlite (Used objections.js (knex.js based) which can connect to MySql, Postgres etc. too)
- react.js + redux + semantic-ui for frontend UI
What ypu need before: Node 10+ LTS, npm, yarn, linux/mac needed
Clone this repo on your machine then follow the below instructions:
-
server backend
- Follow these steps
- Go to server folder using:
cd server
- Run tests in server folder using:
npm install
- Go to server folder using:
- Follow these steps
-
Frontend react app: You will need yarn package manager so install it before: https://yarnpkg.com/en/docs/install npm will also work fine but this react.js app's boilerplate was created using create-react-app utility which uses and recommend yarn so I stuck with it for frontend.
- Follow these steps
- Go to server folder using:
cd comment_spa
- Run tests in server folder using:
yarn install
- Go to server folder using:
- Follow these steps
Backend is tested a lot. Most of code and edge cases have been covered. Simple Non complex Code paths tests remain.
-
Unit tests
- Follow these steps
- Go to server folder using:
cd server
- Run tests in server folder using:
npm run test_unit
- Go to server folder using:
- Follow these steps
-
Integration tests
- Follow these steps
- Go to server folder using:
cd server
- Run tests in server folder using:
npm run test_integration
- Go to server folder using:
- Follow these steps
All tests will pass
Run server first.
-
server backend
- Follow these steps
- Go to server folder using:
cd server
- Run tdev backend server:
npm run dev_server
- Go to server folder using:
- Follow these steps
-
Frontend react app: You will need yarn package manager so install it before: https://yarnpkg.com/en/docs/install npm will also work fine but this react.js app's boilerplate was created using create-react-app utility which uses and recommend yarn so I stuck with it for frontend.
- Follow these steps
- Go to server folder using:
cd comment_spa
- Serve react app using:
yarn start
- Go to server folder using:
- Follow these steps
NOTE: During development the network requests or CORS issue due to different localhost ports of frontend and backend is solved using proxy feature (see package.json
of comment_spa) provided by create-react-app.
Login using any of these combination. Case sensitive.
-
Test user 1
- username: test1
- password: testpass1
-
Test user 2
- username: test2
- password: testpass2
-
Test user 3
- username: test3
- password: testpass3
-
Test user 4
- username: test4
- password: testpass4
https://drive.google.com/file/d/13jrPBvkZjIM0Cp0h86ZrttExFeImjwI1/view?usp=sharing Note: As a user can only vote once on a comment the Vote table must contain only one vote for a particular (comment id,user id) pair so it's defined as Composite Primary Key.
server/
backend codemodels/
contain model classes and methods that access database. Objections.js library used for modelscontrollers/
contain controller methods that take requests and call services and set responseservices/
Business logic separated as services in service folder so that controller are thin. services call models and their methods for DB access.tests/
Test files. Contain unit tests, integration tests and test data fixtures.seed/
Have files needed to seed data in database by knex.migration/
DB schema files defined and used by knexknexfile.js
connection configs for database.db/config.js
return instance of knex db connection. Needed to connect to database.app.js
express.js main app.js fileindex.js
files that make app start listening to port 4000.validators/
files validate incoming request before hitting to controllermiddlewares/
Authentication middleware files in this folder. Uses passport.jserrors/
Custom errors.package.json
Contains dependenciespackage-lock.json
Contain stable locked version of dependenciesroutes/
contain express router defined url routes files. Define which controller will handle request coming to a path or route.
comment_spa
frontend codesrc/
main src all work is done herecomponents/
folder contains all UI components.redux/
All data, API calls and app state related stuff in files under this folderactions.js
For making API calls and other UI actions.state.js
Intial state of app is defined herereducers.js
Catches actions and payload and modify and return new data state for components. UI changes based on state change produced by reducers.configureStore.js
Used for initialising store and applying middlewares like redux-thunks used for API Calls.
build/
contains prod builds whenyarn build
command is run