Repository: CSCfi/rems
Pull request #3093 (2022-11-30 09:55:43)

Rename rems.api.services.* namespaces to rems.service.*
relates #3017 

- renames all `rems.api.services.*` namespaces to `rems.service.*`, including test files under `test/`
- updated all references from other namespaces to these namespaces
- updated ADR's that reference `rems.api.services.*` namespace

# Checklist for author

Remove items that aren't applicable, check items that are done.

## Reviewability
- [x] Link to issue

## Documentation
- [x] Update docs/ (if applicable)



Patch:
diff --git a/docs/architecture/010-transactions.md b/docs/architecture/010-transactions.md
index 4a8faa824..5fbea88e3 100644
--- a/docs/architecture/010-transactions.md
+++ b/docs/architecture/010-transactions.md
@@ -28,7 +28,7 @@ read-only to guarantee that our GETs are pure.
 ## Strict ordering of commands via locking
 
 Our application commands are processed roughly in the following way
-(implementation: `rems.api.services.command/command!`):
+(implementation: `rems.service.command/command!`):
 
 1. get all events for application from the `application_event` table
    - NB! we have caching for `get-all-applications` but not for `get-unrestricted-application`, which is used here
diff --git a/docs/architecture/012-layers.md b/docs/architecture/012-layers.md
index aea4c1607..65c5271ba 100644
--- a/docs/architecture/012-layers.md
+++ b/docs/architecture/012-layers.md
@@ -70,7 +70,7 @@ so it must handle any dependencies etc:
 A service will typically call multiple different DB layer namespaces
 to implement the functionality.
 
-The Service layer lives in the `rems.api.services.*` namespaces.
+The Service layer lives in the `rems.service.*` namespaces.
 
 Historical note: the service layer was created in PR #1487 (and
 expanded subsequent PRs like #1490 #1491 #1495 #1854) to avoid
@@ -100,11 +100,11 @@ on `rems.db.core` to perform the queries they need.
 What to do about circular dependencies between services?
 
 For example after #2261, `rems.api.blacklist` calls
-`rems.api.services.command` and `rems.api.services.blacklist`. This is
+`rems.service.command` and `rems.service.blacklist`. This is
 because `services.command` already calls `services.blacklist`, so we
 can't have `services.blacklist` call `services.command`.
 
-NB: For the data dependencies we have `rems.api.services.dependencies`.
+NB: For the data dependencies we have `rems.service.dependencies`.
 
 ### Namespaces that don't obey these rules
 
diff --git a/src/clj/rems/api/applications.clj b/src/clj/rems/api/applications.clj
index f0b651966..ab350e72a 100644
--- a/src/clj/rems/api/applications.clj
+++ b/src/clj/rems/api/applications.clj
@@ -4,10 +4,10 @@
             [compojure.api.sweet :refer :all]
             [medley.core :refer [update-existing]]
             [rems.api.schema :as schema]
-            [rems.api.services.attachment :as attachment]
-            [rems.api.services.command :as command]
-            [rems.api.services.licenses :as licenses]
-            [rems.api.services.todos :as todos]
+            [rems.service.attachment :as attachment]
+            [rems.service.command :as command]
+            [rems.service.licenses :as licenses]
+            [rems.service.todos :as todos]
             [rems.api.util :as api-util] ; required for route :roles
             [rems.application.commands :as commands]
             [rems.application.search :as search]
