# progbisht/microservice_e_comm architecture

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

- Interactive diagram: https://gitdiagram.com/progbisht/microservice_e_comm
- Repository: https://github.com/progbisht/microservice_e_comm

## Overview

##### Main Components Identification
- Catalog Service: This handles the product catalog using an object-oriented approach. Represent its several layers, such as:
- API Layer: Contains the catalog.routes in both the compiled (dist/api) and source (src/api) directories.
- Service Layer: Includes business logic (catalog.service).
- Repository Layer: Manages data access (catalog.repository).
- Domain Models and DTOs: Reflect product data (product.model.ts and product.dto.ts).
- Supporting Utilities: Error handling, logging, request validation, and fixtures.
- Order Service: This deals with cart and order management using a functional programming style. Represent its layers similarly:
- API/Routes: Contains endpoints (e.g., order.routes and cart.routes).
- Service Layer: Business logic for orders (order.service, cart.service).
- Repository Layer: Data access logic (order.repository, cart.repository).
- DTOs and Schema: For request validation and database schema.
- Additional Utilities: Error handling and logging.

##### Architectural Relationships and Interactions
- For incoming client requests to each service and then service-to-database interactions.
- That each service follows Clean Architecture, making them independent of external frameworks and databases (use layered architecture concepts).

##### Important Architectural Patterns
- Microservice Architecture: Emphasize independent services that communicate through defined interfaces.
- Clean Architecture: Show separation of concerns with layers (controllers/routes, services, repositories, domain models).
- Paradigm Distinctions: Note that catalog service uses object-oriented design, whereas order service leverages a functional approach.

