# nika2811/fintech-solution architecture

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

- Interactive diagram: https://gitdiagram.com/nika2811/fintech-solution
- Repository: https://github.com/nika2811/fintech-solution

## Overview

##### High-Level Components

a) Client-Facing Layer:
- API Gateway (Ocelot)
- Swagger Documentation endpoints

b) Core Microservices:
- Identity Service
- Order Service
- Payment Processor Service

c) Infrastructure Components:
- RabbitMQ (Message Broker)
- PostgreSQL Databases (one per service)
- Consul (Service Discovery)
- Observability Stack:
- OTEL Collector
- Grafana
- Prometheus
- Loki
- Tempo

##### Component Relationships

a) External Communications:
- Client requests → API Gateway
- API Gateway → Individual Services

b) Inter-Service Communications:
- Order Service ↔ Identity Service (authentication)
- Order Service ↔ Payment Processor (payment processing)
- Services → RabbitMQ (event publishing)
- Services ← RabbitMQ (event consumption)

c) Data Layer:
- Each service → Its dedicated PostgreSQL database

##### Specific Implementation Details

Architectural patterns:

a) For Each Microservice:
- API Endpoints
- Services Layer
- Repository Layer
- Database Context

b) Cross-Cutting Concerns:
- Rate Limiting
- Error Handling Middleware
- Authentication/Authorization
- Observability Integration

##### Event Flow Patterns

Event-driven architecture:
- Payment Processing Events
- Order Status Updates
- Asynchronous Communication Paths

##### Specific Implementation Notes

Annotations for:

a) Identity Service:
- Company registration flow
- API credential management
- Authentication endpoints

b) Order Service:
- Order creation and validation
- Payment status handling
- Daily limit checking ($10,000)

c) Payment Processor:
- Payment routing logic
- External payment service integration
- Status update broadcasting

##### Infrastructure Details

a) Containerization:
- Docker containers for each service
- Docker Compose orchestration

b) Monitoring Stack:
- Metrics flow to Prometheus
- Logs to Loki
- Traces to Tempo
- Grafana dashboards

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CL[Client Applications]
    end

    subgraph Gateway
        AG[API Gateway]:::gateway
        SW[Swagger Documentation]:::docs
    end

    subgraph Services
        subgraph IS[Identity Service]
            IS_API[API Layer]:::api
            IS_SVC[Service Layer]:::service
            IS_REPO[Repository Layer]:::repo
            IS_DB[(PostgreSQL)]:::database
        end

        subgraph OS[Order Service]
            OS_API[API Layer]:::api
            OS_SVC[Service Layer]:::service
            OS_REPO[Repository Layer]:::repo
            OS_DB[(PostgreSQL)]:::database
        end

        subgraph PS[Payment Processor]
            PS_API[API Layer]:::api
            PS_SVC[Service Layer]:::service
            PS_REPO[Repository Layer]:::repo
            PS_DB[(PostgreSQL)]:::database
        end
    end

    subgraph Infrastructure
        RMQ{{RabbitMQ}}:::messagebroker
        CONSUL[Consul Service Discovery]:::infra
        
        subgraph Observability
            OTEL[OTEL Collector]:::observability
            GRAF[Grafana]:::observability
            PROM[Prometheus]:::observability
            LOKI[Loki]:::observability
            TEMPO[Tempo]:::observability
        end
    end

    subgraph CrossCutting
        RL[Rate Limiting]:::security
        EH[Error Handling]:::security
        AUTH[Authentication]:::security
    end

    %% Connections
    CL --> AG
    AG --> IS_API
    AG --> OS_API
    AG --> PS_API

    %% Service Interactions
    OS_API <--> IS_API
    OS_API <--> PS_API

    %% Database Connections
    IS_API --> IS_SVC
    IS_SVC --> IS_REPO
    IS_REPO --> IS_DB

    OS_API --> OS_SVC
    OS_SVC --> OS_REPO
    OS_REPO --> OS_DB

    PS_API --> PS_SVC
    PS_SVC --> PS_REPO
    PS_REPO --> PS_DB

    %% Message Broker
    IS_SVC <-.-> RMQ
    OS_SVC <-.-> RMQ
    PS_SVC <-.-> RMQ

    %% Infrastructure Connections
    IS_API --> CONSUL
    OS_API --> CONSUL
    PS_API --> CONSUL

    IS_API --> OTEL
    OS_API --> OTEL
    PS_API --> OTEL

    OTEL --> PROM
    OTEL --> LOKI
    OTEL --> TEMPO
    PROM --> GRAF
    LOKI --> GRAF
    TEMPO --> GRAF

    %% Click Events
    click AG "https://github.com/nika2811/Fintech-Solution/tree/master/OcelotApiGateway"
    click IS "https://github.com/nika2811/Fintech-Solution/tree/master/IdentityService"
    click OS "https://github.com/nika2811/Fintech-Solution/tree/master/OrderService"
    click PS "https://github.com/nika2811/Fintech-Solution/tree/master/PaymentProcessorService"
    click RMQ "https://github.com/nika2811/Fintech-Solution/blob/master/IdentityService/StartupExtensions/MassTransit/MassTransitConfiguration.cs"
    click CONSUL "https://github.com/nika2811/Fintech-Solution/tree/master/IdentityService/StartupExtensions/Consul"
    click OTEL "https://github.com/nika2811/Fintech-Solution/blob/master/config/otel-collector-config.yaml"
    click GRAF "https://github.com/nika2811/Fintech-Solution/tree/master/config/grafana"
    click PROM "https://github.com/nika2811/Fintech-Solution/blob/master/config/prometheus.yml"
    click LOKI "https://github.com/nika2811/Fintech-Solution/blob/master/config/loki/loki-config.yaml"
    click TEMPO "https://github.com/nika2811/Fintech-Solution/blob/master/config/tempo/tempo-config.yaml"
    click EH "https://github.com/nika2811/Fintech-Solution/blob/master/IdentityService/Middleware/ErrorHandlingMiddleware.cs"
    click RL "https://github.com/nika2811/Fintech-Solution/tree/master/IdentityService/StartupExtensions/RateLimiter"
    click AUTH "https://github.com/nika2811/Fintech-Solution/tree/master/OrderService/Services/Auth"

    %% Styles
    classDef gateway fill:#9932CC,stroke:#333,stroke-width:2px
    classDef docs fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef api fill:#87CEEB,stroke:#333,stroke-width:1px
    classDef service fill:#98FB98,stroke:#333,stroke-width:1px
    classDef repo fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef database fill:#20B2AA,stroke:#333,stroke-width:2px
    classDef messagebroker fill:#FFD700,stroke:#333,stroke-width:2px
    classDef infra fill:#A9A9A9,stroke:#333,stroke-width:1px
    classDef observability fill:#B8860B,stroke:#333,stroke-width:1px
    classDef security fill:#FF6347,stroke:#333,stroke-width:1px
```
