# arda1228/untitled-arda-dogan-project architecture

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

- Interactive diagram: https://gitdiagram.com/arda1228/untitled-arda-dogan-project
- Repository: https://github.com/arda1228/untitled-arda-dogan-project

## Overview

##### Project type and purpose
- This is a serverless, microservice-style backend project built and deployed with AWS CDK.
- It provides four distinct API endpoints:
1. trip price by car
2. trip price by public transport
3. CO₂ emissions by car
4. CO₂ emissions by public transport
- Its goal is to reduce car dependency by making cost and emissions data available.

##### File structure
- Top level:
- cdk-api-stack/ – AWS CDK application defining the cloud infrastructure
- driving/driving-price/ – Python modules for driving cost calculations
- public-transport/public-transport-price/ – Python modules for public-transport cost calculations
- Inside cdk-api-stack/:
- app.py, cdk.json – CDK entrypoint & config
- cdk_api_stack/ – CDK stack definition, includes a HitCounter construct
- lambda/ – all Lambda handler code (co2_driving, co2_pt, co2, hitcount, etc.)
- tests/ – unit tests for stack

##### README
- Clarifies the four main components (price & CO₂, for car & public transport)
- States the project’s aims (reduce carbon footprint, encourage public transport)

##### Main components
a. AWS Cloud Boundary
- API Gateway – exposes four REST endpoints
- HitCounter layer – sits between API Gateway and each Lambda to record invocation counts (records to DynamoDB)
- Lambda functions (4 business-logic Lambdas + hitcount helper)
- DynamoDB table for hit counts
b. External services & data sources
- Vehicle Enquiry Service API (vehicle lookup)
- Citymapper API (public transport routing)
- Transport-API (public transport data)
- vehicles.csv – local dataset for fuel consumption calculations
c. Relationships & data flow
1. Client → API Gateway (4 endpoints)
2. API Gateway → HitCounter → specific Lambda (e.g., co2_driving)
3. Lambda executes:
– May query vehicles.csv for fuel efficiency
– Calls Vehicle Enquiry API or Transport APIs or Citymapper
4. Lambda returns JSON response → API Gateway → Client
5. HitCounter writes invocation record → DynamoDB

##### Architectural patterns & principles
- Serverless microservices: each endpoint = one Lambda
- Infrastructure as Code: AWS CDK for reproducible deployment
- Single Responsibility: separate modules for pricing vs. CO₂ logic; driving vs. public transport
- Observability: HitCounter + DynamoDB for basic usage metrics

##### Detail level
- Be explicit: each Lambda, each data store, each external API.
- Technology choices: AWS CDK (Python), Python 3.x Lambdas, DynamoDB, external REST APIs, CSV data file.
- Don’t overcomplicate: keep to components that exist in your file tree and CDK definitions.

