# ahmetb/baklava architecture

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

- Interactive diagram: https://gitdiagram.com/ahmetb/baklava
- Repository: https://github.com/ahmetb/baklava

## Overview

Below are the detailed steps and guidelines tailored for this project:

##### Main Components
- Cloud Run Service: The core of the application is implemented in main.go (with supporting logic in currency.go and Go modules). This service is deployed with “ko” to a Cloud Run environment.
- Provider Modules: In the providers folder, you have several directories (e.g., celebiogullari, elmacipazarigulluoglu, farukgulluoglu, etc.) each containing a provider.go file. There is also a generic parser component with its own tests. These modules likely encapsulate integrations with external data sources or APIs.
- Utility Layer: The util directory, containing files like errors.go and matching.go, provides shared helper functions and error handling across the application.
- Deployment and Scheduling: The tf directory contains Terraform configurations (main.tf and terraform.tfstate) used to deploy the scheduler (which might trigger tasks in the Cloud Run service or schedule regular operations).

##### Relationships and Data Flows
- The Cloud Run core (main.go) acts as the brain of the application. It likely invokes various provider modules to perform its tasks (data retrieval, processing, etc.).
- The individual provider modules interact with external systems (APIs, web pages, etc.) to get provider-specific data.
- The utility functions (errors and matching) are used by both the core service and the providers to standardize error handling and data matching.
- Terraform (in the tf folder) manages the deployment and scheduling aspects of the system, ensuring that the Cloud Run service is kept up-to-date and that periodic tasks are triggered as necessary.

##### Architectural Patterns and Design Principles
- Modularity: The separation of provider logic into different subdirectories shows a modular design. Each provider encapsulates its own integration logic, making it easier to extend or modify.
- Separation of Concerns: The core business logic (main.go, currency.go) is kept separate from integration concerns (providers) and utility functions.
- Infrastructure as Code: The tf directory signifies the use of Terraform for managing deployment configurations, ensuring reproducibility and consistent environment setups.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Cloud Run Service"
        MS["Main Service (main.go)"]:::core
        CL["Currency Logic (currency.go)"]:::core
    end

    subgraph "Provider Modules"
        CP["Celebiogullari Provider"]:::provider
        EP["Elmacipazarigulluoglu Provider"]:::provider
        FP["Farukgulluoglu Provider"]:::provider
        GP["Gaziantepgulluoglu Provider"]:::provider
        IP["Imamcagdas Provider"]:::provider
        KGP["Karakoygulluoglu Provider"]:::provider
        KKB["Kocakbaklava Provider"]:::provider
        KP["Koskeroglu Provider"]:::provider
        SP["Secbaklava Provider"]:::provider
        GPP["Generic Parser Provider"]:::provider
    end

    subgraph "Utilities"
        EU["Errors (util/errors.go)"]:::utils
        MU["Matching (util/matching.go)"]:::utils
    end

    subgraph "Deployment and Scheduling"
        TC["Terraform Config (tf/main.tf)"]:::deploy
        TS["Terraform State (tf/terraform.tfstate)"]:::deploy
    end

    ES[("External Data Sources")]:::external

    %% Relationships
    MS --> CL

    MS -->|"calls"| CP
    MS -->|"calls"| EP
    MS -->|"calls"| FP
    MS -->|"calls"| GP
    MS -->|"calls"| IP
    MS -->|"calls"| KGP
    MS -->|"calls"| KKB
    MS -->|"calls"| KP
    MS -->|"calls"| SP
    MS -->|"calls"| GPP

    %% Main Service uses Utilities
    MS -->|"uses"| EU
    MS -->|"uses"| MU

    %% Providers use Utilities and fetch External Data
    CP -->|"uses"| EU
    CP -->|"uses"| MU
    CP -->|"fetches"| ES

    EP -->|"uses"| EU
    EP -->|"uses"| MU
    EP -->|"fetches"| ES

    FP -->|"uses"| EU
    FP -->|"uses"| MU
    FP -->|"fetches"| ES

    GP -->|"uses"| EU
    GP -->|"uses"| MU
    GP -->|"fetches"| ES

    IP -->|"uses"| EU
    IP -->|"uses"| MU
    IP -->|"fetches"| ES

    KGP -->|"uses"| EU
    KGP -->|"uses"| MU
    KGP -->|"fetches"| ES

    KKB -->|"uses"| EU
    KKB -->|"uses"| MU
    KKB -->|"fetches"| ES

    KP -->|"uses"| EU
    KP -->|"uses"| MU
    KP -->|"fetches"| ES

    SP -->|"uses"| EU
    SP -->|"uses"| MU
    SP -->|"fetches"| ES

    GPP -->|"uses"| EU
    GPP -->|"uses"| MU
    GPP -->|"fetches"| ES

    %% Deployment connections
    TC -->|"deploys"| MS
    TS -->|"tracks"| TC

    %% Class Definitions for Styling
    classDef core fill:#8FB3D2,stroke:#333,stroke-width:2px;
    classDef provider fill:#FAD7A0,stroke:#333,stroke-width:2px;
    classDef utils fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef deploy fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#333,stroke-width:2px;

    %% Click Events
    click MS "https://github.com/ahmetb/baklava/blob/master/main.go"
    click CL "https://github.com/ahmetb/baklava/blob/master/currency.go"

    click CP "https://github.com/ahmetb/baklava/blob/master/providers/celebiogullari/provider.go"
    click EP "https://github.com/ahmetb/baklava/blob/master/providers/elmacipazarigulluoglu/provider.go"
    click FP "https://github.com/ahmetb/baklava/blob/master/providers/farukgulluoglu/provider.go"
    click GP "https://github.com/ahmetb/baklava/blob/master/providers/gaziantepgulluoglu/provider.go"
    click IP "https://github.com/ahmetb/baklava/blob/master/providers/imamcagdas/provider.go"
    click KGP "https://github.com/ahmetb/baklava/blob/master/providers/karakoygulluoglu/provider.go"
    click KKB "https://github.com/ahmetb/baklava/blob/master/providers/kocakbaklava/provider.go"
    click KP "https://github.com/ahmetb/baklava/blob/master/providers/koskeroglu/provider.go"
    click SP "https://github.com/ahmetb/baklava/blob/master/providers/secbaklava/provider.go"
    click GPP "https://github.com/ahmetb/baklava/blob/master/providers/genericparser/base.go"

    click EU "https://github.com/ahmetb/baklava/blob/master/util/errors.go"
    click MU "https://github.com/ahmetb/baklava/blob/master/util/matching.go"

    click TC "https://github.com/ahmetb/baklava/blob/master/tf/main.tf"
    click TS "https://github.com/ahmetb/baklava/blob/master/tf/terraform.tfstate"
```
