typescript-ddd-example
repository·master·Indexed 23 days ago
https://github.com/codelytv/typescript-ddd-exampleA reference implementation of a TypeScript application demonstrating Hexagonal Architecture, Domain-Driven Design (DDD), Command Query Responsibility Segregation (CQRS), and Event-Driven Architecture (EDA) principles. The project includes a backoffice frontend and backend, a MOOC backend, and infrastructure configurations for MongoDB, PostgreSQL, RabbitMQ, Elasticsearch, and Kibana.
What's inside typescript-ddd-example
- This repository serves as a complete project example demonstrating the application of Domain-Driven Design (DDD), Command Query Responsibility Segregation (CQRS), and Event-Driven Architecture (EDA) principles using TypeScript. It is designed to show how to implement Hexagonal Architecture while keeping the code as simple as possible.
Run the frontend in development mode
masterUsenpm startto run the application in development mode. The app will be available at http://localhost:3000. The development server supports hot reloading (the page reloads automatically on edits) and will display linting errors in the browser console.npm startEject from Create React App configuration
masterIf you need full control over the underlying build tools (Webpack, Babel, ESLint, etc.), you can run
npm run eject.Warning: This is a one-way operation. Once you eject, you cannot undo it.
Ejecting removes the single build dependency and copies all configuration files and transitive dependencies directly into your project. After ejecting, you are responsible for maintaining these configurations.
npm run ejectBuild the app for production
masterUsenpm run buildto create a production-ready bundle in thebuildfolder. This command optimizes the build for performance by minifying files and including hashes in filenames for cache busting. The resulting folder is ready for deployment.npm run buildRun tests in interactive watch mode
masterUsenpm testto launch the test runner. This runs in interactive watch mode, allowing you to see test results as you make changes to your code.npm testConfigure Elasticsearch service
masterThe
elasticsearchservice uses imagedocker.elastic.co/elasticsearch/elasticsearch:7.9.3. It is configured as a single-node cluster.Key configurations:
- Ports: Exposed on
9200. - Memory:
ES_JAVA_OPTSis set to-Xms2048m -Xmx2048m.bootstrap.memory_lockis enabled. - Ulimits:
memlockis set to-1(unlimited) to allow Elasticsearch to lock memory. - Persistence: Uses the
esdatavolume.
elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3 container_name: codely-elasticsearch environment: - node.name=codely-elasticsearch - discovery.type=single-node - bootstrap.memory_lock=true - 'ES_JAVA_OPTS=-Xms2048m -Xmx2048m' ulimits: memlock: soft: -1 hard: -1 volumes: - esdata:/usr/share/elasticsearch/data ports: - '9200:9200'- Ports: Exposed on
Configure Kibana service
masterThe
kibanaservice uses imagedocker.elastic.co/kibana/kibana:7.8.1. It connects to the Elasticsearch service via the following environment variables:ELASTICSEARCH_URL: The URL of the Elasticsearch instance (default:http://codely-elasticsearch:9200)ELASTICSEARCH_HOSTS: The hosts for Elasticsearch (default:http://codely-elasticsearch:9200)
It exposes the Kibana UI on port
5601.kibana: image: docker.elastic.co/kibana/kibana:7.8.1 container_name: codely-kibana environment: ELASTICSEARCH_URL: http://codely-elasticsearch:9200 ELASTICSEARCH_HOSTS: http://codely-elasticsearch:9200 ports: - 5601:5601Configure MongoDB service
masterThe
mongoservice uses themongo:5.0.0image. It exposes port27017and provides a connection string via theMONGO_URLenvironment variable. Data is persisted in the local./data/mongodirectory.mongo: image: mongo:5.0.0 environment: - MONGO_URL=mongodb://mongo:27017/dev volumes: - ./data/mongo:/data/db:delegated ports: - 27017:27017Configure RabbitMQ service
masterThe
rabbitmqservice uses therabbitmq:3.8-managementimage, which includes the management plugin. It exposes port5672for AMQP traffic and port15672for the management UI.rabbitmq: image: 'rabbitmq:3.8-management' ports: - 5672:5672 - 15672:15672Configure PostgreSQL service
masterThe
postgresservice uses the defaultpostgresimage. It exposes port5432. You can configure the database credentials and name using the following environment variables:POSTGRES_PASSWORD: The database password (default:codely)POSTGRES_USER: The database user (default:codely)POSTGRES_DB: The database name (default:mooc-backend-dev)
postgres: image: postgres environment: - POSTGRES_PASSWORD=codely - POSTGRES_USER=codely - POSTGRES_DB=mooc-backend-dev ports: - '5432:5432' restart: alwaysAvailable npm scripts reference
masterThe following scripts are available in the project directory for managing the frontend application:Handle CommandNotRegisteredError
masterTheCommandNotRegisteredErroris thrown when an attempt is made to execute aCommandthat does not have a corresponding command handler registered in the system. This typically indicates a configuration or wiring issue where the command exists but the application logic responsible for processing it has not been mapped.