Skip to content

Commit b279803

Browse files
Feature/refactor repo layer (#16)
* update libs * update libs * move abstractions and repositories from infrastructure layer to domain layer * move unit of work from infrastructure layer to patterns * re-init and reimport new repos and abstractions * update README.md about new project structure
1 parent db31eb0 commit b279803

File tree

26 files changed

+929
-632
lines changed

26 files changed

+929
-632
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ By following Clean Architecture, this project ensures that the core business log
3434
├──────────────────────────────┤
3535
│ Use Cases │ → Encapsulates core business logic
3636
├──────────────────────────────┤
37+
│ Repositories │ → Acts as an adapter that decouples the business layer from the infrastructure
38+
├──────────────────────────────┤
3739
│ Infrastructures (DB, Cache) │ → Handles external dependencies like databases & queues
3840
└──────────────────────────────┘
3941
```
@@ -69,16 +71,16 @@ The **Unit of Work pattern** ensures that multiple repository operations are **e
6971
internal/
7072
│── app/ # Defines servers and middlewares (protocols)
7173
│── controllers/ # Handles requests and responses (endpoints)
72-
│── domains/ # Core business logic (services, use cases, entities)
74+
│── domains/ # Core business logic (services, use cases, entities, repositories)
7375
│── infrastructures/ # External dependencies (databases, caches, queues)
74-
│── patterns/ # Dependency injection
76+
│── patterns/ # Dependency injection, Unit Of Work
7577
└── main.py # Application entry point
7678
```
7779

7880
- **App**: Define servers (protocols) and middlewares.
7981
- **Controllers**: Define the API endpoints and route requests to services.
80-
- **Domains**: Contains core business logic, including services and use cases.
81-
- **Infrastructures**: Houses repositories and database interactions.
82+
- **Domains**: Contains core business logic, including services, use cases, and repositories.
83+
- **Infrastructures**: Database interactions, other third-party services.
8284
- **Patterns**: Implements design patterns like Dependency Injection and Unit of Work.
8385
- **Main.py**: Initializes the application, including dependency injection and routing setup.
8486

internal/infrastructures/relational_db/postgres/repositories/__init__.py renamed to internal/domains/repositories/__init__.py

File renamed without changes.

internal/infrastructures/relational_db/abstraction/__init__.py renamed to internal/domains/repositories/abstraction/__init__.py

File renamed without changes.

internal/infrastructures/relational_db/abstraction/comment.py renamed to internal/domains/repositories/abstraction/comment.py

File renamed without changes.

internal/infrastructures/relational_db/abstraction/post.py renamed to internal/domains/repositories/abstraction/post.py

File renamed without changes.

internal/infrastructures/relational_db/abstraction/user.py renamed to internal/domains/repositories/abstraction/user.py

File renamed without changes.

internal/infrastructures/relational_db/postgres/repositories/comment.py renamed to internal/domains/repositories/comment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sqlalchemy.ext.asyncio import AsyncSession
66

77
from internal.domains.entities import CommentEntity, GetMultiCommentsFilter
8-
from internal.infrastructures.relational_db.abstraction import AbstractCommentRepo
8+
from internal.domains.repositories.abstraction.comment import AbstractCommentRepo
99
from internal.infrastructures.relational_db.postgres.models import (
1010
Comment,
1111
CommentModelMapper,

internal/infrastructures/relational_db/postgres/repositories/post.py renamed to internal/domains/repositories/post.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sqlalchemy.ext.asyncio import AsyncSession
66

77
from internal.domains.entities import GetMultiPostsFilter, PostEntity
8-
from internal.infrastructures.relational_db.abstraction import AbstractPostRepo
8+
from internal.domains.repositories.abstraction.post import AbstractPostRepo
99
from internal.infrastructures.relational_db.postgres.models import Post, PostModelMapper
1010
from utils.time_utils import DATETIME_DEFAULT_FORMAT, from_str_to_dt
1111

internal/infrastructures/relational_db/postgres/repositories/user.py renamed to internal/domains/repositories/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sqlalchemy.ext.asyncio import AsyncSession
66

77
from internal.domains.entities import UserEntity
8-
from internal.infrastructures.relational_db.abstraction import AbstractUserRepo
8+
from internal.domains.repositories.abstraction.user import AbstractUserRepo
99
from internal.infrastructures.relational_db.postgres.models import User, UserModelMapper
1010

1111

internal/domains/services/authentication.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
AbstractAuthenticationUC,
1818
AbstractUserUC,
1919
)
20-
from internal.infrastructures.relational_db.patterns import (
21-
AbstractUnitOfWork as RelationalDBUnitOfWork,
22-
)
20+
from internal.patterns import AbstractUnitOfWork as RelationalDBUnitOfWork
2321
from utils.logger_utils import get_shared_logger
2422
from utils.time_utils import DATETIME_DEFAULT_FORMAT, from_dt_to_str
2523

0 commit comments

Comments
 (0)