Replies: 1 comment
-
I think dividing code by feature is usually the right way to go. This is the approach taken in different frameworks, e.g. django, nestjs or in such design patterns as MVVM. This correlates with the second option you've given. In a nutshell:
You can also see a nestJS example i made a while back as an example for my colleagues: https://github.com/Goldziher/secret-note, it demonstrates a similar structure. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Given the current discussions regarding CLI tools to help jump start projects, I wanted to share my team's experience with filesystem layouts in Starlite. This is just one opinion and not meant to be a criticism - people have different needs and situations.
The examples in the documentation largely demonstrate a project filesystem layout organized by framework function:
In this layout, imports would generally look like:
For my specific project/team, I/we found that this layout quickly left us with questions/issues that we couldn't solve in a way that made us happy.
Where would global dependencies/exceptions/responses/etc go?
If I have a directory called
dependencies
that holds my component dependencies I can't also have a top-leveldependencies.py
(without magic). Havingdependencies/global.py
ordependencies/my_app.py
or other iterations of "shared", "common", etc felt wrong.Where do things that aren't "native" to Starlite go?
We have an authentication component that uses CASBin. That library has a configuration file (
model.conf
- not to be confused with Starlite models). We also have a GitHub component that uses an auto-generated schema file using a utility from SGQLC (graphql_schema.py
).Where should these items live? They aren't models, controllers, or dependencies (in Starlite terms), and they aren't specific to Starlite or related to any other component in the app.
Alternate Layout
We landed on a filesystem layout organized by component. We think of these components as semi-pluggable "apps".
In this layout, imports would generally look like:
Some points we like about this layout:
isort
) so that all imports from the same component are togetherFor our project, there will eventually be different development team owners of the different components. Organizing by component allows for us to put rules in GitHub's
CODEOWNERS
for approval purposes that reflect that ownership simply.Here's a real-world example of this layout:
And an example of how imports shape up from our
main.py
:Beta Was this translation helpful? Give feedback.
All reactions