mirror of
https://codeberg.org/forgejo/docs.git
synced 2024-12-28 23:15:47 -05:00
98dac9cb1f
Preview: * https://forgejo.codeberg.page/@docs_pull_639/docs/next/developer/federation-architecture/ * https://forgejo.codeberg.page/@docs_pull_639/docs/next/developer/threat-analysis/ * https://forgejo.codeberg.page/@docs_pull_639/docs/next/developer/adr/ Co-authored-by: patdyn <erik.seiert@meissa-gmbh.de> Co-authored-by: Clemens <clemens.geibel@meissa-gmbh.de.de> Reviewed-on: https://codeberg.org/forgejo/docs/pulls/639 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Panagiotis "Ivory" Vasilopoulos <git@n0toose.net> Co-authored-by: Michael Jerger <michael.jerger@meissa-gmbh.de> Co-committed-by: Michael Jerger <michael.jerger@meissa-gmbh.de>
3.2 KiB
3.2 KiB
title | license |
---|---|
ADR: DDD for Federation | CC-BY-SA-4.0 |
Status
WIP
Context
With federation we introduced a topic independent to existing gitea. This will give us the chance to choose other architecture principles.
Discussion see: https://codeberg.org/forgejo/discussions/issues/179
Decision
tbd
Choices
1. Do federation stuff following Domain Driven Design in combination with Dependency Injection
Let's do federation related stuff following DDD as whole. But let's keep the existing codebase as is.
Reason for this proposal are:
- Federation is new, so it might be possible to adjust the architecture for the new code. For existing (f3 code) we might find a way of migration and I offer help :-)
- Keep the existing functionality in existing layout will keep compatibility for gitea contributions - as long as we can use them.
Code-Example can be found here: https://codeberg.org/forgejo/forgejo/pulls/4193
1.1 Aspects and Properties
- Entities and value structs: they contain as much domain logic as possible.
- Aggregates: they are atomary units in terms of persistence. This, however, has still some room for improvement :)
- Interfaces for infrastructure: infrastructure is encapsulated from domain logic by interfaces. This allows unit testing in combination with mocks.
- Service: services provide logic that does not belong to a single aggregate or entity, or is using infrastructure.
- Poor man's dependency injection: services contain infrastructure implementations. This allows to differentiate composition of used infrastructure between production or test usage. This also has room for improvement, because we do not have an application context singleton (as in Spring Boot).
1.2 Expected Benefit
- We can unittest all paths in service. Integration test has only to cover the most important paths like "Happy Path" or "Failure Path".
- We can decide to separate
domain
fromdomain_test
- We can split up the (in future probable) huge federation service along the domain aggregates
FederationHost
,User
. This will lead to packagesdomain/FederationHost
having aFederationService
ordomain/User
having aUserService
. This will help to keep the services focussed around one domain. - Refactorings of domain stays simple, as we have all paths under unit tests.
- Aggregates are way to model out meaningful submodules in terms of domain. We can improve & sharpen this model in a iterative way. Therefor are Aggregates also the point defining the shape of used repositories and apis.
- Aggregates bring the chance of performance improvements: If accessing db multiple times for one use case in my experience often leads to bad performance compared to "load all on start & save all at the end". But minimizing the times of accessing db stands against amount of data being loaded every time. A good & sharp modelled aggregate might reflect the sweet spot between both bad performing borders.