{"id":491073,"date":"2026-08-16T11:26:37","date_gmt":"2026-08-16T11:26:37","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=491073"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=491073","title":{"rendered":"Domain Driven Design \u0438 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043d\u043e\u043b\u0438\u0442 \u0432\u00a0Python"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041f\u0440\u043e\u043b\u043e\u0433<\/h2>\n<p>\u0412\u00a0\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0435\u00a0\u0431\u0443\u0434\u0443 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0432\u0441\u044e \u0442\u0435\u043e\u0440\u0438\u044e, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u0441\u00a0\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043e\u0439 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430 \u0438 Domain Driven Design, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u0432\u00a0\u0441\u0435\u0442\u0438 \u0438\u043b\u0438\u00a0\u043a\u043d\u0438\u0433\u0430\u0445, \u0433\u0434\u0435 \u0430\u0432\u0442\u043e\u0440\u044b \u0443\u0436\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043b\u0438 \u0432\u0441\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u044b.<\/p>\n<p>\u041c\u043d\u043e\u044e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0442\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u0442\u0438\u0445 \u0438\u0434\u0435\u0439 \u043d\u0430\u00a0\u044f\u0437\u044b\u043a\u0435 Python, \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u0434\u043b\u044f\u00a0\u043d\u0435\u0433\u043e \u044d\u0442\u043e \u043d\u0435\u00a0\u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0430\u044f\u0441\u044f \u0442\u0435\u043c\u0430 \u0432\u00a0\u0432\u0438\u0434\u0443 \u0435\u0433\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043c\u0435\u043d\u0435\u0435 \u0441\u0442\u0440\u043e\u0433\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u043d\u0435\u0436\u0435\u043b\u0438 \u0432\u00a0\u0441\u0442\u0440\u043e\u0433\u043e \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u0433\u0434\u0435 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0438 \u0437\u0430\u0440\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u044d\u0442\u0438 \u0438\u0434\u0435\u0438. \u0414\u043b\u044f\u00a0\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0432\u00a0\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0442\u0435\u043e\u0440\u0438\u044e, \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430\u00a0\u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e\u00a0\u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0443 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432\u00a0\u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438*. <\/p>\n<p>\u0412\u0441\u044f \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437\u00a0\u043c\u043e\u0435\u0433\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430\u00a0Python, \u0447\u0442\u043e\u00a0\u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435\u00a0\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0439 \u0432\u00a0\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0432\u044b \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435\u00a0\u0431\u044b\u0442\u044c \u043d\u0435\u00a0\u0441\u043e\u0433\u043b\u0430\u0441\u043d\u044b \u0441\u00a0\u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439, \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u043d\u0438\u0436\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u044e\u0431\u0430\u044f \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043a\u0440\u0438\u0442\u0438\u043a\u0430 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f.<\/p>\n<h2>\u041f\u043e\u0447\u0435\u043c\u0443 \u0432\u043e\u043e\u0431\u0449\u0435 DDD \u0438 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043d\u043e\u043b\u0438\u0442 \u0432\u00a0Python? <\/h2>\n<p>\u041f\u043e\u00a0\u043c\u0435\u0440\u0435 \u043c\u043e\u0435\u0439 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u043e\u0439 \u0434\u0435\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a\u00a0Python backend \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u044f \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0441\u044f \u0441\u00a0\u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0431\u044a\u0435\u043c\u043d\u044b\u043c\u0438, \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438, \u0433\u0434\u0435\u00a0\u0431\u044b\u043b\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0438. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043c, \u0442\u043e \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0439 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f\u00a0Python\u2011\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u0441\u043b\u043e\u0438\u0441\u0442\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e. \u0413\u0440\u0430\u043d\u0438\u0446\u044b \u0440\u0430\u0437\u043c\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u0432, \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f god\u2011objects, \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0445\u043b\u0430\u043c\u043b\u0435\u043d\u043d\u043e\u0439, \u0447\u0442\u043e\u00a0\u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u0435\u0442, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c\u00a0\u0431\u044b, \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0447\u0430\u0442\u044c \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 200\u00a0\u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430. \u0412\u00a0\u0441\u0432\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043f\u0440\u043e\u0432\u043e\u0434\u044f \u0432\u0440\u0435\u043c\u044f \u0432\u00a0\u043f\u043e\u0438\u0441\u043a\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430\u00a0\u0442\u0435\u043c\u0443 Domain Driven Design. \u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435\u00a0\u2014 Domain Driven \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0432\u043e\u043a\u0440\u0443\u0433 \u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043b\u043e\u0433\u0438\u043a\u0438 \u0438 \u0435\u0435 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432. <\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u00a0\u043d\u0438\u0437\u043a\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043b\u043e\u0433\u0438\u043a\u0438 \u043e\u0442\u00a0\u0432\u0441\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e, \u0447\u0442\u043e\u00a0\u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432\u00a0\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c \u043e\u0434\u043d\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u00a0\u0434\u0440\u0443\u0433\u0438\u0435 \u0431\u0435\u0437\u00a0\u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u043e\u043b\u043e\u043c\u043a\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432. <\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 \u043f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043d\u043e\u043b\u0438\u0442? \u0412\u0435\u0434\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c DDD \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438 \u0432\u00a0\u043e\u0431\u044b\u0447\u043d\u043e\u043c \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0435. \u0412\u00a0\u0447\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430? \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043e\u043c \u0438\u00a0\u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u043c \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u00a0\u0447\u0451\u0442\u043a\u043e\u043c\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u0433\u0440\u0430\u043d\u0438\u0446, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0438\u0437\u00a0\u043f\u043b\u044e\u0441\u043e\u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435\u00a0\u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u0443\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443, \u0434\u0435\u043f\u043b\u043e\u0439 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a\u00a0\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u00a0\u0441\u0438\u0445 \u043f\u043e\u0440 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043e\u043c. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430 \u0441\u043e\u0447\u0435\u0442\u0430\u0435\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u043f\u043b\u044e\u0441\u044b \u043e\u0431\u043e\u0438\u0445 \u044d\u0442\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432. <\/p>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u00a0\u043a\u043e\u0434\u0435<\/h2>\n<p>\u041a\u00a0\u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432\u00a0Python \u043d\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u044b\u0445, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043a\u0430\u043a,\u00a0\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Spring Modulith \u0432\u00a0Java \u0438\u043b\u0438\u00a0EF\/.NET \u0432\u00a0C#, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u043e. \u0412\u00a0Python \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u00a0\u043d\u0443\u043b\u044f, \u0447\u0442\u043e\u00a0\u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 \u0432\u00a0\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435\u00a0\u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442 \u0435\u0451 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0438 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0432\u043e\u0431\u043e\u0434\u0443 \u0432\u044b\u0431\u043e\u0440\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u0434\u00a0\u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438. \u0414\u0430\u043b\u0435\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a\u00a0\u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u00a0\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0432\u0441\u0451 \u0442\u043e, \u0447\u0442\u043e\u00a0\u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u00a0\u0442\u0435\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u00a0\u044d\u0442\u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u0438 \u043d\u0430\u0447\u043d\u0435\u043c, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u00a0\u0440\u0430\u0437\u0431\u043e\u0440\u0430 Domain Driven Design.<\/p>\n<h3>\u0414\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c<\/h3>\n<p>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0443 \u0438 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u0447\u0442\u043e\u00a0\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u044f\u0434\u0440\u043e \u0432\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0443\u0440\u043e\u0432\u043d\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0432\u043e\u043a\u0440\u0443\u0433 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0433\u043e. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f:<\/p>\n<p><strong>\u0414\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438\u00a0\u2014 <\/strong> \u043a\u0430\u043a\u00a0\u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u043e\u0434\u043d\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c (\u0430\u0433\u0440\u0435\u0433\u0430\u0442), \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u044e\u0442 \u043f\u0440\u0438\u0441\u0443\u0449\u0438\u0435 \u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043b\u043e\u0433\u0438\u043a\u0443. \u042f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u044f\u0434\u0440\u043e\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0415\u0441\u0442\u044c \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438: <\/p>\n<p>1) \u041e\u0431\u044b\u0447\u043d\u044b\u0439 Python \u043a\u043b\u0430\u0441\u0441\u00a0\u2014 \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431:<\/p>\n<pre><code class=\"python\">class Product:  id: int  name: str    def __init__(self, id: int, name: str):    self.id = id    self.name = name# \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435product = Product(id=1, name=\"Lamp\")<\/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>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437\u00a0\u043b\u0438\u0448\u043d\u0438\u0445 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u0432 \u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043e\u0434\u043d\u0430\u043a\u043e \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a\u00a0\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u043c\u0435\u0442\u043e\u0434\u0430 \u0440\u0435\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438 (\u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e), \u0430\u00a0\u0442\u0430\u043a\u0436\u0435\u00a0\u043b\u0438\u043d\u0442\u0435\u0440\u044b \u0438 \u0442\u0438\u043f\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0436\u0430\u043b\u0443\u044e\u0442\u0441\u044f \u043d\u0430\u00a0built\u2011in \u0438\u043c\u0435\u043d\u0430 \u043f\u043e\u043b\u0435\u0439 \u043f\u043e\u00a0\u0442\u0438\u043f\u0443 id, type \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>2) Python dataclass\u00a0\u2014 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f dataclasses:<\/p>\n<pre><code class=\"python\">from dataclasses import dataclass@dataclassclass Product:  id: int  name: str# \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435product = Product(id=1, name=\"Lamp\")<\/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\u0437\u00a0\u043f\u043b\u044e\u0441\u043e\u0432\u00a0\u2014 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438 \u0440\u0435\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438\u0437\u00a0\u043a\u043e\u0440\u043e\u0431\u043a\u0438, \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0\u0434\u0435\u0444\u043e\u043b\u0442\u0430\u043c\u0438 \u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0430\u043c\u0438 \u0443\u00a0\u043f\u043e\u043b\u0435\u0439, \u043d\u0435\u0442 \u0436\u0430\u043b\u043e\u0431 \u043e\u0442\u00a0\u043b\u0438\u043d\u0442\u0435\u0440\u043e\u0432 \u0438 \u0442\u0438\u043f\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432. \u041c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c frozen=True \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 read\u2011only \u043c\u043e\u0434\u0435\u043b\u044c. \u0418\u0437\u00a0\u043c\u0438\u043d\u0443\u0441\u043e\u0432\u00a0\u2014 \u0438\u043c\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0443\u043b\u044f dataclasses, \u0432\u00a0\u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442\u00a0\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, dataclass \u0432\u0435\u0440\u0441\u0438\u044f \u043f\u043e\u00a0\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u0435\u00a0\u0445\u0435\u0448\u0438\u0440\u0443\u0435\u043c\u0430 (\u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c <code>frozen=True<\/code>), \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441\u00a0set \u0438 dict \u0442\u0438\u043f\u0430\u043c\u0438.<\/p>\n<p>3) Pydantic BaseModel\u00a0\u2014 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 pydantic:<\/p>\n<pre><code class=\"python\">from pydantic import BaseModelclass Product(BaseModel):  id: int  name: str# \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435product = Product(id=1, name=\"Lamp\")<\/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\u0437\u00a0\u043f\u043b\u044e\u0441\u043e\u0432\u00a0\u2014 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u043e\u0442\u00a0\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e\u00a0\u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438\u00a0\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437\u00a0\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0432\u00a0\u0434\u0440\u0443\u0433\u043e\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043e\u043c\u0435\u043d \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442\u00a0\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0447\u0442\u043e,\u00a0\u043f\u043e\u00a0\u043c\u043e\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e, \u043d\u0435\u00a0\u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0434\u0444\u043b\u0430\u0433, \u043f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a\u00a0\u0440\u0430\u0432\u043d\u044b\u0445 \u043f\u043e\u00a0\u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044e, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 \u0438 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 pydantic \u0432\u00a0Python \u043d\u0435\u0442, \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c pydantic \u0432\u00a0Python \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0430\u00a0\u0447\u0442\u043e\u2011\u0442\u043e \u0438\u043d\u043e\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435\u00a0\u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430. \u041e\u0431\u044a\u0435\u043a\u0442 \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0430\u043a\u00a0\u0436\u0435 \u043d\u0435\u00a0\u0445\u0435\u0448\u0438\u0440\u0443\u0435\u043c, \u043f\u043e\u043a\u0430 \u043d\u0435\u00a0\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d <code>model_config = ConfigDict(frozen=True)<\/code>.<\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442\u00a0\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0438\u043b\u0438\u00a0\u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0447\u0442\u043e\u0431\u044b \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0435\u0444\u043e\u043b\u0442\u043e\u0432 \u0443\u00a0\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0438\u043b\u0438\u00a0\u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0432\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043c\u0435\u044e\u0442\u0441\u044f. <\/p>\n<pre><code class=\"python\"># \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430class Product(BaseModel):  id: UUID  name: str  status: ProductStatus  def __init__(self, name: str):    super().__init__(      id=uuid4(),      name=name,      status=ProductStatus.ACTIVE,    )    # \u0418\u043b\u0438 \u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u043c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435class User(BaseModel):  id: UUID  name: str    @classmethod  def register(cls, name: str) -&gt; \"User\":    return cls(      id=uuid4(),      name=name    )<\/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> <strong>\u041e\u0431\u044a\u0435\u043a\u0442\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 (value objects)\u00a0\u2014<\/strong> \u0441\u043b\u0443\u0436\u0430\u0442 \u043a\u0430\u043a\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e\/\u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e\u043b\u0435\u0439 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0438\u043d\u0441\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0440\u0430\u0437\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0432\u043e\u0439 \u043c\u043d\u043e\u0433\u043e. \u041c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0437\u00a0\u0441\u0435\u0431\u044f \u043b\u044e\u0431\u043e\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u00a0\u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e type alias \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435\u0439.<\/p>\n<pre><code class=\"python\">from uuid import UUIDfrom enum import StrEnumfrom dataclasses import dataclasstype EntityId = UUIDclass Currency(StrEnum):  UZS = \"uzs\"  USD = \"usd\"  # \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438\u043b\u0438 Pydantic, \u043a\u0430\u043a \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438@dataclassclass Money:  currency: Currency  amount: int    def __init__(self, currency: Currency, amount: int):    if amount &lt;= 0:      raise ValueError(\"Money amount should be greater than zero\")          self.currency = currency    self.amount = amount      def convert(self, to: Currency):    if self.currency != to:      if to == Currency.USD:        self.amount = int(self.amount \/ 12000)      else:      self.amount = self.amount * 12000      self.currency = to<\/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> <strong>\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u00a0\u2014<\/strong> \u043e\u0431\u044b\u0447\u043d\u043e \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u0431\u0430\u0437\u043e\u0432\u043e\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043d\u0430\u00a0\u043e\u0431\u0449\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430.<\/p>\n<pre><code class=\"python\"># \u041e\u0431\u0449\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044cclass DomainError(Exception):  status: int = 500  code: str = \"internal_server_error\"  message: str      def __init__(self, message: str):      self.message = message      # \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432 \u0434\u043e\u043c\u0435\u043d\u0435class OrderNotFound(DomainError):  status = 404  code = \"order_not_found\"  class InvalidOrderStatus(DomainError):  status = 400  code = \"invalid_order_status\"  # \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435def cancel_order(repo: OrderRepo, order_id: int):  order = repo.get_by_id(order_id)  if order is None:    raise OrderNotFound(f\"Order {order_id} not found\")      order.cancel()  class Order:  id: int  status: OrderStatus    def cancel(self):  if self.status != OrderStatus.ACTIVE:    raise InvalidOrderStatus(      f\"Invalid order {self.id} status {self.status}, expected status      {OrderStatus.ACTIVE} to cancel\"    )  self.status = OrderStatus.CANCELLED<\/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\u00a0\u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043e\u0442\u0432\u0435\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043a\u0430\u043a\u00a0\u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0442\u0440\u0438 \u0432\u0435\u0449\u0438\u00a0\u2014 \u0441\u0442\u0430\u0442\u0443\u0441, \u043a\u043e\u0434 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443. \u042f \u043d\u0435\u00a0\u0432\u0438\u0436\u0443 \u043d\u0438\u0447\u0435\u0433\u043e \u0437\u0430\u0437\u043e\u0440\u043d\u043e\u0433\u043e \u0432\u00a0\u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u0438 \u043a\u043e\u0434\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430\u00a0\u0443\u0440\u043e\u0432\u043d\u0435 \u0434\u043e\u043c\u0435\u043d\u0430, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0438 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432\u00a0HTTP \u043e\u0442\u0432\u0435\u0442\u044b, \u0447\u0442\u043e\u00a0\u044f \u0441\u0447\u0438\u0442\u0430\u044e \u0438\u0437\u043b\u0438\u0448\u043d\u0435\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e. \u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u043c\u043f\u0440\u043e\u043c\u0438\u0441\u0441 \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c: \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0432\u0435\u0440\u0445 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u00a0\u0445\u0435\u043d\u0434\u043b\u0438\u043d\u0433 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0441\u043b\u043e\u044e, \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043b\u043e\u0433\u0438\u043a\u0438 \u043d\u0430\u00a0\u0441\u043b\u0443\u0447\u0430\u0439 \u043e\u0448\u0438\u0431\u043a\u0438, \u0438\u043b\u0438\u00a0\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u0434\u043b\u044f\u00a0\u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u0447\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f exception handlers (\u0435\u0441\u043b\u0438 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e\u00a0FastAPI) \u0438\u043b\u0438\u00a0\u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u0430\u044f middleware.<\/p>\n<p><strong>\u0421\u043e\u0431\u044b\u0442\u0438\u044f\u00a0\u2014<\/strong> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u044b (\u043e\u0431\u044b\u0447\u043d\u044b\u0435, Pydantic \u0438\u043b\u0438\u00a0\u0434\u0430\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b), \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043f\u043b\u043e\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0431\u0435\u0437 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0431\u0435\u0437\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u0440\u043e\u043c\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430), \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u043b\u044f\u00a0\u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e\u00a0\u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0432\u00a0\u043e\u0434\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0434\u043b\u044f\u00a0\u0434\u0440\u0443\u0433\u0438\u0445 \u0447\u0430\u0441\u0442\u0435\u0439, \u0431\u0435\u0437\u00a0\u0438\u0445 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430. \u041c\u043e\u0433\u0443\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a\u00a0\u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0442\u0430\u043a \u0438 \u043d\u0430\u00a0\u0430\u043f\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f batch \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430\u0434 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u0438\u043b\u0438\u00a0\u043d\u0443\u0436\u043d\u043e \u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043e\u00a0\u043a\u0430\u043a\u043e\u043c\u00a0\u043b\u0438\u0431\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438, \u043d\u0435\u00a0\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u043c \u043d\u0438 \u0441\u00a0\u043e\u0434\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<pre><code class=\"python\">from pydantic import BaseModelfrom dataclasses import dataclass, field# \u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430 \u043e\u0431\u0449\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435class DomainEvent(BaseModel):  pass# \u041a\u043b\u0430\u0441\u0441 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439@dataclassclass DomainModel:  _events: list[DomainEvent] = field(default_factory=list, init=False)# \u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0434\u043e\u043c\u0435\u043d\u0430class OrderCancelled(DomainEvent):  order_id: int# \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435@dataclassclass Order(DomainModel):  id: int  status: OrderStatus  def cancel(self):    self.status = OrderStatus.CANCELLED    self._events.append(OrderCancelled(order_id=self.id))<\/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<h3>\u0418\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c <\/h3>\n<p>\u041d\u0430\u00a0\u044d\u0442\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430\u00a0\u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441\u00a0\u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0443\u0437\u043b\u0430\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a\u00a0\u0431\u0434, \u0432\u043d\u0435\u0448\u043d\u0438\u0439 API, \u043a\u0435\u0448 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b:<\/p>\n<p><strong>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441\u00a0\u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445\u00a0\u2014 <\/strong>\u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e DDD \u0434\u043e\u043c\u0435\u043d \u0434\u043e\u043b\u0436\u0435\u043d\u00a0\u0431\u044b\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u0435\u043d \u0438 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c \u043e\u0442\u00a0\u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0442\u0438\u043f\u044b, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0434\u043b\u044f\u00a0\u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0\u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u00a0\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u00a0\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u041f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a\u00a0\u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SQLAlchemy \u0438 Postgres \u0432\u00a0\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430\u00a0\u0437\u0430\u0432\u0442\u0440\u0430 \u043f\u0435\u0440\u0435\u0435\u0434\u0435\u0442\u0435 \u043d\u0430\u00a0Motor \u043e\u0442\u00a0MongoDB \u0438 \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u043b\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043f\u043e\u0434\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0443\u044e \u0431\u0434, \u0447\u0442\u043e\u00a0\u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0442 \u0441\u0430\u043c\u043e\u0439 \u0441\u0443\u0442\u0438 Domain Driven \u043f\u043e\u0434\u0445\u043e\u0434\u0430. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0441\u0442\u043e\u0438\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0438\u0445 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0438 \u043c\u0430\u043f\u043f\u0438\u0442\u044c \u0434\u0440\u0443\u0433 \u043d\u0430\u00a0\u0434\u0440\u0443\u0433\u0430 \u0432\u00a0\u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0412\u044b \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0442\u0435 \u0446\u0435\u043d\u0443 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043e\u0432\u0435\u0440\u0445\u0435\u0434\u0430 \u0437\u0430\u00a0\u0447\u0438\u0441\u0442\u043e\u0442\u0443 \u043a\u043e\u0434\u0430 \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. <\/p>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043d\u0430\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0435 SQLAlchemy (\u0434\u043b\u044f nosql \u0438\u043b\u0438\u00a0\u0438\u043d\u044b\u0445 sql\u2011oriented \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0442\u0435\u2011\u0436\u0435), \u043f\u043e\u00a0\u0441\u0443\u0442\u0438 \u0432\u0441\u0435 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u043a\u00a0\u0434\u0432\u0443\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0430\u00a0\u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0434 \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442:<\/p>\n<p> <em>1) \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0430\u043f\u043f\u0435\u0440\u0430:<\/em> \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043b\u0430\u0441\u0441, \u043b\u044e\u0431\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0441\u043e\u0431\u043e\u0439 \u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0435\u0435 \u0437\u0432\u0435\u043d\u043e \u043c\u0435\u0436\u0434\u0443 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0438 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0435\u0441\u0442\u044c ORM \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"python\">class ProductORM(Base):  __tablename__ = \"products\"    id: Mapped[int] = mapped_column(Integer, primary_key=True)  name: Mapped[str] = mapped_column(String)<\/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>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u043c\u0430\u043f\u043f\u0438\u0442\u044c \u0435\u0435 \u0432\u00a0\u043d\u0430\u0448\u0443 \u0434\u043e\u043c\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u00a0\u0447\u0438\u0441\u0442\u043e\u043c Python \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442: <\/p>\n<pre><code class=\"python\">@dataclassclass Product:  id: int  name: str    def update_name(self, name: str):    self.name = name<\/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\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043c\u0430\u043f\u043f\u0435\u0440\u0430:<\/p>\n<pre><code class=\"python\">class ProductMapper:  @staticmethod  def map_domain_to_orm(domain: Product) -&gt; ProductORM:    return ProductORM(      id=domain.id,      name=domain.name    )      @staticmethod  def map_orm_to_domain(orm: ProductORM) -&gt; Product:    return Product(      id=orm.id,      name=orm.name    )      @staticmethod  def map_domain_to_values(domain: Product) -&gt; dict:    return {      \"name\": domain.name    }<\/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\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f\u00a0\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0447\u0435\u0440\u0435\u0437 batch update \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c values, \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u0432\u00a0\u0434\u043e\u043c\u0435\u043d\u043d\u043e\u043c \u0441\u043b\u043e\u0435 \u043c\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u00a0Python \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0430\u00a0\u043d\u0435\u00a0\u0441\u00a0ORM \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e.<\/p>\n<pre><code class=\"python\">class ProductRepo:  def __init__(self, session: AsyncSession, mapper: ProductMapper):    self.session = session    self.mapper = mapper      async def find_by_id(self, product_id: int) -&gt; Product | None:    orm = await self.session.get(ProductORM, product_id)    if orm is None:      return None        return self.mapper.map_orm_to_domain(orm)    async def save(self, product: Product) -&gt; None:    orm = self.mapper.map_domain_to_orm(product)    self.session.add(orm)      async def update(self, product: Product) -&gt; None:    values = self.mapper.map_domain_to_values(product)    await self.session.execute(      update(ProductORM)      .where(ProductORM.id == product.id)      .values(**values)    )<\/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> <em>2) \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430 \u0447\u0435\u0440\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/em> \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f\u00a0\u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441\u00a0\u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437\u00a0\u0431\u0434 \u0432\u00a0\u043e\u0431\u044b\u0447\u043d\u044b\u0435 Python \u043a\u043b\u0430\u0441\u0441\u044b, \u0432\u00a0\u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 SQLAlchemy, \u0442\u0430\u043c \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 (\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439) \u043c\u0430\u043f\u043f\u0438\u043d\u0433:<\/p>\n<pre><code class=\"python\">product_table = Table(  \"products\",  metadata,  Column(\"id\", Integer, primary_key=True),  Column(\"name\", String, nullable=False))# \u041a\u043b\u0430\u0441\u0441 Product \u044d\u0442\u043e \u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 dataclass \u0447\u0442\u043e \u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u0440\u0430\u043d\u0435\u0435mapper_registry.map_imperatively(  Product,  product_table)<\/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\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u00a0\u043d\u0430\u0448\u0438\u043c Python \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u043a\u0430\u043a\u00a0\u0441\u00a0ORM, \u043d\u0435\u00a0\u0432\u043d\u043e\u0441\u044f \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 SQLAlchemy \u0432\u00a0\u0434\u043e\u043c\u0435\u043d.<\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431\u00a0\u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0435 SQLAlchemy \u0438\u043b\u0438\u00a0\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0439 \u0432\u0430\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f\u00a0\u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441\u00a0\u0431\u0434 \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432\u00a0\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438. <\/p>\n<p> <strong>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u044b\u00a0\u2014<\/strong> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f\u00a0\u0441\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u043e\u0442\u00a0\u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u0435\u0439, \u0432\u00a0\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u00a0\u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0447\u0435\u0440\u0435\u0437 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439\u00a0\u2014 abc. \u0412\u00a0\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0440\u0430\u043d\u0435\u0435 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439: <\/p>\n<pre><code class=\"python\">from abc import ABC, abstractmethodclass IProductRepo(ABC):  @abstractmethod  async def find_by_id(self, product_id: int) -&gt; Product | None:    raise NotImplementedError()      @abstractmethod  async def save(self, product: Product) -&gt; None:    raise NotImplementedError()    class ProductRepo(IProductRepo):  def __init__(self, session: AsyncSession):    self.session = session      async def find_by_id(self, product_id: int) -&gt; Product | None:    return await self.session.get(Product, product_id)  async def save(self, product: Product) -&gt; None:    self.session.add(product)<\/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\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0441\u043a\u0440\u044b\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0437\u0430\u00a0\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a\u00a0\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u043c \u0434\u0435\u0442\u0430\u043b\u044f\u043c \u0432\u00a0\u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043b\u043e\u044f\u0445.<\/p>\n<pre><code class=\"python\">def get_repo(session: AsyncSession) -&gt; IProductRepo:  return ProductRepo(session=session)async def service():  async with session_factory() as session:    repo = get_repo(session)    await repo.session.commit() # Unresolved attribute reference 'session' for class 'IProductRepo'<\/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<h3>\u0410\u043f\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c <\/h3>\n<p>\u041d\u0430\u00a0\u044d\u0442\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0441\u00a0\u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b:<\/p>\n<p> <strong>DataTransferObjects \/ \u0421\u0445\u0435\u043c\u044b \/ Response models\u00a0\u2014<\/strong> \u042d\u0442\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0442 \u0437\u0430\u00a0\u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u044e \u0438 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043d\u0443\u0442\u0440\u044c \u0438 \u0432\u043e\u0432\u043d\u0435 \u0430\u043f\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f. \u041f\u043e\u00a0\u0441\u0443\u0442\u0438 \u0432\u0441\u0435 \u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u0435\u0440\u043c\u0438\u043d\u0430 \u044d\u0442\u043e \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u044b, \u0432\u044b\u0431\u043e\u0440 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u0430\u0440\u044c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u00a0\u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043a\u00a0\u043f\u0440\u043e\u0435\u043a\u0442\u0443. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043a\u0430\u043a\u0438\u0435\u00a0\u043b\u0438\u0431\u043e \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u043b\u044f\u00a0\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u043b\u0438\u00a0\u0443\u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435 \u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043a\u00a0\u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 DTO \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c dataclass@dataclass(frozen=True)class CreateProductDTO:  name: str  price: int# \u041f\u0440\u0438\u043c\u0435\u0440 Pydantic \u0441\u0445\u0435\u043c\u044b \u0434\u043b\u044f \u0432\u044b\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u0443class CategoryRef(BaseModel):  name: str  priority: intclass ProductOut(BaseModel):  id: int  name: str  categories: list[CategoryRef]<\/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\u00a0\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0443\u00a0\u043c\u0435\u043d\u044f \u0432\u00a0\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0432\u0441\u0435 \u0441\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043a\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e Pydantic, \u043a\u0430\u043a\u00a0\u0434\u043b\u044f\u00a0\u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0432\u043e\u0434\u0430, \u0432\u044b\u0432\u043e\u0434\u0430 \u0442\u0430\u043a \u0438 \u0434\u043b\u044f\u00a0\u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0441\u043b\u043e\u044f\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u0440\u0438\u00a0\u044d\u0442\u043e\u043c \u044f \u043d\u0435\u00a0\u0441\u0447\u0438\u0442\u0430\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 DTO \u0441\u0445\u0435\u043c\u044b \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u044f, \u043f\u043e\u00a0\u0442\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b \u0432\u044b\u0448\u0435 (Pydantic \u043f\u043e\u00a0\u0441\u0443\u0442\u0438 \u043c\u043e\u043d\u043e\u043f\u043e\u043b\u0438\u0441\u0442 \u043d\u0430\u00a0\u0440\u044b\u043d\u043a\u0435 Python). \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441\u0432\u043e\u0434\u0438\u0442 \u043a\u00a0\u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0443 \u0431\u043e\u0439\u043b\u0435\u0440\u043f\u043b\u0435\u0439\u0442 \u0441\u00a0\u043c\u0430\u043f\u043f\u0438\u043d\u0433\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043b\u043e\u0439 \u0438 \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043a\u043e\u0433\u043d\u0438\u0442\u0438\u0432\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443.<\/p>\n<p><strong>\u0421\u0435\u0440\u0432\u0438\u0441\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430\u00a0\u2014<\/strong> \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0443\u0442 \u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0432\u0441\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u0430, \u0432\u00a0\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442\u00a0\u0432\u0438\u0434\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0430 \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u043c\u0435\u043d\u0430. \u041f\u0440\u0438\u00a0\u044d\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b, \u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u00a0\u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445.<\/p>\n<p> <em>1) \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u00a0\u043e\u0434\u043d\u043e\u043c Python\u2011\u043c\u043e\u0434\u0443\u043b\u0435: <\/em><\/p>\n<pre><code class=\"python\">async def create_product(uow: UnitOfWork, repo: ProductRepo, data: CreateProductData) -&gt; ProductOut:  async with uow:    product = Product.create(name=data.name, category=data.category)    await repo.save(product)      return ProductOut.model_validate(product, from_attributes=True)  async def cancel_order(uow: UnitOfWork, repo: OrderRepo, data: CancelOrderData) -&gt; None:...<\/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\u043b\u044e\u0441\u044b \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432\u00a0\u0442\u043e\u043c \u0447\u0442\u043e\u00a0\u043c\u044b \u043d\u0435\u00a0\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u043b\u044f\u00a0\u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, Python \u0444\u0430\u0439\u043b \u0443\u0436\u0435 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u044d\u0442\u0438\u043c \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u00a0\u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0438 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u00a0\u043e\u0434\u043d\u043e\u043c\u0443 \u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434. <\/p>\n<p>\u041f\u0440\u0438\u00a0\u044d\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u00a0\u0432\u044b\u0437\u043e\u0432\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u044b\u0435 \u0435\u043c\u0443 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u0431\u0435\u0437\u00a0\u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u0442\u044c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0432\u0441\u0435, \u043a\u0430\u043a\u00a0\u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u00a0\u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0447\u0443\u0442\u044c \u043d\u0438\u0436\u0435.<\/p>\n<p>\u0418\u0437\u00a0\u043c\u0438\u043d\u0443\u0441\u043e\u0432 \u0442\u043e \u0447\u0442\u043e\u00a0\u043d\u0430\u00a0\u0443\u0440\u043e\u0432\u043d\u0435 \u0442\u043e\u0447\u0435\u043a \u0432\u0445\u043e\u0434\u0430 \u0432\u00a0\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. <\/p>\n<p><em>2) \u0415\u0434\u0438\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441: <\/em><\/p>\n<pre><code class=\"python\">class ShopService:   def __init__(self, uow: UnitOfWork, product_repo: ProductRepo, order_repo: OrderRepo):     self.uow = uow     self.product_repo = product_repo     self.order_repo = order_repo       async def create_product(self, data: CreateProductData) -&gt; ProductOut:     async with self.uow:       product = Product.create(name=data.name, category=data.category)       await self.product_repo.save(product)       return ProductOut.model_validate(product, from_attributes=True)       async def cancel_order(self, data: CancelOrderData) -&gt; None:     ...<\/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\u0437\u00a0\u043f\u043b\u044e\u0441\u043e\u0432\u00a0\u2014 \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0440\u044f\u0434\u0443 \u0441\u00a0\u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u00a0\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0434\u043b\u044f\u00a0\u0432\u0441\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u0440\u0430\u0437\u0443. <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043c\u0438\u043d\u0443\u0441\u043e\u043c \u0435\u0441\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 \u043e\u0431\u0440\u0430\u0441\u0442\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0440\u0430\u0437\u043d\u043e\u0448\u0435\u0440\u0441\u0442\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0438\u0437\u00a0\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043f\u0430\u0440\u0443 \u0448\u0442\u0443\u043a \u0432\u043e\u00a0\u0432\u0440\u0435\u043c\u044f runtime. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u043f\u043e\u00a0\u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 SRP: <\/p>\n<pre><code class=\"python\">class ProductService:  def __init__(self, uow: UnitOfWork, repo: ProductRepo):    self.uow = uow    self.repo = repo    async def create(self, data: CreateProductData) -&gt; ProductOut:    async with self.uow:      product = Product.create(name=data.name, category=data.category)      await self.repo.save(product)      return ProductOut.model_validate(product, from_attributes=True)      class OrderService:    def __init__(self, uow: UnitOfWork, repo: OrderRepo):      self.uow = uow      self.repo = repo    async def cancel(self, data: CancelOrderData) -&gt; None:      ...<\/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\u043e\u00a0\u0434\u0430\u0436\u0435 \u0442\u0443\u0442 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b: \u0435\u0441\u043b\u0438 \u0434\u043b\u044f\u00a0\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u0430 \u043d\u0443\u0436\u043d\u044b \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043d\u0435\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u043e\u043c, \u043d\u043e\u00a0\u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u044b (\u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u044d\u0442\u043e \u0432\u00a0DI), \u0431\u0440\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u00a0\u043f\u0443\u043b\u0430 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435<\/p>\n<p><em>3) (\u041f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430\u00a0\u0442\u043e \u0447\u0442\u043e\u00a0\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u00a0Java \u0438\u043b\u0438\u00a0C#) \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435:<\/em><\/p>\n<pre><code class=\"python\">class CreateProductHandler:  def __init__(self, uow: UnitOfWork, repo: ProductRepo):    self.uow = uow    self.repo = repo    async def handle(self, data: CreateProductData) -&gt; ProductOut:    async with self.uow:      product = Product.create(name=data.name, category=data.category)      await self.repo.save(product)      return ProductOut.model_validate(product, from_attributes=True)  class CancelOrderHandler:  def __init__(self, uow: UnitOfWork, repo: OrderRepo):    self.uow = uow    self.repo = repo    async def handle(self, data: CancelOrderData) -&gt; None:    ...<\/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>\u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441\u043e\u0447\u0435\u0442\u0430\u0435\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u043f\u043b\u044e\u0441\u044b \u043e\u0431\u043e\u0438\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445, \u043e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0438\u0445 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u043e\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e, \u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a\u00a0\u043e\u0432\u0435\u0440\u0445\u0435\u0434\u0443 \u0438\u0437\u00a0\u0437\u0430\u00a0\u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u0430\u00a0\u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u0435\u043c \u0444\u0430\u0431\u0440\u0438\u043a \u0432\u00a0\u0442\u043e\u0447\u043a\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0442\u0430\u043c \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 wiring \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f DI \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440).<\/p>\n<h3>\u0422\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 (\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c) <\/h3>\n<p>\u041d\u0430\u0434\u043e\u043b\u0433\u043e \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u00a0\u044d\u0442\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043d\u0435\u00a0\u0431\u0443\u0434\u0443, \u044d\u0442\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c, \u043d\u0430\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0435 \u0447\u0442\u043e\u00a0\u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441\u00a0\u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043a\u00a0\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e. API \u0440\u043e\u0443\u0442\u0435\u0440\u044b, \u0432\u0435\u0431 \u0441\u043e\u043a\u0435\u0442\u044b, \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0434\u0430\u0436\u0435 \u0437\u0430\u043f\u0443\u0441\u043a \u043a\u0440\u043e\u043d \u0442\u0430\u0441\u043e\u043a \u0438 \u0434\u0436\u043e\u0431\u043e\u0432. \u041b\u044e\u0431\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0437\u0434\u0435\u0441\u044c. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0441\u0443\u0434\u0438\u0442\u044c \u043d\u0430\u00a0\u044d\u0442\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u044d\u0442\u043e \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0447\u0435\u0440\u0435\u0437 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b Web \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0438\u043b\u0438\u00a0\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e DI \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 DI \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u044f\u0437\u044b\u043a\u0430 Python. \u041d\u043e\u00a0\u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043d\u0430\u00a0\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0439, \u043f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a\u00a0\u0441\u00a0\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0440\u044f\u0434 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0443\u0436\u043d\u0430 \u0432\u00a0\u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u044f\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 (\u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d\u044b, per\u2011request), \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0432 \u043e\u0431\u00a0\u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f\u0445 DDD, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0441\u0443\u0434\u0438\u0442\u044c, \u043a\u0430\u043a\u00a0\u0436\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043d\u043e\u043b\u0438\u0442? <\/p>\n<h2>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <\/h2>\n<p>\u041e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430\u00a0\u0438\u0437\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u044f \u043f\u0440\u0438\u0448\u0435\u043b \u043a\u00a0\u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u0432\u044b\u0432\u043e\u0434\u0443\u00a0\u2014 \u0447\u0442\u043e\u00a0\u043c\u043e\u0434\u0443\u043b\u044c, \u043e\u0431\u044b\u0447\u043d\u043e, \u044d\u0442\u043e \u0434\u043e\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c (\u0438\u043b\u0438\u00a0\u0436\u0435 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441), \u0430\u00a0\u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043d\u043e\u043b\u0438\u0442 \u044d\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0442\u0430\u043a\u0438\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0432\u00a0\u043e\u0434\u043d\u043e\u0439 \u0435\u0434\u0438\u043d\u0438\u0446\u0435 \u0434\u0435\u043f\u043b\u043e\u044f. \u041e\u0434\u0438\u043d \u043c\u043e\u0434\u0443\u043b\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0438\u0441\u0443\u0449\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0433\u043e \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u041a\u0430\u043a\u00a0\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0434\u0443\u043b\u044c Shop \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432, \u0437\u0430\u043a\u0430\u0437\u043e\u0432, \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430, \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u00a0\u043d\u0438\u043c\u0438 \u0438 \u043d\u0435\u00a0\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c, \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438\u0437\u00a0\u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0438\u043b\u0438\u00a0\u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u00a0\u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0443\u044e\u0441\u044f \u043a\u00a0\u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0443 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443. \u041e\u0434\u0438\u043d \u043c\u043e\u0434\u0443\u043b\u044c \u043c\u043e\u0436\u0435\u0442\u00a0\u043b\u0438\u0448\u044c \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043b\u0438\u00a0\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u00a0\u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u044f\u043c\u0443\u044e \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0432\u0445\u043e\u0434\u0430, \u0438\u043b\u0438\u00a0\u0436\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u043e\u00a0\u0441\u0432\u043e\u0438\u0445 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 (\u0442\u0430\u043a\u043e\u0439\u2011\u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a\u0430\u043a\u00a0\u0438 \u0432\u00a0\u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445).<\/p>\n<p>\u042d\u0442\u043e \u0434\u0430\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u043e\u0441\u0442\u044c, \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430\u00a0\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445 \u0438 \u043b\u0435\u0433\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0445, \u0447\u0442\u043e\u00a0\u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0432\u00a0\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u00a0\u0441\u0447\u0435\u0442 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u043a\u043e\u0433\u043d\u0438\u0442\u0438\u0432\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 (\u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u043a\u0443\u0447\u0443 \u0432\u0437\u0430\u0438\u043c\u043d\u044b\u0445 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u0432 \u0438 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b \u043d\u0430 200\u00a0\u0441\u0442\u0440\u043e\u043a \u043a\u0430\u0436\u0434\u044b\u0439). \u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u042f\u00a0\u0431\u044b \u0432\u044b\u0434\u0435\u043b\u0438\u043b \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043b\u043e\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/p>\n<div class=\"floating-image\">\n<figure class=\"float \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dc2\/91c\/28f\/dc291c28f9e220b50584dee960669095.png\" alt=\"\u0424\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043e\u0431\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f\" title=\"\u0424\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043e\u0431\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f\" width=\"303\" height=\"564\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/dc2\/91c\/28f\/dc291c28f9e220b50584dee960669095.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dc2\/91c\/28f\/dc291c28f9e220b50584dee960669095.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0424\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043e\u0431\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f<\/figcaption><\/div>\n<\/figure>\n<p><em>1) \u0432\u0435\u0440\u0445\u043d\u0438\u0439 (\u043e\u0431\u0449\u0438\u0439) \u0443\u0440\u043e\u0432\u0435\u043d\u044c\u00a0\u2014 <\/em>\u0433\u0434\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u0444\u0430\u0439\u043b\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (main.py \u0438\u043b\u0438\u00a0run.py), \u043e\u0431\u0449\u0438\u0435 \u0438\u043b\u0438\u00a0\u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b, \u043e\u0431\u0449\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0441\u0431\u043e\u0440\u043a\u0438 \u0438 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430. \u041d\u0430\u00a0\u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u0435 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e: \u0444\u0430\u0439\u043b\u044b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432\u00a0core\/, \u043e\u0431\u0449\u0438\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u00a0shared\/, \u0444\u0430\u0439\u043b\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438 \u0441\u043a\u043b\u0435\u0439\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u00a0\u0432\u0435\u0440\u0445\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435, \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u043e\u0441\u043e\u0431\u043b\u0435\u043d\u043d\u043e. \u0422\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0443\u043b\u044e Shop \u043d\u0443\u0436\u0435\u043d \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439, \u0437\u0430\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u00a0\u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043a\u0430\u0437\u0430 Order \u0438 \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Postgres \u0447\u0435\u0440\u0435\u0437 sqlalchemy, \u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043d\u0430\u00a0\u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f, \u0430\u00a0\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u00a0\u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043d\u0430\u00a0\u0432\u0435\u0440\u0445\u043d\u0438\u0439 (\u043e\u0431\u0449\u0438\u0439) \u0443\u0440\u043e\u0432\u0435\u043d\u044c, \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u044d\u0442\u043e \u0435\u0434\u0438\u043d\u0430\u044f \u0435\u0434\u0438\u043d\u0438\u0446\u0430 \u0434\u0435\u043f\u043b\u043e\u044f, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u0432\u00a0\u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u043e\u0434\u0443\u043b\u044f\u0445.<\/p>\n<\/div>\n<div class=\"floating-image\">\n<figure class=\"float \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cf5\/14f\/afd\/cf514fafd3ed3eea052827cbe0d47172.png\" alt=\"\u0424\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043b\u043e\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439\" title=\"\u0424\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043b\u043e\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439\" width=\"227\" height=\"688\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/cf5\/14f\/afd\/cf514fafd3ed3eea052827cbe0d47172.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cf5\/14f\/afd\/cf514fafd3ed3eea052827cbe0d47172.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0424\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043b\u043e\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/figcaption><\/div>\n<\/figure>\n<p><em>2) \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043c\u043e\u0434\u0443\u043b\u0435\u0439\u00a0\u2014<\/em> \u0433\u0434\u0435 \u043c\u044b \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0445 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c. \u041f\u0440\u0438\u00a0\u044d\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0440\u0430\u0437\u043d\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e. \u0425\u043e\u0442\u0438\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c Shop \u0432\u00a0\u0441\u0442\u0438\u043b\u0435 DDD? \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430. \u0414\u043b\u044f\u00a0\u043c\u043e\u0434\u0443\u043b\u044f Notifications \u0432\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0430\u0440\u044b \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u00a0\u0440\u043e\u0443\u0442\u0435\u0440\u0435? \u043a\u0430\u043a\u00a0\u0443\u0433\u043e\u0434\u043d\u043e. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u044c market \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 DDD \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, notification \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043e\u0432\u0441\u0435\u043c \u043b\u0435\u0433\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u0430\u00a0storage \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0434\u043b\u044f\u00a0Python service\u2011based \u043f\u043e\u0434\u0445\u043e\u0434. \u041a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441\u0431\u043e\u0440\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442\u00a0\u0431\u044b\u0442\u044c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u044b \u0438\u043b\u0438\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f, \u0432\u00a0\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442\u00a0\u0442\u043e\u0433\u043e \u043a\u0430\u043a\u00a0\u0432\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. <\/p>\n<\/div>\n<h2>\u041c\u0435\u0436\u043c\u043e\u0434\u0443\u043b\u044c\u043d\u0430\u044f \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u044f<\/h2>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a\u00a0\u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u0433\u0438\u0435 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043c\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u00a0\u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0440\u0430\u0442\u044c \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e\u00a0\u043b\u0438\u0431\u043e \u0438\u0437\u00a0\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0432\u00a0\u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u00a0\u044d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c \u0441\u0430\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u0430\u043a\u00a0\u0441\u0432\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442. \u0412\u00a0\u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u043c \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0435 \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430\u043c\u0438 \u043c\u043e\u0433\u0443\u0442\u00a0\u0431\u044b\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435, \u0438 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u0448\u043b\u044e\u0437. \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u043e\u00a0\u043f\u043e\u0440\u044f\u0434\u043a\u0443:<\/p>\n<p><em>1) \u041f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u0448\u043b\u044e\u0437\u00a0\u2014<\/em> \u0412\u00a0\u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0442\u0430\u043a\u043e\u0432\u044b\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438\u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 API, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u043e\u0434\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f\u00a0\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041d\u043e\u00a0\u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043c\u043e\u043d\u043e\u043b\u0438\u0442, \u0442\u043e \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a\u00a0\u0442\u0430\u043a\u043e\u043c\u0443 \u0448\u043b\u044e\u0437\u0443 \u0431\u0435\u0437\u00a0\u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043c\u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a\u00a0\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043e\u0434\u0438\u043d \u0438\u0437\u00a0\u043d\u0438\u0445 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u00a0\u0442\u043e\u043c \u0447\u0442\u043e\u00a0\u0448\u043b\u044e\u0437 \u0442\u043e\u043b\u044c\u043a\u043e\u00a0\u043b\u0438\u0448\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0430\u043f\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u0441\u043b\u043e\u0435\u043c \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b\/\u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0447\u0442\u043e\u00a0\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0434\u043b\u044f\u00a0\u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\"># src\/modules\/shop\/presentation\/public.py# \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u0448\u043b\u044e\u0437 \u044d\u0442\u043e \u0442\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 - \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0430 \u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435from src.modules.shop.application import handlers, commandsfrom src.modules.shop.domain.infrastructure.repo import ProductRepofrom src.core.sqlalchemy import UnitOfWork# \u041f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0442\u0435 \u0436\u0435 \u0447\u0442\u043e \u0438 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f# \u041c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c SRP \u0438\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438class ShopPublicGateway:  # \u041f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439  def __init__(self, uow: UnitOfWork, product_repo: ProductRepo):    self.uow = uow    self.product_repo = product_repo  # \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0438 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0440\u0432\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438# \u0415\u0441\u043b\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0435 DTO \u0438 ACL \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e  async def check_product_reliability(self, product_id: int) -&gt; bool:    command = commands.CheckProductReliability(product_id=product_id)    return await handlers.check_product_reliability(uow=self.uow, repo=self.product_repo, command=command)  # src\/modules\/storage\/application\/handlers.py# \u041f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 gateway \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439async def replenish_stock_item(uow: UnitOfWork, repo: StockRepo, shop_gateway: ShopPublicGateway, command: ReplienishStockItem) -&gt; None:  async with uow:    item = await repo.find_by_id(command.item_id)    if item is None:      raise StockItemNotFound(...)          # \u0414\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u044f\u043c\u043e\u0439 in-memory \u0432\u044b\u0437\u043e\u0432    reliable = await shop_gateway.check_product_reliability(product_id=item.product_id)    if reliable:      item.replenish(command.quantity)<\/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>\u041c\u043e\u0436\u043d\u043e \u0441\u043a\u0440\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u0448\u043b\u044e\u0437\u0430 \u0437\u0430\u00a0\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c, \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a\u00a0\u043c\u044b \u0434\u0435\u043b\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435 \u0434\u043b\u044f\u00a0\u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b:<\/p>\n<pre><code class=\"python\"># src\/modules\/shop\/presentation\/public.pyfrom abc import ABC, abstractmethodclass IShopPublicGateway(ABC):  @abstractmethod  async def check_product_reliability(self, product_id: int) -&gt; bool:    raise NotImplementedError()class ShopPublicGateway(IShopPublicGateway):  ...  # src\/modules\/storage\/application\/handlers.pyasync def replenish_stock_item(uow: UnitOfWork, repo: StockRepo, shop_gateway: IShopPublicGateway, command: ReplienishStockItem) -&gt; None:  ...<\/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\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0437\u0430\u0442\u043e\u0447\u0435\u043d\u043d\u044b\u0445 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u00a0\u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442, \u043f\u0440\u044f\u043c\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0448\u043b\u044e\u0437\u0430: <\/p>\n<pre><code class=\"python\">from src.modules.shop.domain.models import Productfrom src.modules.shop.domain.infrastructure.repo import ProductRepofrom src.core.sqlalchemy import UnitOfWorkclass ShopPublicGateway:  def __init__(self, uow: UnitOfWork, product_repo: ProductRepo):    self.uow = uow    self.product_repo = product_repo  # \u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0430\u043f\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0441\u043b\u043e\u0439, \u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u044f\u043c\u043e \u0437\u0434\u0435\u0441\u044c  async def check_product_reliability(self, product_id: int) -&gt; bool:    async with self.uow:      product = self.product_repo.find_by_id(product_id)      if product is None:        return False    return product.is_reliable<\/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\u0443\u0442\u044c \u0442\u0430\u00a0\u0436\u0435 \u0441\u0430\u043c\u0430\u044f \u043a\u0430\u043a\u00a0\u0435\u0441\u043b\u0438\u00a0\u0431\u044b \u0432\u044b \u0434\u0435\u043b\u0430\u043b\u0438 API \u0440\u043e\u0443\u0442\u0435\u0440\u044b. \u0418 \u0434\u0430, \u0432\u0430\u043c \u0432\u0441\u0435\u00a0\u0436\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u0448\u043b\u044e\u0437\u0430 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043a\u0443\u0434\u0430 \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0442\u044f\u043d\u0443\u0442\u044c \u0432\u0441\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u0432\u00a0\u0431\u0443\u0434\u0443\u0449\u0435\u043c (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441), \u043f\u0440\u0438\u00a0\u0432\u044b\u043d\u043e\u0441\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u043b\u0438\u00a0\u0432\u0441\u0435\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0432\u00a0\u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0432\u0430\u043c \u043d\u0435\u00a0\u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u0440\u0443\u0434\u0430 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 gateway \u043c\u043e\u0434\u0443\u043b\u044f \u043d\u0430\u00a0HTTP \u043a\u043b\u0438\u0435\u043d\u0442, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p> <em>2) \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439\u00a0\u2014<\/em> \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u044f\u043c\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439\u043d\u043e\u2011\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0432\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u00a0\u0442\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u044f\u0442 \u0437\u043d\u0430\u0442\u044c \u043e\u00a0\u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0435\u0434\u0448\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0438, \u0441\u0430\u043c\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0438 \u0441\u043b\u0443\u0448\u0430\u044e\u0442 \u044d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f (\u041f\u0443\u0442\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0448\u0438\u043d\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0430\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432, \u0438\u043b\u0438\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0433\u043e \u0431\u0440\u043e\u043a\u0435\u0440\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u043e\u00a0\u0442\u0438\u043f\u0443 Kafka \u0438\u043b\u0438\u00a0RabbitMQ). \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442\u00a0\u0442\u0438\u043f\u0438\u0447\u043d\u043e\u0439 \u0434\u043b\u044f\u00a0\u0441\u043f\u0430\u0433\u0435\u0442\u0442\u0438\u2011\u043a\u043e\u0434\u0430 \u043b\u043e\u0433\u0438\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u0432\u00a0\u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u043f\u043e\u043c\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0431\u043e\u0447\u043d\u044b\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432. \u042d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0447\u0442\u043e\u00a0\u0432\u00a0\u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f\u00a0\u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0422\u0443\u0442 \u044f \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430\u00a0\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u0445 \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u043a\u043e\u0434\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 in\u2011memory message bus \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0431\u0440\u043e\u043a\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432\u00a0\u043c\u043e\u0435\u043c <a href=\"https:\/\/github.com\/SergeyevSergey\/PythonModularMonolith\" rel=\"noopener noreferrer nofollow\">GitHub \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a><\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c event\u2011driven \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u043d\u0430\u00a0\u0434\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438: <\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e7a\/1f7\/d84\/e7a1f7d84c170ccce7d37f37aba64f2e.jpg\" alt=\"In-memory \u0441\u043e\u0431\u044b\u0442\u0438\u0439\u043d\u0430\u044f \u0448\u0438\u043d\u0430\" title=\"In-memory \u0441\u043e\u0431\u044b\u0442\u0438\u0439\u043d\u0430\u044f \u0448\u0438\u043d\u0430\" width=\"1995\" height=\"783\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/e7a\/1f7\/d84\/e7a1f7d84c170ccce7d37f37aba64f2e.jpg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e7a\/1f7\/d84\/e7a1f7d84c170ccce7d37f37aba64f2e.jpg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>In\u2011memory \u0441\u043e\u0431\u044b\u0442\u0438\u0439\u043d\u0430\u044f \u0448\u0438\u043d\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0443\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0432\u00a0\u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0431\u0435\u0437\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0433\u043e \u0431\u0440\u043e\u043a\u0435\u0440\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439, \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u00a0\u0448\u0438\u043d\u044b \u0432\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u00a0\u043e\u043d\u0430 \u0441\u0430\u043c\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u00a0\u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u044b. \u0412\u044b\u0437\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043a\u0430\u043a\u00a0\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e (\u0432 async \u0440\u0435\u0436\u0438\u043c\u0435\u00a0\u2014 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e). <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0448\u0438\u043d\u044b \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441\u00a0thread\u2011safe \u0438\u043b\u0438\u00a0\u043c\u0435\u0436\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043d\u043e\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u044c\u044e, \u0433\u0434\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f reader\u2011writer \u043d\u0430\u00a0\u0443\u0440\u043e\u0432\u043d\u0435 OS. \u041d\u043e\u00a0\u044d\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u00a0\u0431\u0440\u043e\u043a\u0435\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043f\u043e\u00a0\u0442\u0438\u043f\u0443 Kafka, RabbitMQ \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0439 \u0441\u00a0\u043d\u0443\u043b\u044f.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e7c\/f14\/32f\/e7cf1432ff71cad021db9107bc904b00.jpg\" alt=\" \u0412\u043d\u0435\u0448\u043d\u0438\u0439 \u0431\u0440\u043e\u043a\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439  \" title=\" \u0412\u043d\u0435\u0448\u043d\u0438\u0439 \u0431\u0440\u043e\u043a\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439  \" width=\"1826\" height=\"855\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/e7c\/f14\/32f\/e7cf1432ff71cad021db9107bc904b00.jpg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e7c\/f14\/32f\/e7cf1432ff71cad021db9107bc904b00.jpg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0412\u043d\u0435\u0448\u043d\u0438\u0439 \u0431\u0440\u043e\u043a\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 <\/figcaption><\/div>\n<\/figure>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u00a0\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0433\u0434\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e reader\u2011writer (pub\/sub), \u0433\u0434\u0435 \u043f\u0430\u0431\u043b\u0438\u0448\u0435\u0440\u043e\u043c \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u0442\u043e\u0440 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0430\u00a0\u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0430\u043c\u0438\u00a0\u2014 \u0435\u0433\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u0438. \u0411\u0440\u043e\u043a\u0435\u0440\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u043a\u0430\u043a\u00a0RabbitMQ, Kafka, Redis \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u043d\u0430\u00a0\u0432\u0430\u0448 \u0432\u044b\u0431\u043e\u0440. \u0412\u00a0\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0444\u0440\u0435\u043c\u0432\u043e\u0440\u043a\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044f \u043d\u0430\u00a0Python \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FastStream, \u043e\u0434\u0438\u043d \u0438\u0437\u00a0\u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043d\u0430\u00a0\u0440\u044b\u043d\u043a\u0435 \u043d\u0430\u00a0\u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u00a0\u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435, \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u044f\u0436\u0435\u043b\u0435\u0435 \u0447\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0439\u043d\u0430\u044f \u0448\u0438\u043d\u0430. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432\u00a0\u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0435 \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441\u00a0\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u044c\u044e (\u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u043c\u043d\u0435\u00a0\u0431\u044b\u043b\u043e \u0442\u0440\u0443\u0434\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u043b \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441)\u00a0\u2014 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0449\u0443\u044e \u043a\u043e\u0434\u043e\u0432\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u043b\u044f\u00a0Web \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0438 \u0434\u043b\u044f\u00a0\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. <\/p>\n<p>\u0411\u043b\u0430\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0435\u0432 \u0438 \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443. \u0415\u0441\u043b\u0438 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434, \u0442\u043e \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u043b\u043e\u0438 \u0432\u0430\u0448\u0435\u0439 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b \u043e\u0442\u00a0\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0442\u043e\u0433\u043e \u0438\u043b\u0438\u00a0\u0438\u043d\u043e\u0433\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430, \u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u00a0\u0442\u043e\u0447\u043a\u0435 \u0432\u0445\u043e\u0434\u0430. FastAPI \u0438 FastStream \u0438\u043c\u0435\u044e\u0442 \u0441\u0445\u043e\u0436\u0438\u0439 DI \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u0447\u0442\u043e\u00a0\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c \u044f\u0437\u044b\u043a\u0430 (\u0444\u0430\u0431\u0440\u0438\u043a\u0438), \u043e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0440\u0435\u0448\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u043e\u0439 \u0441\u0442\u0435\u043a, \u0442\u043e \u0432\u0430\u043c \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f DI \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u043c\u0438. <\/p>\n<p>\u041d\u043e\u00a0\u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u0430, \u043d\u0435\u00a0\u043c\u0435\u043d\u0435\u0435 \u0432\u0430\u0436\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432\u00a0\u0441\u043e\u0431\u044b\u0442\u0438\u0439\u043d\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435\u00a0\u2014 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u00a0\u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u041f\u0440\u0435\u0436\u0434\u0435 \u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043f\u0440\u044f\u043c\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443\/\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043d\u043e\u00a0\u0447\u0442\u043e\u00a0\u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0443\u043f\u0430\u0434\u0435\u0442 \u0432\u043e\u00a0\u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f? \u041d\u0430\u0448\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043d\u0435\u00a0\u043a\u043e\u043d\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u043e\u0439. <\/p>\n<p>\u0422\u0443\u0442 \u043d\u0430\u00a0\u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d Outbox! (\u0447\u0435\u0440\u043d\u044b\u0439 \u044f\u0449\u0438\u043a)<\/p>\n<p>\u0421\u0443\u0442\u044c \u0432\u043a\u0440\u0430\u0442\u0446\u0435\u00a0\u2014 \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0432\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0435 \u0435\u0433\u043e \u0432\u00a0\u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 (\u0431\u0434, \u043a\u0435\u0448) \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u0430\u0448\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u041f\u043e\u0437\u0436\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438\u0437\u00a0\u044d\u0442\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0432\u043e\u0440\u043a\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043a\u0430\u043a\u00a0\u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u00a0\u0431\u0440\u043e\u043a\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439: <\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b06\/079\/c28\/b06079c28c7c482d08ba43afbccb84e0.jpg\" alt=\"\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432 \u0431\u0440\u043e\u043a\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Outbox\" title=\"\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432 \u0431\u0440\u043e\u043a\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Outbox\" width=\"1935\" height=\"807\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/b06\/079\/c28\/b06079c28c7c482d08ba43afbccb84e0.jpg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b06\/079\/c28\/b06079c28c7c482d08ba43afbccb84e0.jpg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u00a0\u0431\u0440\u043e\u043a\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Outbox<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0430\u043a \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e: <\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/262\/155\/034\/262155034844a41c4862d1d5a52dc208.jpg\" alt=\"\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Outbox\" title=\"\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Outbox\" width=\"1962\" height=\"796\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/262\/155\/034\/262155034844a41c4862d1d5a52dc208.jpg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/262\/155\/034\/262155034844a41c4862d1d5a52dc208.jpg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Outbox<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e, \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u0430 \u043a\u00a0\u043f\u0430\u0434\u0435\u043d\u0438\u044f\u043c.<\/p>\n<h2>\u042d\u043f\u0438\u043b\u043e\u0433<\/h2>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u043d\u0435\u00a0\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c, \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043b\u0435\u043d\u0434\u0438\u043d\u0433\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0435 \u043d\u0435\u00a0\u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u00a0\u043c\u043e\u0434\u0443\u043b\u0438 \u0438\u043b\u0438\u00a0\u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 DDD (\u0430 \u0442\u043e \u0438 \u0432\u043e\u0432\u0441\u0435 \u0441\u0430\u043c \u0431\u0435\u043a\u0435\u043d\u0434), \u043e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441\u00a0\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u043f\u0440\u0438\u00a0\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u0438 \u0432\u00a0\u0431\u043e\u043b\u044c\u0448\u0438\u0445 Python \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0435\u0434\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u043c\u043d\u043e\u044e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0432\u044b \u043d\u0430\u0448\u043b\u0438 \u0447\u0442\u043e\u00a0\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u0434\u043b\u044f\u00a0\u0441\u0435\u0431\u044f.<\/p>\n<p><strong>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b:<\/strong><\/p>\n<p> <em>Robert C. Martin\u00a0\u2014 Clean Architecture: A Craftsman&#8217;s Guide to Software Structure and Design:<\/em> \u041a\u043d\u0438\u0433\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0447\u0438\u0441\u0442\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0434\u043b\u044f\u00a0\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u043d\u0438\u0446 \u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p> <em>\u0421\u0438\u043d\u044f\u044f \u043a\u043d\u0438\u0433\u0430: Eric Evans\u00a0\u2014 Domain\u2011Driven Design: Tackling Complexity in the Heart of Software:<\/em> \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430, \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 DDD. <\/p>\n<p> <em>\u041a\u0440\u0430\u0441\u043d\u0430\u044f \u043a\u043d\u0438\u0433\u0430: Vaughn Vernon\u00a0\u2014 Implementing Domain\u2011Driven Design:<\/em> \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0432\u0441\u0435 \u0442\u0435 \u0438\u0434\u0435\u0438 \u0447\u0442\u043e\u00a0\u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432\u00a0\u0441\u0438\u043d\u0435\u0439 \u043a\u043d\u0438\u0433\u0435 \u0441\u00a0\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u00a0\u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445.<\/p>\n<p><em>Cosmic Python\u00a0\u2014<\/em> \u0440\u0430\u0431\u043e\u0442\u0430, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u043d\u0430\u00a0Python, \u0432\u00a0\u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c DDD. <\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u044b.NET \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0432\u00a0\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430:<br \/><a href=\"https:\/\/www.kamilgrzybek.com\/blog\/posts\/modular-monolith-primer\/\" rel=\"noopener noreferrer nofollow\">https:\/\/www.kamilgrzybek.com\/blog\/posts\/modular\u2011monolith\u2011primer\/<\/a> <a href=\"https:\/\/milanjovanovic.tech\/blog\/what-is-a-modular-monolith\/\" rel=\"noopener noreferrer nofollow\">https:\/\/milanjovanovic.tech\/blog\/what\u2011is\u2011a\u2011modular\u2011monolith\/<\/a><\/p>\n<p>\u0411\u043b\u043e\u0433 Python \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0430\u0432\u0442\u043e\u0440 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b (Entities, Outbox, CommandBus, Handlers, DomainModels):<br \/> <a href=\"https:\/\/blog.szymonmiks.pl\/\" rel=\"noopener noreferrer nofollow\">https:\/\/blog.szymonmiks.pl\/<\/a> <\/p>\n<p>\u0415\u0449\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 DDD \u0432\u00a0Python:<br \/><a href=\"https:\/\/github.com\/NEONKID\/fastapi-ddd-example\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/NEONKID\/fastapi\u2011ddd\u2011example<\/a><br \/><a href=\"https:\/\/github.com\/cosmicpython\/code\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/cosmicpython\/code<\/a><\/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\/1070934\/\">https:\/\/habr.com\/ru\/articles\/1070934\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u043e\u043b\u043e\u0433\u0412\u00a0\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0435\u00a0\u0431\u0443\u0434\u0443 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0432\u0441\u044e \u0442\u0435\u043e\u0440\u0438\u044e, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0443\u044e \u0441\u00a0\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043e\u0439 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430 \u0438 Domain Driven Design, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u0432\u00a0\u0441\u0435\u0442\u0438 \u0438\u043b\u0438\u00a0\u043a\u043d\u0438\u0433\u0430\u0445, \u0433\u0434\u0435 \u0430\u0432\u0442\u043e\u0440\u044b \u0443\u0436\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043b\u0438 \u0432\u0441\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u044b.\u041c\u043d\u043e\u044e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0442\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u0442\u0438\u0445 \u0438\u0434\u0435\u0439 \u043d\u0430\u00a0\u044f\u0437\u044b\u043a\u0435 Python, \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u0434\u043b\u044f\u00a0\u043d\u0435\u0433\u043e \u044d\u0442\u043e \u043d\u0435\u00a0\u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0430\u044f\u0441\u044f \u0442\u0435\u043c\u0430 \u0432\u00a0\u0432\u0438\u0434\u0443 \u0435\u0433\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u043c\u0435\u043d\u0435\u0435 \u0441\u0442\u0440\u043e\u0433\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u043d\u0435\u0436\u0435\u043b\u0438 \u0432\u00a0\u0441\u0442\u0440\u043e\u0433\u043e \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445, \u0433\u0434\u0435 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0438 \u0437\u0430\u0440\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u044d\u0442\u0438 \u0438\u0434\u0435\u0438. \u0414\u043b\u044f\u00a0\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0432\u00a0\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0442\u0435\u043e\u0440\u0438\u044e, \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430\u00a0\u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e\u00a0\u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0443 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432\u00a0\u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438*. \u0412\u0441\u044f \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437\u00a0\u043c\u043e\u0435\u0433\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u043f\u044b\u0442\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430\u00a0Python, \u0447\u0442\u043e\u00a0\u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435\u00a0\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0439 \u0432\u00a0\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0432\u044b \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435\u00a0\u0431\u044b\u0442\u044c \u043d\u0435\u00a0\u0441\u043e\u0433\u043b\u0430\u0441\u043d\u044b \u0441\u00a0\u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439, \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u043d\u0438\u0436\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u044e\u0431\u0430\u044f \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043a\u0440\u0438\u0442\u0438\u043a\u0430 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f.\u041f\u043e\u0447\u0435\u043c\u0443 \u0432\u043e\u043e\u0431\u0449\u0435 DDD \u0438 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043d\u043e\u043b\u0438\u0442 \u0432\u00a0Python? \u041f\u043e\u00a0\u043c\u0435\u0440\u0435 \u043c\u043e\u0435\u0439 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u043e\u0439 \u0434\u0435\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a\u00a0Python backend \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u044f \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0441\u044f \u0441\u00a0\u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0431\u044a\u0435\u043c\u043d\u044b\u043c\u0438, \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438, \u0433\u0434\u0435\u00a0\u0431\u044b\u043b\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0438. \u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043c, \u0442\u043e \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0439 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f\u00a0Python\u2011\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u0441\u043b\u043e\u0438\u0441\u0442\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e. \u0413\u0440\u0430\u043d\u0438\u0446\u044b \u0440\u0430\u0437\u043c\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0446\u0438\u043a\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u0432, \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f god\u2011objects, \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0445\u043b\u0430\u043c\u043b\u0435\u043d\u043d\u043e\u0439, \u0447\u0442\u043e\u00a0\u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u0435\u0442, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c\u00a0\u0431\u044b, \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0447\u0430\u0442\u044c \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 200\u00a0\u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430. \u0412\u00a0\u0441\u0432\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043f\u0440\u043e\u0432\u043e\u0434\u044f \u0432\u0440\u0435\u043c\u044f \u0432\u00a0\u043f\u043e\u0438\u0441\u043a\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u044f \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430\u00a0\u0442\u0435\u043c\u0443 Domain Driven Design. \u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435\u00a0\u2014 Domain Driven \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0435\u0431 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0432\u043e\u043a\u0440\u0443\u0433 \u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043b\u043e\u0433\u0438\u043a\u0438 \u0438 \u0435\u0435 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u00a0\u043d\u0438\u0437\u043a\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043b\u043e\u0433\u0438\u043a\u0438 \u043e\u0442\u00a0\u0432\u0441\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e, \u0447\u0442\u043e\u00a0\u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0432\u00a0\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c \u043e\u0434\u043d\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u00a0\u0434\u0440\u0443\u0433\u0438\u0435 \u0431\u0435\u0437\u00a0\u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u043e\u043b\u043e\u043c\u043a\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432. \u0422\u043e\u0433\u0434\u0430 \u043f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043d\u043e\u043b\u0438\u0442? \u0412\u0435\u0434\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c DDD \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438 \u0432\u00a0\u043e\u0431\u044b\u0447\u043d\u043e\u043c \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0435. \u0412\u00a0\u0447\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430? \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043e\u043c \u0438\u00a0\u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u043c \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u00a0\u0447\u0451\u0442\u043a\u043e\u043c\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u0433\u0440\u0430\u043d\u0438\u0446, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0438\u0437\u00a0\u043f\u043b\u044e\u0441\u043e\u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435\u00a0\u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u0443\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443, \u0434\u0435\u043f\u043b\u043e\u0439 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a\u00a0\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u00a0\u0441\u0438\u0445 \u043f\u043e\u0440 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043e\u043c. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430 \u0441\u043e\u0447\u0435\u0442\u0430\u0435\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u043f\u043b\u044e\u0441\u044b \u043e\u0431\u043e\u0438\u0445 \u044d\u0442\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u00a0\u043a\u043e\u0434\u0435\u041a\u00a0\u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432\u00a0Python \u043d\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u044b\u0445, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043a\u0430\u043a,\u00a0\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Spring Modulith \u0432\u00a0Java \u0438\u043b\u0438\u00a0EF\/.NET \u0432\u00a0C#, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u043e. \u0412\u00a0Python \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u00a0\u043d\u0443\u043b\u044f, \u0447\u0442\u043e\u00a0\u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 \u0432\u00a0\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435\u00a0\u043e\u0442\u043c\u0435\u043d\u044f\u0435\u0442 \u0435\u0451 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0438 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0432\u043e\u0431\u043e\u0434\u0443 \u0432\u044b\u0431\u043e\u0440\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u0434\u00a0\u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438. \u0414\u0430\u043b\u0435\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a\u00a0\u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u00a0\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0432\u0441\u0451 \u0442\u043e, \u0447\u0442\u043e\u00a0\u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u00a0\u0442\u0435\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u00a0\u044d\u0442\u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b, \u0438 \u043d\u0430\u0447\u043d\u0435\u043c, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u00a0\u0440\u0430\u0437\u0431\u043e\u0440\u0430 Domain Driven Design.\u0414\u043e\u043c\u0435\u043d\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0443 \u0438 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u0447\u0442\u043e\u00a0\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u044f\u0434\u0440\u043e \u0432\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0443\u0440\u043e\u0432\u043d\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0432\u043e\u043a\u0440\u0443\u0433 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0433\u043e. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f:\u0414\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438\u00a0\u2014  \u043a\u0430\u043a\u00a0\u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u043e\u0434\u043d\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c (\u0430\u0433\u0440\u0435\u0433\u0430\u0442), \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u044e\u0442 \u043f\u0440\u0438\u0441\u0443\u0449\u0438\u0435 \u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0431\u0438\u0437\u043d\u0435\u0441\u2011\u043b\u043e\u0433\u0438\u043a\u0443. \u042f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u044f\u0434\u0440\u043e\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0415\u0441\u0442\u044c \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438: 1) \u041e\u0431\u044b\u0447\u043d\u044b\u0439 Python \u043a\u043b\u0430\u0441\u0441\u00a0\u2014 \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431:class Product:  id: int  name: str    def __init__(self, id: int, name: str):    self.id = id    self.name = name# \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435product = Product(id=1, name=&#187;Lamp&#187;)\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437\u00a0\u043b\u0438\u0448\u043d\u0438\u0445 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u0432 \u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043e\u0434\u043d\u0430\u043a\u043e \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a\u00a0\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u043c\u0435\u0442\u043e\u0434\u0430 \u0440\u0435\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438 (\u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e), \u0430\u00a0\u0442\u0430\u043a\u0436\u0435\u00a0\u043b\u0438\u043d\u0442\u0435\u0440\u044b \u0438 \u0442\u0438\u043f\u0438\u0437\u0430\u0442\u043e\u0440\u044b \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0436\u0430\u043b\u0443\u044e\u0442\u0441\u044f \u043d\u0430\u00a0built\u2011in \u0438\u043c\u0435\u043d\u0430 \u043f\u043e\u043b\u0435\u0439 \u043f\u043e\u00a0\u0442\u0438\u043f\u0443 id, type \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.2) Python dataclass\u00a0\u2014 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f dataclasses:from dataclasses import dataclass@dataclassclass Product:  id: int  name: str# \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435product = Product(id=1, name=&#187;Lamp&#187;)\u0418\u0437\u00a0\u043f\u043b\u044e\u0441\u043e\u0432\u00a0\u2014 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438 \u0440\u0435\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438\u0437\u00a0\u043a\u043e\u0440\u043e\u0431\u043a\u0438, \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0\u0434\u0435\u0444\u043e\u043b\u0442\u0430\u043c\u0438 \u0438 \u0444\u0430\u0431\u0440\u0438\u043a\u0430\u043c\u0438 \u0443\u00a0\u043f\u043e\u043b\u0435\u0439, \u043d\u0435\u0442 \u0436\u0430\u043b\u043e\u0431 \u043e\u0442\u00a0\u043b\u0438\u043d\u0442\u0435\u0440\u043e\u0432 \u0438 \u0442\u0438\u043f\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432. \u041c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c frozen=True \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 read\u2011only \u043c\u043e\u0434\u0435\u043b\u044c. \u0418\u0437\u00a0\u043c\u0438\u043d\u0443\u0441\u043e\u0432\u00a0\u2014 \u0438\u043c\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0443\u043b\u044f dataclasses, \u0432\u00a0\u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442\u00a0\u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, dataclass \u0432\u0435\u0440\u0441\u0438\u044f \u043f\u043e\u00a0\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u0435\u00a0\u0445\u0435\u0448\u0438\u0440\u0443\u0435\u043c\u0430 (\u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c frozen=True), \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441\u00a0set \u0438 dict \u0442\u0438\u043f\u0430\u043c\u0438.3) Pydantic BaseModel\u00a0\u2014 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 pydantic:from pydantic import BaseModelclass Product(BaseModel):  id: int  name: str# \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435product = Product(id=1, name=&#187;Lamp&#187;)\u0418\u0437\u00a0\u043f\u043b\u044e\u0441\u043e\u0432\u00a0\u2014 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u043e\u0442\u00a0\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u0447\u0442\u043e\u00a0\u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438\u00a0\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437\u00a0\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0432\u00a0\u0434\u0440\u0443\u0433\u043e\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043e\u043c\u0435\u043d \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442\u00a0\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0447\u0442\u043e,\u00a0\u043f\u043e\u00a0\u043c\u043e\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e, \u043d\u0435\u00a0\u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0434\u0444\u043b\u0430\u0433, \u043f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a\u00a0\u0440\u0430\u0432\u043d\u044b\u0445 \u043f\u043e\u00a0\u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044e, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 \u0438 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 pydantic \u0432\u00a0Python \u043d\u0435\u0442, \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c pydantic \u0432\u00a0Python \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0430\u00a0\u0447\u0442\u043e\u2011\u0442\u043e \u0438\u043d\u043e\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435\u00a0\u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430. \u041e\u0431\u044a\u0435\u043a\u0442 \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0430\u043a\u00a0\u0436\u0435 \u043d\u0435\u00a0\u0445\u0435\u0448\u0438\u0440\u0443\u0435\u043c, \u043f\u043e\u043a\u0430 \u043d\u0435\u00a0\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d model_config = ConfigDict(frozen=True).\u0418\u043d\u043e\u0433\u0434\u0430, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442\u00a0\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0438\u043b\u0438\u00a0\u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0447\u0442\u043e\u0431\u044b \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0435\u0444\u043e\u043b\u0442\u043e\u0432 \u0443\u00a0\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0438\u043b\u0438\u00a0\u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0432\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043c\u0435\u044e\u0442\u0441\u044f. # \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430class Product(BaseModel):  id: UUID  name: str  status: ProductStatus  def __init__(self, name: str):    super().__init__(      id=uuid4(),      name=name,      status=ProductStatus.ACTIVE,    )    # \u0418\u043b\u0438 \u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u043c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435class User(BaseModel):  id: UUID  name: str    @classmethod  def register(cls, name: str) -&gt; &#171;User&#187;:    return cls(      id=uuid4(),      name=name    ) \u041e\u0431\u044a\u0435\u043a\u0442\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 (value objects)\u00a0\u2014 \u0441\u043b\u0443\u0436\u0430\u0442 \u043a\u0430\u043a\u00a0\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e\/\u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e\u043b\u0435\u0439 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0438\u043d\u0441\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0440\u0430\u0437\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0432\u043e\u0439 \u043c\u043d\u043e\u0433\u043e. \u041c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0437\u00a0\u0441\u0435\u0431\u044f \u043b\u044e\u0431\u043e\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u00a0\u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e type alias \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u0442 \u0432\u00a0\u0441\u0435\u0431\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435\u0439.from uuid import UUIDfrom enum import StrEnumfrom dataclasses import dataclasstype EntityId = UUIDclass Currency(StrEnum):  UZS = &#171;uzs&#187;  USD = &#171;usd&#187;  # \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438\u043b\u0438 Pydantic, \u043a\u0430\u043a \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438@dataclassclass Money:  currency: Currency  amount: int    def __init__(self, currency: Currency, amount: int):    if amount &lt;= 0:      raise ValueError(&#171;Money amount should be greater than zero&#187;)          self.currency = currency    self.amount = amount      def convert(self, to: Currency):    if self.currency != to:      if to == Currency.USD:        self.amount = int(self.amount \/ 12000)      else:      self.amount = self.amount * 12000      self.currency = to \u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u00a0\u2014 \u043e\u0431\u044b\u0447\u043d\u043e \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u0431\u0430\u0437\u043e\u0432\u043e\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043d\u0430\u00a0\u043e\u0431\u0449\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u0430.# \u041e\u0431\u0449\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044cclass DomainError(Exception):  status: int = 500  code: str = &#171;internal_server_error&#187;  message: str      def __init__(self, message: str):      self.message = message      # \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432 \u0434\u043e\u043c\u0435\u043d\u0435class OrderNotFound(DomainError):  status = 404  code = &#171;order_not_found&#187;  class InvalidOrderStatus(DomainError):  status = 400  code = &#171;invalid_order_status&#187;  # \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435def cancel_order(repo: OrderRepo, order_id: int):  order = repo.get_by_id(order_id)  if order is None:    raise OrderNotFound(f&#187;Order {order_id} not found&#187;)      order.cancel()  class Order:  id: int  status: OrderStatus    def cancel(self):  if self.status != OrderStatus.ACTIVE:    raise InvalidOrderStatus(      f&#187;Invalid order {self.id} status {self.status}, expected status      {OrderStatus.ACTIVE} to cancel&#187;    )  self.status = OrderStatus.CANCELLED\u0412\u00a0\u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043e\u0442\u0432\u0435\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043a\u0430\u043a\u00a0\u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0442\u0440\u0438 \u0432\u0435\u0449\u0438\u00a0\u2014 \u0441\u0442\u0430\u0442\u0443\u0441, \u043a\u043e\u0434 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443. \u042f \u043d\u0435\u00a0\u0432\u0438\u0436\u0443 \u043d\u0438\u0447\u0435\u0433\u043e \u0437\u0430\u0437\u043e\u0440\u043d\u043e\u0433\u043e \u0432\u00a0\u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u0438 \u043a\u043e\u0434\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430\u00a0\u0443\u0440\u043e\u0432\u043d\u0435 \u0434\u043e\u043c\u0435\u043d\u0430, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0438 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432\u00a0HTTP \u043e\u0442\u0432\u0435\u0442\u044b, \u0447\u0442\u043e\u00a0\u044f \u0441\u0447\u0438\u0442\u0430\u044e \u0438\u0437\u043b\u0438\u0448\u043d\u0435\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e. \u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u043c\u043f\u0440\u043e\u043c\u0438\u0441\u0441 \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c: \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0432\u0435\u0440\u0445 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u00a0\u0445\u0435\u043d\u0434\u043b\u0438\u043d\u0433 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0441\u043b\u043e\u044e, \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043b\u043e\u0433\u0438\u043a\u0438 \u043d\u0430\u00a0\u0441\u043b\u0443\u0447\u0430\u0439 \u043e\u0448\u0438\u0431\u043a\u0438, \u0438\u043b\u0438\u00a0\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u0434\u043b\u044f\u00a0\u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u0447\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f exception handlers (\u0435\u0441\u043b\u0438 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e\u00a0FastAPI) \u0438\u043b\u0438\u00a0\u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u0430\u044f middleware.\u0421\u043e\u0431\u044b\u0442\u0438\u044f\u00a0\u2014 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u044b (\u043e\u0431\u044b\u0447\u043d\u044b\u0435, Pydantic \u0438\u043b\u0438\u00a0\u0434\u0430\u0442\u0430\u043a\u043b\u0430\u0441\u0441\u044b), \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043f\u043b\u043e\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0431\u0435\u0437 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0431\u0435\u0437\u00a0\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u0440\u043e\u043c\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430), \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u043b\u044f\u00a0\u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e\u00a0\u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0432\u00a0\u043e\u0434\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0434\u043b\u044f\u00a0\u0434\u0440\u0443\u0433\u0438\u0445 \u0447\u0430\u0441\u0442\u0435\u0439, \u0431\u0435\u0437\u00a0\u0438\u0445 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430. \u041c\u043e\u0433\u0443\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a\u00a0\u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0442\u0430\u043a \u0438 \u043d\u0430\u00a0\u0430\u043f\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f batch \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430\u0434 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u0438\u043b\u0438\u00a0\u043d\u0443\u0436\u043d\u043e \u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043e\u00a0\u043a\u0430\u043a\u043e\u043c\u00a0\u043b\u0438\u0431\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438, \u043d\u0435\u00a0\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u043c \u043d\u0438 \u0441\u00a0\u043e\u0434\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e.from pydantic import BaseModelfrom dataclasses import dataclass, field# \u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430 \u043e\u0431\u0449\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435class DomainEvent(BaseModel):  pass# \u041a\u043b\u0430\u0441\u0441 \u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439@dataclassclass DomainModel:  _events: list[DomainEvent] = field(default_factory=list, init=False)# \u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0434\u043e\u043c\u0435\u043d\u0430class OrderCancelled(DomainEvent):  order_id: int#&#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-491073","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/491073","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=491073"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/491073\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=491073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=491073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=491073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}