# jonathanarroyavegonzalez/backend-marketplace architecture

> Architecture diagram of the GitHub repository jonathanarroyavegonzalez/backend-marketplace, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jonathanarroyavegonzalez/backend-marketplace
- Repository: https://github.com/jonathanarroyavegonzalez/backend-marketplace

## Overview

##### Project Type and Purpose
- This is a backend-only application: a RESTful Marketplace API for local entrepreneurs.
- It uses Python + FastAPI, organized according to the Clean Architecture (API, Application, Domain, Infrastructure).

##### File Structure and Layers
- API Layer
- main.py – FastAPI app entrypoint
- controllers/… – HTTP handlers (authController, postController, etc.)
- Application Layer (dddpy/application)
- Models – DTOs and input models (loginDataModel.py, postModel.py, etc.)
- ResponseModels – response DTOs (postDetailResponseModel.py)
- Services – business use-case implementations (authService.py, postService.py…)
- Shared – common abstractions (ResponseModel)
- abstract – interface definitions (abstractStorage.py)
- Domain Layer (dddpy/domain)
- Enums – domain value sets (orderStatus, postStatus…)
- schemas – internal data representations (order_dto.py, user_dto.py…)
- repository.py – domain interface for data access
- Infrastructure Layer (dddpy/insfrastructure)
- Auth – JWT dependency & manager (jwt_depends.py, jwt_manage.py)
- services – low-level helpers (encryptService.py, storageService.py)
- sqlite – SQLAlchemy database & concrete repository implementation
- Configuration & Resources
- environment/env.py – environment variables
- resources/images + requirements.txt
- Tests – validate controllers and services

##### README Insights
- Confirms Clean Architecture and the four layers.
- Lists key technologies: FastAPI, SQLAlchemy, Python.

##### Main Components
a. Clients (Web/Mobile UI or Postman)
b. API Layer (FastAPI app + Controllers)
c. Application Layer (Use-Case Services + Models)
d. Domain Layer (Entities, Enums, Repository Interfaces)
e. Infrastructure Layer
- Auth (JWT)
- Persistence (SQLite via SQLAlchemy + Repository)
- Auxiliary services (Encryption, File Storage)
f. Database (marketplace.db)
g. Environment/Config

##### Relationships and Data Flow
- Clients → HTTP Request → FastAPI Router (controllers)
- Controllers → call Application Services
- Services → validate/use Models and call Repository Interfaces
- Repository Interfaces (Domain) → implemented by Infrastructure Repository → SQLAlchemy → Database
- Services use Infrastructure Auth/Encrypt/Storage as needed → return ResponseModels → Controllers → HTTP Response → Clients

##### Architectural Patterns
- Clean Architecture (layered, inward dependencies)
- Dependency Inversion: Application depends on Domain abstractions, not implementations
- Separation of Concerns: Controllers vs. Business Logic vs. Data Access vs. Domain Entities

## Diagram (Mermaid)

