{"id":480737,"date":"2026-05-23T09:47:53","date_gmt":"2026-05-23T09:47:53","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=480737"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=480737","title":{"rendered":"Feature Based Clean Architecture. \u0427\u0430\u0441\u0442\u044c 4: FBCA: \u0444\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0433\u0440\u0430\u043d\u0438\u0446 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0432 NestJS-\u043c\u043e\u0434\u0443\u043b\u0435"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<blockquote>\n<p>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u0430\u044f \u0434\u043e\u043a\u0442\u0440\u0438\u043d\u0430 \u0434\u043b\u044f NestJS-\u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432: \u0440\u0430\u0437\u0431\u043e\u0440 \u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0434\u0435\u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0435 \u0435\u0451 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u0438 \u0440\u043e\u0441\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430.<\/p>\n<\/blockquote>\n<p>\u0422\u0440\u0438 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u00ab\u043e\u0431\u044b\u0447\u043d\u044b\u0439\u00bb NestJS-\u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043a forwardRef \u0438 \u043f\u0440\u043e\u0447\u0435\u0439 \u0441\u0442\u0435\u043d\u043a\u0435. \u041f\u043e\u0440\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u00ab\u043a\u0430\u043a \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c\u00bb. \u0422\u0443\u0442 \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0438\u0437\u043d\u0435\u0441\u0442\u0438 \u00abClean Architecture\u00bb \u2014 \u0438 \u0441\u0440\u0430\u0437\u0443 \u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c\u0441\u044f. \u041b\u044e\u0431\u043e\u0439, \u043a\u0442\u043e \u0447\u0438\u0442\u0430\u043b \u043f\u0440\u043e \u043d\u0435\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u044f\u0442\u0438 \u043c\u0438\u043d\u0443\u0442, \u0437\u043d\u0430\u0435\u0442: \u0432\u043e\u043a\u0440\u0443\u0433 \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u043e\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f \u043f\u0430\u0441\u0451\u0442\u0441\u044f \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0432\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0439, \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u043b\u044e\u0434\u0435\u0439 \u00abClean Architecture\u00bb \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u042d\u0442\u043e \u043d\u0435 \u043e\u0434\u0438\u043d \u043f\u043e\u0434\u0445\u043e\u0434 \u0438 \u043d\u0435 \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0411\u043e\u0431\u043e\u043c \u041c\u0430\u0440\u0442\u0438\u043d\u043e\u043c \u043a\u0440\u0443\u0436\u043e\u0447\u043a\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0437\u0430\u043f\u043e\u0432\u0435\u0434\u0435\u0439. \u042d\u0442\u043e \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u043e \u0438\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0442\u0435\u0437\u0438\u0441\u0435: <strong>\u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u0442\u0434\u0435\u043b\u0435\u043d\u0430 \u043e\u0442 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0442\u0435\u043a\u0443\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u0443<\/strong>. \u0412\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u2014 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<h4>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0438\u0434\u0435\u044f<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u044e \u201c\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u0443\u044e \u043c\u0430\u0433\u0438\u044e\u201d, \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b:<\/p>\n<ul>\n<li>\n<p>\u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0434\u0442\u0438 \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u2014 \u0432\u043d\u0443\u0442\u0440\u044c \u043a \u0434\u043e\u043c\u0435\u043d\u0443<\/p>\n<\/li>\n<li>\n<p>\u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0433\u0440\u0430\u043d\u0438\u0446\u044b, \u0430 \u043d\u0435 \u0431\u044b\u0442\u044c \u0441\u0432\u0430\u043b\u043a\u043e\u0439<\/p>\n<\/li>\n<li>\n<p>\u0431\u0430\u0437\u0430, HTTP, \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u0442\u0430\u043b\u0438, \u0430 \u043d\u0435 \u0446\u0435\u043d\u0442\u0440 \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u2014 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b.<\/p>\n<h3>Domain \/ Use Case \/ Infrastructure \/ Presentation<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043b\u0435\u0433\u0430\u0441\u0438, \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u0433\u0440\u0430\u043d\u0438\u0446\u044b. \u041d\u0435 \u00ab\u043f\u0430\u043f\u043a\u0438 \u0440\u0430\u0434\u0438 \u043f\u043e\u0440\u044f\u0434\u043a\u0430\u00bb, \u0430 \u0442\u0430\u043a\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u043d\u0430\u0440\u0443\u0448\u0438\u0442\u044c \u2014 \u043d\u0435 \u043f\u0440\u043e\u0431\u0438\u0432 TypeScript, NestJS DI \u0438\u043b\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0434\u0438\u0441\u0446\u0438\u043f\u043b\u0438\u043d\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<p>\u0421\u0430\u043c\u0430\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0438 \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c:<\/p>\n<ul>\n<li>\n<p><strong>Domain<\/strong> \u2014 \u0447\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441\u0435<\/p>\n<\/li>\n<li>\n<p><strong>Use Case<\/strong> \u2014 \u043a\u0430\u043a\u0438\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c<\/p>\n<\/li>\n<li>\n<p><strong>Infrastructure<\/strong> \u2014 \u043a\u0430\u043a \u044d\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438<\/p>\n<\/li>\n<li>\n<p><strong>Presentation<\/strong> \u2014 \u043a\u0430\u043a \u0432 \u044d\u0442\u043e \u0432\u0441\u0451 \u0437\u0430\u0445\u043e\u0434\u044f\u0442 \u0441\u043d\u0430\u0440\u0443\u0436\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e \u00ab\u043a\u0440\u0430\u0441\u0438\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u00bb, \u0430 \u043f\u0440\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043d\u0430\u0434 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439: \u0431\u0435\u0437 \u0433\u0440\u0430\u043d\u0438\u0446 \u043b\u043e\u0433\u0438\u043a\u0430 \u0442\u0435\u0447\u0451\u0442 \u043a\u0443\u0434\u0430 \u043f\u043e\u043f\u0430\u043b\u043e, \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u0442\u0443\u0442, \u043a\u043e\u0434 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0445\u0430\u043e\u0441. \u0418 \u044d\u0442\u043e \u043d\u0435 \u0432\u043a\u0443\u0441\u043e\u0432\u0449\u0438\u043d\u0430 \u2014 \u0443 \u043b\u044e\u0431\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0435\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 \u0442\u0435\u043e\u0440\u0438\u044e \u0433\u0440\u0430\u0444\u043e\u0432, \u0433\u0434\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u2014 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u2014 \u0440\u0451\u0431\u0440\u0430. \u041d\u0430 \u0442\u0430\u043a\u043e\u043c \u0433\u0440\u0430\u0444\u0435 \u0441\u0442\u0440\u043e\u0433\u043e \u0432\u0438\u0434\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u0434\u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0434\u0435\u0433\u0440\u0430\u0434\u0438\u0440\u0443\u0435\u0442, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439. Clean Architecture \u0432 \u044d\u0442\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u2014 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043b\u043e\u0436\u0438\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u044d\u0442\u043e\u0442 \u0433\u0440\u0430\u0444. \u0421 \u0446\u0438\u0444\u0440\u0430\u043c\u0438 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0432 \u0447\u0430\u0441\u0442\u0438 5.<\/p>\n<p>\u0418\u0434\u0451\u043c \u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043a \u0441\u043b\u043e\u0436\u043d\u043e\u043c\u0443 \u2014 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0435\u043c \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.<\/p>\n<h4>\u0421\u0442\u0430\u0440\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h4>\n<pre><code class=\"bash\">src\/\u251c\u2500\u2500 main.ts\u251c\u2500\u2500 app.module.ts\u2502\u251c\u2500\u2500 modules\/\u2502   \u251c\u2500\u2500 auth\/\u2502   \u251c\u2500\u2500 users\/\u2502   \u251c\u2500\u2500 tweets\/\u2502   \u251c\u2500\u2500 feed\/\u2502   \u251c\u2500\u2500 likes\/\u2502   \u251c\u2500\u2500 comments\/\u2502   \u251c\u2500\u2500 retweets\/\u2502   \u251c\u2500\u2500 follows\/\u2502   \u251c\u2500\u2500 notifications\/\u2502   \u251c\u2500\u2500 search\/\u2502   \u2514\u2500\u2500 media\/\u2502\u251c\u2500\u2500 common\/\u2502   \u251c\u2500\u2500 guards\/\u2502   \u251c\u2500\u2500 interceptors\/\u2502   \u251c\u2500\u2500 filters\/\u2502   \u251c\u2500\u2500 decorators\/\u2502   \u2514\u2500\u2500 utils\/\u2502\u251c\u2500\u2500 database\/\u2502   \u251c\u2500\u2500 typeorm\/\u2502   \u2514\u2500\u2500 migrations\/\u2502\u251c\u2500\u2500 config\/\u2502   \u2514\u2500\u2500 configuration.ts<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0421\u0430\u043c\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043d\u0435\u043f\u043b\u043e\u0445\u0430\u044f, \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u043e \u0444\u0438\u0447\u0430\u043c \u2014 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434. \u0411\u0435\u0434\u0430 \u043d\u0435 \u0432 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435, \u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0443 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0438 \u0438\u0445 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u043d\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0440\u0436\u0430\u043b\u0438 \u0431\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0432 \u0444\u043e\u0440\u043c\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<h4>\u0420\u0430\u043d\u044c\u0448\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0431\u044b\u043b \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0442\u0430\u043a<\/h4>\n<pre><code class=\"bash\">src\/modules\/tweets\/\u251c\u2500\u2500 tweets.module.ts\u251c\u2500\u2500 tweets.controller.ts\u251c\u2500\u2500 tweets.service.ts\u251c\u2500\u2500 dto\/\u2502   \u2514\u2500\u2500 create-tweet.dto.ts\u251c\u2500\u2500 entities\/\u2502   \u2514\u2500\u2500 tweet.entity.ts<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<h4>\u041a\u0430\u043a \u0431\u0443\u0434\u0435\u043c \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c Clean Architecture?<\/h4>\n<p>\u042f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043d\u0435 \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0438\u0434\u0435\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u043e \u0444\u0438\u0447\u0430\u043c \u043b\u0438\u0431\u043e \u0436\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0434\u043e\u043c\u0435\u043d\u0430\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0423 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e Clean Architecture \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u0432\u043e\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u0436\u0435 \u0442\u044f\u0436\u0435\u043b\u043e \u0440\u0435\u0448\u0430\u0442\u044c. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e <code>Feature Based Clean Architecture<\/code>.<\/p>\n<h4>\u041a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043c\u043e\u0434\u0443\u043b\u044c<\/h4>\n<pre><code class=\"bash\">src\/modules\/tweets\/\u251c\u2500\u2500 domain\/\u2502   \u2514\u2500\u2500 tweet.ts\u2502\u251c\u2500\u2500 use-case\/\u2502   \u2514\u2500\u2500 create-tweet\/\u2502       \u251c\u2500\u2500 create-tweet.handler.ts\u2502       \u2514\u2500\u2500 create-tweet.module.ts\u2502\u251c\u2500\u2500 infrastructure\/\u2502   \u2514\u2500\u2500 repositories\/\u2502       \u251c\u2500\u2500 tweet.entity.ts\u2502       \u251c\u2500\u2500 tweet.repository.ts\u2502       \u2514\u2500\u2500 tweet.repository.module.ts\u2502\u2514\u2500\u2500 presentation\/    \u251c\u2500\u2500 tweets-presentation.controller.ts    \u251c\u2500\u2500 tweets-presentation.service.ts    \u251c\u2500\u2500 tweets-presentation.module.ts    \u2514\u2500\u2500 dto\/        \u2514\u2500\u2500 create-tweet.dto.ts<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u044f\u043c\u0438.<\/p>\n<ul>\n<li>\n<p><strong>Presentation<\/strong> \u2014 <code>presentation\/<\/code>. \u0422\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442: \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, DTO, presentation-service. \u0417\u043d\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e HTTP \u0438 \u043f\u0440\u043e \u0442\u043e, \u043a\u0430\u043a\u043e\u0439 use-case \u0434\u0451\u0440\u043d\u0443\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p><strong>Use-case<\/strong> \u2014 <code>use-case\/create-tweet\/<\/code>. \u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u00ab\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0432\u0438\u0442\u00bb: \u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0446\u0438\u044f, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u0432\u0441\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430. \u0422\u043e \u0441\u0430\u043c\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u0432 feature-based \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u043b\u0441\u044f <code>TweetsService<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Infrastructure<\/strong> \u2014 <code>infrastructure\/repositories\/<\/code>. \u0414\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439-\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e \u043f\u043b\u044e\u0441 ORM-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u0438\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>Domain<\/strong> \u2014 <code>domain\/tweet.ts<\/code>. \u041c\u043e\u0434\u0435\u043b\u044c \u0438 \u0435\u0451 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u0431\u0435\u0437 \u0437\u043d\u0430\u043d\u0438\u044f \u043e \u0442\u043e\u043c, \u0433\u0434\u0435 \u043e\u043d\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438 \u043a\u0430\u043a \u0441\u044e\u0434\u0430 \u043f\u043e\u043f\u0430\u043b\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0441\u0451 \u044d\u0442\u043e \u0434\u0435\u0440\u0436\u0438\u0442 \u2014 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u0432\u043d\u0443\u0442\u0440\u044c: presentation \u2192 use-case \u2192 infrastructure (\u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0440\u0442 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f) \u2192 domain. Domain \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043d\u0438 \u043f\u0440\u043e \u043a\u043e\u0433\u043e. Use-case \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043f\u0440\u043e HTTP. Infrastructure \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043f\u0440\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439.<\/p>\n<h4>\u041d\u0430\u0447\u043d\u0435\u043c \u0442\u0430\u043a\u0436\u0435 \u0441 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/h4>\n<pre><code class=\"typescript\">@Controller(\"auth\")export class AuthPresentationController {  constructor(    private readonly authPresentationService: AuthPresentationService,  ) {}  @Post(\"sign-up\")  async signUp(@Body() dto: SignUpDto): Promise&lt;SignUpResponse&gt; {    return this.authPresentationService.signUp(dto.email, dto.password);  }  @Post(\"sign-in\")  async signIn(@Body() dto: SignInDto): Promise&lt;SignInResponse&gt; {    return this.authPresentationService.signIn(dto.email, dto.password);  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0418 \u0432\u043e\u0442 \u0442\u0443\u0442 \u2014 \u0441\u0430\u043c\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 <code>feature-based<\/code> \u043c\u044b \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b\u0438 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0437\u0434\u043d\u043e: \u0430 \u043a\u0430\u043a <code>Auth<\/code> \u0434\u043e\u0441\u0442\u0430\u0451\u0442 \u044e\u0437\u0435\u0440\u0430? \u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 <code>AuthService.signUp<\/code> \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0432\u043a\u0430\u043b\u044b\u0432\u0430\u043b \u0432\u043d\u0443\u0442\u0440\u044c <code>UsersService.create(...)<\/code>, \u043f\u043e\u0442\u043e\u043c \u0442\u043e\u0442 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u0451\u0440\u0433\u0430\u043b \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0449\u0451, \u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0438 <code>forwardRef<\/code>, \u0446\u0438\u043a\u043b \u0438 \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u043a\u0435\u0439\u0441 \u0438\u0437 \u0447\u0430\u0441\u0442\u0438 3. \u0417\u0434\u0435\u0441\u044c \u0436\u0435 <code>SignUpHandler<\/code> \u0436\u0438\u0432\u0451\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 <code>Auth<\/code>, \u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e \u044e\u0437\u0435\u0440\u0430 \u043b\u0435\u0436\u0430\u0442 \u0432 <code>Users<\/code>. \u041c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u043e\u0439\u0442\u0438 \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u2014 \u0438\u043d\u0430\u0447\u0435 \u0432\u0441\u0451, \u0447\u0442\u043e \u043c\u044b \u0442\u0443\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043b\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0435\u0434\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u044c use-case\u2019\u0430, \u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0441\u043f\u0440\u0438\u043d\u0442\u043e\u0432 handler \u043d\u0430\u0447\u043d\u0451\u0442 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>UserRepository<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0433\u0440\u0430\u043d\u0438\u0446\u0443 \u2014 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u0430\u043c \u043c\u043e\u0434\u0443\u043b\u044c <code>Users<\/code>.<\/p>\n<pre><code class=\"bash\">src\/modules\/users\/\u251c\u2500\u2500 domain\/\u2502   \u2514\u2500\u2500 user.ts\u2502\u251c\u2500\u2500 use-case\/\u2502   \u251c\u2500\u2500 create-user\/\u2502   \u2502   \u251c\u2500\u2500 create-user.handler.ts\u2502   \u2502   \u2514\u2500\u2500 create-user.module.ts\u2502   \u2502\u2502   \u2514\u2500\u2500 get-user-by-email\/\u2502      \u251c\u2500\u2500 get-user-by-email.handler.ts\u2502      \u2514\u2500\u2500 get-user-by-email.module.ts\u2502\u251c\u2500\u2500 infrastructure\/\u2502   \u2514\u2500\u2500 repositories\/\u2502       \u251c\u2500\u2500 user.entity.ts\u2502       \u251c\u2500\u2500 user.repository.ts\u2502       \u2514\u2500\u2500 user.repository.module.ts<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u0430\u043a <code>Auth<\/code> \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0441 <code>Users<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e\u0448\u043b\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438? \u041d\u0443\u0436\u0435\u043d \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u2014 \u0438 \u0441\u0430\u043c\u044b\u0439 \u0447\u0435\u0441\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0435\u0433\u043e \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u0412 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u043c \u043c\u0438\u0440\u0435 \u0434\u0430\u0432\u043d\u043e \u0436\u0438\u0432\u0451\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d <code>database per service<\/code>: \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0441\u0432\u043e\u044f \u0431\u0430\u0437\u0430, \u0438 \u0441\u043e\u0441\u0435\u0434 \u0432 \u0442\u0432\u043e\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043d\u0435 \u0445\u043e\u0434\u0438\u0442, \u043a\u0430\u043a \u0431\u044b \u043d\u0438 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c. \u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u0435\u0442\u0430 \u0441\u0430\u043c \u0441\u043e\u0431\u043e\u0439 \u0440\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u2014 <code>Auth<\/code> \u0438 <code>Users<\/code> \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 \u044f\u0432\u043d\u044b\u0439, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u043d\u0430\u0447\u0435 \u043d\u0438\u043a\u0430\u043a. \u0418\u0434\u0435\u044f \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u0430, \u0447\u0442\u043e \u0435\u0451 \u0436\u0430\u043b\u043a\u043e \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u0441\u0435\u0442\u0438: \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0435\u0451 \u0432\u043d\u0443\u0442\u0440\u044c \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430, \u043d\u0435 \u0440\u0430\u0437\u0432\u043e\u0434\u044f \u0437\u043e\u043e\u043f\u0430\u0440\u043a\u0430 \u0438\u0437 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. \u042d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>\u043f\u043e\u0440\u0442\u043e\u043c<\/strong>.<\/p>\n<blockquote>\n<p>\u041f\u043e\u0440\u0442 \u2014 \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043c\u043e\u0434\u0443\u043b\u044f, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439, \u0447\u0442\u043e \u043e\u043d \u043e\u0442\u0434\u0430\u0451\u0442 \u043d\u0430\u0440\u0443\u0436\u0443 \u2014 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e.<\/p>\n<\/blockquote>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043d\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439, \u043d\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439. \u042d\u0442\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u044f \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u043c \u043c\u043e\u0434\u0443\u043b\u044f\u043c, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u0437\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u043c \u0441\u0442\u043e\u044f\u043b\u0430 \u0441\u0435\u0442\u0435\u0432\u0430\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430. \u041d\u0435\u0439\u043c\u0438\u043d\u0433 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0432\u043e\u0439, \u0432\u0430\u0436\u0435\u043d \u0441\u043c\u044b\u0441\u043b. \u0414\u0430\u043b\u044c\u0448\u0435 \u2014 \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u043f\u043e\u0440\u0442 \u043b\u044f\u0436\u0435\u0442 \u0432 <code>Users<\/code>.<\/p>\n<pre><code class=\"bash\">src\/modules\/users\/\u251c\u2500\u2500 domain\/\u2502   \u2514\u2500\u2500 user.ts\u2502\u251c\u2500\u2500 use-case\/\u2502   \u251c\u2500\u2500 create-user\/\u2502   \u2502   \u251c\u2500\u2500 create-user.handler.ts\u2502   \u2502   \u2514\u2500\u2500 create-user.module.ts\u2502   \u2502\u2502   \u2514\u2500\u2500 get-user-by-email\/\u2502       \u251c\u2500\u2500 get-user-by-email.handler.ts\u2502       \u2514\u2500\u2500 get-user-by-email.module.ts\u2502\u251c\u2500\u2500 infrastructure\/\u2502   \u2514\u2500\u2500 repositories\/\u2502       \u251c\u2500\u2500 user.entity.ts\u2502       \u251c\u2500\u2500 user.repository.ts\u2502       \u2514\u2500\u2500 user.repository.module.ts\u2502\u251c\u2500\u2500 external\/                         # \u041f\u043e\u0440\u0442 (\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442) \u043c\u043e\u0434\u0443\u043b\u044f Users\u2502   \u251c\u2500\u2500 users-external.module.ts\u2502   \u2514\u2500\u2500 users-external.service.ts<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0412\u0430\u0436\u043d\u0430\u044f \u0434\u0435\u0442\u0430\u043b\u044c: \u043d\u0438 \u043d\u0430\u0440\u0443\u0436\u0443, \u043d\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u043e\u0434\u0443\u043b\u044f entity \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u2014 \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u043a\u043e\u0434 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f, \u0435\u0434\u0435\u0442 <code>user.ts<\/code>. Handler, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0433\u043e\u043d\u044f\u0435\u0442 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0443, \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0440\u0443\u043a\u0430\u0445 <code>UserEntity<\/code>: \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441\u0430\u043c \u0445\u043e\u0434\u0438\u0442 \u0432 \u0431\u0430\u0437\u0443, \u043c\u0430\u043f\u0438\u0442 \u0440\u044f\u0434 \u0432 entity, \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u043e\u0442\u0434\u0430\u0451\u0442 \u0435\u0433\u043e \u0434\u0430\u043b\u044c\u0448\u0435. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e use-case\u2019\u0443 \u0431\u0435\u0437\u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e, \u043a\u0430\u043a\u0430\u044f ORM \u043b\u0435\u0436\u0438\u0442 \u043f\u043e\u0434 \u043d\u0438\u043c \u2014 TypeORM, Prisma, \u0433\u043e\u043b\u044b\u0439 SQL \u2014 \u0438 \u043a\u0430\u043a\u0430\u044f \u0442\u0430\u043c \u0431\u0430\u0437\u0430. \u0422\u0430\u043a \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u0437\u0430\u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0443\u0439\u0442\u0438 \u0441 TypeORM \u043d\u0430 Prisma \u0438\u043b\u0438 \u0441 Postgres \u043d\u0430 Mongo \u2014 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0443\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u0441\u043b\u043e\u0439: \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c entity, \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u043b\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f, \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u0411\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e\u0434\u043c\u0435\u043d\u044b \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442. \u0415\u0441\u043b\u0438 \u0431\u044b entity \u0432\u0441\u043f\u043b\u044b\u043b\u0430 \u043d\u0430\u0440\u0443\u0436\u0443 \u2014 \u0445\u043e\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0440\u0442, \u0445\u043e\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0432 use-case \u0447\u0435\u0440\u0435\u0437 <code>findOne()<\/code> \u2014 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0435\u0439 \u043d\u0430\u0440\u0443\u0436\u0443 \u0443\u0435\u0445\u0430\u043b\u0438 \u0431\u044b \u0438 <code>save()<\/code>, \u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b, \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u0441\u0445\u0435\u043c\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b; \u0438 \u043b\u044e\u0431\u043e\u0439 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u043d\u0430\u0447\u0430\u043b \u0431\u044b \u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0431\u0445\u043e\u0434 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u0442\u0430.<\/p>\n<pre><code class=\"typescript\">\/\/ user.tsexport type User = {  id: string;  email: string;  password: string;  createdAt: Date;};\/\/ user.entity.ts@Entity(\"users\")export class UserEntity {  @PrimaryGeneratedColumn(\"uuid\")  id: string;  @Column({ unique: true })  email: string;  @Column()  password: string;  @CreateDateColumn()  createdAt: Date;}\/\/ user.repository.ts@Injectable()export class UserRepository {  constructor(    @InjectRepository(UserEntity)    private readonly repository: Repository&lt;UserEntity&gt;,  ) {}  async create(data: CreateUserData): Promise&lt;Result&lt;User, CreateErrorCode&gt;&gt; {    const insertUserResult = await fromAsyncThrowable(async () =&gt;      this.repository.insert(data),    )();    if (insertUserResult.isErr()) {      if (isUniqueQueryError(insertUserResult.error)) {        return err(\"CREATE_USER_CONFLICT\");      }      return err(\"CREATE_USER_DATABASE_ERROR\");    }    const now = new Date();    return ok({      id: insertUserResult.value.identifiers[0].id,      email: data.email,      password: data.password,      createdAt: now,    });  }  async findByEmail(    email: string,  ): Promise&lt;Result&lt;User | undefined, FindErrorCode&gt;&gt; {    const findUserResult = await fromAsyncThrowable(async () =&gt;      this.repository.findOne({ where: { email } }),    )();    if (findUserResult.isErr()) {      return err(\"FIND_USER_DATABASE_ERROR\");    }    return ok(findUserResult.value ?? undefined);  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0420\u0430\u0437 \u0443\u0436 \u043c\u044b \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 NestJS, \u043d\u0430\u0434\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c, \u043a\u0430\u043a <code>use-case<\/code> \u0438 \u043f\u043e\u0440\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442\u044c \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. \u041f\u0440\u0430\u0432\u0438\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435: \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0436\u0438\u0432\u0451\u0442 \u0432 \u0441\u0432\u043e\u0451\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443, \u0442\u0430\u043c, \u0433\u0434\u0435 \u043d\u0443\u0436\u0435\u043d. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 <code>UsersInfrastructureModule<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u0432\u0441\u0451. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u2014 \u0432 \u0433\u0440\u0430\u0444\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u041a\u043e\u0433\u0434\u0430 <code>get-user-by-email.module.ts<\/code> \u044f\u0432\u043d\u043e \u043f\u0438\u0448\u0435\u0442 <code>imports: [UserRepositoryModule]<\/code>, \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0437\u0433\u043b\u044f\u0434\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u043c\u0443 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044e \u043d\u0443\u0436\u043d\u043e. \u041a\u043e\u0433\u0434\u0430 \u0442\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0449\u0438\u0439 <code>UsersInfrastructureModule<\/code> \u2014 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e: handler \u043c\u043e\u0436\u0435\u0442 \u0445\u043e\u0434\u0438\u0442\u044c \u0432 <code>UserRepository<\/code>, \u0432 <code>UserProfileRepository<\/code>, \u0432 <code>UserSettingsRepository<\/code>, \u0438 \u0432\u0441\u0451 \u044d\u0442\u043e \u043d\u0435\u0432\u0438\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0440\u0435\u0432\u044c\u044e\u0435\u0440\u0430. \u0410 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e <code>get-user-by-email<\/code> \u0442\u0438\u0445\u043e \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 \u0442\u0440\u0438 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u00ab\u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0438\u0437 \u043e\u0431\u0449\u0435\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u00bb.<\/p>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438 \u043c\u044b \u0442\u0443\u0442 \u0431\u0435\u0440\u0451\u043c \u0438\u0434\u0435\u044e Clean Architecture \u0438 \u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0435\u0451 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c DI-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430: \u0442\u0435 \u0436\u0435 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043c\u0435\u0436\u0434\u0443 \u0441\u043b\u043e\u044f\u043c\u0438, \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043d\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u044b \u043d\u0435 \u0447\u0435\u0440\u0435\u0437 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e, \u0430 \u0447\u0435\u0440\u0435\u0437 Nest-\u043c\u043e\u0434\u0443\u043b\u044c. \u041f\u0440\u0430\u0432\u0438\u043b\u043e \u00abhandler \u0437\u043d\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e \u0441\u0432\u043e\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438\u00bb \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0451\u0442 \u0431\u044b\u0442\u044c \u043f\u0443\u043d\u043a\u0442\u043e\u043c \u043a\u043e\u043d\u0432\u0435\u043d\u0446\u0438\u0438 \u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u043c. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0438 DI-\u0433\u0440\u0430\u0444 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c.<\/p>\n<pre><code class=\"typescript\">\/\/ user.repository.module.ts@Module({  imports: [TypeOrmModule.forFeature([UserEntity])],  providers: [UserRepository],  exports: [UserRepository],})export class UserRepositoryModule {}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0442\u0430\u0449\u0438\u0442\u044c \u043d\u0430\u0440\u0443\u0436\u0443 2 \u043c\u0435\u0442\u043e\u0434\u0430 createUser \u0438 getUserByEmail \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0440\u0442, \u0447\u0442\u043e \u0431\u044b auth \u0441\u043c\u043e\u0433 \u0438\u043c\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u0418 \u0442\u0443\u0442 \u0441\u0442\u043e\u0438\u0442 \u0443\u0447\u0435\u0441\u0442\u044c, \u0447\u0442\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043c\u0435\u0442\u043e\u0434 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0440\u0442 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f. Repository \u2014 \u044d\u0442\u043e \u0441\u043b\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432 \u043d\u0451\u043c \u043d\u0435\u0442 \u043d\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u043d\u0438 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u043d\u0438 \u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0446\u0438\u0438; \u0435\u0441\u043b\u0438 \u043f\u043e\u0440\u0442 \u0437\u043e\u0432\u0451\u0442 \u0435\u0433\u043e \u043c\u0438\u043d\u0443\u044f use-case, \u043b\u044e\u0431\u0430\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u043e\u043a\u0440\u0443\u0433 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u0433\u0434\u0435 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u00ab\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u044e\u0437\u0435\u0440\u0430 \u043f\u043e email\u00bb \u2014 \u044d\u0442\u043e \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441. \u0417\u0430\u0432\u0442\u0440\u0430 \u2014 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043b\u044e\u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438, \u043a\u044d\u0448 \u0438 \u0442\u0440\u0435\u043a\u0438\u043d\u0433. \u0412\u0441\u0451 \u044d\u0442\u043e \u0436\u0438\u0432\u0451\u0442 \u0432 handler\u2019\u0435. \u0415\u0441\u043b\u0438 \u043f\u043e\u0440\u0442 \u0445\u043e\u0434\u0438\u0442 \u043c\u0438\u043c\u043e \u2014 handler \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d \u0438\u0437 \u0446\u0435\u043f\u043e\u0447\u043a\u0438, \u0438 \u043b\u044e\u0431\u0430\u044f \u043d\u043e\u0432\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043b\u0438\u0431\u043e \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 (\u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u044f), \u043b\u0438\u0431\u043e \u0432 \u043f\u043e\u0440\u0442 (\u0442\u043e\u0436\u0435). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u0435\u043d \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 handler, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<pre><code class=\"typescript\">\/\/ get-user-by-email.handler.ts@Injectable()export class GetUserByEmailHandler {  constructor(private readonly userRepository: UserRepository) {}  async run(    email: string,  ): Promise&lt;Result&lt;User | undefined, GetUserByEmailHandlerErrorCode&gt;&gt; {    const findUserResult = await this.userRepository.findByEmail(email);    if (findUserResult.isErr()) {      return err(\"GET_USER_BY_EMAIL_DATABASE_ERROR\");    }    return ok(findUserResult.value);  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0422\u043e \u0436\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0447\u0442\u043e \u0438 \u0434\u043b\u044f \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f: \u043e\u0434\u0438\u043d \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u2014 \u0441\u0432\u043e\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u0441\u0432\u043e\u0439 \u044d\u043a\u0441\u043f\u043e\u0440\u0442. \u0422\u043e\u0442, \u043a\u043e\u043c\u0443 \u043d\u0443\u0436\u0435\u043d <code>GetUserByEmailHandler<\/code>, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u0435\u0433\u043e, \u0430 \u043d\u0435 \u00ab\u0432\u0441\u0435 use-case\u2019\u044b Users \u0441\u043a\u043e\u043f\u043e\u043c\u00bb.<\/p>\n<pre><code class=\"typescript\">\/\/ get-user-by-email.module.ts@Module({  imports: [UserRepositoryModule],  providers: [GetUserByEmailHandler],  exports: [GetUserByEmailHandler],})export class GetUserByEmailModule {}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 <code>UsersExternalService<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0442\u043e\u043d\u043a\u0438\u0439 \u0444\u0430\u0441\u0430\u0434: \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0435\u0440\u0436\u0438\u0442 handler\u2019\u044b \u0438 \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0432 \u043d\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u044b, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0440\u0435\u0448\u0430\u044f \u0441\u0430\u043c. \u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442, \u0440\u0430\u0434\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0438 <code>database per service<\/code>. \u0421\u043e\u0441\u0435\u0434\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u043d\u0435 \u0432\u0438\u0434\u044f\u0442 \u043d\u0438 <code>UserRepository<\/code>, \u043d\u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 handler\u2019\u043e\u0432 \u2014 \u043e\u043d\u0438 \u0432\u0438\u0434\u044f\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0442 \u043d\u0430\u0431\u043e\u0440 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 Users \u044f\u0432\u043d\u043e \u0432\u044b\u043b\u043e\u0436\u0438\u043b \u0432 <code>external<\/code>. \u0412\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u00ab\u0437\u0430 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435\u0439\u00bb, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u043d\u0435\u0442, \u043d\u043e \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0435\u0441\u0442\u044c \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u0445.<\/p>\n<pre><code class=\"typescript\">\/\/ users-external.service.ts@Injectable()export class UsersExternalService {  constructor(    private readonly createUserHandler: CreateUserHandler,    private readonly getUserByEmailHandler: GetUserByEmailHandler,  ) {}  async getUserByEmail(    email: string,  ): Promise&lt;Result&lt;User | undefined, GetUserByEmailHandlerErrorCode&gt;&gt; {    return this.getUserByEmailHandler.run(email);  }  async createUser(    data: CreateUserData,  ): Promise&lt;Result&lt;User, CreateUserHandlerErrorCode&gt;&gt; {    return this.createUserHandler.run(data);  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043c\u043e\u0434\u0443\u043b\u044e <code>Auth<\/code>. \u041d\u043e\u0432\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043d\u0435 \u0434\u0430\u0451\u0442 \u0432\u043f\u0438\u0445\u043d\u0443\u0442\u044c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043a\u0443\u0434\u0430 \u043f\u043e\u043f\u0430\u043b\u043e \u2014 \u043d\u043e \u0438 \u043d\u0435 \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u043e\u0442\u043a\u043d\u0451\u0442\u0435 \u0435\u0433\u043e \u043d\u0435 \u0442\u0443\u0434\u0430. \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u0438\u043f\u0438\u0447\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443: \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c <code>UsersExternalService<\/code> \u043f\u0440\u044f\u043c\u043e \u0432 <code>AuthPresentationService<\/code>, \u0432 \u0441\u0430\u043c\u043e\u043c \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0435.<\/p>\n<p>\u041e\u0434\u0438\u043d \u0432\u0430\u0436\u043d\u044b\u0439 \u043d\u044e\u0430\u043d\u0441. Nest \u043d\u0430 \u044d\u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439 \u043d\u0435 \u043f\u043e\u0436\u0430\u043b\u0443\u0435\u0442\u0441\u044f: DI \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0437\u0430\u0440\u0435\u0437\u043e\u043b\u0432\u0438\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>UsersExternalService<\/code> \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d, \u0430 <code>AuthPresentationService<\/code> \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u0435\u0433\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0417\u0430\u043f\u0440\u0435\u0442\u044b \u00ab\u043a\u0442\u043e \u043a\u043e\u0433\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u0432\u0430\u0442\u044c\u00bb \u2014 \u044d\u0442\u043e \u043d\u0435 DI-\u0433\u0440\u0430\u0444, \u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0441\u043b\u043e\u0451\u0432; \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u043b\u043e\u0432\u0438\u043b\u0430 \u043c\u0430\u0448\u0438\u043d\u0430, \u043d\u0443\u0436\u0435\u043d \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043b\u0438\u043d\u0442\u0435\u0440 \u0432\u0440\u043e\u0434\u0435 <a href=\"https:\/\/github.com\/javierbrea\/eslint-plugin-boundaries\" rel=\"noopener noreferrer nofollow\">eslint-plugin-boundaries<\/a>. \u0411\u0435\u0437 \u043d\u0435\u0433\u043e \u0442\u0430\u043a\u0438\u0435 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0433\u043b\u0430\u0437\u0430\u043c\u0438 \u043d\u0430 \u0440\u0435\u0432\u044c\u044e \u2014 \u0447\u0442\u043e, \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043c\u043d\u0438\u043c, \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0442\u0440\u0438\u0434\u0446\u0430\u0442\u044c \u0441\u0435\u043a\u0443\u043d\u0434.<\/p>\n<h4>\u041f\u043b\u043e\u0445\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h4>\n<pre><code class=\"typescript\">@Injectable()export class AuthPresentationService {  constructor(    private readonly jwtService: JwtService,    private readonly usersExternalService: UsersExternalService,  ) {}  async signUp(    email: string,    password: string,    res: Response,  ): Promise&lt;SignUpResponse&gt; {    const findUserResult =      await this.usersExternalService.getUserByEmail(email);    if (findUserResult.isErr()) {      throw new InternalServerErrorException();    }    if (findUserResult.value) {      throw new ConflictException(\"User already exists\");    }    const createUserResult = await this.usersExternalService.createUser({      email,      password,    });    if (createUserResult.isErr()) {      throw new InternalServerErrorException();    }    const signTokenResult = await fromAsyncThrowable(async () =&gt;      this.jwtService.signAsync({ sub: createUserResult.value.id }),    )();    if (signTokenResult.isErr()) {      throw new InternalServerErrorException();    }    res.cookie(\"accessToken\", signTokenResult.value, {      httpOnly: true,      secure: true,      sameSite: \"strict\",    });    return {      id: createUserResult.value.id,      email: createUserResult.value.email,    };  }  async signIn(    email: string,    password: string,    res: Response,  ): Promise&lt;SignInResponse&gt; {    const findUserResult =      await this.usersExternalService.getUserByEmail(email);    if (findUserResult.isErr()) {      throw new InternalServerErrorException();    }    if (!findUserResult.value) {      throw new UnauthorizedException(\"Invalid credentials\");    }    if (findUserResult.value.password !== password) {      throw new UnauthorizedException(\"Invalid credentials\");    }    const signTokenResult = await fromAsyncThrowable(async () =&gt;      this.jwtService.signAsync({ sub: findUserResult.value.id }),    )();    if (signTokenResult.isErr()) {      throw new InternalServerErrorException();    }    res.cookie(\"accessToken\", signTokenResult.value, {      httpOnly: true,      secure: true,      sameSite: \"strict\",    });    return {      id: findUserResult.value.id,      email: findUserResult.value.email,    };  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043d\u0435\u043b\u044c\u0437\u044f? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u0441\u0451 \u0435\u0449\u0451 \u0436\u0438\u0432\u0451\u0442 \u0432 <code>AuthPresentationService<\/code>. \u0412\u044b \u0443\u0431\u0440\u0430\u043b\u0438 \u043f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044e, \u043d\u043e \u043d\u0435 \u0443\u0431\u0440\u0430\u043b\u0438 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0430\u0446\u0438\u044e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435.<\/p>\n<p>\u041a \u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442:<\/p>\n<ul>\n<li>\n<p>\u0412 <code>AuthPresentationService<\/code> \u043d\u0430\u0447\u043d\u0443\u0442 \u0441\u0442\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438: sign-up, sign-in, refresh, logout, social login, 2FA, recovery.<\/p>\n<\/li>\n<li>\n<p>\u041a \u043d\u0435\u043c\u0443 \u043f\u043e\u0434\u0442\u044f\u043d\u0443\u0442\u0441\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438: <code>Users<\/code>, <code>Tokens<\/code>, <code>Sessions<\/code>, <code>Email<\/code>, <code>AntiFraud<\/code>, <code>Analytics<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0435\u0440\u0432\u0438\u0441 \u0441\u043d\u043e\u0432\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u0432 \u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0442\u043e\u0440 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u0434\u0440\u044f\u0434, \u0445\u043e\u0442\u044f \u0435\u0433\u043e \u043f\u0435\u0440\u0432\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0439 \u0441\u043b\u043e\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0440\u043e\u0432\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u0432 feature-based. \u041d\u0435\u0432\u0430\u0436\u043d\u043e, \u0447\u0435\u0440\u0435\u0437 \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0445\u043e\u0434\u0438\u0442 \u043a\u043e\u0434 \u2014 <code>UserRepository<\/code> \u0438\u043b\u0438 <code>UsersExternalService<\/code>. \u0423 \u0432\u0430\u0441 \u0441\u043d\u043e\u0432\u0430 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u043d\u0430\u0435\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0438 \u0442\u0430\u0449\u0438\u0442 \u043d\u0430 \u0441\u0435\u0431\u0435 \u0432\u0441\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443.<\/p>\n<h4>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/h4>\n<pre><code class=\"bash\">src\/modules\/auth\/\u251c\u2500\u2500 use-case\/\u2502   \u251c\u2500\u2500 sign-up\/\u2502   \u2502   \u251c\u2500\u2500 sign-up.handler.ts\u2502   \u2502   \u2514\u2500\u2500 sign-up.module.ts\u2502   \u2502\u2502   \u2514\u2500\u2500 sign-in\/\u2502       \u251c\u2500\u2500 sign-in.handler.ts\u2502       \u2514\u2500\u2500 sign-in.module.ts\u2502\u251c\u2500\u2500 presentation\/\u2502   \u251c\u2500\u2500 auth-presentation.controller.ts\u2502   \u251c\u2500\u2500 auth-presentation.service.ts\u2502   \u2514\u2500\u2500 dto\/\u2502       \u251c\u2500\u2500 sign-up.dto.ts\u2502       \u2514\u2500\u2500 sign-in.dto.ts<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u0435\u043d handler, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0435\u0437\u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e, \u043a\u0442\u043e \u0435\u0433\u043e \u0432\u044b\u0437\u0432\u0430\u043b. \u041d\u0430 \u0432\u0445\u043e\u0434\u0435 \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f, \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u2014 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u2014 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430. \u0411\u0435\u0437 HTTP-\u043e\u0431\u0451\u0440\u0442\u043a\u0438, \u0431\u0435\u0437 \u0437\u043d\u0430\u043d\u0438\u044f \u043e\u0431 Express, Fastify \u0438\u043b\u0438 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440. \u042d\u0442\u043e \u0434\u0430\u0451\u0442 \u0434\u0432\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0432\u0435\u0449\u0438. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043e\u0434\u043d\u0438\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code>handler.run(...)<\/code> \u2014 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043c\u043e\u043a\u043e\u0432 HTTP-\u0441\u0442\u0435\u043a\u0430, \u043d\u0438\u043a\u0430\u043a\u0438\u0445 e2e-\u043e\u0431\u0451\u0440\u0442\u043e\u043a. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0435\u0441\u043b\u0438 \u0437\u0430\u0432\u0442\u0440\u0430 \u043f\u043e\u0432\u0435\u0440\u0445 REST-API \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f GraphQL-\u0441\u0445\u0435\u043c\u0430 \u0438\u043b\u0438 gRPC-\u0441\u0435\u0440\u0432\u0438\u0441, \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0440\u043e\u0432\u043d\u043e presentation-\u0441\u043b\u043e\u0439; handler \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0435\u0441\u0442\u044c.<\/p>\n<pre><code class=\"typescript\">@Injectable()export class SignUpHandler {  constructor(    private readonly jwtService: JwtService,    private readonly usersExternalService: UsersExternalService,  ) {}  async run(    email: string,    password: string,  ): Promise&lt;Result&lt;SignUpResult, SignUpErrorCode&gt;&gt; {    const findUserResult =      await this.usersExternalService.getUserByEmail(email);    if (findUserResult.isErr()) {      return err(\"SIGN_UP_GET_USER_FAILED\");    }    if (findUserResult.value) {      return err(\"SIGN_UP_USER_ALREADY_EXISTS\");    }    const createUserResult = await this.usersExternalService.createUser({      email,      password,    });    if (createUserResult.isErr()) {      return err(\"SIGN_UP_CREATE_USER_FAILED\");    }    const signTokenResult = await fromAsyncThrowable(async () =&gt;      this.jwtService.signAsync({ sub: createUserResult.value.id }),    )();    if (signTokenResult.isErr()) {      return err(\"SIGN_UP_TOKEN_SIGN_FAILED\");    }    return ok({      user: createUserResult.value,      accessToken: signTokenResult.value,    });  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u2014 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 presentation. \u0417\u0434\u0435\u0441\u044c \u0436\u0438\u0432\u0451\u0442 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043d\u043e \u0437\u043d\u0430\u0435\u0442 \u043f\u0440\u043e \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442: \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e HTTP \u0447\u0435\u0440\u0435\u0437 Express, \u0438 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u2014 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438, cookies, \u0441\u0442\u0430\u0442\u0443\u0441\u044b, \u0432\u0441\u0451, \u0447\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043a \u044d\u0442\u043e\u043c\u0443 \u043a\u0430\u043d\u0430\u043b\u0443 \u0441\u0432\u044f\u0437\u0438.<\/p>\n<pre><code class=\"typescript\">@Injectable()export class AuthPresentationService {  constructor(private readonly signUpHandler: SignUpHandler) {}  async signUp(dto: SignUpDto, res: Response): Promise&lt;SignUpResponse&gt; {    const signUpResult = await this.signUpHandler.run(dto.email, dto.password);    if (signUpResult.isErr()) {      if (signUpResult.error === \"SIGN_UP_USER_ALREADY_EXISTS\") {        throw new ConflictException(\"User already exists\");      }      throw new InternalServerErrorException();    }    res.cookie(\"accessToken\", signUpResult.value.accessToken, {      httpOnly: true,      secure: true,      sameSite: \"strict\",    });    return {      id: signUpResult.value.user.id,      email: signUpResult.value.user.email,    };  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u0440\u0436\u0430\u0442\u044c cookie-\u043b\u043e\u0433\u0438\u043a\u0443 \u0438 \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u2014 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u044d\u0442\u043e \u0442\u0430 \u0436\u0435 presentation-\u0437\u043e\u043d\u0430, \u0438 <code>@Controller<\/code> \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442 cookies \u0447\u0435\u0440\u0435\u0437 <code>@Res() res<\/code>. \u042d\u0442\u043e \u0432\u043a\u0443\u0441\u043e\u0432\u0449\u0438\u043d\u0430, \u043d\u043e \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0447\u0438\u0442\u0430\u043b\u0441\u044f \u043a\u0430\u043a \u043a\u0430\u0440\u0442\u0430: \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0443\u0447\u0435\u043a, \u0438\u0445 \u043f\u0443\u0442\u0438, \u0432\u0445\u043e\u0434\u043d\u044b\u0435 DTO, <code>Guards<\/code>, \u0438\u043d\u0442\u0435\u0440\u0446\u0435\u043f\u0442\u043e\u0440\u044b \u2014 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e. \u0412\u0441\u0451, \u0447\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0442\u0435\u043b\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u2014 \u043f\u0430\u043a\u043e\u0432\u0430\u043d\u0438\u0435 cookies, \u0441\u0431\u043e\u0440\u043a\u0430 \u043e\u0442\u0432\u0435\u0442\u0430, \u043c\u0430\u043f\u0438\u043d\u0433 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432 HTTP-\u0441\u0442\u0430\u0442\u0443\u0441\u044b \u2014 \u0443\u0435\u0437\u0436\u0430\u0435\u0442 \u0432 presentation-service. \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u0435\u0439 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0434\u0443\u043b\u044f; presentation-service \u2014 \u043c\u0435\u0441\u0442\u043e\u043c, \u0433\u0434\u0435 \u043e\u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"typescript\">@Controller(\"auth\")export class AuthPresentationController {  constructor(    private readonly authPresentationService: AuthPresentationService,  ) {}  @Post(\"sign-up\")  async signUp(    @Body() dto: SignUpDto,    @Res({ passthrough: true }) res: Response,  ): Promise&lt;SignUpResponse&gt; {    return this.authPresentationService.signUp(dto, res);  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0430\u0448 \u0433\u0440\u0430\u0444 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/\/post_images\/c7a\/050\/f92\/c7a050f927f53835cae8db9fdf0e4d73.svg\" alt=\"\u0413\u0440\u0430\u0444 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 FBCA: \u043c\u043e\u0434\u0443\u043b\u0438 Auth \u0438 Users\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/\/post_images\/c7a\/050\/f92\/c7a050f927f53835cae8db9fdf0e4d73.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/\/post_images\/c7a\/050\/f92\/c7a050f927f53835cae8db9fdf0e4d73.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0413\u0440\u0430\u0444 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 FBCA: \u043c\u043e\u0434\u0443\u043b\u0438 Auth \u0438 Users<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u0434\u043e\u043b\u044c\u0448\u0435 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0443? \u041d\u0435 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e Nest \u0437\u0430 \u044d\u0442\u0438\u043c \u0441\u043b\u0435\u0434\u0438\u0442 \u2014 \u043e\u043d \u043d\u0435 \u0441\u043b\u0435\u0434\u0438\u0442, \u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e DI-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a, \u0438 \u043f\u0440\u043e \u0441\u043b\u043e\u0438 \u043e\u043d \u0437\u043d\u0430\u0435\u0442 \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c <code>tsc<\/code>. \u0417\u0430\u0449\u0438\u0442\u0430 \u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043d\u0430 \u0442\u0440\u0451\u0445 \u0432\u0435\u0449\u0430\u0445, \u043d\u0438 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u0438\u0434\u0451\u0442 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438.<\/p>\n<p><strong>\u041a\u043e\u043d\u0432\u0435\u043d\u0446\u0438\u044f.<\/strong> \u041a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u043d\u0430\u0440\u0443\u0436\u0443 \u0442\u043e\u043b\u044c\u043a\u043e <code>*External*Service<\/code>; handler\u2019\u044b, \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u0434\u043e\u043c\u0435\u043d \u2014 \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0440\u0443\u0448\u0438\u0442\u044c, Nest \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043e\u0442\u0434\u0430\u0441\u0442 \u043b\u044e\u0431\u043e\u0439 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u044b \u0440\u0435\u0448\u0438\u0448\u044c \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041d\u043e \u0448\u043e\u0440\u0442\u043a\u0430\u0442 \u00ab\u043e\u0442\u043a\u0440\u043e\u044e-\u043a\u0430 <code>GetUserByEmailHandler<\/code> \u0434\u043b\u044f Auth\u00bb \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u0435\u0434: \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f <code>users-external.module.ts<\/code>, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 Auth-handler. \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 diff \u0438 \u043d\u0430 \u0440\u0435\u0432\u044c\u044e.<\/p>\n<p><strong>\u041b\u0438\u043d\u0442\u0435\u0440.<\/strong> <code>eslint-plugin-boundaries<\/code> \u0438\u043b\u0438 <code>dependency-cruiser<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u00ab<code>auth\/<\/code> \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 <code>users\/external\/*<\/code>\u00bb \u2014 \u0438 \u043b\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u0432 IDE \u0434\u043e \u043a\u043e\u043c\u043c\u0438\u0442\u0430. \u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0442\u043e\u0442 \u0441\u043b\u043e\u0439, \u0433\u0434\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u044b\u043c \u043d\u0430 \u0441\u0431\u043e\u0440\u043a\u0435. \u041e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e, \u043d\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u0434\u0438\u0441\u0446\u0438\u043f\u043b\u0438\u043d\u0443 \u0438\u0437 \u00ab\u0434\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438\u0441\u044c\u00bb \u0432 \u00ab\u043d\u0435 \u043f\u0440\u043e\u0439\u0434\u0451\u0442\u00bb.<\/p>\n<p><strong>\u0420\u0435\u0432\u044c\u044e.<\/strong> \u041a\u043e\u0433\u0434\u0430 \u043b\u0438\u043d\u0442\u0435\u0440\u0430 \u043d\u0435\u0442, \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0433\u043b\u0430\u0437\u0430. \u0411\u0435\u0437 \u043b\u0438\u043d\u0442\u0435\u0440\u0430 FBCA-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043d\u0435 \u00ab\u043d\u0435 \u0434\u0435\u0433\u0440\u0430\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u00bb, \u0430 \u00ab\u0434\u0435\u0433\u0440\u0430\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043c\u0435\u0442\u043d\u0435\u0435\u00bb: \u043a\u0430\u0436\u0434\u044b\u0439 \u0448\u043e\u0440\u0442\u043a\u0430\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 diff, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e. \u042d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u0448\u0430\u043d\u0441\u044b, \u043d\u043e \u0438 \u043d\u0435 \u0434\u043e \u043d\u0443\u043b\u044f.<\/p>\n<p>\u0412 \u0441\u0443\u043c\u043c\u0435: \u043d\u043e\u0432\u0430\u044f \u0444\u0438\u0447\u0430 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u043b\u043e\u0436\u0438\u0442\u0441\u044f \u0432 \u043d\u043e\u0432\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u043b\u0435\u0433\u0447\u0435, \u0447\u0435\u043c \u043d\u0435\u0431\u0440\u0435\u0436\u043d\u043e, \u2014 \u043d\u0435 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435\u0431\u0440\u0435\u0436\u043d\u043e \u043d\u0435\u043b\u044c\u0437\u044f, \u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435\u0431\u0440\u0435\u0436\u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0438\u0434\u043d\u043e. \u0427\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0430 \u0430\u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0444\u0438\u0447\u0438.<\/p>\n<p>\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438 \u043a\u0430\u043a \u0431\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0433\u0440\u0430\u0444 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 feature-based \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/\/post_images\/148\/30b\/acf\/14830bacf5b230b7157bf0b691d0fa06.svg\" alt=\"\u0413\u0440\u0430\u0444 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 FBCA: \u043c\u043e\u0434\u0443\u043b\u0438 Auth \u0438 Users\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/\/post_images\/148\/30b\/acf\/14830bacf5b230b7157bf0b691d0fa06.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/\/post_images\/148\/30b\/acf\/14830bacf5b230b7157bf0b691d0fa06.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0413\u0440\u0430\u0444 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 FBCA: \u043c\u043e\u0434\u0443\u043b\u0438 Auth \u0438 Users<\/figcaption><\/div>\n<\/figure>\n<p>\u041e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u044f\u0436\u0435\u043b\u043e \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0441\u043c\u044b\u0441\u043b <code>Clean Architecture<\/code>. \u041e\u0431\u043c\u0430\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c FB-\u0433\u0440\u0430\u0444\u0430 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0449\u0438: \u0435\u0433\u043e \u0440\u0438\u0441\u0443\u044e\u0442 \u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b. \u041b\u0435\u0433\u0430\u0441\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c <code>AuthService<\/code> \u043e\u0431\u0440\u043e\u0441 \u0434\u0435\u0441\u044f\u0442\u044c\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438 \u0438 <code>forwardRef<\/code>\u2019\u043e\u043c, \u0433\u0440\u0430\u0444\u043e\u0432 \u0441\u0432\u043e\u0438\u0445 \u043d\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u2014 \u043e\u043d \u0438 \u0442\u0430\u043a \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043a\u043e\u043c\u0430\u043d\u0434\u0435, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0433\u0434\u0430 \u043d\u043e\u0432\u0438\u0447\u043e\u043a \u0432\u0438\u0434\u0438\u0442 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u00ab\u0432\u043e\u0442 FB \u2014 \u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0441\u0442\u0440\u0435\u043b\u043a\u0430\u00bb, \u00ab\u0432\u043e\u0442 FBCA \u2014 \u0434\u0435\u0441\u044f\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b\u00bb, \u043e\u043d \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u043d\u0430 \u0442\u0443 \u0444\u0430\u0437\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 FB \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442: \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u0435\u0441\u044f\u0446 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u042d\u0442\u043e survivorship bias \u0432 \u0447\u0438\u0441\u0442\u043e\u043c \u0432\u0438\u0434\u0435: \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0435 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u0435\u0449\u0451 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0443\u0441\u043f\u0435\u043b\u043e \u0441\u043b\u043e\u043c\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>\u041f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 Clean Architecture \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e\u0439, \u0430 \u0447\u0435\u0440\u0435\u0437 \u0433\u043e\u0434 \u2014 \u043a\u043e\u0433\u0434\u0430 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043d\u0430 \u043d\u0435 \u0440\u0430\u0437\u0432\u0430\u043b\u0438\u043b\u0430\u0441\u044c. \u0418 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0443 \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0442\u044f\u0436\u0435\u043b\u043e \u043f\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0440\u0430\u043d\u0435\u0435: \u043b\u044e\u0434\u0438 \u0432\u0438\u0434\u044f\u0442 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u044e\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c, \u0438 \u0438\u043c \u0442\u0440\u0443\u0434\u043d\u043e \u043f\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u044f \u0441\u0435\u0431\u044f \u043e\u043a\u0443\u043f\u0438\u0442.<\/p>\n<p>\u0412 \u0441\u043b\u0435\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0436\u0443, \u043f\u043e\u0447\u0435\u043c\u0443 <code>feature-based<\/code> \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0435\u0433\u0440\u0430\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0430 <code>feature-based-clean<\/code> \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0441\u0432\u043e\u0451 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0447\u0435\u043d\u044c \u0434\u043e\u043b\u0433\u043e.<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1038438\/\">https:\/\/habr.com\/ru\/articles\/1038438\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u0430\u044f \u0434\u043e\u043a\u0442\u0440\u0438\u043d\u0430 \u0434\u043b\u044f NestJS-\u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432: \u0440\u0430\u0437\u0431\u043e\u0440 \u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u0434\u0435\u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0435 \u0435\u0451 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u0438 \u0440\u043e\u0441\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430.\u0422\u0440\u0438 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u00ab\u043e\u0431\u044b\u0447\u043d\u044b\u0439\u00bb NestJS-\u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043a forwardRef \u0438 \u043f\u0440\u043e\u0447\u0435\u0439 \u0441\u0442\u0435\u043d\u043a\u0435. \u041f\u043e\u0440\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u00ab\u043a\u0430\u043a \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c\u00bb. \u0422\u0443\u0442 \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0438\u0437\u043d\u0435\u0441\u0442\u0438 \u00abClean Architecture\u00bb \u2014 \u0438 \u0441\u0440\u0430\u0437\u0443 \u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c\u0441\u044f. \u041b\u044e\u0431\u043e\u0439, \u043a\u0442\u043e \u0447\u0438\u0442\u0430\u043b \u043f\u0440\u043e \u043d\u0435\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u044f\u0442\u0438 \u043c\u0438\u043d\u0443\u0442, \u0437\u043d\u0430\u0435\u0442: \u0432\u043e\u043a\u0440\u0443\u0433 \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u043e\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f \u043f\u0430\u0441\u0451\u0442\u0441\u044f \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0432\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0439, \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u043b\u044e\u0434\u0435\u0439 \u00abClean Architecture\u00bb \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u042d\u0442\u043e \u043d\u0435 \u043e\u0434\u0438\u043d \u043f\u043e\u0434\u0445\u043e\u0434 \u0438 \u043d\u0435 \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0411\u043e\u0431\u043e\u043c \u041c\u0430\u0440\u0442\u0438\u043d\u043e\u043c \u043a\u0440\u0443\u0436\u043e\u0447\u043a\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0437\u0430\u043f\u043e\u0432\u0435\u0434\u0435\u0439. \u042d\u0442\u043e \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u043e \u0438\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0442\u0435\u0437\u0438\u0441\u0435: \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u0442\u0434\u0435\u043b\u0435\u043d\u0430 \u043e\u0442 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0442\u0435\u043a\u0443\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u0443. \u0412\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u2014 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0438\u0434\u0435\u044f\u0415\u0441\u043b\u0438 \u0443\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u044e \u201c\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u0443\u044e \u043c\u0430\u0433\u0438\u044e\u201d, \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b:\u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0434\u0442\u0438 \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u2014 \u0432\u043d\u0443\u0442\u0440\u044c \u043a \u0434\u043e\u043c\u0435\u043d\u0443\u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0433\u0440\u0430\u043d\u0438\u0446\u044b, \u0430 \u043d\u0435 \u0431\u044b\u0442\u044c \u0441\u0432\u0430\u043b\u043a\u043e\u0439\u0431\u0430\u0437\u0430, HTTP, \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u0442\u0430\u043b\u0438, \u0430 \u043d\u0435 \u0446\u0435\u043d\u0442\u0440 \u0441\u0438\u0441\u0442\u0435\u043c\u044b\u0412\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u2014 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b.Domain \/ Use Case \/ Infrastructure \/ Presentation\u0427\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043b\u0435\u0433\u0430\u0441\u0438, \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u0433\u0440\u0430\u043d\u0438\u0446\u044b. \u041d\u0435 \u00ab\u043f\u0430\u043f\u043a\u0438 \u0440\u0430\u0434\u0438 \u043f\u043e\u0440\u044f\u0434\u043a\u0430\u00bb, \u0430 \u0442\u0430\u043a\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u043d\u0430\u0440\u0443\u0448\u0438\u0442\u044c \u2014 \u043d\u0435 \u043f\u0440\u043e\u0431\u0438\u0432 TypeScript, NestJS DI \u0438\u043b\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0434\u0438\u0441\u0446\u0438\u043f\u043b\u0438\u043d\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.\u0421\u0430\u043c\u0430\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0438 \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c:Domain \u2014 \u0447\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0431\u0438\u0437\u043d\u0435\u0441\u0435Use Case \u2014 \u043a\u0430\u043a\u0438\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043cInfrastructure \u2014 \u043a\u0430\u043a \u044d\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438Presentation \u2014 \u043a\u0430\u043a \u0432 \u044d\u0442\u043e \u0432\u0441\u0451 \u0437\u0430\u0445\u043e\u0434\u044f\u0442 \u0441\u043d\u0430\u0440\u0443\u0436\u0438\u042d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e \u00ab\u043a\u0440\u0430\u0441\u0438\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u00bb, \u0430 \u043f\u0440\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043d\u0430\u0434 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439: \u0431\u0435\u0437 \u0433\u0440\u0430\u043d\u0438\u0446 \u043b\u043e\u0433\u0438\u043a\u0430 \u0442\u0435\u0447\u0451\u0442 \u043a\u0443\u0434\u0430 \u043f\u043e\u043f\u0430\u043b\u043e, \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u0442\u0443\u0442, \u043a\u043e\u0434 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0445\u0430\u043e\u0441. \u0418 \u044d\u0442\u043e \u043d\u0435 \u0432\u043a\u0443\u0441\u043e\u0432\u0449\u0438\u043d\u0430 \u2014 \u0443 \u043b\u044e\u0431\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0435\u0441\u0442\u044c \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 \u0442\u0435\u043e\u0440\u0438\u044e \u0433\u0440\u0430\u0444\u043e\u0432, \u0433\u0434\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u2014 \u0432\u0435\u0440\u0448\u0438\u043d\u044b, \u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u2014 \u0440\u0451\u0431\u0440\u0430. \u041d\u0430 \u0442\u0430\u043a\u043e\u043c \u0433\u0440\u0430\u0444\u0435 \u0441\u0442\u0440\u043e\u0433\u043e \u0432\u0438\u0434\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u0434\u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0434\u0435\u0433\u0440\u0430\u0434\u0438\u0440\u0443\u0435\u0442, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439. Clean Architecture \u0432 \u044d\u0442\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u2014 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043b\u043e\u0436\u0438\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u044d\u0442\u043e\u0442 \u0433\u0440\u0430\u0444. \u0421 \u0446\u0438\u0444\u0440\u0430\u043c\u0438 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0432 \u0447\u0430\u0441\u0442\u0438 5.\u0418\u0434\u0451\u043c \u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043a \u0441\u043b\u043e\u0436\u043d\u043e\u043c\u0443 \u2014 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0435\u043c \u0442\u043e\u0442 \u0436\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.\u0421\u0442\u0430\u0440\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430src\/\u251c\u2500\u2500 main.ts\u251c\u2500\u2500 app.module.ts\u2502\u251c\u2500\u2500 modules\/\u2502   \u251c\u2500\u2500 auth\/\u2502   \u251c\u2500\u2500 users\/\u2502   \u251c\u2500\u2500 tweets\/\u2502   \u251c\u2500\u2500 feed\/\u2502   \u251c\u2500\u2500 likes\/\u2502   \u251c\u2500\u2500 comments\/\u2502   \u251c\u2500\u2500 retweets\/\u2502   \u251c\u2500\u2500 follows\/\u2502   \u251c\u2500\u2500 notifications\/\u2502   \u251c\u2500\u2500 search\/\u2502   \u2514\u2500\u2500 media\/\u2502\u251c\u2500\u2500 common\/\u2502   \u251c\u2500\u2500 guards\/\u2502   \u251c\u2500\u2500 interceptors\/\u2502   \u251c\u2500\u2500 filters\/\u2502   \u251c\u2500\u2500 decorators\/\u2502   \u2514\u2500\u2500 utils\/\u2502\u251c\u2500\u2500 database\/\u2502   \u251c\u2500\u2500 typeorm\/\u2502   \u2514\u2500\u2500 migrations\/\u2502\u251c\u2500\u2500 config\/\u2502   \u2514\u2500\u2500 configuration.ts\u0421\u0430\u043c\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043d\u0435\u043f\u043b\u043e\u0445\u0430\u044f, \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u043e \u0444\u0438\u0447\u0430\u043c \u2014 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434. \u0411\u0435\u0434\u0430 \u043d\u0435 \u0432 \u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435, \u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0443 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0438 \u0438\u0445 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u043d\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0440\u0436\u0430\u043b\u0438 \u0431\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0432 \u0444\u043e\u0440\u043c\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u044b.\u0420\u0430\u043d\u044c\u0448\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0431\u044b\u043b \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0442\u0430\u043asrc\/modules\/tweets\/\u251c\u2500\u2500 tweets.module.ts\u251c\u2500\u2500 tweets.controller.ts\u251c\u2500\u2500 tweets.service.ts\u251c\u2500\u2500 dto\/\u2502   \u2514\u2500\u2500 create-tweet.dto.ts\u251c\u2500\u2500 entities\/\u2502   \u2514\u2500\u2500 tweet.entity.ts\u041a\u0430\u043a \u0431\u0443\u0434\u0435\u043c \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c Clean Architecture?\u042f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043d\u0435 \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0438\u0434\u0435\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u043e \u0444\u0438\u0447\u0430\u043c \u043b\u0438\u0431\u043e \u0436\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0434\u043e\u043c\u0435\u043d\u0430\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0423 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e Clean Architecture \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u0432\u043e\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u0436\u0435 \u0442\u044f\u0436\u0435\u043b\u043e \u0440\u0435\u0448\u0430\u0442\u044c. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e Feature Based Clean Architecture.\u041a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043c\u043e\u0434\u0443\u043b\u044csrc\/modules\/tweets\/\u251c\u2500\u2500 domain\/\u2502   \u2514\u2500\u2500 tweet.ts\u2502\u251c\u2500\u2500 use-case\/\u2502   \u2514\u2500\u2500 create-tweet\/\u2502       \u251c\u2500\u2500 create-tweet.handler.ts\u2502       \u2514\u2500\u2500 create-tweet.module.ts\u2502\u251c\u2500\u2500 infrastructure\/\u2502   \u2514\u2500\u2500 repositories\/\u2502       \u251c\u2500\u2500 tweet.entity.ts\u2502       \u251c\u2500\u2500 tweet.repository.ts\u2502       \u2514\u2500\u2500 tweet.repository.module.ts\u2502\u2514\u2500\u2500 presentation\/    \u251c\u2500\u2500 tweets-presentation.controller.ts    \u251c\u2500\u2500 tweets-presentation.service.ts    \u251c\u2500\u2500 tweets-presentation.module.ts    \u2514\u2500\u2500 dto\/        \u2514\u2500\u2500 create-tweet.dto.ts\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u044f\u043c\u0438.Presentation \u2014 presentation\/. \u0422\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442: \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, DTO, presentation-service. \u0417\u043d\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e HTTP \u0438 \u043f\u0440\u043e \u0442\u043e, \u043a\u0430\u043a\u043e\u0439 use-case \u0434\u0451\u0440\u043d\u0443\u0442\u044c.Use-case \u2014 use-case\/create-tweet\/. \u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u00ab\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0432\u0438\u0442\u00bb: \u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0446\u0438\u044f, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u0432\u0441\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430. \u0422\u043e \u0441\u0430\u043c\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u0432 feature-based \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u043b\u0441\u044f TweetsService.Infrastructure \u2014 infrastructure\/repositories\/. \u0414\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439-\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e \u043f\u043b\u044e\u0441 ORM-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u0438\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439.Domain \u2014 domain\/tweet.ts. \u041c\u043e\u0434\u0435\u043b\u044c \u0438 \u0435\u0451 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u0431\u0435\u0437 \u0437\u043d\u0430\u043d\u0438\u044f \u043e \u0442\u043e\u043c, \u0433\u0434\u0435 \u043e\u043d\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0438 \u043a\u0430\u043a \u0441\u044e\u0434\u0430 \u043f\u043e\u043f\u0430\u043b\u0430.\u041f\u0440\u0430\u0432\u0438\u043b\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0441\u0451 \u044d\u0442\u043e \u0434\u0435\u0440\u0436\u0438\u0442 \u2014 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u0432\u043d\u0443\u0442\u0440\u044c: presentation \u2192 use-case \u2192 infrastructure (\u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0440\u0442 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f) \u2192 domain. Domain \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043d\u0438 \u043f\u0440\u043e \u043a\u043e\u0433\u043e. Use-case \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043f\u0440\u043e HTTP. Infrastructure \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043f\u0440\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439.\u041d\u0430\u0447\u043d\u0435\u043c \u0442\u0430\u043a\u0436\u0435 \u0441 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438@Controller(&#171;auth&#187;)export class AuthPresentationController {  constructor(    private readonly authPresentationService: AuthPresentationService,  ) {}  @Post(&#171;sign-up&#187;)  async signUp(@Body() dto: SignUpDto): Promise&lt;SignUpResponse&gt; {    return this.authPresentationService.signUp(dto.email, dto.password);  }  @Post(&#171;sign-in&#187;)  async signIn(@Body() dto: SignInDto): Promise&lt;SignInResponse&gt; {    return this.authPresentationService.signIn(dto.email, dto.password);  }}\u0418 \u0432\u043e\u0442 \u0442\u0443\u0442 \u2014 \u0441\u0430\u043c\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 feature-based \u043c\u044b \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b\u0438 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0437\u0434\u043d\u043e: \u0430 \u043a\u0430\u043a Auth \u0434\u043e\u0441\u0442\u0430\u0451\u0442 \u044e\u0437\u0435\u0440\u0430? \u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 AuthService.signUp \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0432\u043a\u0430\u043b\u044b\u0432\u0430\u043b \u0432\u043d\u0443\u0442\u0440\u044c UsersService.create(&#8230;), \u043f\u043e\u0442\u043e\u043c \u0442\u043e\u0442 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u0451\u0440\u0433\u0430\u043b \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0449\u0451, \u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0438 forwardRef, \u0446\u0438\u043a\u043b \u0438 \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u043a\u0435\u0439\u0441 \u0438\u0437 \u0447\u0430\u0441\u0442\u0438 3. \u0417\u0434\u0435\u0441\u044c \u0436\u0435 SignUpHandler \u0436\u0438\u0432\u0451\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 Auth, \u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e \u044e\u0437\u0435\u0440\u0430 \u043b\u0435\u0436\u0430\u0442 \u0432 Users. \u041c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u043e\u0439\u0442\u0438 \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u2014 \u0438\u043d\u0430\u0447\u0435 \u0432\u0441\u0451, \u0447\u0442\u043e \u043c\u044b \u0442\u0443\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043b\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0435\u0434\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u044c use-case\u2019\u0430, \u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0441\u043f\u0440\u0438\u043d\u0442\u043e\u0432 handler \u043d\u0430\u0447\u043d\u0451\u0442 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c UserRepository \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0433\u0440\u0430\u043d\u0438\u0446\u0443 \u2014 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u0430\u043c \u043c\u043e\u0434\u0443\u043b\u044c Users.src\/modules\/users\/\u251c\u2500\u2500 domain\/\u2502   \u2514\u2500\u2500 user.ts\u2502\u251c\u2500\u2500 use-case\/\u2502   \u251c\u2500\u2500 create-user\/\u2502   \u2502   \u251c\u2500\u2500 create-user.handler.ts\u2502   \u2502   \u2514\u2500\u2500 create-user.module.ts\u2502   \u2502\u2502   \u2514\u2500\u2500 get-user-by-email\/\u2502      \u251c\u2500\u2500 get-user-by-email.handler.ts\u2502      \u2514\u2500\u2500 get-user-by-email.module.ts\u2502\u251c\u2500\u2500 infrastructure\/\u2502   \u2514\u2500\u2500 repositories\/\u2502       \u251c\u2500\u2500 user.entity.ts\u2502       \u251c\u2500\u2500 user.repository.ts\u2502       \u2514\u2500\u2500 user.repository.module.ts\u041a\u0430\u043a Auth \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0441 Users, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e\u0448\u043b\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438? \u041d\u0443\u0436\u0435\u043d \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u2014 \u0438 \u0441\u0430\u043c\u044b\u0439 \u0447\u0435\u0441\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0435\u0433\u043e \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b. \u0412 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u043c \u043c\u0438\u0440\u0435 \u0434\u0430\u0432\u043d\u043e \u0436\u0438\u0432\u0451\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d database per service: \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0441\u0432\u043e\u044f \u0431\u0430\u0437\u0430, \u0438 \u0441\u043e\u0441\u0435\u0434 \u0432 \u0442\u0432\u043e\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043d\u0435 \u0445\u043e\u0434\u0438\u0442, \u043a\u0430\u043a \u0431\u044b \u043d\u0438 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c. \u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u0435\u0442\u0430 \u0441\u0430\u043c \u0441\u043e\u0431\u043e\u0439 \u0440\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u2014 Auth \u0438 Users \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 \u044f\u0432\u043d\u044b\u0439, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u043d\u0430\u0447\u0435 \u043d\u0438\u043a\u0430\u043a. \u0418\u0434\u0435\u044f \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u0430, \u0447\u0442\u043e \u0435\u0451 \u0436\u0430\u043b\u043a\u043e \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u0441\u0435\u0442\u0438: \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0435\u0451 \u0432\u043d\u0443\u0442\u0440\u044c \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430, \u043d\u0435 \u0440\u0430\u0437\u0432\u043e\u0434\u044f \u0437\u043e\u043e\u043f\u0430\u0440\u043a\u0430 \u0438\u0437 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. \u042d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0440\u0442\u043e\u043c.\u041f\u043e\u0440\u0442 \u2014 \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043c\u043e\u0434\u0443\u043b\u044f, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439, \u0447\u0442\u043e \u043e\u043d \u043e\u0442\u0434\u0430\u0451\u0442 \u043d\u0430\u0440\u0443\u0436\u0443 \u2014 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e.\u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u043d\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439, \u043d\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439. \u042d\u0442\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u044f \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u043c \u043c\u043e\u0434\u0443\u043b\u044f\u043c, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u0437\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u043c \u0441\u0442\u043e\u044f\u043b\u0430 \u0441\u0435\u0442\u0435\u0432\u0430\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430. \u041d\u0435\u0439\u043c\u0438\u043d\u0433 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0432\u043e\u0439, \u0432\u0430\u0436\u0435\u043d \u0441\u043c\u044b\u0441\u043b. \u0414\u0430\u043b\u044c\u0448\u0435 \u2014 \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u043f\u043e\u0440\u0442 \u043b\u044f\u0436\u0435\u0442 \u0432 Users.src\/modules\/users\/\u251c\u2500\u2500 domain\/\u2502   \u2514\u2500\u2500 user.ts\u2502\u251c\u2500\u2500 use-case\/\u2502   \u251c\u2500\u2500 create-user\/\u2502   \u2502   \u251c\u2500\u2500 create-user.handler.ts\u2502   \u2502   \u2514\u2500\u2500 create-user.module.ts\u2502   \u2502\u2502   \u2514\u2500\u2500 get-user-by-email\/\u2502       \u251c\u2500\u2500 get-user-by-email.handler.ts\u2502       \u2514\u2500\u2500 get-user-by-email.module.ts\u2502\u251c\u2500\u2500 infrastructure\/\u2502   \u2514\u2500\u2500 repositories\/\u2502       \u251c\u2500\u2500 user.entity.ts\u2502       \u251c\u2500\u2500 user.repository.ts\u2502       \u2514\u2500\u2500 user.repository.module.ts\u2502\u251c\u2500\u2500 external\/                         # \u041f\u043e\u0440\u0442 (\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442) \u043c\u043e\u0434\u0443\u043b\u044f Users\u2502   \u251c\u2500\u2500 users-external.module.ts\u2502   \u2514\u2500\u2500 users-external.service.ts\u0412\u0430\u0436\u043d\u0430\u044f \u0434\u0435\u0442\u0430\u043b\u044c: \u043d\u0438 \u043d\u0430\u0440\u0443\u0436\u0443, \u043d\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u043e\u0434\u0443\u043b\u044f entity \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u2014 \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u043a\u043e\u0434 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f, \u0435\u0434\u0435\u0442 user.ts. Handler, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0433\u043e\u043d\u044f\u0435\u0442 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0443, \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0440\u0443\u043a\u0430\u0445 UserEntity: \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441\u0430\u043c \u0445\u043e\u0434\u0438\u0442 \u0432 \u0431\u0430\u0437\u0443, \u043c\u0430\u043f\u0438\u0442 \u0440\u044f\u0434 \u0432 entity, \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u043e\u0442\u0434\u0430\u0451\u0442 \u0435\u0433\u043e \u0434\u0430\u043b\u044c\u0448\u0435. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e use-case\u2019\u0443 \u0431\u0435\u0437\u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e, \u043a\u0430\u043a\u0430\u044f ORM \u043b\u0435\u0436\u0438\u0442 \u043f\u043e\u0434 \u043d\u0438\u043c \u2014 TypeORM, Prisma, \u0433\u043e\u043b\u044b\u0439 SQL \u2014 \u0438 \u043a\u0430\u043a\u0430\u044f \u0442\u0430\u043c \u0431\u0430\u0437\u0430. \u0422\u0430\u043a \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u0437\u0430\u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0443\u0439\u0442\u0438 \u0441 TypeORM \u043d\u0430 Prisma \u0438\u043b\u0438 \u0441 Postgres \u043d\u0430 Mongo \u2014 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0443\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0432 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u0441\u043b\u043e\u0439: \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c entity, \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u043b\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f, \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u0411\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e\u0434\u043c\u0435\u043d\u044b \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442. \u0415\u0441\u043b\u0438 \u0431\u044b entity \u0432\u0441\u043f\u043b\u044b\u043b\u0430 \u043d\u0430\u0440\u0443\u0436\u0443 \u2014 \u0445\u043e\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0440\u0442, \u0445\u043e\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0432 use-case \u0447\u0435\u0440\u0435\u0437 findOne() \u2014 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0435\u0439 \u043d\u0430\u0440\u0443\u0436\u0443 \u0443\u0435\u0445\u0430\u043b\u0438 \u0431\u044b \u0438 save(), \u0438 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b, \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u0441\u0445\u0435\u043c\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b; \u0438 \u043b\u044e\u0431\u043e\u0439 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u043d\u0430\u0447\u0430\u043b \u0431\u044b \u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0431\u0445\u043e\u0434 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u0442\u0430.\/\/ user.tsexport type User = {  id: string;  email: string;  password: string;  createdAt: Date;};\/\/ user.entity.ts@Entity(&#171;users&#187;)export class UserEntity {  @PrimaryGeneratedColumn(&#171;uuid&#187;)  id: string;  @Column({ unique: true })  email: string;  @Column()  password: string;  @CreateDateColumn()  createdAt: Date;}\/\/ user.repository.ts@Injectable()export class UserRepository {  constructor(    @InjectRepository(UserEntity)    private readonly repository: Repository&lt;UserEntity&gt;,  ) {}  async create(data: CreateUserData): Promise&lt;Result&lt;User, CreateErrorCode&gt;&gt; {    const insertUserResult = await fromAsyncThrowable(async () =&gt;      this.repository.insert(data),    )();    if (insertUserResult.isErr()) {      if (isUniqueQueryError(insertUserResult.error)) {        return err(&#171;CREATE_USER_CONFLICT&#187;);      }      return err(&#171;CREATE_USER_DATABASE_ERROR&#187;);    }    const now = new Date();    return ok({      id: insertUserResult.value.identifiers[0].id,      email: data.email,      password: data.password,      createdAt: now,    });  }  async findByEmail(    email: string,  ): Promise&lt;Result&lt;User | undefined, FindErrorCode&gt;&gt; {    const findUserResult = await fromAsyncThrowable(async () =&gt;      this.repository.findOne({ where: { email } }),    &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-480737","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/480737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=480737"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/480737\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=480737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=480737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=480737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}