A modern, scalable chat application built with Domain-Driven Design (DDD) and Command Query Responsibility Segregation (CQRS) patterns using Ruby on Rails 8.
This application demonstrates clean architecture principles with a clear separation of concerns:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend Layer β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Controllers (Rails) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Application Layer (CQRS) β
β βββββββββββββββββββ βββββββββββββββββββ β
β β Commands β β Queries β β
β β (Write/Postgres β β (Read/Redis) β β
β βββββββββββββββββββ βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Domain Layer (DDD) β
β βββββββββββββββββββ βββββββββββββββββββ β
β β Aggregates β β Value Objects β β
β β Domain Events β β Repositories β β
β βββββββββββββββββββ βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Infrastructure Layer β
β βββββββββββββββββββ βββββββββββββββββββ β
β β PostgreSQL β β Redis β β
β β RabbitMQ β β Gemini β β
β βββββββββββββββββββ βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- π― Domain-Driven Design: Clean domain models with aggregates, value objects, and domain events
- β‘ CQRS Pattern: Separate command and query models for optimal performance
- ποΈ Clean Architecture: Clear separation between domain, application, and infrastructure layers
- π³ Docker Support: Complete containerized development environment
- π± Real-time Chat: WebSocket support with Action Cable
- π§ͺ Comprehensive Testing: RSpec test suite with proper test isolation
- π Security: Brakeman security scanning and best practices
- Ruby 3.3.0 - Ruby programming language
- Rails 8.0.2 - Ruby on Rails framework
- PostgreSQL 15 - Robust relational database
- Redis 7.2.0 - In-memory data structure store
- RabbitMQ 3.12 - Message broker for event-driven architecture
- Gemini - LLM / Embeddings service used for RAG (Retrieval-Augmented Generation)
- RSpec - Framework for testing
- RuboCop - Ruby code style checker
- Brakeman - Security vulnerability scanner
- Faker - Test data generation
- Docker Compose - Multi-container development environment
- Domain Events - Event-driven communication between aggregates
- Aggregate Roots - Consistency boundaries for domain objects
- Value Objects - Immutable domain concepts
- Repository Pattern - Domain-focused data access abstraction that acts as a collection of aggregates and hides infrastructure details.
- Command/Query Separation - Optimized read/write operations
- Ruby 3.3.0
- Docker & Docker Compose
- PostgreSQL client (optional)
git clone https://github.com/mapeveri/ruby-ddd-cqrs.git
cd ruby-ddd-cqrs
cp env.example .env
# Edit .env with your configuration
docker-compose up -d
bundle install
bin/rails db:create db:migrate
bin/rails server
Visit http://localhost:3000 to see your application!
src/
βββ shared/ # Shared domain components
β βββ domain/
β β βββ aggregate_root.rb # Base aggregate root class
β β βββ domain_events/ # Domain event infrastructure
β β βββ bus/ # Event bus implementation
β β βββ value_objects/ # Shared value objects
β βββ infrastructure/ # Shared infrastructure
βββ chat/ # Chat bounded context
β βββ domain/ # Domain layer
β β βββ message/ # Message aggregate
β β βββ user/ # User aggregate
β βββ application/ # Application layer (CQRS)
β β βββ message/
β β βββ commands/ # Write operations
β β βββ queries/ # Read operations
β βββ infrastructure/ # Infrastructure layer
Run the complete test suite:
bundle exec rspec
Run specific test files:
bundle exec rspec spec/chat/domain/message
- PostgreSQL:
localhost:5435
- Redis:
localhost:6379
- Redis Test:
localhost:6380
- RabbitMQ:
localhost:5672
- RabbitMQ Management:
localhost:15672
# View logs
docker-compose logs -f
# Restart services
docker-compose restart
# Stop all services
docker-compose down
# Rebuild containers
docker-compose up --build
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.