Skip to content

Commit 096a62e

Browse files
committed
Fix spelling error
1 parent 13a3cb2 commit 096a62e

File tree

9 files changed

+43
-46
lines changed

9 files changed

+43
-46
lines changed

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Mercurius
22

3-
This project is a toy application developed with the purpose of exploring [Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) concepts in the context of functional programming languages, specifically Clojure.
3+
This project is a toy application developed with the purpose of exploring [Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) concepts in the context of functional programming languages, specifically [Clojure](https://clojure.org/).
44

55
[![Build Status](https://travis-ci.org/eeng/mercurius.svg?branch=master)](https://travis-ci.org/eeng/mercurius)
66

@@ -16,35 +16,32 @@ As it was previously mentioned, Clean Architecture principles were applied to st
1616

1717
### Entities
1818

19-
The core of the architecture contains the domain **entities** (wallets, orders, trades, etc.) that, being Clojure a functional language, consists of a set data structures and pure functions implementing the business logic. No side-effects are allowed in this layer, so its extremely easy to test.
20-
21-
You may find the code for this layer in the `mercurius.*.domain.entities` namespaces.
19+
The core of the architecture contains the domain **entities** (wallets, orders, trades, etc.) that, being Clojure a functional language, consists of a set data structures and pure functions implementing the business logic. No side-effects nor dependencies on any framework are allowed in this layer, so its extremely easy to test.
2220

2321
### Use Cases
2422

25-
Surrounding the entities we have the **use cases** layer. They will be in charge of coordinating all the steps required to fulfill the use case, e.g. fetching an entity from the database, calling the business logic, persisting the changes, and publishing the events. This layer does have side-effects, however, everything is done through protocols, and concrete implementations are injected from the outer layer, so it doesn't depend on any specific database or framework.
23+
Surrounding the entities we have the **use cases** layer. They will be in charge of coordinating all the steps required to fulfill the use case, e.g. fetching an entity from the database, calling the business logic, persisting the changes, and publishing the events. This layer does have side-effects, however, everything is done through protocols, and concrete implementations are injected from outer layers, so it doesn't depend on any specific database or framework.
2624

2725
All use cases will be in the form of a high-order _builder_ function, i.e., a function that receives its dependencies and returns another function that finally executes the logic. This pattern allows us to treat all use cases uniformly, so we can apply cross-cutting concerns (like logging or transaction management) without repeating the same code everywhere. This is done in the _mediator_, which is the entry point to the domain.
2826

29-
The code for this layer is the `mercurius.*.domain.use-cases.*` namespaces.
30-
3127
### Adapters
3228

3329
Moving up, we have the interface adapters. Here there are repository implementations, controllers, and background processes. Regarding the repositories, simple in-memory implementations are provided (making use of the excellent Clojure STM), although, because the use cases depend exclusively on protocols, it should be fairly simple to swap them with real database implementations.
3430

35-
Also in this layer, there is a core.async implementation of an event bus that it's used to broadcast the domain events.
31+
### Infrastructure
3632

37-
The code is in the `mercurius.*.adapters.(repositories|controllers|processes).*` namespaces.
33+
In the outer layer we have the _details_ (as Uncle Bob likes to call them): The web server, the real-time communication framework, and a basic [core.async](https://github.com/clojure/core.async) implementation of a PubSub that it's used by the background processes to notify users when certain events occurred. It's based on protocols as well, so we can swap it by a Redis implementation, for example.
3834

39-
### Infrastructure
35+
### Configuration
36+
37+
This is the place where the entire backend is assembled. All the components are built and wired together with [Integrant](https://github.com/weavejester/integrant). This allows us to start/stop the whole system from the REPL.
4038

4139
## Implementation
4240

4341
The system consists of a backend written in [Clojure](https://clojure.org/) and a frontend SPA built with [ClojureScript](https://clojurescript.org/). In addition, the following libraries assisted in the project:
4442

4543
- [Integrant](https://github.com/weavejester/integrant) was used to wire all the component's dependencies and manage the stateful resources.
46-
- [core.async] TODO PubSub EventBus
47-
- [Sente](https://github.com/ptaoussanis/sente) provides realtime communication between frontend and backend through Web Sockets.
44+
- [Sente](https://github.com/ptaoussanis/sente) provides real-time communication between frontend and backend through Web Sockets.
4845
- [Reagent](https://reagent-project.github.io/) was used to build the user interface.
4946
- [re-frame](https://github.com/day8/re-frame/) cleanly separated the views from the state and event management in the frontend.
5047
- [shadow-cljs](http://shadow-cljs.org/) simplified the process of compiling ClojureScript.

dev/fiddles/pub_sub.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns fiddles.pub-sub
22
(:require [user :refer [system]]
3-
[mercurius.core.infraestructure.messaging.channel-based-pub-sub :refer [start-channel-based-pub-sub stop-channel-based-pub-sub]]
3+
[mercurius.core.infrastructure.messaging.channel-based-pub-sub :refer [start-channel-based-pub-sub stop-channel-based-pub-sub]]
44
[mercurius.core.adapters.messaging.pub-sub :refer [publish subscribe unsubscribe]]))
55

66
(comment
@@ -11,5 +11,5 @@
1111
(unsubscribe bus subscription)
1212
(stop-channel-based-pub-sub bus)
1313

14-
(let [bus (:infraestructure/pub-sub system)]
14+
(let [bus (:infrastructure/pub-sub system)]
1515
(publish bus "push.ticker-updated.BTCUSD" {:ticker "BTCUSD" :last-price 10 :volume 90})))

src/mercurius/core/configuration/system.clj

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
[mercurius.core.domain.use-cases.mediator.middleware.stm :refer [stm]]
99
[mercurius.core.domain.messaging.event-bus :refer [emit]]
1010
[mercurius.core.adapters.messaging.pub-sub-event-bus :refer [new-pub-sub-event-bus]]
11-
[mercurius.core.infraestructure.messaging.channel-based-pub-sub :refer [start-channel-based-pub-sub stop-channel-based-pub-sub]]
11+
[mercurius.core.infrastructure.messaging.channel-based-pub-sub :refer [start-channel-based-pub-sub stop-channel-based-pub-sub]]
1212
[mercurius.core.adapters.processes.activity-logger :refer [new-activity-logger]]
1313
[mercurius.core.adapters.controllers.use-case-controller :refer [new-use-case-controller]]
1414
[mercurius.core.adapters.controllers.event-notifier :refer [start-event-notifier]]
15-
[mercurius.core.infraestructure.web.server :refer [start-web-server stop-web-server]]
16-
[mercurius.core.infraestructure.web.sente :refer [start-sente stop-sente]]
15+
[mercurius.core.infrastructure.web.server :refer [start-web-server stop-web-server]]
16+
[mercurius.core.infrastructure.web.sente :refer [start-sente stop-sente]]
1717
[mercurius.accounts.domain.use-cases.authenticate :refer [new-authenticate-use-case]]
1818
[mercurius.accounts.adapters.repositories.in-memory-user-repository :refer [new-in-memory-user-repo]]
1919
[mercurius.wallets.adapters.repositories.in-memory-wallet-repository :refer [new-in-memory-wallet-repo]]
@@ -85,26 +85,26 @@
8585
:adapters/ticker-repo nil
8686
:adapters/trade-repo nil
8787
:adapters/user-repo nil
88-
:adapters/event-bus {:pub-sub (ig/ref :infraestructure/pub-sub)}
88+
:adapters/event-bus {:pub-sub (ig/ref :infrastructure/pub-sub)}
8989
:processes/trade-finder {:event-bus (ig/ref :adapters/event-bus)
9090
:dispatch (ig/ref :use-cases/dispatch)}
9191
:processes/trade-processor {:event-bus (ig/ref :adapters/event-bus)
9292
:dispatch (ig/ref :use-cases/dispatch)}
9393
:processes/activity-logger {:event-bus (ig/ref :adapters/event-bus)}
9494
:processes/simulator {:dispatch (ig/ref :use-cases/dispatch)
95-
:pub-sub (ig/ref :infraestructure/pub-sub)}
95+
:pub-sub (ig/ref :infrastructure/pub-sub)}
9696
:controllers/use-case-controller {:dispatch (ig/ref :use-cases/dispatch)}
9797
:controllers/simulation-controller {:simulator (ig/ref :processes/simulator)}
9898
:controllers/event-notifier {:event-bus (ig/ref :adapters/event-bus)
99-
:pub-sub (ig/ref :infraestructure/pub-sub)}
100-
:infraestructure/pub-sub nil
101-
:infraestructure/web-server {:port port
102-
:session-key session-key
103-
:sente (ig/ref :infraestructure/sente)
104-
:dispatch (ig/ref :use-cases/dispatch)}
105-
:infraestructure/sente {:use-case-controller (ig/ref :controllers/use-case-controller)
106-
:simulation-controller (ig/ref :controllers/simulation-controller)
107-
:pub-sub (ig/ref :infraestructure/pub-sub)}})
99+
:pub-sub (ig/ref :infrastructure/pub-sub)}
100+
:infrastructure/pub-sub nil
101+
:infrastructure/web-server {:port port
102+
:session-key session-key
103+
:sente (ig/ref :infrastructure/sente)
104+
:dispatch (ig/ref :use-cases/dispatch)}
105+
:infrastructure/sente {:use-case-controller (ig/ref :controllers/use-case-controller)
106+
:simulation-controller (ig/ref :controllers/simulation-controller)
107+
:pub-sub (ig/ref :infrastructure/pub-sub)}})
108108

109109
(defmethod ig/init-key :adapters/wallet-repo [_ _]
110110
(new-in-memory-wallet-repo))
@@ -121,10 +121,10 @@
121121
(defmethod ig/init-key :adapters/user-repo [_ _]
122122
(new-in-memory-user-repo))
123123

124-
(defmethod ig/init-key :infraestructure/pub-sub [_ _]
124+
(defmethod ig/init-key :infrastructure/pub-sub [_ _]
125125
(start-channel-based-pub-sub))
126126

127-
(defmethod ig/halt-key! :infraestructure/pub-sub [_ pub-sub]
127+
(defmethod ig/halt-key! :infrastructure/pub-sub [_ pub-sub]
128128
(stop-channel-based-pub-sub pub-sub))
129129

130130
(defmethod ig/init-key :adapters/event-bus [_ deps]
@@ -209,10 +209,10 @@
209209
(defmethod ig/halt-key! :processes/simulator [_ simulator]
210210
(stop-simulator simulator))
211211

212-
(defmethod ig/init-key :infraestructure/web-server [_ deps]
212+
(defmethod ig/init-key :infrastructure/web-server [_ deps]
213213
(start-web-server deps))
214214

215-
(defmethod ig/halt-key! :infraestructure/web-server [_ server]
215+
(defmethod ig/halt-key! :infrastructure/web-server [_ server]
216216
(stop-web-server server))
217217

218218
(defmethod ig/init-key :controllers/use-case-controller [_ deps]
@@ -224,10 +224,10 @@
224224
(defmethod ig/init-key :controllers/event-notifier [_ deps]
225225
(start-event-notifier deps))
226226

227-
(defmethod ig/init-key :infraestructure/sente [_ deps]
227+
(defmethod ig/init-key :infrastructure/sente [_ deps]
228228
(start-sente deps))
229229

230-
(defmethod ig/halt-key! :infraestructure/sente [_ sente]
230+
(defmethod ig/halt-key! :infrastructure/sente [_ sente]
231231
(stop-sente sente))
232232

233233
(defn start

src/mercurius/core/infraestructure/messaging/channel_based_pub_sub.clj renamed to src/mercurius/core/infrastructure/messaging/channel_based_pub_sub.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns mercurius.core.infraestructure.messaging.channel-based-pub-sub
1+
(ns mercurius.core.infrastructure.messaging.channel-based-pub-sub
22
(:require [clojure.core.async :refer [put! chan close! go-loop <! sliding-buffer]]
33
[clojure.string :as str]
44
[taoensso.timbre :as log]

src/mercurius/core/infraestructure/web/handler.clj renamed to src/mercurius/core/infrastructure/web/handler.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns mercurius.core.infraestructure.web.handler
1+
(ns mercurius.core.infrastructure.web.handler
22
(:require [reitit.ring :as ring]
33
[ring.middleware.keyword-params :refer [wrap-keyword-params]]
44
[ring.middleware.params :refer [wrap-params]]
@@ -7,7 +7,7 @@
77
[ring.middleware.session.cookie :refer [cookie-store]]
88
[reitit.ring.middleware.muuntaja :as muuntaja]
99
[muuntaja.core :as m]
10-
[mercurius.core.infraestructure.web.index :refer [index]]
10+
[mercurius.core.infrastructure.web.index :refer [index]]
1111
[mercurius.accounts.adapters.controllers.auth-controller :as auth]))
1212

1313
(defn router [{{:keys [ring-ajax-get-or-ws-handshake ring-ajax-post]} :sente

src/mercurius/core/infraestructure/web/index.clj renamed to src/mercurius/core/infrastructure/web/index.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns mercurius.core.infraestructure.web.index
1+
(ns mercurius.core.infrastructure.web.index
22
(:require [hiccup.page :as page]
33
[mercurius.util.ring :refer [ok]]))
44

src/mercurius/core/infraestructure/web/sente.clj renamed to src/mercurius/core/infrastructure/web/sente.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns mercurius.core.infraestructure.web.sente
1+
(ns mercurius.core.infrastructure.web.sente
22
(:require [taoensso.sente :as sente]
33
[taoensso.sente.server-adapters.http-kit :refer [get-sch-adapter]]
44
[clojure.core.async :refer [go-loop <!]]

src/mercurius/core/infraestructure/web/server.clj renamed to src/mercurius/core/infrastructure/web/server.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
(ns mercurius.core.infraestructure.web.server
1+
(ns mercurius.core.infrastructure.web.server
22
(:require [org.httpkit.server :refer [run-server]]
3-
[mercurius.core.infraestructure.web.handler :refer [handler]]
3+
[mercurius.core.infrastructure.web.handler :refer [handler]]
44
[taoensso.timbre :as log]))
55

66
(defn start-web-server [{:keys [port] :or {port 3000} :as deps}]

test/mercurius/core/infraestructure/messaging/channel_based_pub_sub_test.clj renamed to test/mercurius/core/infrastructure/messaging/channel_based_pub_sub_test.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
(ns mercurius.core.infraestructure.messaging.channel-based-pub-sub-test
1+
(ns mercurius.core.infrastructure.messaging.channel-based-pub-sub-test
22
(:require [clojure.test :refer [deftest testing is]]
33
[mercurius.support.helpers :refer [with-system]]
44
[mercurius.core.adapters.messaging.pub-sub :refer [publish subscribe]]
5-
[mercurius.core.infraestructure.messaging.channel-based-pub-sub :refer [match-topic?]]))
5+
[mercurius.core.infrastructure.messaging.channel-based-pub-sub :refer [match-topic?]]))
66

77
(deftest pub-sub-test
88
(testing "one subscriber to a specific topic"
9-
(with-system [{pub-sub :infraestructure/pub-sub} {:only [:infraestructure/pub-sub]}]
9+
(with-system [{pub-sub :infrastructure/pub-sub} {:only [:infrastructure/pub-sub]}]
1010
(let [msgs (atom [])]
1111
(subscribe pub-sub "t1" {:on-message #(swap! msgs conj %)})
1212
(publish pub-sub "t1" "m1")
@@ -15,7 +15,7 @@
1515
(is (match-eventually? ["m1" "m2"] msgs)))))
1616

1717
(testing "multiple subscribers to the same specific topic"
18-
(with-system [{pub-sub :infraestructure/pub-sub} {:only [:infraestructure/pub-sub]}]
18+
(with-system [{pub-sub :infrastructure/pub-sub} {:only [:infrastructure/pub-sub]}]
1919
(let [topic "some topic"
2020
msgs (atom [])]
2121
(subscribe pub-sub topic {:on-message #(swap! msgs conj {:sub 1 :msg %})})
@@ -24,7 +24,7 @@
2424
(is (match-eventually? [{:sub 1 :msg "msg"} {:sub 2 :msg "msg"}] msgs)))))
2525

2626
(testing "subscribing with a pattern"
27-
(with-system [{pub-sub :infraestructure/pub-sub} {:only [:infraestructure/pub-sub]}]
27+
(with-system [{pub-sub :infrastructure/pub-sub} {:only [:infrastructure/pub-sub]}]
2828
(let [msgs (atom [])]
2929
(subscribe pub-sub "events.*" {:on-message #(swap! msgs conj %)})
3030
(publish pub-sub "events.orders" "m1")

0 commit comments

Comments
 (0)