Ventas是一個完全用Clojure編寫的WIP電子商務平台。
文件
沒有開源電子商務項目使我滿意。我一直在與大多數人一起工作已有多年了,我認為它們很爛。我什麼都不會命名,但這大致是我對可用解決方案的看法:
它們往往很難擴展或修改。他們試圖通過擴展系統解決問題,但最終您需要修改核心代碼以進行有意義的更改。這迫使您在永不更新軟件或付出非凡的努力以保持更改的應用之間進行選擇。這就是為什麼該項目的主要設計決策之一是使擴展和修改非常容易。
他們往往很難推理。因為它們是基於一種根本可變的模型,所以不可能知道數據庫是如何進入當前狀態的。在最好的情況下,發生了一些不好的事情,我不知道為什麼。在最壞的情況下,發生了一些不好的事情,我什至沒有註意到(直到為時已晚)。到處都有可變的物體也無濟於事。
他們的表現往往很差。當然,一切都可以使表演者做到,但是我不需要努力。特別是當“努力”是指重寫SQL查詢時,或者浪費幾天的時間試圖找出導致我的商店需要20秒鐘的原因。
它們傾向於過度設計,或者俱有用戶敵對的“功能”。這在很多軟件中都是一個問題,但是它仍然存在。
請注意,這些觀點並不意味著Ventas不會或不會犯同樣的罪過。我只是盡量不要。
目前,Ventas不適合其目的。但是,如果您是開發人員,並且只想查看該項目的行動,請繼續閱讀。
您需要安裝git和leiningen 。您還需要訪問數據程序數據庫和Elasticsearch實例。 (如果您對Docker感到滿意,請參閱設置帶有Docker-Compose的本地環境)
首先clone該項目,並cd其中:
$ git clone https://github.com/JoelSanchez/ventas
$ cd ventas現在您可以啟動重複:
$ lein repl準備就緒後,執行init :
user=> ( init )
:reloading (ventas.common.utils ventas.utils ventas.config ventas.database ventas.database.schema ventas.database.entity ventas.entities.product-variation ventas.database.generators ventas.entities.i18n ventas.entities.brand ventas.plugin ventas.database.seed ventas.entity-test ventas.events repl ventas.entities.image-size ventas.paths ventas.entities.file ventas.server.ws ventas.logging ventas.server ventas.server-test ventas.auth ventas.entities.user ventas.test-tools ventas.database-test ventas.entities.product-taxonomy ventas.server.pagination ventas.utils.images ventas.server.api ventas.entities.configuration ventas.entities.address ventas.entities.product-term client ventas.plugins.featured-categories.core ventas.plugins.slider.core ventas.entities.order-line ventas.entities.order ventas.common.utils-test ventas.entities.resource ventas.entities.category ventas.entities.product ventas.entities.country ventas.entities.tax ventas.entities.state ventas.plugins.blog.core ventas.plugins.featured-products.core user)
INFO [ventas.database:27] - Starting database, URL: datomic:dev://localhost:4334/ventas
INFO [ventas.server:99] - Starting server
INFO [ventas.server:102] - Starting server on 0.0 .0.0:3450
INFO [client:28] - Starting Figwheel
Figwheel: Starting server at http:// 0.0 .0.0:3449
Figwheel: Watching build - app
Compiling " resources/public/files/js/compiled/ventas.js " from [ " src/cljs " " src/cljc " " test/cljs " " test/cljc " ]...
Successfully compiled " resources/public/files/js/compiled/ventas.js " in 8.252 seconds.
Figwheel: Starting CSS Watcher for paths [ " resources/public/files/css " ]
INFO [client:42] - Starting SASS
:done然後,執行setup!功能,將遷移數據庫,安裝固定裝置等:
( ventas.core/setup! )現在,您可以打開localhost:3450/admin來查看管理。不包括一個前部,但是您可以查看Ventas-Demo以獲取示例。
要輸入退縮,您需要自己創建管理用戶:
(entity/create :user {:first-name "Admin"
:email "[email protected]"
:password "yourpassword"}
在退縮中進行前端開發:
lein sass4clj auto
shadow-cljs watch :admin
您可以連接到Shadow-Cljs創建的NREPL服務器以獲取CLJS RPEL:
lein repl :connect localhost:4002
user= > (shadow.cljs.devtools.api/nrepl-select :admin)包括docker-compose.yaml文件:
docker-compose up -d
用Clojure寫。
使用安裝座,真的喜歡以臥式驅動的開發。代碼重新加載是通過調用repl/r完成的。應用程序初始化是通過調用repl/init來完成的。
; ; (r) reloads changed namespaces, restarts defstates within them, and optionally
; ; restarts given defstates as keywords
( r :db )
INFO [ventas.database:34] - Stopping database
:reloading ()
INFO [ventas.database:27] - Starting database, URL: datomic:dev://localhost:4334/ventas
=> :done數據庫是數據組。依賴core.spec的自定義數據庫實體系統摘要數據庫並允許輕鬆測試和生成示例數據。
; ; recreates the database, applies the schema, creates the fixtures and seeds the database with randomly generated entities
( seed/seed :recreate? true :generate? true )許多實用程序功能使探索數據庫並從中獲取數據更加互動和快速。
; ; returns a list of active users
( entity/query :user { :status :user.status/active })
; ; returns an entity by EID
( entity/find 17592186045760 )
; ; creates an user and returns the result
( entity/create :user { :email " test@email "
:first-name " Test "
:last-name " User " })
; ; generates three users
( entity/generate :user 3 )
; ; updates an user's company
( entity/update { :id 17592186045920
:company " Test " })添加新實體很容易,並且在窗簾後面處理架構添加(搜索到entity/register-type!了解更多)
HTTP服務器是http-kit。路由是通過Compojure處理的,但它們只是4個處理程序,因為在和弦的幫助下,實際通信發生在Websocket上。
( register-endpoint!
:products/get
( fn [{ :keys [params]} state]
( entity/serialize ( entity/find ( :id params)))))通過JWT令牌(由Buddy提供)進行身份驗證。
用clojurescript編寫,並使用重新框架。
開發是通過Shadow-CLJ進行的。
與服務器的通信是使用抽象Websocket請求的重新構架效應完成的。所有請求和響應都記錄到JS控制台的verbose級別,因此您可以看到正在發生的事情。
客戶端路由由BIDI處理,但是為此存在自定義包裝器,這使得事情更容易處理。
( routes/define-route!
:frontend.product ; ; this route is nested inside the :frontend route
{ :name ( i18n ::the-name-of-this-page )
:url [ " product/ " :id ]
:component a-re-frame-component-for-this-route})樣式表是用SCSS編寫的。守望者還由服務器的替補處理。
I18N用舌頭完成
語義UI組件。
我感謝項目的任何部分的幫助。
請閱讀貢獻