Skip to content

Commit

Permalink
fix: style
Browse files Browse the repository at this point in the history
  • Loading branch information
cdddg committed Aug 16, 2023
1 parent e603008 commit e45786e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GIT_ARGS := --name-only --diff-filter=d --cached
ifneq ($(DIFF_SRC),)
GIT_ARGS := --name-only --diff-filter=d $(DIFF_SRC)...HEAD
endif
DIFF_FILES = `git diff $(GIT_ARGS) | grep .py$$ | grep -v migrations`
DIFF_FILES = `git diff $(GIT_ARGS) | grep .py$$`


format:
Expand Down
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is an example of implementing a Pokémon API based on the Clean Architectur
archived to v1 branch on 2021/04 <br>desc: Initial proposal by me
- **v2**: checkout to the [v2 branch ](https://github.com/cdddg/py-clean-arch/tree/v2)<br>archived to v1 branch on 2023/07 <br>
desc: Improvement from v1, the details can be seen on this PR [#1](https://github.com/cdddg/py-clean-arch/pull/1)
- **v3**: [master branch](https://github.com/cdddg/py-clean-arch/tree/master) <br>merged to master on 2023/08. <br>desc: Transitioned from Go-centric design to conventional Python practices. Details available in this PR [#11](https://github.com/cdddg/py-clean-arch/pull/11).https://github.com/cdddg/py-clean-arch/pull/11)
- **v3**: master branch <br>merged to master on 2023/08. <br>desc: Transitioned from Go-centric design to conventional Python practices. Details available in this PR [#11](https://github.com/cdddg/py-clean-arch/pull/11)

## Description

Expand All @@ -27,13 +27,25 @@ The project, like the original project, has 4 domain layers:
- Usecase Layer
- Delivery Layer

In addition, Add [Unit of Work Pattern](./src/settings/unit_of_work.py) [^2], [Dependency Injection Pattern](./src/settings/dependency_injection.py) [^3] <br>
and use Asynchronous SQLalchemy[^4]
![clean-arch-01](./docs/clean-arch-01.png)

![clean-arch-02](./docs/clean-arch-02.png)

### Additional Features and Patterns in This Project

Apart from being based on Uncle Bob's Clean Architecture, this project also incorporates the following features and patterns:

- **Unit of Work Pattern**[^2]: Ensures that all work is completed as a single unit for every transactional operation.
- **Dependency Injection Pattern**[^3]: Helps in reducing direct dependencies between codes, increasing the testability and flexibility of modules.
- **Asynchronous SQLalchemy**[^4]: By utilizing asynchronous SQLalchemy, database operations are optimized for performance and efficiently handle multitasking.

### Project Structure Overview & Clean Architecture Mapping

The directory structure below provides a high-level view of the project. Each directory or module corresponds to a layer in Uncle Bob's Clean Architecture. Please note that only the main directories and key files are listed here. Some specific files or subdirectories might be omitted to highlight the overall architecture and the primary purpose of each layer.

In addition, Add [Unit of Work Pattern](./src/settings/unit_of_work.py) [^2], [Dependency Injection Pattern](./src/settings/dependency_injection.py) [^3] <br>
and use Asynchronous SQLalchemy[^4]

```
src
├── app/ - Directory for business logic.
Expand All @@ -47,6 +59,8 @@ src
│ │ ("Interface" Adapters Layer in Clean Architecture)
│ │
│ └── di/ - Dependency injection module.
│ ├── dependency_injection.py - Configurations and classes implementing the "Dependency Injection Pattern"
│ └── unit_of_work.py - Manages the lifetimes of database sessions, implementing the "Unit of Work Pattern"
├── models/ - Domain models representing core business logic.
│ ("Entities" Layer in Clean Architecture)
Expand All @@ -57,13 +71,9 @@ src
└── main.py - Main file to launch the application.
```

![clean-arch-01](./docs/clean-arch-01.png)

<img src="./docs/clean-arch-02.png" alt="clean-arch-02" style="zoom:75%;" />

### How To Run This Project
## How To Run This Project

#### Run the Application
### Run the Application

```sh
$ docker-compose up
Expand All @@ -87,7 +97,7 @@ application run on http://localhost:8000

<img src="./docs/fastapi-doc.png" alt="fastapi-doc" style="zoom:40%;" />

#### Run the Testing
### Run the Testing

To test a single database, set the `SQLALCHEMY_DATABASE_URI` environment variable to the database URI and run:

Expand Down Expand Up @@ -141,3 +151,4 @@ $ pytest --cov
[^3]: https://en.wikipedia.org/wiki/Dependency_injection
[^4]: The asyncio extension as of SQLAlchemy 1.4.3 can now be considered to be **beta level** software. API details are subject to change however at this point it is unlikely for there to be significant backwards-incompatible changes. https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html

[^5]: Test results as of [today's date, e.g., August 12, 2023].
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion src/app/repositories/rdbms/pokemon/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from sqlalchemy.orm import selectinload
from sqlalchemy.sql import delete, func, insert, select, update

from models.exception import PokemonNotFound
from common.type import UUIDStr
from models.exception import PokemonNotFound
from models.pokemon import (
CreatePokemonModel,
GetPokemonParamsModel,
Expand Down

0 comments on commit e45786e

Please sign in to comment.