The idea is to create a simple API where it will save leads from the website's contact form. Also, this API should be responsible to send an email to:
- The client
- The stakeholder
If you can't explain it simply, you don't understand it well enough.
-- Albert Einstein
Each Class should have only one responbility and proporse. It's preferable to have simple and smaller classes.
Each Class should be:
- Open for extensions (through Design Patterns)
- Closed for changes
It's very similar to SRP, but more focused on Interfaces. Each Interface should have your own responsability and they should not have unnecessary items.
A Interface should be a contract with very strict and necessary terms (methods).
Depends on Interfaces instead of Objects and Classes. With Interfaces you have:
- A Contract, so it doesn't matter external details (like database type, presentation, etc.);
- This Contract has only the necessary items. When we have unnecessary items being available and being able to be used, undesired problems could come
This principle doesn't belong to SOLID, but it's important to remind some concetps from it and apply them.
A Class should call only:
- Its methods
- Methods from objects (receiveds through params)
- Methods from objects (built by Class itself)
This project will follow the Clean Architecture (SOLID) suggested by Robert C. Martin. I know there are other architectures (Onion, Hexagonal), but for this specific project it's gonna be Clean Architecture.
src
+-- entities
+-- entity
+-- Lead.js
+-- LeadRepositoryInterface.js
+-- app
+-- CreateLead
+-- CreateLead.js # Class
+-- CreateLead.test.js # Unit Tests
+-- CreateLead.requirements.md # Use Case in Normal Language
+-- adapters
+-- topic (e.g.: controllers, routes, serializers)
+-- item
+-- item1.js (e.g.: LeadController.js, LeadRoutes.js, LeadSerializer.js)
+-- item1.requirements.md
+-- item1.test.js
+-- externals # External Details like database, loggers, servers, Express, Inquirer, ...
+-- Express.js
+-- EmailService.js
+-- index.js # Starts the application (in this case, the server - from externals)
The automated tests will be checked for every pre commit. It will not be allowed to commit if they don't pass.
By doing this simple project, I discovered some answers for my questions:
- WIP
- Why Unit Tests are better than Integration?
- Why should we keep both?
WIP
- Think about the Use Cases
- Start by Entities and Interfaces
- Create the files following project's structure
- Go to unit tests
- Go to Controllers
- Go to integration tests
- Code!