Skip to content

Commit 15c943f

Browse files
authored
Import php-ddd-skeleton (#124)
1 parent 0d1f9f4 commit 15c943f

File tree

659 files changed

+10043
-13291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

659 files changed

+10043
-13291
lines changed

Diff for: .circleci/config.yml

-31
This file was deleted.

Diff for: .editorconfig

-9
This file was deleted.

Diff for: .env

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
### Symfony - framework-bundle
2+
APP_ENV=test
3+
APP_SECRET=29ac4a5187930cd4b689aa0f3ee7cbc0
4+
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
5+
#TRUSTED_HOSTS='^localhost|example\.com$'
6+
7+
# MOOC #
8+
#--------------------------------#
9+
# MySql
10+
MOOC_DATABASE_DRIVER=pdo_mysql
11+
MOOC_DATABASE_HOST=codelytv-php_ddd_skeleton-mooc-mysql
12+
MOOC_DATABASE_PORT=3306
13+
MOOC_DATABASE_NAME=mooc
14+
MOOC_DATABASE_USER=root
15+
MOOC_DATABASE_PASSWORD=
16+
17+
# BACKOFFICE #
18+
#--------------------------------#
19+
# MySql
20+
BACKOFFICE_DATABASE_DRIVER=pdo_mysql
21+
BACKOFFICE_DATABASE_HOST=codelytv-php_ddd_skeleton-mooc-mysql
22+
BACKOFFICE_DATABASE_PORT=3306
23+
BACKOFFICE_DATABASE_NAME=mooc
24+
BACKOFFICE_DATABASE_USER=root
25+
BACKOFFICE_DATABASE_PASSWORD=
26+
27+
# Elasticsearch
28+
BACKOFFICE_ELASTICSEARCH_HOST=127.0.0.1
29+
BACKOFFICE_ELASTICSEARCH_INDEX_PREFIX=backoffice
30+
31+
# COMMON #
32+
#--------------------------------#
33+
# RabbitMQ
34+
RABBITMQ_HOST=codelytv-php_ddd_skeleton-rabbitmq
35+
RABBITMQ_PORT=5672
36+
RABBITMQ_LOGIN=codelytv
37+
RABBITMQ_PASSWORD=c0d3ly
38+
RABBITMQ_EXCHANGE=domain_events
39+
RABBITMQ_MAX_RETRIES=5
40+
# RabbitMQ - Application Specific
41+
RABBITMQ_MOOC_VHOST=/

Diff for: .env.dist

-11
This file was deleted.

Diff for: .github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom: https://bit.ly/CodelyTvPro

Diff for: .github/stale.yml

-23
This file was deleted.

Diff for: .github/workflows/ci.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
13+
- name: Install dependencies
14+
run: make composer-install
15+
16+
- name: Start all the environment
17+
run: make start
18+
19+
- name: Wait for the environment to get up
20+
run: |
21+
while ! docker exec codelytv-php_ddd_skeleton-mooc-mysql mysqladmin --user=root --password= --host "127.0.0.1" ping --silent &> /dev/null ; do
22+
echo "Waiting for database connection..."
23+
sleep 2
24+
done
25+
26+
- name: Run the tests
27+
run: make test

Diff for: .gitignore

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
applications/*/var/*
2-
!applications/*/var/*/.gitkeep
1+
/.env.local
2+
/.env.*.local
33

4-
src/*/Infrastructure/Symfony/Bundle/DependencyInjection/Resources/*_parameters.yml
5-
src/*/Shared/Infrastructure/Symfony/Bundle/DependencyInjection/Resources/*_parameters.yml
4+
/apps/*/*/var/
65

7-
/applications/mooc_backend/config/supervisor/*
8-
!/applications/mooc_backend/config/supervisor/.gitkeep
6+
/apps/*/*/build/
7+
!/apps/*/*/build/supervisor/.gitkeep
98

10-
/phpunit.xml
9+
/vendor/
10+
.phpunit.result.cache
1111

12-
vendor/
13-
14-
.env
15-
16-
build/
12+
/build

Diff for: LICENCE

-21
This file was deleted.

Diff for: Makefile

+19-21
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,58 @@
1-
.PHONY: all build deps composer-install composer-update composer reload test run-tests start stop destroy doco rebuild
1+
.PHONY: build deps composer-install composer-update composer reload test run-tests start stop destroy doco rebuild start-local
22

33
current-dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
44

5-
# 👌 Main targets
6-
75
build: deps start
86

97
deps: composer-install
108

119
# 🐘 Composer
12-
1310
composer-install: CMD=install
1411
composer-update: CMD=update
15-
16-
# Usage example (add a new dependency): `make composer CMD="require --dev symfony/var-dumper ^4.2"`
1712
composer composer-install composer-update:
18-
@docker run --rm --interactive --tty --volume $(current-dir):/app --user $(id -u):$(id -g) \
13+
@docker run --rm --interactive --volume $(current-dir):/app --user $(id -u):$(id -g) \
1914
clevyr/prestissimo $(CMD) \
2015
--ignore-platform-reqs \
2116
--no-ansi \
2217
--no-interaction
2318

24-
# 🕵️ Clear cache
25-
# OpCache: Restarts the unique process running in the PHP FPM container
26-
# Nginx: Reloads the server
27-
2819
reload:
2920
@docker-compose exec php-fpm kill -USR2 1
3021
@docker-compose exec nginx nginx -s reload
3122

32-
# ✅ Tests
33-
3423
test:
35-
@docker exec -it codelytv-cqrs_ddd_php_example-php make run-tests
24+
@docker exec codelytv-php_ddd_skeleton-php make run-tests
3625

3726
run-tests:
3827
mkdir -p build/test_results/phpunit
39-
./vendor/bin/phpstan analyse -l 7 -c etc/phpstan/phpstan.neon applications/mooc_backend/src
4028
./vendor/bin/phpunit --exclude-group='disabled' --log-junit build/test_results/phpunit/junit.xml tests
4129
./vendor/bin/behat -p mooc_backend --format=progress -v
4230

4331
# 🐳 Docker Compose
44-
45-
start:
46-
@docker-compose up -d
47-
32+
start: CMD=up -d
4833
stop: CMD=stop
49-
5034
destroy: CMD=down
5135

5236
# Usage: `make doco CMD="ps --services"`
5337
# Usage: `make doco CMD="build --parallel --pull --force-rm --no-cache"`
54-
doco stop destroy:
38+
doco start stop destroy:
5539
@docker-compose $(CMD)
5640

5741
rebuild:
5842
docker-compose build --pull --force-rm --no-cache
5943
make deps
6044
make start
45+
46+
prepare-local:
47+
curl -sS https://get.symfony.com/cli/installer | bash
48+
49+
start-local:
50+
symfony serve --dir=apps/mooc/backend/public --port=8030 -d --no-tls --force-php-discovery
51+
symfony serve --dir=apps/backoffice/frontend/public --port=8032 -d --no-tls --force-php-discovery
52+
symfony serve --dir=apps/backoffice/backend/public --port=8034 -d --no-tls --force-php-discovery
53+
54+
stop-local:
55+
symfony server:stop --dir=apps/mooc/backend/public
56+
symfony server:stop --dir=apps/backoffice/frontend/public
57+
symfony server:stop --dir=apps/backoffice/backend/public
58+

Diff for: README.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<p align="center">
1212
<a href="https://github.com/CodelyTV"><img src="https://img.shields.io/badge/CodelyTV-OS-green.svg?style=flat-square" alt="codely.tv"/></a>
1313
<a href="http://pro.codely.tv"><img src="https://img.shields.io/badge/CodelyTV-PRO-black.svg?style=flat-square" alt="CodelyTV Courses"/></a>
14-
<a href="#"><img src="https://img.shields.io/badge/Symfony-4.2-purple.svg?style=flat-square&logo=symfony" alt="Symfony 4.2"/></a>
15-
<a href="https://circleci.com/gh/CodelyTV/cqrs-ddd-php-example/tree/master"><img src="https://circleci.com/gh/CodelyTV/cqrs-ddd-php-example/tree/master.svg?style=svg&circle-token=ce12d04556fa79b78bb2beefa0356a6f6934b26b" alt="CircleCI Status"/></a>
14+
<a href="#"><img src="https://img.shields.io/badge/Symfony-4.4-purple.svg?style=flat-square&logo=symfony" alt="Symfony 4.4"/></a>
15+
<a href="https://github.com/CodelyTV/php-ddd-example/actions"><img src="https://github.com/CodelyTV/php-ddd-example/workflows/CI/badge.svg" alt="CI pipeline status" /></a>
1616
</p>
1717

1818
<p align="center">
@@ -63,8 +63,7 @@
6363

6464
### 🛠️ Environment configuration
6565

66-
1. Copy the default environment variables: `cp .env.dist .env`
67-
2. Modify the environment variables if needed: `vim .env`
66+
1. Create a local environment file if needed: `cp .env .env.local`
6867
3. Add `api.codelytv.localhost` domain to your local hosts: `echo "127.0.0.1 api.codelytv.localhost"| sudo tee -a /etc/hosts > /dev/null`
6968

7069
### 🌍 Application execution
@@ -80,13 +79,13 @@
8079
## 🤔 Project explanation
8180

8281
This project tries to be a MOOC (Massive Open Online Course) platform.
83-
For now it only has an [API](applications/mooc_backend/src/Controller)
84-
and some [Consumers](applications/mooc_backend/src/Command).
82+
It has a [Web](apps/backoffice/frontend/src/Controller), an [API](apps/mooc/backend/src/Controller) and
83+
some [Consumers](apps/mooc/backend/src/Command).
8584

8685
### ⛱️ Bounded Contexts
8786

8887
* [Mooc](src/Mooc): Place to look in if you wanna see some code 🙂. Massive Open Online Courses public platform with users, videos, notifications, and so on
89-
* [Backoffice](src/Backoffice): Work in progress. Here you'll find the use cases needed by the Customer Support department in order to manage users, courses, videos, and so on.
88+
* [Backoffice](src/Backoffice): Here you'll find the use cases needed by the Customer Support department in order to manage users, courses, videos, and so on.
9089

9190
### 🎯 Hexagonal Architecture
9291

@@ -121,7 +120,7 @@ src
121120
| `-- Infrastructure // The infrastructure of our module
122121
| |-- DependencyInjection
123122
| `-- Persistence
124-
| `--VideoRepositoryMySql.php // An implementation of the repository
123+
| `--MySqlVideoRepository.php // An implementation of the repository
125124
`-- Shared // Shared Kernel: Common infrastructure and domain shared between the different Bounded Contexts
126125
|-- Domain
127126
`-- Infrastructure
@@ -132,23 +131,24 @@ Our repositories try to be as simple as possible usually only containing 2 metho
132131
If we need some query with more filters we use the `Strategy` pattern also known as `Criteria` pattern. So we add a
133132
`searchByCriteria` method.
134133

135-
You can see an example [here](src/Mooc/Videos/Domain/VideoRepository.php)
136-
and its implementation [here](src/Mooc/Videos/Infrastructure/Persistence/VideoRepositoryMySql.php).
134+
You can see an example [here](src/Mooc/Courses/Domain/CourseRepository.php)
135+
and its implementation [here](src/Mooc/Courses/Infrastructure/Persistence/DoctrineCourseRepository.php).
137136

138137
### Aggregates
139-
You can see an example of an aggregate [here](src/Mooc/Videos/Domain/Video.php). All aggregates should
138+
You can see an example of an aggregate [here](src/Mooc/Courses/Domain/Course.php). All aggregates should
140139
extends the [AggregateRoot](src/Shared/Domain/Aggregate/AggregateRoot.php).
141140

142141
### Command Bus
143-
There are 2 implementations of the [command bus](src/Shared/Domain/Bus/Command/CommandBus.php).
144-
1. [Sync](src/Shared/Infrastructure/Bus/Command/SymfonySyncCommandBus.php) using the Symfony Message Bus
145-
2. [Async](src/Shared/Infrastructure/Bus/Command/CommandBusAsync.php) using a local file
142+
There is 1 implementations of the [command bus](src/Shared/Domain/Bus/Command/CommandBus.php).
143+
1. [Sync](src/Shared/Infrastructure/Bus/Command/InMemorySymfonyCommandBus.php) using the Symfony Message Bus
146144

147145
### Query Bus
148-
The [Query Bus](src/Shared/Infrastructure/Bus/Query/SymfonySyncQueryBus.php) uses the Symfony Message Bus.
146+
The [Query Bus](src/Shared/Infrastructure/Bus/Query/InMemorySymfonyQueryBus.php) uses the Symfony Message Bus.
149147

150148
### Event Bus
151-
The [Event Bus](src/Shared/Infrastructure/Bus/Event/SymfonySyncEventBus.php) uses the Symfony Message Bus.
149+
The [Event Bus](src/Shared/Infrastructure/Bus/Event/InMemory/InMemorySymfonyEventBus.php) uses the Symfony Message Bus.
150+
The [MySql Bus](src/Shared/Infrastructure/Bus/Event/MySql/MySqlDoctrineEventBus.php) uses a MySql+Pulling as a bus.
151+
The [RabbitMQ Bus](src/Shared/Infrastructure/Bus/Event/RabbitMq/RabbitMqEventBus.php) uses RabbitMQ C extension.
152152

153153
## 🤔 Contributing
154154
There are some things missing (add swagger, improve documentation...), feel free to add this if you want! If you want
@@ -158,6 +158,7 @@ some guidelines feel free to contact us :)
158158
This code was show in the [From framework coupled code to #microservices through #DDD](http://codely.tv/screencasts/codigo-acoplado-framework-microservicios-ddd) talk and doubts where answered in [DDD y CQRS: Preguntas Frecuentes](http://codely.tv/screencasts/ddd-cqrs-preguntas-frecuentes/) video.
159159

160160
🎥 Used in the CodelyTV Pro courses:
161+
* [🇪🇸 DDD in PHP](https://pro.codely.tv/library/ddd-en-php/about/)
161162
* [🇪🇸 Arquitectura Hexagonal](https://pro.codely.tv/library/arquitectura-hexagonal/66748/about/)
162163
* [🇪🇸 CQRS: Command Query Responsibility Segregation](https://pro.codely.tv/library/cqrs-command-query-responsibility-segregation-3719e4aa/62554/about/)
163164
* [🇪🇸 Comunicación entre microservicios: Event-Driven Architecture](https://pro.codely.tv/library/comunicacion-entre-microservicios-event-driven-architecture/74823/about/)

Diff for: applications/bootstrap.php

-7
This file was deleted.

Diff for: applications/mooc_backend/bin/console

-23
This file was deleted.

0 commit comments

Comments
 (0)