Skip to content

This project is a ToDo List application built using Node.js. It is made following the principles of hexagonal architecture and vertical slicing. It provides an interface for managing tasks. The application files are located in domain, application and infrastructure layers, depending on their functionality. The app connects to MongoDB.

Notifications You must be signed in to change notification settings

OllinDesigns/toDoCleanArchitecture

Repository files navigation

toDoCleanArchitecture

  • Node.js Project

This project is a ToDo List application built using Node.js. It is made following the principles of hexagonal architecture and vertical slicing. It provides an interface for managing tasks. The application files are located in domain, application and infrastructure layers, depending on their functionality. The app connects to MongoDB.

Getting Started

To get started with the application, follow these steps:

  1. Clone the repository to your local machine.

  2. Install the required dependencies by running the following command:

    npm install
    
  3. Build the application using TypeScript by running:

    npm run build
    
  4. To start the application, in the root folder type:

    npm start
    

You should see the messages "Gurrus is using express and sleeping in port 3000" and "Gurrus says hello from MongoDB." if the application is initialized correctly.

  1. Open your web browser and visit http://localhost:3000/tasks to access the MongoDB collection.

MongoDb

The file src/infrastructure/db.ts is responsible for the connection settings to the database. It uses an .env file to protect the connection string of every user. It works as follows:

Setup .env

Create a file .env in the root directory. The contens should be only this.

MONGO_CONNECTION_STRING=mongodb+srv://(yourMongoDBAtlasUserName):(yourMongoDbAtlasPassword).1b2ylxi.mongodb.net/(nameOfYourCollection)?retryWrites=true&w=majority.

Replace yourMongoDBAtlasUserName with your MongoDB Atlas user name, delete the parenthesis.

Replace yourMongoDbAtlasPassword with your MongoDB Atlas password, delete the parenthesis.

Replace nameOfYourCollection with the name you want to give to this collection. This is very important to locate and handle your connection in Atlas. Delete the parenthesis.

You can do this by going into your Atlas User home page. Then choose a Cluster. Then click on Connect (beside the chosen cluster). Then choose Connect to your application, Driver: Node.js. MongoDB proposes a connection string that should be modified with the things mentioned above.

If everything works correctly, you will see your chosen collection name under your chosen Cluster when you click "Browse collections".

Routes

The routes are defined under src/infrastructure/routes.

1: http://localhost:3000/tasks : route to the collection "toDolistCA". This is my chosen name for my MongoDB colection. It handles a GET HTTP request.

2: http://localhost:3000/posts/tasks : route for making a POST HTTP request in Postman.

3: http://localhost:3000/tasks/giveIdOfAnExistingTask : route for handling HTTP put request. Replace giveIdOfAnExistingTask with the id of an exisiting task. Must be an Id generated by MongoDb.

4: http://localhost:3000/tasks/giveIdOfAnExistingTask : Route for handling a DELETE HTTP request. Replace giveIdOfAnExistingTask with the id of an exisiting task.

Postman

This project is tested with Postman. Here a link to test the HTTP requests of my project.

Run in Postman

  • note: for a POST HTTP request use addTakswithbetterroutes instead of addTask. addTakswithbetterroutes has the right toutes

Dependencies and Development Dependencies

Check my package.json

Testing

To run the tests, use the following command:

npm test

The tests are written using Jest and are located in the tests directory.

Scripts

  • npm run dev # run the "dev" package script

  • npm run tsc: Trnaspiles Typescript files into JavaScript files. this happens in the folder src/dist.

  • npm test: run jest test

Contribution

to this project are welcome! If you find any issues or want to add new features, feel free to create a pull request or submit an issue.

Happy ToDoListing! 🚀

About

This project is a ToDo List application built using Node.js. It is made following the principles of hexagonal architecture and vertical slicing. It provides an interface for managing tasks. The application files are located in domain, application and infrastructure layers, depending on their functionality. The app connects to MongoDB.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published