# benoror/taxi-driver architecture

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

- Interactive diagram: https://gitdiagram.com/benoror/taxi-driver
- Repository: https://github.com/benoror/taxi-driver

## Overview

##### Main Components Identification

a) API Layer
- Three main endpoints (/countries, /rules, /taxes)
- POST /taxes as the primary calculation endpoint

b) Core Processing Engine
- Tax Rule Matcher
- Formula Evaluator
- Calculator Module

c) Data Store
- LowDB Database
- Tax Rules Repository

##### Component Relationships

- External clients → API Layer
- API Layer → Core Processing Engine
- Core Processing Engine ↔ Data Store

##### Specific Implementation Details

Technical elements:
- Micro framework (Zeit/Micro) as the API server
- LowDB as the database
- Formula Parser for tax calculations
- Currency.js for precise monetary calculations

**[Client Layer]**
- ↓
**[API Layer (Micro)]**
- GET /countries
- GET /rules
- POST /taxes
- ↓
**[Processing Layer]**
- Rule Matcher (lib/match.js)
- Formula Evaluator (lib/eval.js)
- Calculator (lib/calc.js)
- ↓
**[Data Layer]**
- LowDB
- Tax Rules
- Country Configurations

##### Important Elements to Highlight

a) Input Processing:
- How queries are processed with required fields (country, taxes)
- Optional match parameters (region, bpType, txType, etc.)

b) Rule Matching Flow:
- Demonstrate how rules are matched based on query parameters
- Formula evaluation process

c) Calculation Pipeline:
- How tax calculations are performed
- Dependency handling between taxes

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        C[External Client]
    end

    subgraph API["API Layer"]
        direction TB
        AE["API Entry Point"]
        CE["/countries Endpoint"]
        RE["/rules Endpoint"]
        TE["/taxes Endpoint"]
        AE --> CE
        AE --> RE
        AE --> TE
    end

    subgraph Processing["Processing Layer"]
        direction TB
        TRM["Tax Rule Matcher"]
        FE["Formula Evaluator"]
        CM["Calculator Module"]
        DPH["Decimal Precision Handler"]
        Core["Core Library"]
        Core --> TRM
        Core --> FE
        Core --> CM
        Core --> DPH
    end

    subgraph Data["Data Layer"]
        direction TB
        DB[(LowDB Database)]
        DBD[("Tax Rules &\nCountry Configs")]
    end

    subgraph Testing["Country Implementations"]
        direction TB
        MEX["Mexico Tests"]
        ARG["Argentina Tests"]
        KSA["Saudi Arabia Tests"]
    end

    C --> AE
    CE --> Core
    RE --> Core
    TE --> Core
    Core --> DB
    DB --> DBD
    
    %% Error handling connection
    EH["Error Handler"] --> AE
    EH --> Core

    %% Click events for component mapping
    click AE "https://github.com/benoror/taxi-driver/blob/master/api/index.js"
    click CE "https://github.com/benoror/taxi-driver/blob/master/api/countries/index.js"
    click RE "https://github.com/benoror/taxi-driver/blob/master/api/rules/index.js"
    click TE "https://github.com/benoror/taxi-driver/blob/master/api/taxes/index.js"
    click TRM "https://github.com/benoror/taxi-driver/blob/master/lib/match.js"
    click FE "https://github.com/benoror/taxi-driver/blob/master/lib/eval.js"
    click CM "https://github.com/benoror/taxi-driver/blob/master/lib/calc.js"
    click Core "https://github.com/benoror/taxi-driver/blob/master/lib/index.js"
    click DB "https://github.com/benoror/taxi-driver/blob/master/db.js"
    click DBD "https://github.com/benoror/taxi-driver/blob/master/db_data.js"
    click DPH "https://github.com/benoror/taxi-driver/blob/master/lib/decimal_precision.js"
    click MEX "https://github.com/benoror/taxi-driver/blob/master/tests/integration/mex.test.js"
    click ARG "https://github.com/benoror/taxi-driver/blob/master/tests/integration/arg.test.js"
    click KSA "https://github.com/benoror/taxi-driver/blob/master/tests/integration/ksa.test.js"
    click EH "https://github.com/benoror/taxi-driver/blob/master/error.js"

    classDef api fill:#2374AB,color:white
    classDef processing fill:#45B7D1,color:white
    classDef data fill:#F7A072,color:black
    classDef client fill:#98B9AB,color:black
    classDef error fill:#FF6B6B,color:white
    classDef testing fill:#8789C0,color:white

    class CE,RE,TE,AE api
    class TRM,FE,CM,Core,DPH processing
    class DB,DBD data
    class C client
    class EH error
    class MEX,ARG,KSA testing
```
