Skip to content

Commit

Permalink
Separate in server, common and client projects
Browse files Browse the repository at this point in the history
  • Loading branch information
skydread1 committed Feb 13, 2023
1 parent 2bee973 commit 9488ed0
Show file tree
Hide file tree
Showing 50 changed files with 139 additions and 137 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ To work on the backend:
For development with UI:
1) Be sure to have a `main.js` in the resources. if not present, you can generate it via `clj T:build js-bundle`
2) Check if `main.js` is the script source in `index.html`
3) Start the dev-system in the `clj.flybot.systems` namespace to get the website running on port `8123`
3) Start the dev-system in the `flybot.server.systems` namespace to get the website running on port `8123`

### TEST in terminal

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns flybot.mobile.main
(ns flybot.client.mobile.main
(:require [ajax.edn :refer [edn-request-format edn-response-format]]
[reagent.core :as r]
[cljc.flybot.utils :as utils]
[flybot.common.utils :as utils]
["@react-navigation/native" :refer [NavigationContainer]]
["@react-navigation/bottom-tabs" :as tab-nav]
["react-native-vector-icons/Ionicons" :as icon]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns cljs.flybot.components.admin-panel
(:require [cljs.flybot.components.error :refer [errors]]
[cljs.flybot.components.svg :as svg]
(ns flybot.client.web.components.admin-panel
(:require [flybot.client.web.components.error :refer [errors]]
[flybot.client.web.components.svg :as svg]
[re-frame.core :as rf]))

;;---------- Buttons ----------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cljs.flybot.components.error
(ns flybot.client.web.components.error
(:require [re-frame.core :as rf]))

(defn errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cljs.flybot.components.footer)
(ns flybot.client.web.components.footer)

(defn footer-comp []
[:footer#footer-contact.container
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns cljs.flybot.components.header
(:require [cljs.flybot.components.svg :as svg]
(ns flybot.client.web.components.header
(:require [flybot.client.web.components.svg :as svg]
[reitit.frontend.easy :as rfe]
[re-frame.core :as rf]))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns cljs.flybot.components.page
(:require [cljs.flybot.lib.hiccup :as h]
[cljs.flybot.components.page.post :refer [page-post]]
[cljs.flybot.components.page.page-config :refer [page-config]]
(ns flybot.client.web.components.page
(:require [flybot.client.web.lib.hiccup :as h]
[flybot.client.web.components.page.post :refer [page-post]]
[flybot.client.web.components.page.page-config :refer [page-config]]
[re-frame.core :as rf]))

(defn sort-posts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns cljs.flybot.components.page.page-config
(:require [cljs.flybot.components.error :refer [errors]]
[cljs.flybot.components.svg :as svg]
(ns flybot.client.web.components.page.page-config
(:require [flybot.client.web.components.error :refer [errors]]
[flybot.client.web.components.svg :as svg]
[re-frame.core :as rf]))

;;---------- Buttons ----------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns cljs.flybot.components.page.post
(:require [cljc.flybot.utils :as utils]
[cljs.flybot.lib.hiccup :as h]
[cljs.flybot.components.header :refer [theme-logo]]
[cljs.flybot.components.error :refer [errors]]
[cljs.flybot.components.svg :as svg]
(ns flybot.client.web.components.page.post
(:require [flybot.common.utils :as utils]
[flybot.client.web.lib.hiccup :as h]
[flybot.client.web.components.header :refer [theme-logo]]
[flybot.client.web.components.error :refer [errors]]
[flybot.client.web.components.svg :as svg]
[re-frame.core :as rf]))

;;---------- Buttons ----------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cljs.flybot.components.svg)
(ns flybot.client.web.components.svg)

;; theme

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(ns cljs.flybot.core
(:require [cljs.flybot.components.header :refer [header-comp]]
[cljs.flybot.components.admin-panel :refer [admin-section]]
[cljs.flybot.components.page :refer [page]]
[cljs.flybot.components.footer :refer [footer-comp]]
[cljs.flybot.db]
[cljs.flybot.lib.router :as router]
(ns flybot.client.web.core
(:require [flybot.client.web.components.header :refer [header-comp]]
[flybot.client.web.components.admin-panel :refer [admin-section]]
[flybot.client.web.components.page :refer [page]]
[flybot.client.web.components.footer :refer [footer-comp]]
[flybot.client.web.db]
[flybot.client.web.lib.router :as router]

[reagent.dom :as rdom]
[re-frame.core :as rf]))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cljs.flybot.db
(ns flybot.client.web.db
"State management using re-frame.
## Naming convention (inspired by Ivan Fedorov)
Expand All @@ -8,10 +8,10 @@
:fx.domain/fx-id for effects
:cofx.domain/cofx-id for coeffects"
(:require [ajax.edn :refer [edn-request-format edn-response-format]]
[cljc.flybot.utils :as utils :refer [toggle]]
[cljc.flybot.validation :as valid]
[cljs.flybot.lib.localstorage :as l-storage]
[cljs.flybot.lib.class-utils :as cu]
[flybot.common.utils :as utils :refer [toggle]]
[flybot.common.validation :as valid]
[flybot.client.web.lib.localstorage :as l-storage]
[flybot.client.web.lib.class-utils :as cu]
[clojure.edn :as edn]
[re-frame.core :as rf]
[day8.re-frame.http-fx]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cljs.flybot.lib.class-utils
(ns flybot.client.web.lib.class-utils
(:require [clojure.string :as string]))

(defn classes-of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cljs.flybot.lib.hiccup
(ns flybot.client.web.lib.hiccup
(:require [clojure.walk :refer [postwalk]]
[markdown-to-hiccup.core :as mth]
[re-frame.core :as rf]))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cljs.flybot.lib.localstorage)
(ns flybot.client.web.lib.localstorage)

(defn set-item
"Set `key' in browser's localStorage to `val`."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns cljs.flybot.lib.router
(:require [cljs.flybot.components.page :refer [page]]
(ns flybot.client.web.lib.router
(:require [flybot.client.web.components.page :refer [page]]
[goog.object :as gobj]
[reitit.frontend :as rei]
[reitit.frontend.easy :as rfe]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
(ns cljs.flybot.db-test
(ns flybot.client.web.db-test
"Hot reloading regression tests for the re-frame logic.
The tests are executed everytime a cljs file is saved.
The results are displayed in http://localhost:9500/figwheel-extra-main/auto-testing"
(:require [cljc.flybot.test-sample-data :as s]
[cljs.flybot.db]
[cljs.flybot.lib.router :as router]
(:require [flybot.common.test-sample-data :as s]
[flybot.client.web.db]
[flybot.client.web.lib.router :as router]
[cljs.test :refer-macros [deftest is testing use-fixtures]]
[day8.re-frame.test :as rf-test]
[re-frame.core :as rf]
[re-frame.db :as rf.db]
[cljc.flybot.utils :as utils]))
[flybot.common.utils :as utils]))

;; ---------- Fixtures ----------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns cljs.flybot.test-runner
(ns flybot.client.web.test-runner
(:require
[figwheel.main.testing :refer-macros [run-tests-async]]
;; require all the namespaces that have tests in them
[cljs.flybot.db-test]))
[flybot.client.web.db-test]))

(defn -main [& args]
;; this needs to be the last statement in the main function so that it can
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cljc.flybot.utils
(ns flybot.common.utils
(:require #?(:clj [datalevin.core :as d])))

(defn mk-uuid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cljc.flybot.validation
(ns flybot.common.validation
"The schemas can be used for both validation and pull pattern.
The main difference between validation schema and pull pattern schema is
that pull pattern schems has all keys optional as we do not want to
Expand All @@ -7,7 +7,7 @@
we often need the client to provide some mandatory fields."
(:require [malli.core :as m]
[malli.util :as mu]
[cljc.flybot.utils :as u]))
[flybot.common.utils :as u]))

;;---------- Validation Schemas ----------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns cljc.flybot.test-sample-data
(ns flybot.common.test-sample-data
"Sample data that can be used in both backend and frontend tests."
(:require [cljc.flybot.utils :as u]))
(:require [flybot.common.utils :as u]))

;;---------- Pages ----------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns cljc.flybot.validation-test
(ns flybot.common.validation-test
(:require [clojure.test :refer [deftest testing is]]
[cljc.flybot.test-sample-data :as s]
[cljc.flybot.validation :as sut]
[flybot.common.test-sample-data :as s]
[flybot.common.validation :as sut]
[malli.util :as mu]
[cljc.flybot.utils :as utils]))
[flybot.common.utils :as utils]))

(deftest all-keys-optional
(testing "All the schema keys are made optional."
Expand Down
78 changes: 40 additions & 38 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,69 @@
datalevin/datalevin {:mvn/version "0.7.6"}
skydread1/reitit-oauth2 {:git/url "https://github.com/skydread1/reitit-oauth2.git"
:sha "c06a3be2f00d5358a50c108816fe0cbfa9f67be1"}}
:paths ["src" "resources"]
:paths ["server/src" "common/src" "resources"]
:aliases
{;;---------- BACKEND (clj) aliases ----------
;; JVM options to make datalevin work with java version > java8
:jvm-base {:jvm-opts ["--add-opens=java.base/java.nio=ALL-UNNAMED"
"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"]}

;; CLJ backend figwheel-system handler
:fig {:extra-deps {;; frontend
com.bhauman/figwheel-main {:mvn/version "0.2.18"}
org.clojure/clojurescript {:mvn/version "1.11.60"}
reagent/reagent {:mvn/version "1.1.1"}
cljsjs/react {:mvn/version "18.2.0-0"}
cljsjs/react-dom {:mvn/version "18.2.0-0"}
markdown-to-hiccup/markdown-to-hiccup {:mvn/version "0.6.2"}
cljs-ajax/cljs-ajax {:mvn/version "0.8.4"}
re-frame/re-frame {:mvn/version "1.3.0"}
day8.re-frame/http-fx {:mvn/version "0.2.4"}
day8.re-frame/test {:mvn/version "0.1.5"}}
:extra-paths ["test" "dev/src" "config" "target"]}

;; CLJ backend figwheel-system handler
:client {:extra-deps {;; frontend
com.bhauman/figwheel-main {:mvn/version "0.2.18"}
org.clojure/clojurescript {:mvn/version "1.11.60"}
reagent/reagent {:mvn/version "1.1.1"}
cljsjs/react {:mvn/version "18.2.0-0"}
cljsjs/react-dom {:mvn/version "18.2.0-0"}
markdown-to-hiccup/markdown-to-hiccup {:mvn/version "0.6.2"}
cljs-ajax/cljs-ajax {:mvn/version "0.8.4"}
re-frame/re-frame {:mvn/version "1.3.0"}
day8.re-frame/http-fx {:mvn/version "0.2.4"}
day8.re-frame/test {:mvn/version "0.1.5"}}
:extra-paths ["client/web/src" "client/web/test"
"common/test"
"config" "target"]}

;; React Native
:rn {:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.773"}
io.vouch/reagent-react-native {:git/url "https://github.com/vouch-opensource/reagent-react-native.git"
:sha "0fe1c600c9b81180f76b94ef6004c2f85e7d4aa0"}}
:extra-paths ["mobile/src"]}
:mobile/rn {:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.773"}
io.vouch/reagent-react-native {:git/url "https://github.com/vouch-opensource/reagent-react-native.git"
:sha "0fe1c600c9b81180f76b94ef6004c2f85e7d4aa0"}}
:extra-paths ["client/mobile/src"]}

;; CLJ paths for the backend systems and tests
:clj/dev {:extra-paths ["test" "dev/src" "config" "target"]}
:server/dev {:extra-paths ["config" "target" "common/test" "server/test"]}

;; Run clj tests
:clj/test {:extra-paths ["test" "dev/src" "config"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}}
:main-opts ["-m" "kaocha.runner"]}
;; Run clj tests - use with :server/dev
:server/test {:extra-paths ["common/test" "server/test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}}
:main-opts ["-m" "kaocha.runner"]}

;;---------- FRONTEND WEB (cljs) aliases ----------
;; cljs repl for figwheel hot reloading development/testing
;; be sure to not have a js bundle in resources/public and used :fig alias for clj repl
:cljs/dev {:main-opts ["--main" "figwheel.main"
"--build" "dev"
"--repl"]}
:web/dev {:main-opts ["--main" "figwheel.main"
"--build" "dev"
"--repl"]}

;; build the optimised js bundle
:cljs/prod {:main-opts ["--main" "figwheel.main"
"--build-once" "prod"]}
:web/prod {:main-opts ["--main" "figwheel.main"
"--build-once" "prod"]}

;; Run the cljs tests
:cljs/test {:main-opts ["-m" "figwheel.main"
"-m" "cljs.flybot.test-runner"]}
:web/test {:main-opts ["-m" "figwheel.main"
"-m" "flybot.client.web.test-runner"]}

;; Run the cljs tests with chrome headless
:cljs/test-headless {:main-opts ["-m" "figwheel.main"
"-co" "tests.cljs.edn"
"-m" "cljs.flybot.test-runner"]}
:web/test-headless {:main-opts ["-m" "figwheel.main"
"-co" "tests.cljs.edn"
"-m" "flybot.client.web.test-runner"]}

;;---------- FRONTEND MOBILE (cljs) aliases ----------
;; cljs repl for figwheel hot reloading development/testing
;; Run `npm run ios` in another terminal to start the simulator
:cljs/ios {:main-opts ["--main" "figwheel.main"
"--build" "ios"
"--repl"]}
:mobile/ios {:main-opts ["--main" "figwheel.main"
"--build" "ios"
"--repl"]}

;;---------- CD aliases ----------
;; build frontend js bundle : clj -T:build js-bundle
Expand Down
4 changes: 2 additions & 2 deletions dev.cljs.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
^{:watch-dirs ["src" "test"]
^{:watch-dirs ["client/web/src" "client/web/test"]
:css-dirs ["resources/public/css"]}
{:main cljs.flybot.core
{:main flybot.client.web.core
:optimizations :none}
2 changes: 1 addition & 1 deletion figwheel-main.edn
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{:ring-handler clj.flybot.systems/figwheel-handler
{:ring-handler flybot.server.systems/figwheel-handler
:auto-testing true}
2 changes: 1 addition & 1 deletion ios.cljs.edn
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
^{:react-native :cli}
{:main flybot.mobile.main}
{:main flybot.client.mobile.main}
2 changes: 1 addition & 1 deletion jib-dev.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;; Image config to test de containerised app locally.
;; defalut base image for this is gcr.io/distroless/java.
{:main clj.flybot.core
{:main flybot.server.core
:aliases [:jvm-base]
:user "root"
:group "root"
Expand Down
2 changes: 1 addition & 1 deletion jib.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;; Image config to create the image and push it to ECR
{:main clj.flybot.core
{:main flybot.server.core
:aliases [:jvm-base]
:user "root"
:group "root"
Expand Down
2 changes: 1 addition & 1 deletion prod.cljs.edn
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{:main cljs.flybot.core
{:main flybot.client.web.core
:optimizations :advanced}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns clj.flybot.auth
(ns flybot.server.auth
(:require [aleph.http :as http]
[cheshire.core :as cheshire]
[clj-commons.byte-streams :as bs]
Expand Down
8 changes: 4 additions & 4 deletions src/clj/flybot/core.clj → server/src/flybot/server/core.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns clj.flybot.core
(ns flybot.server.core
(:require [aleph.http :as http]
[clj.flybot.handler :as handler]
[clj.flybot.db :as db]
[clj.flybot.init-data :as sample]
[flybot.server.handler :as handler]
[flybot.server.db :as db]
[flybot.server.init-data :as sample]
[clojure.edn :as edn]
[datalevin.core :as d]
[ring.middleware.session.memory :refer [memory-store]]
Expand Down
Loading

0 comments on commit 9488ed0

Please sign in to comment.