diff --git a/src/clj/rems/api/blacklist.clj b/src/clj/rems/api/blacklist.clj
index 55e7b2149..516fc3f6d 100644
--- a/src/clj/rems/api/blacklist.clj
+++ b/src/clj/rems/api/blacklist.clj
@@ -2,8 +2,8 @@
   (:require [clojure.tools.logging :as log]
             [compojure.api.sweet :refer :all]
             [rems.api.schema :as schema]
-            [rems.api.services.command :as command]
-            [rems.api.services.blacklist :as blacklist]
+            [rems.service.command :as command]
+            [rems.service.blacklist :as blacklist]
             [rems.api.util :refer [unprocessable-entity-json-response]] ; required for route :roles
             [rems.application.rejecter-bot :as rejecter-bot]
             [rems.common.roles :refer [+admin-read-roles+]]
diff --git a/src/clj/rems/api/catalogue.clj b/src/clj/rems/api/catalogue.clj
index 58d247a1e..2af39dbb3 100644
--- a/src/clj/rems/api/catalogue.clj
+++ b/src/clj/rems/api/catalogue.clj
@@ -1,7 +1,7 @@
 (ns rems.api.catalogue
   (:require [compojure.api.sweet :refer :all]
             [rems.api.schema :as schema]
-            [rems.api.services.catalogue :as catalogue]
+            [rems.service.catalogue :as catalogue]
             [rems.api.util] ; required for route :roles
             [rems.auth.util :refer [throw-forbidden throw-unauthorized]]
             [rems.config :refer [env]]
diff --git a/src/clj/rems/api/catalogue_items.clj b/src/clj/rems/api/catalogue_items.clj
index 684a0101a..36c34bd19 100644
--- a/src/clj/rems/api/catalogue_items.clj
+++ b/src/clj/rems/api/catalogue_items.clj
@@ -2,7 +2,7 @@
   (:require [clojure.string :as str]
             [compojure.api.sweet :refer :all]
             [rems.api.schema :as schema]
-            [rems.api.services.catalogue :as catalogue]
+            [rems.service.catalogue :as catalogue]
             [rems.api.util :refer [not-found-json-response check-user]] ; required for route :roles
             [rems.common.roles :refer [+admin-write-roles+]]
             [rems.db.core :as db]
diff --git a/src/clj/rems/api/categories.clj b/src/clj/rems/api/categories.clj
index 8cdcf3ca4..b01dfc73f 100644
--- a/src/clj/rems/api/categories.clj
+++ b/src/clj/rems/api/categories.clj
@@ -2,7 +2,7 @@
   (:require [compojure.api.sweet :refer :all]
             [rems.api.schema :as schema]
             [rems.schema-base :as schema-base]
-            [rems.api.services.category :as category]
+            [rems.service.category :as category]
             [rems.api.util :refer [not-found-json-response]]
             [rems.common.roles :refer [+admin-read-roles+ +admin-write-roles+]]
             [ring.util.http-response :refer :all]
diff --git a/src/clj/rems/api/forms.clj b/src/clj/rems/api/forms.clj
index 964b5f709..0e5577ffb 100644
--- a/src/clj/rems/api/forms.clj
+++ b/src/clj/rems/api/forms.clj
@@ -1,6 +1,6 @@
 (ns rems.api.forms
   (:require [compojure.api.sweet :refer :all]
-            [rems.api.services.form :as form]
+            [rems.service.form :as form]
             [rems.api.schema :as schema]
             [rems.api.util :refer [not-found-json-response]] ; required for route :roles
             [rems.common.roles :refer [+admin-read-roles+ +admin-write-roles+]]
diff --git a/src/clj/rems/api/invitations.clj b/src/clj/rems/api/invitations.clj
index 1eb6b9bac..72f1fc056 100644
--- a/src/clj/rems/api/invitations.clj
+++ b/src/clj/rems/api/invitations.clj
@@ -1,6 +1,6 @@
 (ns rems.api.invitations
   (:require [compojure.api.sweet :refer :all]
-            [rems.api.services.invitation :as invitation]
+            [rems.service.invitation :as invitation]
             [rems.api.util :refer [not-found-json-response]] ; required for route :roles
             [rems.common.roles :refer [+admin-read-roles+ +admin-write-roles+]]
             [rems.schema-base :as schema-base]
diff --git a/src/clj/rems/api/licenses.clj b/src/clj/rems/api/licenses.clj
index eaa86d8f9..0b82a3cc7 100644
--- a/src/clj/rems/api/licenses.clj
+++ b/src/clj/rems/api/licenses.clj
@@ -1,8 +1,8 @@
 (ns rems.api.licenses
   (:require [compojure.api.sweet :refer :all]
             [rems.api.schema :as schema]
-            [rems.api.services.attachment :as attachment]
-            [rems.api.services.licenses :as licenses]
+            [rems.service.attachment :as attachment]
+            [rems.service.licenses :as licenses]
             [rems.api.util :refer [not-found-json-response]] ; required for route :roles
             [rems.common.roles :refer [+admin-read-roles+ +admin-write-roles+]]
             [rems.schema-base :as schema-base]
diff --git a/src/clj/rems/api/organizations.clj b/src/clj/rems/api/organizations.clj
index 948396e05..b6af9ca23 100644
--- a/src/clj/rems/api/organizations.clj
+++ b/src/clj/rems/api/organizations.clj
@@ -2,7 +2,7 @@
   (:require [compojure.api.sweet :refer :all]
             [rems.api.schema :as schema]
             [rems.api.util :refer [not-found-json-response]] ; required for route :roles
-            [rems.api.services.organizations :as organizations]
+            [rems.service.organizations :as organizations]
             [rems.schema-base :as schema-base]
             [rems.util :refer [getx-user-id]]
             [ring.util.http-response :refer :all]
diff --git a/src/clj/rems/api/public.clj b/src/clj/rems/api/public.clj
index de95237f9..0b1154652 100644
--- a/src/clj/rems/api/public.clj
+++ b/src/clj/rems/api/public.clj
@@ -1,7 +1,7 @@
 (ns rems.api.public
   (:require [compojure.api.sweet :refer :all]
             [rems.api.util] ; required for route :roles
-            [rems.api.services.public :as public]
+            [rems.service.public :as public]
             [ring.util.http-response :refer :all]
             [schema.core :as s]))
 
diff --git a/src/clj/rems/api/resources.clj b/src/clj/rems/api/resources.clj
index 25aba9d24..78c2f0fba 100644
--- a/src/clj/rems/api/resources.clj
+++ b/src/clj/rems/api/resources.clj
@@ -1,7 +1,7 @@
 (ns rems.api.resources
   (:require [compojure.api.sweet :refer :all]
             [rems.api.schema :as schema]
-            [rems.api.services.resource :as resource]
+            [rems.service.resource :as resource]
             [rems.api.util :refer [not-found-json-response]] ; required for route :roles
             [rems.common.roles :refer [+admin-read-roles+ +admin-write-roles+]]
             [rems.ext.duo :as duo]
diff --git a/src/clj/rems/api/user_settings.clj b/src/clj/rems/api/user_settings.clj
index 7e18a430a..5ab719217 100644
--- a/src/clj/rems/api/user_settings.clj
+++ b/src/clj/rems/api/user_settings.clj
@@ -2,8 +2,8 @@
   (:require [compojure.api.sweet :refer :all]
             [rems.api.schema :as schema]
             [rems.config :refer [env]]
-            [rems.api.services.ega :as ega]
-            [rems.api.services.user-settings :as user-settings]
+            [rems.service.ega :as ega]
+            [rems.service.user-settings :as user-settings]
             [rems.util :refer [getx-user-id get-user-id]]
             [ring.util.http-response :refer :all]
             [schema.core :as s])
diff --git a/src/clj/rems/api/workflows.clj b/src/clj/rems/api/workflows.clj
index 06375792e..b2b19d4d8 100644
--- a/src/clj/rems/api/workflows.clj
+++ b/src/clj/rems/api/workflows.clj
@@ -1,7 +1,7 @@
 (ns rems.api.workflows
   (:require [compojure.api.sweet :refer :all]
             [rems.api.schema :as schema]
-            [rems.api.services.workflow :as workflow]
+            [rems.service.workflow :as workflow]
             [rems.api.util :refer [not-found-json-response]] ; required for route :roles
             [rems.application.events :as events]
             [rems.common.roles :refer [+admin-read-roles+ +admin-write-roles+]]
diff --git a/src/clj/rems/application/eraser.clj b/src/clj/rems/application/eraser.clj
index 717aa6862..35b1949af 100644
--- a/src/clj/rems/application/eraser.clj
+++ b/src/clj/rems/application/eraser.clj
@@ -2,7 +2,7 @@
   (:require [clojure.tools.logging :as log]
             [clj-time.core :as time]
             [mount.core :as mount]
-            [rems.api.services.command :as command]
+            [rems.service.command :as command]
             [rems.application.expirer-bot :as expirer-bot]
             [rems.config :refer [env]]
             [rems.db.applications :as applications]
diff --git a/src/clj/rems/application/process_managers.clj b/src/clj/rems/application/process_managers.clj
index c40dbb194..b043c18c4 100644
--- a/src/clj/rems/application/process_managers.clj
+++ b/src/clj/rems/application/process_managers.clj
@@ -3,8 +3,8 @@
 
   NB: An event manager should return an empty sequence (or `nil`) if it doesn't create new events itself."
   (:require [clojure.set :refer [difference]]
-            [rems.api.services.attachment :as attachment]
-            [rems.api.services.blacklist :as blacklist]
+            [rems.service.attachment :as attachment]
+            [rems.service.blacklist :as blacklist]
             [rems.common.application-util :as application-util]
             [rems.db.applications :as applications]
             [rems.db.attachments :as attachments]))
diff --git a/src/clj/rems/db/entitlements.clj b/src/clj/rems/db/entitlements.clj
index 55fe0b4ba..721c6205d 100644
--- a/src/clj/rems/db/entitlements.clj
+++ b/src/clj/rems/db/entitlements.clj
@@ -6,7 +6,7 @@
             [clojure.tools.logging :as log]
             [mount.core :as mount]
             [rems.common.application-util :as application-util]
-            [rems.api.services.ega :as ega]
+            [rems.service.ega :as ega]
             [rems.auth.util :refer [throw-forbidden]]
             [rems.config :refer [env]]
             [rems.db.applications :as applications]
diff --git a/src/clj/rems/db/fix_userid.clj b/src/clj/rems/db/fix_userid.clj
index 9269c4639..09b33aefb 100644
--- a/src/clj/rems/db/fix_userid.clj
+++ b/src/clj/rems/db/fix_userid.clj
@@ -1,6 +1,6 @@
 
 (ns rems.db.fix-userid
-  (:require rems.api.services.dependencies
+  (:require rems.service.dependencies
             [rems.db.api-key]
             [rems.db.applications]
             [rems.db.attachments]
diff --git a/src/clj/rems/email/core.clj b/src/clj/rems/email/core.clj
index b3e2ebac5..fe3e42aea 100644
--- a/src/clj/rems/email/core.clj
+++ b/src/clj/rems/email/core.clj
@@ -5,8 +5,8 @@
             [clojure.tools.logging :as log]
             [mount.core :as mount]
             [postal.core :as postal]
-            [rems.api.services.todos :as todos]
-            [rems.api.services.workflow :as workflow]
+            [rems.service.todos :as todos]
+            [rems.service.workflow :as workflow]
             [rems.application.model]
             [rems.config :refer [env]]
             [rems.db.applications :as applications]
diff --git a/src/clj/rems/handler.clj b/src/clj/rems/handler.clj
index 0ead03ad6..a44766cb4 100644
--- a/src/clj/rems/handler.clj
+++ b/src/clj/rems/handler.clj
@@ -5,9 +5,9 @@
             [compojure.route :as route]
             [mount.core :as mount]
             [rems.api :refer [api-routes]]
-            [rems.api.services.attachment :as attachment]
-            [rems.api.services.invitation :as invitation]
-            [rems.api.services.licenses :as licenses]
+            [rems.service.attachment :as attachment]
+            [rems.service.invitation :as invitation]
+            [rems.service.licenses :as licenses]
             [rems.api.util :as api-util]
             [rems.context :as context]
             [rems.auth.auth :as auth]
diff --git a/src/clj/rems/layout.clj b/src/clj/rems/layout.clj
index bf125bdcf..5569d58e4 100644
--- a/src/clj/rems/layout.clj
+++ b/src/clj/rems/layout.clj
@@ -1,7 +1,7 @@
 (ns rems.layout
   (:require [clojure.string :as str]
             [hiccup.page :refer [html5 include-css include-js]]
-            [rems.api.services.public :as public]
+            [rems.service.public :as public]
             [rems.common.git :as git]
             [rems.config :refer [env]]
             [rems.context :as context]
diff --git a/src/clj/rems/main.clj b/src/clj/rems/main.clj
index 083a9c57e..8264f9c72 100644
--- a/src/clj/rems/main.clj
+++ b/src/clj/rems/main.clj
@@ -9,7 +9,7 @@
             [luminus.repl-server :as repl]
             [medley.core :refer [find-first]]
             [mount.core :as mount]
-            [rems.api.services.ega :as ega]
+            [rems.service.ega :as ega]
             [rems.application.search :as search]
             [rems.common.git :as git]
             [rems.config :refer [env]]
diff --git a/src/clj/rems/api/services/attachment.clj b/src/clj/rems/service/attachment.clj
similarity index 99%
rename from src/clj/rems/api/services/attachment.clj
rename to src/clj/rems/service/attachment.clj
index da9517608..4601e227a 100644
--- a/src/clj/rems/api/services/attachment.clj
+++ b/src/clj/rems/service/attachment.clj
@@ -1,4 +1,4 @@
-(ns rems.api.services.attachment
+(ns rems.service.attachment
   (:require [clojure.set :as set]
             [clojure.tools.logging :as log]
             [medley.core :refer [assoc-some find-first]]
diff --git a/src/clj/rems/api/services/blacklist.clj b/src/clj/rems/service/blacklist.clj
similarity index 97%
rename from src/clj/rems/api/services/blacklist.clj
rename to src/clj/rems/service/blacklist.clj
index d125d37f1..d7ba0bcde 100644
--- a/src/clj/rems/api/services/blacklist.clj
+++ b/src/clj/rems/service/blacklist.clj
@@ -1,4 +1,4 @@
-(ns rems.api.services.blacklist
+(ns rems.service.blacklist
   (:require [clj-time.core :as time]
             [rems.db.applications :as applications]
             [rems.db.blacklist :as blacklist]
diff --git a/src/clj/rems/api/services/catalogue.clj b/src/clj/rems/service/catalogue.clj
similarity index 98%
rename from src/clj/rems/api/services/catalogue.clj
rename to src/clj/rems/service/catalogue.clj
index 32eff6a47..204c09246 100644
--- a/src/clj/rems/api/services/catalogue.clj
+++ b/src/clj/rems/service/catalogue.clj
@@ -1,7 +1,7 @@
-(ns rems.api.services.catalogue
+(ns rems.service.catalogue
   (:require [medley.core :refer [assoc-some]]
-            [rems.api.services.dependencies :as dependencies]
-            [rems.api.services.util :as util]
+            [rems.service.dependencies :as dependencies]
+            [rems.service.util :as util]
             [rems.db.applications :as applications]
             [rems.db.core :as db]
             [rems.db.catalogue :as catalogue]
diff --git a/src/clj/rems/api/services/category.clj b/src/clj/rems/service/category.clj
similarity index 95%
rename from src/clj/rems/api/services/category.clj
rename to src/clj/rems/service/category.clj
index ad1925238..5a380fbd8 100644
--- a/src/clj/rems/api/services/category.clj
+++ b/src/clj/rems/service/category.clj
@@ -1,7 +1,7 @@
-(ns rems.api.services.category
+(ns rems.service.category
   (:require [medley.core :refer [update-existing-in]]
             [rems.db.category :as category]
-            [rems.api.services.dependencies :as dependencies]))
+            [rems.service.dependencies :as dependencies]))
 
 (defn join-categories [m ks]
   (update-existing-in m ks category/enrich-categories))
@@ -57,4 +57,4 @@
       (do
         (category/delete-category! (:category/id command))
         (dependencies/reset-cache!)
-        {:success true})))
\ No newline at end of file
+        {:success true})))
diff --git a/src/clj/rems/api/services/command.clj b/src/clj/rems/service/command.clj
similarity index 99%
rename from src/clj/rems/api/services/command.clj
rename to src/clj/rems/service/command.clj
index 5150ffefb..155882cc0 100644
--- a/src/clj/rems/api/services/command.clj
+++ b/src/clj/rems/service/command.clj
@@ -1,4 +1,4 @@
-(ns rems.api.services.command
+(ns rems.service.command
   (:require [clojure.java.jdbc :as jdbc]
             [clojure.tools.logging :as log]
             [rems.application.approver-bot :as approver-bot]
diff --git a/src/clj/rems/api/services/dependencies.clj b/src/clj/rems/service/dependencies.clj
similarity index 99%
rename from src/clj/rems/api/services/dependencies.clj
rename to src/clj/rems/service/dependencies.clj
index 1c0313546..8704e2225 100644
--- a/src/clj/rems/api/services/dependencies.clj
+++ b/src/clj/rems/service/dependencies.clj
@@ -1,4 +1,4 @@
-(ns rems.api.services.dependencies
+(ns rems.service.dependencies
   "Tracking dependencies between catalogue items, resources, forms, workflows and licenses."
   (:require [rems.common.util :refer [build-index]]
             [rems.db.catalogue :as catalogue]
diff --git a/src/clj/rems/api/services/ega.clj b/src/clj/rems/service/ega.clj
similarity index 99%
rename from src/clj/rems/api/services/ega.clj
rename to src/clj/rems/service/ega.clj
index 49caa1966..49de32418 100644
--- a/src/clj/rems/api/services/ega.clj
+++ b/src/clj/rems/service/ega.clj
@@ -1,4 +1,4 @@
-(ns rems.api.services.ega
+(ns rems.service.ega
   "Service for interfacing with EGA Permission API."
   (:require [clj-time.core :as time-core]
             [clojure.string :as str]
diff --git a/src/clj/rems/api/services/form.clj b/src/clj/rems/service/form.clj
similarity index 95%
rename from src/clj/rems/api/services/form.clj
rename to src/clj/rems/service/form.clj
index b51e86baf..77df2f262 100644
--- a/src/clj/rems/api/services/form.clj
+++ b/src/clj/rems/service/form.clj
@@ -1,8 +1,8 @@
-(ns rems.api.services.form
+(ns rems.service.form
   (:require [clojure.test :refer :all]
             [clojure.tools.logging :as log]
-            [rems.api.services.dependencies :as dependencies]
-            [rems.api.services.util :as util]
+            [rems.service.dependencies :as dependencies]
+            [rems.service.util :as util]
             [rems.common.form :as common-form]
             [rems.config :refer [env]]
             [rems.db.core :as db]
diff --git a/src/clj/rems/api/services/invitation.clj b/src/clj/rems/service/invitation.clj
similarity index 97%
rename from src/clj/rems/api/services/invitation.clj
rename to src/clj/rems/service/invitation.clj
index ced919aec..2764f1ede 100644
--- a/src/clj/rems/api/services/invitation.clj
+++ b/src/clj/rems/service/invitation.clj
@@ -1,5 +1,5 @@
-(ns rems.api.services.invitation
-  (:require [rems.api.services.util :as util]
+(ns rems.service.invitation
+  (:require [rems.service.util :as util]
             [rems.db.applications :as applications]
             [rems.db.invitation :as invitation]
             [rems.db.users :as users]
diff --git a/src/clj/rems/api/services/licenses.clj b/src/clj/rems/service/licenses.clj
similarity index 96%
rename from src/clj/rems/api/services/licenses.clj
rename to src/clj/rems/service/licenses.clj
index d581c3805..fe3cd9a9e 100644
--- a/src/clj/rems/api/services/licenses.clj
+++ b/src/clj/rems/service/licenses.clj
@@ -1,8 +1,8 @@
-(ns rems.api.services.licenses
+(ns rems.service.licenses
   "Serving licenses for API."
   (:require [clj-time.core :as time]
-            [rems.api.services.dependencies :as dependencies]
-            [rems.api.services.util :as util]
+            [rems.service.dependencies :as dependencies]
+            [rems.service.util :as util]
             [rems.db.applications :as applications]
             [rems.db.attachments :as attachments]
             [rems.db.core :as db]
diff --git a/src/clj/rems/api/services/organizations.clj b/src/clj/rems/service/organizations.clj
similarity index 93%
rename from src/clj/rems/api/services/organizations.clj
rename to src/clj/rems/service/organizations.clj
index 1407cf430..4574bad4e 100644
--- a/src/clj/rems/api/services/organizations.clj
+++ b/src/clj/rems/service/organizations.clj
@@ -1,8 +1,8 @@
-(ns rems.api.services.organizations
+(ns rems.service.organizations
   (:require [clojure.set :as set]
             [medley.core :refer [assoc-some find-first]]
-            [rems.api.services.dependencies :as dependencies]
-            [rems.api.services.util]
+            [rems.service.dependencies :as dependencies]
+            [rems.service.util]
             [rems.auth.util]
             [rems.db.applications :as applications]
             [rems.db.core :as db]
@@ -56,7 +56,7 @@
 
 (defn edit-organization! [cmd]
   (let [id (:organization/id cmd)]
-    (rems.api.services.util/check-allowed-organization! cmd)
+    (rems.service.util/check-allowed-organization! cmd)
     (organizations/update-organization! id (fn [organization] (->> (dissoc cmd :organization/id)
                                                                    (merge organization))))
     {:success true
diff --git a/src/clj/rems/api/services/public.clj b/src/clj/rems/service/public.clj
similarity index 98%
rename from src/clj/rems/api/services/public.clj
rename to src/clj/rems/service/public.clj
index ab7525751..7c051bc1b 100644
--- a/src/clj/rems/api/services/public.clj
+++ b/src/clj/rems/service/public.clj
@@ -1,4 +1,4 @@
-(ns rems.api.services.public
+(ns rems.service.public
   (:require [rems.config :refer [env]]
             [rems.locales :as locales]
             [rems.common.roles :as roles]))
diff --git a/src/clj/rems/api/services/resource.clj b/src/clj/rems/service/resource.clj
similarity index 92%
rename from src/clj/rems/api/services/resource.clj
rename to src/clj/rems/service/resource.clj
index 2a4c13939..1e8bf5fff 100644
--- a/src/clj/rems/api/services/resource.clj
+++ b/src/clj/rems/service/resource.clj
@@ -1,7 +1,7 @@
-(ns rems.api.services.resource
+(ns rems.service.resource
   (:require [com.rpl.specter :refer [ALL transform]]
-            [rems.api.services.dependencies :as dependencies]
-            [rems.api.services.util :as util]
+            [rems.service.dependencies :as dependencies]
+            [rems.service.util :as util]
             [rems.db.core :as db]
             [rems.db.licenses :as licenses]
             [rems.db.organizations :as organizations]
diff --git a/src/clj/rems/api/services/todos.clj b/src/clj/rems/service/todos.clj
similarity index 99%
rename from src/clj/rems/api/services/todos.clj
rename to src/clj/rems/service/todos.clj
index d74db13cd..28268db43 100644
--- a/src/clj/rems/api/services/todos.clj
+++ b/src/clj/rems/service/todos.clj
@@ -1,4 +1,4 @@
-(ns rems.api.services.todos
+(ns rems.service.todos
   (:require [clojure.set :as set]
             [clojure.test :refer [deftest is]]
             [rems.application.commands :as commands]
diff --git a/src/clj/rems/api/services/user_settings.clj b/src/clj/rems/service/user_settings.clj
similarity index 88%
rename from src/clj/rems/api/services/user_settings.clj
rename to src/clj/rems/service/user_settings.clj
index 39b5bae4d..ef586ecd0 100644
--- a/src/clj/rems/api/services/user_settings.clj
+++ b/src/clj/rems/service/user_settings.clj
@@ -1,4 +1,4 @@
-(ns rems.api.services.user-settings
+(ns rems.service.user-settings
   (:require [rems.db.user-settings :as user-settings]))
 
 (def UserSettings user-settings/UserSettings)
diff --git a/src/clj/rems/api/services/util.clj b/src/clj/rems/service/util.clj
similarity index 99%
rename from src/clj/rems/api/services/util.clj
rename to src/clj/rems/service/util.clj
index a54e46473..fadbaaa2c 100644
--- a/src/clj/rems/api/services/util.clj
+++ b/src/clj/rems/service/util.clj
@@ -1,4 +1,4 @@
-(ns rems.api.services.util
+(ns rems.service.util
   (:require [clojure.test :refer [deftest is testing]]
             [rems.db.organizations]
             [rems.auth.util :refer [throw-forbidden]]
diff --git a/src/clj/rems/api/services/workflow.clj b/src/clj/rems/service/workflow.clj
similarity index 96%
rename from src/clj/rems/api/services/workflow.clj
rename to src/clj/rems/service/workflow.clj
index e57a017c8..92b3f9979 100644
--- a/src/clj/rems/api/services/workflow.clj
+++ b/src/clj/rems/service/workflow.clj
@@ -1,6 +1,6 @@
-(ns rems.api.services.workflow
-  (:require [rems.api.services.dependencies :as dependencies]
-            [rems.api.services.util :as util]
+(ns rems.service.workflow
+  (:require [rems.service.dependencies :as dependencies]
+            [rems.service.util :as util]
             [rems.db.applications :as applications]
             [rems.db.core :as db]
             [rems.db.form :as form]
diff --git a/src/clj/rems/validate.clj b/src/clj/rems/validate.clj
index 8d0f6df41..ee63710c4 100644
--- a/src/clj/rems/validate.clj
+++ b/src/clj/rems/validate.clj
@@ -7,10 +7,10 @@
             [rems.common.form :as common-form]
             [rems.config :refer [env]]
             [rems.api.schema]
-            [rems.api.services.catalogue :as catalogue]
-            [rems.api.services.form :as form]
-            [rems.api.services.licenses :as licenses]
-            [rems.api.services.resource :as resources]
+            [rems.service.catalogue :as catalogue]
+            [rems.service.form :as form]
+            [rems.service.licenses :as licenses]
+            [rems.service.resource :as resources]
             [rems.db.events :as events-db]
             [rems.db.organizations :as organizations]
             [rems.ext.duo]


Test patch:
diff --git a/src/clj/rems/db/test_data.clj b/src/clj/rems/db/test_data.clj
index 94d0e8dab..d38cb03e2 100644
--- a/src/clj/rems/db/test_data.clj
+++ b/src/clj/rems/db/test_data.clj
@@ -5,8 +5,8 @@
             [clojure.test :refer :all]
             [clojure.tools.logging :as log]
             [rems.api.schema :as schema]
-            [rems.api.services.form :as form]
-            [rems.api.services.organizations :as organizations]
+            [rems.service.form :as form]
+            [rems.service.organizations :as organizations]
             [rems.db.api-key :as api-key]
             [rems.db.core :as db]
             [rems.db.roles :as roles]
diff --git a/src/clj/rems/db/test_data_helpers.clj b/src/clj/rems/db/test_data_helpers.clj
index 3fe580115..17acb8ff5 100644
--- a/src/clj/rems/db/test_data_helpers.clj
+++ b/src/clj/rems/db/test_data_helpers.clj
@@ -4,14 +4,14 @@
             [clojure.test :refer [deftest is]]
             [com.rpl.specter :refer [ALL must transform]]
             [clojure.string]
-            [rems.api.services.catalogue :as catalogue]
-            [rems.api.services.category :as category]
-            [rems.api.services.command :as command]
-            [rems.api.services.form :as form]
-            [rems.api.services.licenses :as licenses]
-            [rems.api.services.organizations :as organizations]
-            [rems.api.services.resource :as resource]
-            [rems.api.services.workflow :as workflow]
+            [rems.service.catalogue :as catalogue]
+            [rems.service.category :as category]
+            [rems.service.command :as command]
+            [rems.service.form :as form]
+            [rems.service.licenses :as licenses]
+            [rems.service.organizations :as organizations]
+            [rems.service.resource :as resource]
+            [rems.service.workflow :as workflow]
             [rems.config]
             [rems.db.applications :as applications]
             [rems.db.core :as db]
diff --git a/test/clj/rems/api/test_applications.clj b/test/clj/rems/api/test_applications.clj
index 108195ee9..35c1c5e1c 100644
--- a/test/clj/rems/api/test_applications.clj
+++ b/test/clj/rems/api/test_applications.clj
@@ -3,8 +3,8 @@
             [clojure.java.io :as io]
             [clojure.string :as str]
             [clojure.test :refer :all]
-            [rems.api.services.attachment :as attachment]
-            [rems.api.services.catalogue :as catalogue]
+            [rems.service.attachment :as attachment]
+            [rems.service.catalogue :as catalogue]
             [rems.api.testing :refer :all]
             [rems.config]
             [rems.db.applications]
diff --git a/test/clj/rems/api/test_audit_log.clj b/test/clj/rems/api/test_audit_log.clj
index 8c4f2cfe9..7dcf81456 100644
--- a/test/clj/rems/api/test_audit_log.clj
+++ b/test/clj/rems/api/test_audit_log.clj
@@ -67,7 +67,7 @@
                                                 (json-body {:boing "3"})
                                                 handler))))
             (testing "> status 500"
-              (with-redefs [rems.api.services.command/command! (fn [_] (throw (Error. "BOOM")))]
+              (with-redefs [rems.service.command/command! (fn [_] (throw (Error. "BOOM")))]
                 (is (response-is-server-error? (-> (request :post "/api/applications/submit")
                                                    (authenticate "42" "alice")
                                                    (json-body {:application-id 3})
diff --git a/test/clj/rems/api/test_catalogue.clj b/test/clj/rems/api/test_catalogue.clj
index dcf8662a4..99a230fa1 100644
--- a/test/clj/rems/api/test_catalogue.clj
+++ b/test/clj/rems/api/test_catalogue.clj
@@ -1,6 +1,6 @@
 (ns ^:integration rems.api.test-catalogue
   (:require [clojure.test :refer :all]
-            [rems.api.services.catalogue :as catalogue]
+            [rems.service.catalogue :as catalogue]
             [rems.api.testing :refer :all]
             [rems.db.category :as category]
             [rems.db.test-data :as test-data]
diff --git a/test/clj/rems/api/test_forms.clj b/test/clj/rems/api/test_forms.clj
index 4722e3ccb..7d2faf64b 100644
--- a/test/clj/rems/api/test_forms.clj
+++ b/test/clj/rems/api/test_forms.clj
@@ -686,7 +686,7 @@
     (is (< (count filtered) (count unfiltered)))))
 
 (deftest test-form-missing-languages
-  (let [id (with-redefs [rems.api.services.form/validation-error (constantly nil)] ;; disable validation
+  (let [id (with-redefs [rems.service.form/validation-error (constantly nil)] ;; disable validation
              (test-helpers/create-form! {:form/internal-name "invalid form"
                                          :form/external-title {:en "Invalid Form EN" :fi ""}
                                          :form/fields [{:field/id "fld1"
diff --git a/test/clj/rems/api/test_invitations.clj b/test/clj/rems/api/test_invitations.clj
index 7a238b249..ec3257ddd 100644
--- a/test/clj/rems/api/test_invitations.clj
+++ b/test/clj/rems/api/test_invitations.clj
@@ -1,6 +1,6 @@
 (ns ^:integration rems.api.test-invitations
   (:require [clojure.test :refer :all]
-            [rems.api.services.invitation :as invitation]
+            [rems.service.invitation :as invitation]
             [rems.api.testing :refer :all]
             [rems.db.applications]
             [rems.db.test-data :as test-data]
diff --git a/test/clj/rems/api/test_workflows.clj b/test/clj/rems/api/test_workflows.clj
index bb45452ed..da0ff6858 100644
--- a/test/clj/rems/api/test_workflows.clj
+++ b/test/clj/rems/api/test_workflows.clj
@@ -1,7 +1,7 @@
 (ns ^:integration rems.api.test-workflows
   (:require [clojure.test :refer :all]
-            [rems.api.services.licenses :as licenses]
-            [rems.api.services.workflow :as workflows]
+            [rems.service.licenses :as licenses]
+            [rems.service.workflow :as workflows]
             [rems.api.testing :refer :all]
             [rems.common.util :refer [replace-key]]
             [rems.db.applications :as applications]
diff --git a/test/clj/rems/application/test_eraser.clj b/test/clj/rems/application/test_eraser.clj
index 842f54efb..f7e863403 100644
--- a/test/clj/rems/application/test_eraser.clj
+++ b/test/clj/rems/application/test_eraser.clj
@@ -5,7 +5,7 @@
             [rems.application.commands :as commands]
             [rems.application.eraser :as eraser]
             [rems.application.expirer-bot :as expirer-bot]
-            [rems.api.services.command :as command]
+            [rems.service.command :as command]
             [rems.config :refer [env]]
             [rems.locales]
             [rems.db.applications :as applications]
diff --git a/test/clj/rems/application/test_process_managers.clj b/test/clj/rems/application/test_process_managers.clj
index dc599fcf6..60ce2d446 100644
--- a/test/clj/rems/application/test_process_managers.clj
+++ b/test/clj/rems/application/test_process_managers.clj
@@ -1,7 +1,7 @@
 (ns ^:integration rems.application.test-process-managers
   (:require [clojure.java.io :as io]
             [clojure.test :refer :all]
-            [rems.api.services.command :as command]
+            [rems.service.command :as command]
             [rems.api.testing :refer :all]
             [rems.db.attachments :as attachments]
             [rems.db.applications :as applications]
diff --git a/test/clj/rems/application/test_rejecter_bot.clj b/test/clj/rems/application/test_rejecter_bot.clj
index 52889ed31..727083b27 100644
--- a/test/clj/rems/application/test_rejecter_bot.clj
+++ b/test/clj/rems/application/test_rejecter_bot.clj
@@ -1,7 +1,7 @@
 (ns ^:integration rems.application.test-rejecter-bot
   (:require [clojure.test :refer :all]
-            [rems.api.services.blacklist :as blacklist]
-            [rems.api.services.command :as command]
+            [rems.service.blacklist :as blacklist]
+            [rems.service.command :as command]
             [rems.application.rejecter-bot :as rejecter-bot]
             [rems.db.applications :as applications]
             [rems.db.test-data-helpers :as test-helpers]
@@ -10,7 +10,7 @@
 (use-fixtures :once test-db-fixture)
 (use-fixtures :each rollback-db-fixture)
 
-;; These tests are integration tests via rems.api.service.command
+;; These tests are integration tests via rems.service.command
 ;; since we'd need to mock get-application to unit-test
 ;; run-rejecter-bot.
 
diff --git a/test/clj/rems/db/testing.clj b/test/clj/rems/db/testing.clj
index 04f007450..e59379106 100644
--- a/test/clj/rems/db/testing.clj
+++ b/test/clj/rems/db/testing.clj
@@ -4,7 +4,7 @@
             [conman.core :as conman]
             [luminus-migrations.core :as migrations]
             [mount.core :as mount]
-            [rems.api.services.dependencies :as dependencies]
+            [rems.service.dependencies :as dependencies]
             [rems.application.search]
             [rems.config :refer [env]]
             [rems.db.applications :as applications]
diff --git a/test/clj/rems/api/services/test_catalogue.clj b/test/clj/rems/service/test_catalogue.clj
similarity index 97%
rename from test/clj/rems/api/services/test_catalogue.clj
rename to test/clj/rems/service/test_catalogue.clj
index b630424a2..10c0461fc 100644
--- a/test/clj/rems/api/services/test_catalogue.clj
+++ b/test/clj/rems/service/test_catalogue.clj
@@ -1,10 +1,10 @@
-(ns ^:integration rems.api.services.test-catalogue
+(ns ^:integration rems.service.test-catalogue
   (:require [clojure.test :refer :all]
-            [rems.api.services.catalogue :as catalogue]
-            [rems.api.services.form :as form]
-            [rems.api.services.licenses :as licenses]
-            [rems.api.services.resource :as resource]
-            [rems.api.services.workflow :as workflow]
+            [rems.service.catalogue :as catalogue]
+            [rems.service.form :as form]
+            [rems.service.licenses :as licenses]
+            [rems.service.resource :as resource]
+            [rems.service.workflow :as workflow]
             [rems.db.core :as db]
             [rems.db.category :as category]
             [rems.db.test-data-helpers :as test-helpers]
diff --git a/test/clj/rems/api/services/test_dependencies.clj b/test/clj/rems/service/test_dependencies.clj
similarity index 98%
rename from test/clj/rems/api/services/test_dependencies.clj
rename to test/clj/rems/service/test_dependencies.clj
index 69dc5ba77..860f32945 100644
--- a/test/clj/rems/api/services/test_dependencies.clj
+++ b/test/clj/rems/service/test_dependencies.clj
@@ -1,6 +1,6 @@
-(ns ^:integration rems.api.services.test-dependencies
+(ns ^:integration rems.service.test-dependencies
   (:require [clojure.test :refer :all]
-            [rems.api.services.dependencies :as dependencies]
+            [rems.service.dependencies :as dependencies]
             [rems.db.core :as db]
             [rems.db.test-data-helpers :as test-helpers]
             [rems.db.testing :refer [reset-caches-fixture test-db-fixture rollback-db-fixture]]))
diff --git a/test/clj/rems/api/services/test_invitation.clj b/test/clj/rems/service/test_invitation.clj
similarity index 98%
rename from test/clj/rems/api/services/test_invitation.clj
rename to test/clj/rems/service/test_invitation.clj
index 70fc646ca..cd21ae5ec 100644
--- a/test/clj/rems/api/services/test_invitation.clj
+++ b/test/clj/rems/service/test_invitation.clj
@@ -1,6 +1,6 @@
-(ns ^:integration rems.api.services.test-invitation
+(ns ^:integration rems.service.test-invitation
   (:require [clojure.test :refer :all]
-            [rems.api.services.invitation :as invitation]
+            [rems.service.invitation :as invitation]
             [rems.db.test-data-helpers :as test-helpers]
             [rems.db.testing :refer [reset-caches-fixture rollback-db-fixture test-db-fixture]]
             [rems.email.core :as email]
diff --git a/test/clj/rems/api/services/test_organizations.clj b/test/clj/rems/service/test_organizations.clj
similarity index 97%
rename from test/clj/rems/api/services/test_organizations.clj
rename to test/clj/rems/service/test_organizations.clj
index 644f54841..34283040f 100644
--- a/test/clj/rems/api/services/test_organizations.clj
+++ b/test/clj/rems/service/test_organizations.clj
@@ -1,6 +1,6 @@
-(ns ^:integration rems.api.services.test-organizations
+(ns ^:integration rems.service.test-organizations
   (:require [clojure.test :refer :all]
-            [rems.api.services.organizations :as organizations]
+            [rems.service.organizations :as organizations]
             [rems.db.organizations]
             [rems.db.test-data-helpers :as test-helpers]
             [rems.db.testing :refer [rollback-db-fixture test-db-fixture]]
diff --git a/test/clj/rems/api/services/test_resources.clj b/test/clj/rems/service/test_resources.clj
similarity index 95%
rename from test/clj/rems/api/services/test_resources.clj
rename to test/clj/rems/service/test_resources.clj
index bd26ab70a..7b61c4d48 100644
--- a/test/clj/rems/api/services/test_resources.clj
+++ b/test/clj/rems/service/test_resources.clj
@@ -1,7 +1,7 @@
-(ns ^:integration rems.api.services.test-resources
+(ns ^:integration rems.service.test-resources
   (:require [clojure.test :refer :all]
-            [rems.api.services.licenses :as licenses]
-            [rems.api.services.resource :as resources]
+            [rems.service.licenses :as licenses]
+            [rems.service.resource :as resources]
             [rems.db.test-data-helpers :as test-helpers]
             [rems.db.testing :refer [rollback-db-fixture test-db-fixture]]
             [rems.testing-util :refer [with-user]]))
diff --git a/test/clj/rems/api/services/test_workflow.clj b/test/clj/rems/service/test_workflow.clj
similarity index 98%
rename from test/clj/rems/api/services/test_workflow.clj
rename to test/clj/rems/service/test_workflow.clj
index 7fdd83a61..10482ad36 100644
--- a/test/clj/rems/api/services/test_workflow.clj
+++ b/test/clj/rems/service/test_workflow.clj
@@ -1,6 +1,6 @@
-(ns ^:integration rems.api.services.test-workflow
+(ns ^:integration rems.service.test-workflow
   (:require [clojure.test :refer :all]
-            [rems.api.services.workflow :as workflow]
+            [rems.service.workflow :as workflow]
             [rems.db.test-data-helpers :as test-helpers]
             [rems.db.testing :refer [reset-caches-fixture rollback-db-fixture test-db-fixture]]
             [rems.testing-util :refer [with-user]]))
diff --git a/test/clj/rems/test_browser.clj b/test/clj/rems/test_browser.clj
index 7e46b3743..ba8b3e8b0 100644
--- a/test/clj/rems/test_browser.clj
+++ b/test/clj/rems/test_browser.clj
@@ -14,12 +14,12 @@
             [clojure.test :refer :all]
             [com.rpl.specter :refer [select ALL]]
             [medley.core :refer [find-first]]
-            [rems.api.services.catalogue :as catalogue]
-            [rems.api.services.form :as forms]
-            [rems.api.services.invitation :as invitations]
-            [rems.api.services.organizations :as organizations]
-            [rems.api.services.resource :as resources]
-            [rems.api.services.workflow :as workflows]
+            [rems.service.catalogue :as catalogue]
+            [rems.service.form :as forms]
+            [rems.service.invitation :as invitations]
+            [rems.service.organizations :as organizations]
+            [rems.service.resource :as resources]
+            [rems.service.workflow :as workflows]
             [rems.browser-test-util :as btu]
             [rems.common.util :refer [getx]]
             [rems.context :as context]
diff --git a/test/clj/rems/test_event_notification.clj b/test/clj/rems/test_event_notification.clj
index 48a3e4697..de8b8aeb8 100644
--- a/test/clj/rems/test_event_notification.clj
+++ b/test/clj/rems/test_event_notification.clj
@@ -3,7 +3,7 @@
             [clojure.test :refer :all]
             [medley.core :refer [dissoc-in]]
             [rems.config]
-            [rems.api.services.command :as command]
+            [rems.service.command :as command]
             [rems.api.testing :refer [api-fixture api-call]]
             [rems.db.events]
             [rems.db.test-data :as test-data]
diff --git a/test/clj/rems/test_layers.clj b/test/clj/rems/test_layers.clj
index 410f30539..245b4db37 100644
--- a/test/clj/rems/test_layers.clj
+++ b/test/clj/rems/test_layers.clj
@@ -29,7 +29,6 @@
 (defn rename-ns [s]
   ;; TODO implement these namespace renames
   (-> s
-      (str/replace "rems.api.services" "rems.service")
       (str/replace "rems.db.test-data" "rems.service.test-data")))
 
 (defn ok-transition? [from to]
diff --git a/test/clj/rems/test_performance.clj b/test/clj/rems/test_performance.clj
index a3d050aa7..16441b5e6 100644
--- a/test/clj/rems/test_performance.clj
+++ b/test/clj/rems/test_performance.clj
@@ -3,7 +3,7 @@
             [criterium.core :as criterium]
             [medley.core :refer [map-vals]]
             [mount.core :as mount]
-            [rems.api.services.todos :as todos]
+            [rems.service.todos :as todos]
             [rems.db.applications :as applications]
             [rems.db.events :as events])
   (:import [java.util Locale]))
diff --git a/test/clj/rems/test_redirects.clj b/test/clj/rems/test_redirects.clj
index 44ea122c0..8959908e9 100644
--- a/test/clj/rems/test_redirects.clj
+++ b/test/clj/rems/test_redirects.clj
@@ -1,7 +1,7 @@
 (ns ^:integration rems.test-redirects
   (:require [clojure.test :refer :all]
-            [rems.api.services.attachment :as attachment]
-            [rems.api.services.licenses :as licenses]
+            [rems.service.attachment :as attachment]
+            [rems.service.licenses :as licenses]
             [rems.api.testing :refer :all]
             [rems.db.api-key :as api-key]
             [rems.db.core :as db]