– How clients access each of the four services
– How your CDK stack lays out API Gateway, HitCounter, Lambdas, and DynamoDB
– How each Lambda interacts with external APIs or local data sources
– How usage metrics flow back into DynamoDB

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer Deployment
    Dev["AWS CDK App\n(app.py, cdk.json)"]:::developer
    Dev -->|"deploys"| Cloud

    subgraph "AWS Cloud"
        style Cloud fill:#eef9f8,stroke:#2d6a4f,stroke-width:2px
        Cloud([ ])
        %% API Layer
        APIGW["API Gateway"]:::api

        %% Compute Layer
        subgraph "Lambda Functions"
            direction TB
            HC_Construct["HitCounter Construct\n(hitcounter.py)"]:::construct
            HC_Lambda["HitCounter Lambda\n(hitcount.py)"]:::compute
            Co2_Driving["CO₂ Driving Lambda\n(co2_driving.py)"]:::compute
            Co2_PT["CO₂ Public Transport Lambda\n(co2_pt.py)"]:::compute
            Co2_DrivingDist["CO₂ Driving Distance Lambda\n(co2_driving_distance.py)"]:::compute
            Price_Lambda1["Trip Price Driving Lambda\n(my-lambda.py)"]:::compute
            Price_Lambda2["Trip Price PT Lambda\n(my-lambda.py)"]:::compute
        end

        %% Data Layer
        Dynamo["DynamoDB Table\n(HitCounts)"]:::database

        %% Local Data
        VehiclesCSV["vehicles.csv"]:::file

        %% Connections inside Cloud
        APIGW -->|"calls HitCounter"| HC_Construct
        HC_Construct -->|"invokes"| HC_Lambda
        HC_Lambda -->|Writes count| Dynamo

        APIGW -->|"routes to"| Co2_Driving
        APIGW -->|"routes to"| Co2_PT
        APIGW -->|"routes to"| Co2_DrivingDist
        APIGW -->|"routes to"| Price_Lambda1
        APIGW -->|"routes to"| Price_Lambda2

        Co2_Driving -->|Returns JSON| APIGW
        Co2_PT -->|Returns JSON| APIGW
        Co2_DrivingDist -->|Returns JSON| APIGW
        Price_Lambda1 -->|Returns JSON| APIGW
        Price_Lambda2 -->|Returns JSON| APIGW

        Co2_Driving -->|"Query vehicles.csv"| VehiclesCSV
        Price_Lambda1 -->|"Query vehicles.csv"| VehiclesCSV
    end

    %% External Services
    VehicleAPI["Vehicle Enquiry Service"]:::external
    Citymapper["Citymapper API"]:::external
    TransportAPI["Transport-API"]:::external

    Co2_Driving -->|"HTTP GET /vehicle-info"| VehicleAPI
    Price_Lambda1 -->|"HTTP GET /vehicle-info"| VehicleAPI
    Co2_PT -->|"HTTP GET /route-info"| Citymapper
    Co2_PT -->|"HTTP GET /transport-data"| TransportAPI
    Price_Lambda2 -->|"HTTP GET /route-info"| Citymapper
    Price_Lambda2 -->|"HTTP GET /transport-data"| TransportAPI

    Client["Client"]:::external
    Client -->|"HTTP GET /co2-driving<br>/co2-pt<br>/price-driving<br>/price-pt"| APIGW

    %% Click Events
    click Dev "https://github.com/arda1228/untitled-arda-dogan-project/blob/main/cdk-api-stack/app.py"
    click Dev "https://github.com/arda1228/untitled-arda-dogan-project/blob/main/cdk-api-stack/cdk.json"
    click HC_Construct "https://github.com/arda1228/untitled-arda-dogan-project/blob/main/cdk-api-stack/cdk_api_stack/hitcounter.py"
    click Co2_Driving "https://github.com/arda1228/untitled-arda-dogan-project/blob/main/cdk-api-stack/lambda/co2/co2_driving.py"
    click Co2_PT "https://github.com/arda1228/untitled-arda-dogan-project/blob/main/cdk-api-stack/lambda/co2/co2_pt.py"
    click Co2_DrivingDist "https://github.com/arda1228/untitled-arda-dogan-project/blob/main/cdk-api-stack/lambda/co2/co2_driving_distance.py"
    click HC_Lambda "https://github.com/arda1228/untitled-arda-dogan-project/blob/main/cdk-api-stack/lambda/hitcount.py"
    click Price_Lambda1 "https://github.com/arda1228/untitled-arda-dogan-project/blob/main/cdk-api-stack/lambda/my-lambda.py"
    click Price_Lambda2 "https://github.com/arda1228/untitled-arda-dogan-project/blob/main/cdk-api-stack/lambda/my-lambda.py"
    click VehiclesCSV "https://github.com/arda1228/untitled-arda-dogan-project/blob/main/driving/driving-price/vehicles.csv"

    %% Styles
    classDef developer fill:#ffe8d6,stroke:#f08a5d,stroke-width:1px
    classDef api fill:#ffd6a5,stroke:#ff8c42,stroke-width:1px
    classDef compute fill:#a0c4ff,stroke:#468faf,stroke-width:1px
    classDef database fill:#d0f4de,stroke:#2d6a4f,stroke-width:1px
    classDef external fill:#e0e0e0,stroke:#888888,stroke-width:1px
    classDef construct fill:#bdb2ff,stroke:#9d4edd,stroke-width:1px
```
