# andersonrocha091/bling_pipedrive_integration architecture

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

- Interactive diagram: https://gitdiagram.com/andersonrocha091/bling_pipedrive_integration
- Repository: https://github.com/andersonrocha091/bling_pipedrive_integration

## Overview

##### Main Components

a. External Services Layer:
- Pipedrive API (with API URL endpoint)
- Bling API (with API URL endpoint)

b. API Layer:
- Hapi.js Server (Port 5000)
- Three main route groups:
- PipedriveRoutes
- RevenueRoutes
- UtilRoutes

c. Service Layer:
- PipedriveService
- BlingService

d. Data Layer:
- MongoDB Database
- Strategy Pattern Implementation
- Base Strategy
- MongoDB Strategy
- Revenue Schema

##### Component Relationships

- External clients → API Layer (REST endpoints)
- API Layer → Service Layer (Internal communication)
- Service Layer → External Services (API calls)
- Service Layer → Data Layer (CRUD operations)

##### Architectural Patterns to Highlight

- Strategy Pattern for database operations (shown in src/db/strategies)
- Base Route Pattern (src/routes/base)
- Service Layer Pattern (src/services)

##### Infrastructure Layer

A separate section showing:
- Docker containers
- PM2 process manager
- MongoDB client (port 3000)

##### Environment Configuration

Configuration sources:
- .env files
- Development vs Production environments

**[External Clients]**
- ↓
**[External Services Layer]**
- ↓
**[API Layer (Hapi.js)]**
- ↓
**[Service Layer]**
- ↓
**[Data Layer]**
- ↓
**[Infrastructure Layer]**

Important Details to Include:

##### Technical Specifications
- Node.js 12.8
- MongoDB connection details
- Docker container architecture
- Port mappings (5000 for API, 3000 for Mongo client)

##### Testing Coverage
- A note about TDD implementation
- Test file coverage for main components

- Clear separation of concerns
- Integration points between systems
- Data flow directions
- Infrastructure setup
- Environment configurations

This will provide a complete picture of how the system works while maintaining readability and understanding of the architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        PipedriveAPI[("Pipedrive API")]:::external
        BlingAPI[("Bling API")]:::external
    end

    subgraph APILayer
        Server["Hapi.js Server (Port 5000)"]:::api
        click Server "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/Api.js"

        subgraph Routes
            BaseRoute["Base Route Pattern"]:::route
            click BaseRoute "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/routes/base/BaseRoute.js"
            
            PipedriveRoutes["Pipedrive Routes"]:::route
            click PipedriveRoutes "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/routes/PipedriveRoutes.js"
            
            RevenueRoutes["Revenue Routes"]:::route
            click RevenueRoutes "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/routes/RevenueRoutes.js"
            
            UtilRoutes["Util Routes"]:::route
            click UtilRoutes "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/routes/UtilRoutes.js"
        end
    end

    subgraph ServiceLayer
        PipedriveService["Pipedrive Service"]:::service
        click PipedriveService "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/services/PipedriveService.js"
        
        BlingService["Bling Service"]:::service
        click BlingService "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/services/BlingService.js"
    end

    subgraph DataLayer
        MongoDB[("MongoDB")]:::database
        
        subgraph DatabaseStrategy
            ContextStrategy["Context Strategy"]:::strategy
            click ContextStrategy "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/db/strategies/base/ContextStrategy.js"
            
            MongoDBStrategy["MongoDB Strategy"]:::strategy
            click MongoDBStrategy "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/db/strategies/mongodb/MongoDB.js"
            
            InterfaceCrud["Interface CRUD"]:::strategy
            click InterfaceCrud "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/db/strategies/interfaces/InterfaceCrud.js"
            
            RevenueSchema["Revenue Schema"]:::schema
            click RevenueSchema "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/db/strategies/mongodb/schemes/RevenueSchema.js"
        end
    end

    subgraph Infrastructure
        Docker["Docker Container"]:::infra
        click Docker "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/docker-compose.yml"
        
        PM2["PM2 Process Manager"]:::infra
        click PM2 "https://github.com/andersonRocha091/bling_pipedrive_integration/tree/master/Procfile"
        
        DockerDB["Docker DB Setup"]:::infra
        click DockerDB "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/docker_scripts/mongo-create-user-entry-point.sh"
    end

    subgraph Testing
        BlingTest["Bling Service Tests"]:::test
        click BlingTest "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/tests/BlingService.test.js"
        
        PipedriveTest["Pipedrive Service Tests"]:::test
        click PipedriveTest "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/tests/PipedriveService.test.js"
        
        MongoTest["MongoDB Strategy Tests"]:::test
        click MongoTest "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/tests/MongoDBStrategy.test.js"
        
        RevenueTest["API Revenue Tests"]:::test
        click RevenueTest "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/tests/ZApiRevenues.test.js"
    end

    subgraph Config
        DevEnv["Development Environment"]:::config
        click DevEnv "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/config/.env.dev"
        
        ProdEnv["Production Environment"]:::config
        click ProdEnv "https://github.com/andersonRocha091/bling_pipedrive_integration/blob/master/src/config/.env.prod"
    end

    %% Relationships
    Server --> Routes
    BaseRoute --> PipedriveRoutes & RevenueRoutes & UtilRoutes
    Routes --> ServiceLayer
    PipedriveService --> PipedriveAPI
    BlingService --> BlingAPI
    ServiceLayer --> DatabaseStrategy
    DatabaseStrategy --> MongoDB
    Docker --> MongoDB
    PM2 --> Server

    %% Styles
    classDef external fill:#a8d1f0,stroke:#333
    classDef api fill:#90EE90,stroke:#333
    classDef route fill:#98FB98,stroke:#333
    classDef service fill:#FFE4B5,stroke:#333
    classDef database fill:#FF9999,stroke:#333
    classDef strategy fill:#DDA0DD,stroke:#333
    classDef schema fill:#E6E6FA,stroke:#333
    classDef infra fill:#D3D3D3,stroke:#333
    classDef test fill:#F0E68C,stroke:#333
    classDef config fill:#FFA07A,stroke:#333
```
