polylith

Teemu Kaukoranta 2025-01-14T11:30:29.766449Z

Is it possible to run tests in all components, but not in bases or projects?

Teemu Kaukoranta 2025-01-14T11:31:00.886459Z

Hmm I guess this doesn't make sense, because tests are always ran in the context of a project 🤔

Teemu Kaukoranta 2025-01-14T11:31:37.473339Z

Basically I was wondering how to run unit tests from components, no matter if they are used in a project or not

Teemu Kaukoranta 2025-01-14T11:31:45.496439Z

but I don't think that's how poly testing works

imre 2025-01-14T12:02:04.522369Z

i theory your dev project would have most if not all components referenced

imre 2025-01-14T12:02:43.160019Z

poly test :dev perhaps?

Teemu Kaukoranta 2025-01-14T12:06:32.895459Z

that would include bases too

imre 2025-01-14T12:10:21.079059Z

Hmm. You could set up an alias, say, :+bases that contains all your bases and your dev project only your components?

imre 2025-01-14T12:10:38.327589Z

and use :+bases in your repl

tengstrand 2025-01-14T13:07:37.861939Z

Another option is to create a separate project where you include all your bricks, but https://cljdoc.org/d/polylith/clj-poly/0.2.21/doc/testing#include-exclude the bases from being tested.

Teemu Kaukoranta 2025-01-14T13:08:39.096889Z

That's what we ended up doing 🙂

👍 1
imre 2025-01-14T13:10:32.568669Z

not a bad one

Michael Mossinsohn 2025-01-14T17:17:49.787089Z

Hi, I have a question about naming in Polylith. I would like to have a workspace called, say, example. I would like to develop a core namespace with components inside and develop other services in parallel. A good outcome for my namespaces would be something like this: org.example.core.user org.example.core.cats org.example.mice-overlords.core.cheese org.example.mice-overlords.cheese-portal.auth Etc. I would like to develop the core library and have the flexibility to develop another service (org.example.mice-overlords) without appending it to the org.example.core namespace. Does this make sense? If not, what would be a good alternative? Assuming it is, can I do something along those lines using Polylith (with the tool)? Thank you for this great tool and for the useful abstractions. Michael

seancorfield 2025-01-14T19:59:39.578869Z

Polylith requires a "top ns" then bases and components. And components must have an "interface" ns. But otherwise, most of what you're suggesting sounds like a typical Polylith workspace. So I guess I'm not really understanding what you're asking...?

seancorfield 2025-01-14T20:01:05.490289Z

core would be a component. mice-overlords would be a base (or perhaps another component).

seancorfield 2025-01-14T20:01:25.693709Z

org.example would be your top ns.

Michael Mossinsohn 2025-01-14T20:16:25.121569Z

Just making sure I follow - Components cannot have (sub)components, right? So if mice-overlords is a base, does anything inside this ns belong to the interface of that base?

seancorfield 2025-01-14T20:17:15.661269Z

A base does not have an interface

Michael Mossinsohn 2025-01-14T20:18:09.520989Z

Obviously. Sorry.

seancorfield 2025-01-14T20:19:28.412819Z

I guess I'm still not really sure what you're asking... Polylith has specific conventions you must follow...

Michael Mossinsohn 2025-01-14T20:48:57.219219Z

I would like to develop both a stand-alone app and a server. I would like to have a structure similar to: org.example.core.user org.example.core.db org.example.core.cli (base) org.example.server.networking org.example.server.api (base) or perhaps org.example.app.core.user org.example.app.core.db org.example.app.cli (base) org.example.server.networking org.example.server.api (base) If I make the top ns org.example I don't know how to create a component with the ns org.example.core.user. if I create a component called user, it will have the ns org.example.user. If the top ns will be org.example.core, I will be able to create the user component, but I will not be able to create a server component (unless I place it inside the core ns). I think I missed something, but I can't figure out how to structure my project to allow for a component not to sit directly after the top ns, and I can't figure out how to create the ns hierarchy without this ability.

seancorfield 2025-01-14T21:16:55.664999Z

All components must have <top-ns>.<component-name>.interface as their primary entry point. The implementation can be in any nses (that start with <top-ns>.<component-name>). That's the rule.

seancorfield 2025-01-14T21:18:04.111009Z

All bases must have nses that start with <top-ns>.<brick-name>

seancorfield 2025-01-14T21:20:30.294959Z

Namespaces have no "hierarchy". The ns foo.bar.baz has no relation to foo.bar (the directory structure overlapping is coincidental).

seancorfield 2025-01-14T21:22:47.598349Z

At work, we have about 200 bricks (bases and components) and about 24 projects. So we build two dozen standalone apps from over 175 components.

Michael Mossinsohn 2025-01-14T22:32:45.383699Z

That was very informative, thank you. I think this is exactly the part I was missing - (that) "Namespaces have no "hierarchy". The ns foo.bar.baz has no relation to foo.bar (the directory structure overlapping is coincidental). " Thank you very much.

Michael Mossinsohn 2025-01-14T20:09:08.892659Z

Thank you. My question is - Can I make components that are not directly under the top-level namespace? If I can't, how would I develop a structure with, say: org.example.client-app.core.user org.example.client-app.cli (base) org.example.server.core.networking org.example.server.service org.example.server.api (base) If the top-level ns is org.example and I make a component called user, I think the ns of the component will end up as org.example.user. If the top-level ns is org.example.client-app.core and I make a component called server, it will also not work very well, I think. What am I getting wrong?

seancorfield 2025-01-15T10:28:00.499059Z

This was all answered in the other thread which is why I posted my comment here. Not using threads just duplicates work for people!

👍 1
seancorfield 2025-01-14T20:18:16.387759Z

It's better to use threads so there's a single clear place for folks to reply.

tengstrand 2025-01-15T05:46:23.557949Z

> Can I make components that are not directly under the top-level namespace? No > org.example.server.core.networking > org.example.server.service You normally don't put code directly in each service (project) even if it's allowed. Instead, each project is just a set of bricks (often one base and a bunch of components). > org.example.client-app.core.user If org.example is the top namespace, then you can create a user component that will live in the org.example.user namespace. To be correct, org.example.user is the name of the interface but we often use the same name of the interface and the component (you will notice that when you run the info command). > org.example.server.api (base) If the top namespace is org.example then this base will live in org.example.api or if you name it to e.g. server-api it will live in org.example.server-api. All bricks will live at the same namespace level, directly under org.example. Your deployable projects (`development` not included) are just a set of bricks, often with a single base and a set of components. The base will delegate to interfaces (e.g. org.example.user) via their interface namespace that you import (e.g. org.example.user.interface). This is the Polylith's way of organising code.