How geversonloch/clean-node-api works
Project type and purpose
• This is a backend‑only RESTful API built with Node.js and Express, following Clean Architecture principles.
• Its core feature is user signup (AddAccount), using TDD, SOLID principles, and a modular layered structure.
File structure
• Top‑level layers under src/:
• presentation (controllers, HTTP helpers, errors)
• domain (models, use‑case interfaces)
• data (use‑case implementations, protocol interfaces)
• infrastructure (cryptography, database adapters)
• main (Express adapters, config, factories, middleware, routes, server bootstrap)
• utils (email validation adapter)
• Tests are co‑located with each implementation, reflecting TDD.
• Config files: .env, Express app setup, MongoDB connection in main/config.
• Build/deploy: no separate infra code beyond MongoDB adapter; deployment is via Node process.
Key insights from README
• Clean Architecture with well‑defined layers
• TDD with Jest + MongoDB in‑memory
• Tech stack: Express, MongoDB, bcrypt, dotenv, module‑alias, fast‑glob for dynamic route loading
• Infrastructure Layer
• External Services
1. Client → HTTP Request → Express Server
2. Express Server → Route Loader → Route Matches → ExpressRouteAdapter
3. Adapter → Controller.handle(httpRequest)
4. Controller → Calls Use‑Case (AddAccount) via Domain Interface
5. Use‑Case → Calls Encrypter + AddAccountRepository interfaces
6. Encrypter Adapter (bcrypt) → returns hashed password
7. Use‑Case → Calls MongoDBAdapter to persist account
8. MongoDBAdapter → communicates with MongoDB cluster
9. If errors occur, log via LogErrorRepository → MongoDB log collection
10. Use‑Case returns result → Controller constructs HTTP response
11. Response → back through Express → Client
c. Architectural patterns & design principles
• Dependency Inversion: Domain layer defines interfaces, data & infra implement them
• Factory pattern in main/factories/signup.ts to assemble controller + use‑case + adapters
• Decorator pattern for logging controller errors (LogControllerDecorator)
• Middleware pipeline (body-parser, CORS, content-type JSON)
d. Relevant technologies
• Express (HTTP server, routes)
• Jest + Jest‑MongoDB (testing)
• MongoDB (data store)
• bcrypt (password hashing)
• dotenv (environment config)
• fast‑glob (dynamic route discovery)