##### Relevant Technologies and Frameworks
- Catalog Service: Node.js (with Express, as suggested by the expressApp files), Prisma for database migrations, and Jest for testing.
- Order Service: Node.js, drizzle (as indicated by the drizzle.config), and Jest.
- The “db” directory with docker-compose hints at containerized database services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client Requests"):::client

    subgraph "Catalog Service"
        direction TB
        CatAPISrc["Catalog API (Src)"]:::api
        CatAPIComp["Catalog API (Compiled)"]:::api
        CatService["Catalog Service Business"]:::service
        CatRepository["Catalog Repository (Src)"]:::repository
        CatRepoCompiled["Catalog Repository (Compiled)"]:::repository
        CatMockRepo["Catalog Repository (Mock)"]:::repository
        CatProductModel["Product Model"]:::models
        CatProductDTO["Product DTO"]:::models
        CatErrUtils["Catalog Error & Validator Utils"]:::utils
        CatLogger["Catalog Logger"]:::utils
        CatFixtures["Catalog Fixtures"]:::utils
        CatReqValidator["Catalog Request Validator"]:::utils
        CatGeneralUtils["Catalog General Utils"]:::utils
    end

    subgraph "Order Service"
        direction TB
        subgraph "Order API"
            direction TB
            CartRoutes["Cart Routes"]:::api
            OrderRoutes["Order Routes"]:::api
        end
        subgraph "Order Business"
            direction TB
            OrdService["Order Service Business"]:::service
            CartService["Cart Service Business"]:::service
        end
        subgraph "Order Repository"
            direction TB
            CartRepository["Cart Repository"]:::repository
            OrderRepository["Order Repository"]:::repository
        end
        subgraph "Order DTO & Schema"
            direction TB
            CartRequestDTO["Cart Request DTO"]:::models
            OrdProductDTO["Product DTO (Order)"]:::models
            CartSchema["Cart Schema"]:::models
            DBSchema["DB Schema Index"]:::models
        end
        subgraph "Order Utilities"
            direction TB
            OrdErrUtils["Order Error & Validator Utils"]:::utils
            OrdLogger["Order Logger"]:::utils
            OrdBrokerAPI["Order Broker API"]:::utils
            OrdBrokerUtils["Order Broker Utils"]:::utils
            OrdOtherUtils["Order Other Utils"]:::utils
            OrdValidator["Order Validator"]:::utils
        end
    end

    subgraph "Databases & Migrations"
        direction TB
        CatMigrations["Catalog Migrations"]:::database
        OrdMigrations["Order Migrations"]:::database
        SharedDB["Shared Docker DB"]:::database
    end

    %% Client Requests to Services
    Client -->|"request"| CatAPISrc
    Client -->|"request"| CartRoutes
    Client -->|"request"| OrderRoutes

    %% Catalog Service Internal Flow
    CatAPISrc -->|"compile"| CatAPIComp
    CatAPIComp -->|"calls"| CatService
    CatService -->|"invokes"| CatRepository
    CatRepository -->|"builds"| CatRepoCompiled
    CatRepository -->|"utilizes"| CatProductModel
    CatRepository -->|"maps to"| CatProductDTO
    CatService -->|"handles"| CatErrUtils
    CatService -->|"logs"| CatLogger
    CatService -->|"loads"| CatFixtures
    CatService -->|"validates"| CatReqValidator
    CatService -->|"uses"| CatGeneralUtils
    CatProductModel -->|"persists via"| CatMigrations

    %% Order Service Internal Flow
    CartRoutes -->|"routes"| OrdService
    OrderRoutes -->|"routes"| OrdService
    OrdService -->|"queries"| OrderRepository
    CartService -->|"queries"| CartRepository
    OrderRepository -->|"migrates"| OrdMigrations
    CartRepository -->|"migrates"| OrdMigrations
    OrdService -->|"errors"| OrdErrUtils
    OrdService -->|"logs"| OrdLogger
    OrdService -->|"notifies"| OrdBrokerAPI
    OrdService -->|"communicates"| OrdBrokerUtils
    OrdService -->|"utilizes"| OrdOtherUtils
    OrdService -->|"validates"| OrdValidator

    %% Inter-Service Communication
    CatService ---|"stateChange"| OrdService

    %% Databases Connection
    CatMigrations -->|"container"| SharedDB
    OrdMigrations -->|"container"| SharedDB

    %% Click Events for Catalog Service
    click CatAPISrc "https://github.com/progbisht/microservice_e_comm/blob/master/catalog_service/src/api/catalog.routes.ts"
    click CatAPIComp "https://github.com/progbisht/microservice_e_comm/blob/master/catalog_service/dist/api/catalog.routes.js"
    click CatService "https://github.com/progbisht/microservice_e_comm/blob/master/catalog_service/src/service/catalog.service.ts"
    click CatRepository "https://github.com/progbisht/microservice_e_comm/blob/master/catalog_service/src/repository/catalog.repository.ts"
    click CatRepoCompiled "https://github.com/progbisht/microservice_e_comm/blob/master/catalog_service/dist/repository/catalog.repository.js"
    click CatMockRepo "https://github.com/progbisht/microservice_e_comm/blob/master/catalog_service/src/repository/mockCatalog.repository.ts"
    click CatProductModel "https://github.com/progbisht/microservice_e_comm/blob/master/catalog_service/src/models/product.model.ts"
    click CatProductDTO "https://github.com/progbisht/microservice_e_comm/blob/master/catalog_service/src/dto/product.dto.ts"
    click CatErrUtils "https://github.com/progbisht/microservice_e_comm/tree/master/catalog_service/src/utils/error/"
    click CatLogger "https://github.com/progbisht/microservice_e_comm/blob/master/catalog_service/src/utils/logger/index.ts"
    click CatFixtures "https://github.com/progbisht/microservice_e_comm/blob/master/catalog_service/src/utils/fixtures/index.ts"
    click CatReqValidator "https://github.com/progbisht/microservice_e_comm/blob/master/catalog_service/src/utils/requestValidator.ts"
    click CatGeneralUtils "https://github.com/progbisht/microservice_e_comm/tree/master/catalog_service/src/utils/"

    %% Click Events for Order Service
    click CartRoutes "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/routes/cart.routes.ts"
    click OrderRoutes "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/routes/order.routes.ts"
    click OrdService "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/services/order.service.ts"
    click CartService "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/services/cart.service.ts"
    click CartRepository "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/repository/cart.repository.ts"
    click OrderRepository "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/repository/order.repository.ts"
    click CartRequestDTO "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/dto/cartRequest.dto.ts"
    click OrdProductDTO "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/dto/product.dto.ts"
    click CartSchema "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/db/schema/cart.ts"
    click DBSchema "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/db/schema/index.ts"
    click OrdErrUtils "https://github.com/progbisht/microservice_e_comm/tree/master/order_service/src/utils/error/"
    click OrdLogger "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/utils/logger/index.ts"
    click OrdBrokerAPI "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/utils/broker/api.ts"
    click OrdBrokerUtils "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/utils/broker/index.ts"
    click OrdOtherUtils "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/utils/index.ts"
    click OrdValidator "https://github.com/progbisht/microservice_e_comm/blob/master/order_service/src/utils/validator.ts"

    %% Click Events for Databases & Migrations
    click CatMigrations "https://github.com/progbisht/microservice_e_comm/tree/master/catalog_service/prisma/migrations/"
    click OrdMigrations "https://github.com/progbisht/microservice_e_comm/tree/master/order_service/src/db/migrations/"
    click SharedDB "https://github.com/progbisht/microservice_e_comm/blob/master/db/docker-compose.yml"

classDef client fill:#CCCCFF,stroke:#000,stroke-width:2px;
classDef api fill:#DDEEFF,stroke:#000,stroke-width:2px;
classDef service fill:#FFEFD5,stroke:#000,stroke-width:2px;
classDef repository fill:#FDD,stroke:#000,stroke-width:2px;
classDef models fill:#E0FFE0,stroke:#000,stroke-width:2px;
classDef utils fill:#F0E68C,stroke:#000,stroke-width:2px;
classDef database fill:#FFD700,stroke:#000,stroke-width:2px;
```
