# flagship-io/decision-api architecture

> Architecture diagram of the GitHub repository flagship-io/decision-api, 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/flagship-io/decision-api
- Repository: https://github.com/flagship-io/decision-api

## Overview

##### Main Components

a. Core API Server Components:
- HTTP Server Layer (pkg/server)
- Request Handlers Layer (pkg/handlers)
- API Logic Layer (internal/apilogic)
- Validation Layer (internal/validation)

b. Connector Systems:
- Assignment Managers (Multiple implementations):
- DynamoDB
- Redis
- Local Storage
- In-Memory Storage
- Environment Loaders:
- CDN Loader
- Hits Processors:
- Data Collection Service

c. Supporting Components:
- Configuration Management (pkg/utils/config)
- Logging System (pkg/utils/logger)
- Middleware Stack (pkg/handlers/middlewares)

**[External Clients] → [Load Balancer/Ingress]**
- ↓
**[Middleware Layer (CORS, Metrics, Logging, Recovery)]**
- ↓
**[HTTP Server Layer (Main Request Handler)]**
- ↓
**[API Logic Layer] ←→ [Validation Layer]**
- ↓
**[Connector Interface Layer]**
- ↓
**[Storage Layer (Multiple Implementations)]**

##### Key Relationships to Highlight

- How requests flow through the middleware stack
- Pluggable nature of the storage backends
- Demonstrate the relationship between the API logic and validation layers
- How the configuration system influences all components

##### Important Architectural Patterns to Emphasize

- Plugin Architecture: The connectors system allows for different implementations
- Middleware Pattern: Request processing pipeline
- Clean Architecture: Separation of concerns between layers
- Interface-based Design: Especially in the connectors package

##### Technical Details

- Port 8080 for the HTTP server
- Environment configuration requirements (ENV_ID, API_KEY)
- External service dependencies (Redis, DynamoDB, CDN)
- Metrics and monitoring integration points

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External
        Client([External Clients])
        LB[Load Balancer/Ingress]
    end

    subgraph Middleware
        MW_CORS["CORS"]:::middleware
        MW_METRICS["Metrics"]:::middleware
        MW_LOGGING["Request Logger"]:::middleware
        MW_RECOVERY["Recovery"]:::middleware
    end

    subgraph Core
        Server["HTTP Server"]:::core
        Handlers["Request Handlers"]:::core
        APILogic["API Logic"]:::core
        Validation["Validation"]:::core
    end

    subgraph Connectors
        direction TB
        subgraph AssignmentManagers["Assignment Managers"]
            direction TB
            DynamoDB["DynamoDB"]:::storage
            Redis["Redis"]:::storage
            LocalStorage["Local Storage"]:::storage
            InMemory["In-Memory"]:::storage
        end

        subgraph EnvLoaders["Environment Loaders"]
            CDN["CDN Loader"]:::external
        end

        subgraph HitsProcessors["Hits Processors"]
            DataCollect["Data Collection Service"]:::external
        end
    end

    subgraph Support
        Config["Configuration Management"]:::support
        Logger["Logging System"]:::support
    end

    %% Relationships
    Client --> LB
    LB --> MW_CORS
    MW_CORS --> MW_METRICS
    MW_METRICS --> MW_LOGGING
    MW_LOGGING --> MW_RECOVERY
    MW_RECOVERY --> Server
    Server --> Handlers
    Handlers --> APILogic
    APILogic <--> Validation
    APILogic --> AssignmentManagers
    APILogic --> EnvLoaders
    APILogic --> HitsProcessors
    
    %% Support System Connections
    Config -.-> Server
    Config -.-> APILogic
    Config -.-> Connectors
    Logger -.-> Core
    Logger -.-> Connectors

    %% Styling
    classDef core fill:#2374ab
    classDef middleware fill:#ffb703
    classDef storage fill:#38b000
    classDef external fill:#ff006e
    classDef support fill:#8d99ae

    %% Click Events
    click Server "https://github.com/flagship-io/decision-api/blob/main/pkg/server/server.go"
    click Handlers "https://github.com/flagship-io/decision-api/tree/main/pkg/handlers/"
    click APILogic "https://github.com/flagship-io/decision-api/tree/main/internal/apilogic/"
    click Validation "https://github.com/flagship-io/decision-api/tree/main/internal/validation/"
    click DynamoDB "https://github.com/flagship-io/decision-api/blob/main/pkg/connectors/assignments_managers/dynamo.go"
    click Redis "https://github.com/flagship-io/decision-api/blob/main/pkg/connectors/assignments_managers/redis.go"
    click LocalStorage "https://github.com/flagship-io/decision-api/blob/main/pkg/connectors/assignments_managers/local.go"
    click InMemory "https://github.com/flagship-io/decision-api/blob/main/pkg/connectors/assignments_managers/memory.go"
    click CDN "https://github.com/flagship-io/decision-api/blob/main/pkg/connectors/environment_loaders/cdn.go"
    click DataCollect "https://github.com/flagship-io/decision-api/blob/main/pkg/connectors/hits_processors/datacollect.go"
    click Config "https://github.com/flagship-io/decision-api/tree/main/pkg/utils/config/"
    click Logger "https://github.com/flagship-io/decision-api/blob/main/pkg/utils/logger/logger.go"
    click MW_CORS "https://github.com/flagship-io/decision-api/blob/main/pkg/handlers/middlewares/cors.go"
    click MW_METRICS "https://github.com/flagship-io/decision-api/blob/main/pkg/handlers/middlewares/metrics.go"
    click MW_RECOVERY "https://github.com/flagship-io/decision-api/blob/main/pkg/handlers/middlewares/recover.go"
    click MW_LOGGING "https://github.com/flagship-io/decision-api/blob/main/pkg/handlers/middlewares/request_logger.go"
```
