How akira393/2021-typescript-ddd works
Main Components
• API Gateway / Entry Point: Although not directly seen in the code, the use of SAM to start a local API implies an API gateway (or similar routing mechanism) that receives HTTP requests.
• Lambda Handlers: The handlers located in backend/src/lambda/handlers (e.g., deleteUserLambda.ts, getUserLambda.ts, etc.) act as the entry points to invoke the business logic.
• Application Service Layer: Found under backend/src/lambda/applicationService, this layer (e.g., the Users folder and its various services) contains logic for processing commands and orchestrating the domain operations.
• Command Objects: These are clearly defined in backend/src/lambda/applicationService/Users/command, and their purpose is to encapsulate user operations, which simplifies the application service.
• Domain Layer: Under backend/src/lambda/domains, the domain objects (such as User in model) are present to define business rules and policies. This layer also defines interfaces such as IUserRepository and IUserNotification.
• Infrastructure Layer: The implementation of repository interfaces is visible in backend/src/lambda/infrastructure (e.g., UserRepository.ts), which interacts with DynamoDB (as suggested by the user-table.json and the setup instructions).
• AWS CDK Stack: The file backend/lib/backend-stack.ts defines part of the infrastructure as code, laying out the configuration for AWS resources.
• Tests: The test directories and files indicate a separate test suite for verifying both backend logic and lambda handlers.
• Lambda Handlers invoke the Application Services by passing command objects and data.
• The Application Services call upon Domain Models to perform business logic.
• Domain Models interact with the Repository interface, whose concrete implementation (infrastructure layer) persists data to DynamoDB.
• This shows a clear separation of responsibilities and a unidirectional flow of data.
Architectural Patterns and Key Design Principles
• Domain-Driven Design (DDD): Notice the separation with distinct folders for domains, application services, repository interfaces, and command objects.
• Command Pattern: The project leverages command objects to encapsulate user operations.
• Layered Architecture: The code cleanly divides the system into layers (API, application service, domain, infrastructure).
• Infrastructure as Code: The AWS CDK stack is used to provision AWS resources.
• Testing Layer: There is comprehensive testing ensuring each layer functions as expected.
Relevant Technologies
• AWS Lambda: for serverless business logic execution.
• AWS CDK and SAM: to orchestrate and deploy the infrastructure.
• DynamoDB: as the persistent data store.
• TypeScript: the language used for development.
• AWS SDK: implied for operations with DynamoDB.
• jest: for testing (based on jest.config.js and test directories).