How to deal with configuration files? #257
-
I've recently migrated my repo from a src layout to a Polilyth one, and I am quite satisfied with this decision. However, in the Polylith Architecture documentation, I did not find much about configuration files (or resource files, more generally) and the way to deal with them. Previously, I had a directory named
Right now, I've reproduced this logic with a component named What would be a better way ? Add the json configuration file in the project directory under "Projects" (but will it be added to the package when I build it?)? Use the [tool.*] table of the project's |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @Laurent-Zerah, I'm happy to hear that you like Polylith! About resources, yes, maybe I should add suggestions about that in the docs. Good idea! One option that I think of is to create one "config" component, and put the constants, paths and settings in there. They can be grouped by context, domain or someting that makes sense. If it's not a problem to share the component between the projects I would go for this approach. You could write the component with sub-namespaces, to make the separation clearer or just organize a data structure with keys and values. Maybe some of the config values are loaded from the environment variables too? Then I think it would make a lot of sense to put it in one single component. To make components shareable, I would avoid (if possible) to dedicate them to a single project. The way you have solved it today, is each project-named components loaded in bases for each specific projects? If the configuration data should not be spread out in the different projects, I would try to refactor the json data into environment variables or secrets. Then the component(s) could be written in a more generic way. |
Beta Was this translation helpful? Give feedback.
-
We had a similar problem. We recently switched from JSON config files to
To quick switch between configurations, we have a simple bash function that calls the app-specific config: switchconfig app_foo We also added a pytest hook that hides tests if the corresponding config file is not available. Otherwise, we'd have thousands of tests loaded at the same time. |
Beta Was this translation helpful? Give feedback.
Hi @Laurent-Zerah, I'm happy to hear that you like Polylith! About resources, yes, maybe I should add suggestions about that in the docs. Good idea!
One option that I think of is to create one "config" component, and put the constants, paths and settings in there. They can be grouped by context, domain or someting that makes sense. If it's not a problem to share the component between the projects I would go for this approach. You could write the component with sub-namespaces, to make the separation clearer or just organize a data structure with keys and values.
Maybe some of the config values are loaded from the environment variables too? Then I think it would make a lot of sense to put i…