```mermaid
flowchart TB
    Clients["Clients (Web/Mobile/Postman)"]:::external
    Clients -->|"HTTP Request"| main["main.py"]:::api

    subgraph "API Layer"
        main["main.py"]:::api
        AC["authController"]:::api
        IC["imageController"]:::api
        OC["orderController"]:::api
        PC["postController"]:::api
        QC["qualificationController"]:::api
        UC["userController"]:::api
    end

    main --> AC
    main --> IC
    main --> OC
    main --> PC
    main --> QC
    main --> UC

    AC -->|"calls"| AS_auth
    IC -->|"calls"| AS_img
    OC -->|"calls"| AS_order
    PC -->|"calls"| AS_post
    QC -->|"calls"| AS_qual
    UC -->|"calls"| AS_user

    subgraph "Application Layer"
        AS_auth["authService"]:::app
        AS_img["imageService"]:::app
        AS_order["orderService"]:::app
        AS_post["postService"]:::app
        AS_qual["qualificationService"]:::app
        AS_user["userService"]:::app

        subgraph "Models"
            M_login["loginDataModel"]:::app
            M_post["postModel"]:::app
            M_editPost["editPostModel"]:::app
            M_order["orderModel"]:::app
            M_qualM["qualificationModel"]:::app
            M_user["userModel"]:::app
            M_entity["entityModel"]:::app
        end

        subgraph "ResponseModels"
            RM_postDetail["postDetailResponseModel"]:::app
        end

        Shared["ResponseModel"]:::app
        AbstractStorage["abstractStorage"]:::app
    end

    AS_auth -->|uses| M_login
    AS_img -->|uses| M_entity
    AS_order -->|uses| M_order
    AS_post -->|uses| M_post
    AS_qual -->|uses| M_qualM
    AS_user -->|uses| M_user

    AS_post -->|returns| RM_postDetail
    AS_auth -->|uses| Shared
    AS_img -->|depends| AbstractStorage
    AS_auth -->|depends| AbstractStorage
    AS_order -->|depends| AbstractStorage
    AS_post -->|depends| AbstractStorage
    AS_qual -->|depends| AbstractStorage
    AS_user -->|depends| AbstractStorage

    subgraph "Domain Layer"
        subgraph "Enums"
            E_orderStatus["orderStatus"]:::domain
            E_postCategory["postCategory"]:::domain
            E_postStatus["postStatus"]:::domain
        end
        subgraph "Schemas"
            D_order["order_dto"]:::domain
            D_post["post_dto"]:::domain
            D_qualDTO["qualification_dto"]:::domain
            D_userDTO["user_dto"]:::domain
            D_imageDTO["image_dto"]:::domain
        end
        RepoInterface["repository.py"]:::domain
    end

    AS_auth -->|calls| RepoInterface
    AS_img -->|calls| RepoInterface
    AS_order -->|calls| RepoInterface
    AS_post -->|calls| RepoInterface
    AS_qual -->|calls| RepoInterface
    AS_user -->|calls| RepoInterface

    subgraph "Infrastructure Layer"
        subgraph "Auth"
            I_jwtDep["jwt_depends.py"]:::infra
            I_jwtMan["jwt_manage.py"]:::infra
        end
        subgraph "Services"
            I_encrypt["encryptService.py"]:::infra
            I_storage["storageService.py"]:::infra
        end
        subgraph "Persistence"
            DB_module["database.py"]:::infra
            RepoImpl["repository.py"]:::infra
        end
    end

    AC -->|auth dependency| I_jwtDep
    AS_auth -->|uses encryption| I_encrypt
    AS_img -->|uses storage| I_storage
    RepoImpl -->|implements| RepoInterface
    RepoImpl -->|reads/writes| DB_module
    DB_module -->|connects to| DB

    subgraph "Resources & Config"
        Env["env.py"]:::config
        Images["resources/images"]:::resources
        Requirements["requirements.txt"]:::resources
        DB["marketplace.db"]:::db
    end

    Env --> main
    DB -.-> DB_module
    Images -->|used by| I_storage

    click main "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/main.py"
    click AC "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/controllers/authController.py"
    click IC "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/controllers/imageController.py"
    click OC "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/controllers/orderController.py"
    click PC "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/controllers/postController.py"
    click QC "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/controllers/qualificationController.py"
    click UC "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/controllers/userController.py"
    click M_login "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Models/loginDataModel.py"
    click M_post "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Models/postModel.py"
    click M_editPost "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Models/editPostModel.py"
    click M_order "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Models/orderModel.py"
    click M_qualM "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Models/qualificationModel.py"
    click M_user "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Models/userModel.py"
    click M_entity "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Models/entityModel.py"
    click RM_postDetail "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/ResponseModels/postDetailResponseModel.py"
    click AS_auth "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Services/authService.py"
    click AS_img "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Services/imageService.py"
    click AS_order "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Services/orderService.py"
    click AS_post "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Services/postService.py"
    click AS_qual "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Services/qualificationService.py"
    click AS_user "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Services/userService.py"
    click Shared "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/Shared/ResponseModel.py"
    click AbstractStorage "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/application/abstract/abstractStorage.py"
    click E_orderStatus "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/domain/Enums/orderStatus.py"
    click E_postCategory "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/domain/Enums/postCategory.py"
    click E_postStatus "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/domain/Enums/postStatus.py"
    click D_order "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/domain/schemas/order_dto.py"
    click D_post "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/domain/schemas/post_dto.py"
    click D_qualDTO "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/domain/schemas/qualification_dto.py"
    click D_userDTO "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/domain/schemas/user_dto.py"
    click D_imageDTO "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/domain/schemas/image_dto.py"
    click RepoInterface "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/domain/repository.py"
    click I_jwtDep "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/insfrastructure/Auth/jwt_depends.py"
    click I_jwtMan "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/insfrastructure/Auth/jwt_manage.py"
    click I_encrypt "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/insfrastructure/services/encryptService.py"
    click I_storage "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/insfrastructure/services/storageService.py"
    click DB_module "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/insfrastructure/sqlite/database.py"
    click RepoImpl "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/dddpy/insfrastructure/sqlite/repository/repository.py"
    click Env "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/environment/env.py"
    click Images "https://github.com/jonathanarroyavegonzalez/backend-marketplace/tree/main/resources/images/"
    click Requirements "https://github.com/jonathanarroyavegonzalez/backend-marketplace/blob/main/resources/requirements.txt"

    classDef api fill:#ADD8E6,stroke:#000
    classDef app fill:#90EE90,stroke:#000
    classDef domain fill:#FFFF99,stroke:#000
    classDef infra fill:#FFCCCC,stroke:#000
    classDef external fill:#D3D3D3,stroke:#000
    classDef config fill:#E0FFFF,stroke:#000
    classDef resources fill:#FFE4B5,stroke:#000
    classDef db fill:#F0E68C,stroke:#000
```
