{"id":14957533,"url":"https://github.com/panagiop/node.js-clean-architecture","last_synced_at":"2025-05-15T00:08:20.854Z","repository":{"id":39604858,"uuid":"249538012","full_name":"panagiop/node.js-clean-architecture","owner":"panagiop","description":"A use case of Clean Architecture in Node.js comprising of Express.js, MongoDB and Redis as the main (but replaceable) infrastructure.","archived":false,"fork":false,"pushed_at":"2025-04-25T04:30:55.000Z","size":157,"stargazers_count":1038,"open_issues_count":5,"forks_count":193,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-25T05:31:28.381Z","etag":null,"topics":["clean-architechture","crud","expressjs","microservice","mongodb","nodejs","rest-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/panagiop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-23T20:33:16.000Z","updated_at":"2025-04-24T04:59:07.000Z","dependencies_parsed_at":"2023-12-07T09:24:43.647Z","dependency_job_id":"cfe5c137-6bbb-48ee-86eb-3d9d3a60a556","html_url":"https://github.com/panagiop/node.js-clean-architecture","commit_stats":{"total_commits":95,"total_committers":2,"mean_commits":47.5,"dds":0.03157894736842104,"last_synced_commit":"c17007a6d82dc2801529ee2e9ff78745fff925fc"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panagiop%2Fnode.js-clean-architecture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panagiop%2Fnode.js-clean-architecture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panagiop%2Fnode.js-clean-architecture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panagiop%2Fnode.js-clean-architecture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/panagiop","download_url":"https://codeload.github.com/panagiop/node.js-clean-architecture/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254249201,"owners_count":22039029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clean-architechture","crud","expressjs","microservice","mongodb","nodejs","rest-api"],"created_at":"2024-09-24T13:15:05.909Z","updated_at":"2025-05-15T00:08:15.838Z","avatar_url":"https://github.com/panagiop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node.js-clean-architecture\nA use case of Clean Architecture in Node.js comprising of Express.js, MongoDB and Redis as the main (but replaceable) infrastructure.\n\n### Overview\nThis example is a simple RESTful API application in which a user can create / update / delete / find a post, by using the *Clean Architecture*.\n\nThe objective of *Clean Architecture* by [Robert C. Martin] is the separation of concerns in software. \nThis separation is achieved by dividing the software into layers. Each layer is encapsulated by a higher level layer and the way to communicate between the layers is with the *Dependency Rule*.\n\n![](https://blog.cleancoder.com/uncle-bob/images/2012-08-13-the-clean-architecture/CleanArchitecture.jpg)\n\n#### Dependency Rule\nThis rule says that nothing in an inner circle can know anything at all about something in an outer circle. The dependency direction is from the outside in. Meaning that the *Entities* layer is independent and the *Frameworks \u0026 Drivers* layer (Web, UI, DB etc.) depends on all the other layers.\n#### Entities\nContains all the business entities an application consists of. In our example the *User* and the *Post*.\n#### Use Cases\nContains application specific business rules. These use cases orchestrate the flow of data to and from the entities. In our example some of the use cases are: *AddPost*, *AddUser*, *DeleteById* etc.\n#### Interface Adapters\nThis layer is a set of adapters (controllers, presenters, and gateways) that convert data from the format most convenient for the use cases and entities, to the format most convenient for some external agency such as the DB or the Web. In other words, is an entry and exit points to the Use Cases layer. In our example we implemented controllers and presenters together and these are the PostController and the UserController.\n#### Frameworks and Drivers\nThe outermost layer is generally composed of frameworks and tools such as the Database, the Web Framework, etc.\n### How to run it\n* Make sure you have [mongoDB] installed. At the terminal run the following command:\n```sh\nmongod --dbpath \u003cpath_to_data/db_folder\u003e\n```\n* Make sure [Redis] is also installed and running.\u003cbr /\u003e\u003cbr /\u003e\n* Run the server in development mode by typing the following command:\n```sh\nnpm run dev\n```\n* Run the server in production mode by typing the following command:\n```sh\nnpm run start\n```\n\n### How to run it (using Docker)\n* Make sure you have [docker] installed. At the root folder run the following command:\n```sh\ndocker-compose up -d\n```\n### API documentation\nhttps://documenter.getpostman.com/view/1551953/TzCJgpnb\n\n\n### Further reading\n- https://roystack.home.blog/2019/10/22/node-clean-architecture-deep-dive/\n- https://mannhowie.com/clean-architecture-node\n\n[Robert C. Martin]: \u003chttps://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html\u003e\n[docker]: \u003chttps://www.docker.com/\u003e  \n[mongoDB]: \u003chttps://www.mongodb.com/try/download/community\u003e\n[Redis]: \u003chttps://redis.io/download\u003e\n   \n   \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanagiop%2Fnode.js-clean-architecture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpanagiop%2Fnode.js-clean-architecture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanagiop%2Fnode.js-clean-architecture/lists"}