litestar-org / advanced-alchemy

A carefully crafted, thoroughly tested, optimized companion library for SQLAlchemy
http://docs.advanced-alchemy.litestar.dev/
MIT License
217 stars 26 forks source link

Docs: Explain the intended usage of respositories and services #200

Open ghferrari opened 3 months ago

ghferrari commented 3 months ago

Summary

This package looks very useful but it is (as I'm sure you know) missing some essential documentation. In particular, it would be useful to have more documentation about repositories and services and their intended use cases. I've browsed through the litestar-fullstack application, which uses both, and it's not especially clear to me what are the different intended use cases of each. Not sure if I'm missing some essential background knowledge here that would make the difference clearer, but if so, it would be nice to have it explained. Thanks for listening!

Seemone commented 2 months ago

I agree it's not clear. My take is that repositories handle the DB representation of data on the DB backend, and thus deal with data. Services, in turn, handle what is being done with the data itself, so they are geared towards the controllers

ghferrari commented 2 months ago

As a follow up, I've since spent some time with other API frameworks which also distinguish between between repositories and services, so I suspect the authors are to some extent relying on this terminology already being understood.

For those that don't understand it, I'd describe it something like this:

So in a typical application, you might define the repository layer, then a service layer which calls the repository layer as well as any other external services or other business logic tools. Finally, the controller layer will call the service layer (but not the repository directly).