# navikt/utenlandsadresser architecture

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

- Interactive diagram: https://gitdiagram.com/navikt/utenlandsadresser
- Repository: https://github.com/navikt/utenlandsadresser

## Overview

Key Components to Include:

##### Core Application Components
- Main Application Service (app/)
- Address Fetching Service (hent-utenlandsadresser/)
- Audit Log Cleanup Service (sporingslogg-cleanup/)

##### External Systems Integration
- PDL (Person Data System)
- Skatteetaten
- Kafka Event Stream
- Maskinporten (Authentication)

##### Data Stores
- PostgreSQL Database (for subscriptions and audit logs)

##### Data Flow Representation
- Kafka event streaming from PDL
- REST API calls between components
- Database operations
- Authentication flows through Maskinporten

##### Component Details

a. Main Application Service:
- Subscription Management
- Feed Service
- Address Protection Handler
- API Routes
- Event Consumers

b. Address Fetching Service:
- PDL Integration
- Address Update Logic
- Audit Logging

c. Database Layer:
- Subscription Tables
- Feed Events
- Audit Logs

##### Security Layer
- Maskinporten authentication flow
- Address protection filtering
- Organization number verification

##### Background Processes
- Audit log cleanup job
- Address update processes
- Event consumers

Specific Implementation Guidelines:

##### Monitoring and metrics flow

Key Relationships to Highlight:

##### Cleanup Job → Database (Maintenance)

Important Notes:
- Subscription-based nature of the service
- Address protection filtering mechanism
- 10-year retention policy for audit logs
- Error handling and fallback paths
- Monitoring and alerting paths

## Diagram (Mermaid)

```mermaid
graph TB
    %% Main Services
    MainApp["Main Application Service"]:::service
    AddressFetch["Address Fetching Service"]:::service
    AuditCleanup["Audit Log Cleanup Service"]:::service

    %% External Systems
    PDL["PDL (Person Data)"]:::external
    Skatt["Skatteetaten"]:::external
    Maskinporten["Maskinporten"]:::auth
    KafkaEvents["Kafka Event Stream"]:::messaging

    %% Core Services
    subgraph CoreServices["Core Services"]
        direction TB
        SubService["Subscription Service"]:::core
        FeedService["Feed Service"]:::core
        EventConsumer["Event Consumer"]:::core
        AddressProtection["Address Protection Handler"]:::security
    end

    %% API Layer
    subgraph APIRoutes["API Routes"]
        direction TB
        AddressRoute["Address Route"]:::api
        AuditRoute["Audit Log Route"]:::api
    end

    %% Data Layer
    subgraph DataLayer["Data Layer"]
        direction TB
        DB[(PostgreSQL)]:::database
        SubRepo["Subscription Repository"]:::repo
        FeedRepo["Feed Repository"]:::repo
        AuditRepo["Audit Log Repository"]:::repo
    end

    %% Relationships
    PDL --> KafkaEvents
    KafkaEvents --> EventConsumer
    Maskinporten --> MainApp
    MainApp --> SubService
    MainApp --> FeedService
    SubService --> SubRepo
    FeedService --> FeedRepo
    EventConsumer --> AddressProtection
    AddressProtection --> FeedService
    APIRoutes --> CoreServices
    SubRepo --> DB
    FeedRepo --> DB
    AuditRepo --> DB
    AuditCleanup --> DB
    AddressFetch --> PDL
    MainApp --> Skatt

    %% Click Events
    click MainApp "https://github.com/navikt/utenlandsadresser/blob/main/app/src/main/kotlin/no/nav/utenlandsadresser/Application.kt"
    click AddressFetch "https://github.com/navikt/utenlandsadresser/blob/main/hent-utenlandsadresser/src/main/kotlin/no/nav/utenlandsadresser/hent/utenlandsadresser/Main.kt"
    click AuditCleanup "https://github.com/navikt/utenlandsadresser/blob/main/sporingslogg-cleanup/src/main/kotlin/no/nav/utenlandsadresser/sporingslogg/cleanup/Main.kt"
    click PDL "https://github.com/navikt/utenlandsadresser/blob/main/hent-utenlandsadresser/src/main/kotlin/no/nav/utenlandsadresser/hent/utenlandsadresser/client/pdl/mottak/PdlMottakHttpClient.kt"
    click Maskinporten "https://github.com/navikt/utenlandsadresser/blob/main/app/src/main/kotlin/no/nav/utenlandsadresser/infrastructure/client/http/maskinporten/MaskinportenHttpClient.kt"
    click EventConsumer "https://github.com/navikt/utenlandsadresser/blob/main/app/src/main/kotlin/no/nav/utenlandsadresser/app/LivshendelserConsumer.kt"
    click SubService "https://github.com/navikt/utenlandsadresser/blob/main/app/src/main/kotlin/no/nav/utenlandsadresser/app/AbonnementService.kt"
    click FeedService "https://github.com/navikt/utenlandsadresser/blob/main/app/src/main/kotlin/no/nav/utenlandsadresser/app/FeedService.kt"
    click SubRepo "https://github.com/navikt/utenlandsadresser/blob/main/app/src/main/kotlin/no/nav/utenlandsadresser/infrastructure/persistence/postgres/PostgresAbonnementRepository.kt"
    click FeedRepo "https://github.com/navikt/utenlandsadresser/blob/main/app/src/main/kotlin/no/nav/utenlandsadresser/infrastructure/persistence/postgres/PostgresFeedRepository.kt"
    click AuditRepo "https://github.com/navikt/utenlandsadresser/blob/main/app/src/main/kotlin/no/nav/utenlandsadresser/infrastructure/persistence/postgres/PostgresSporingsloggRepository.kt"
    click AddressProtection "https://github.com/navikt/utenlandsadresser/blob/main/app/src/main/kotlin/no/nav/utenlandsadresser/domain/AdressebeskyttelseGradering.kt"
    click AddressRoute "https://github.com/navikt/utenlandsadresser/blob/main/app/src/main/kotlin/no/nav/utenlandsadresser/infrastructure/route/PostadresseRoute.kt"
    click AuditRoute "https://github.com/navikt/utenlandsadresser/blob/main/app/src/main/kotlin/no/nav/utenlandsadresser/infrastructure/route/SporingsloggRoute.kt"

    %% Styles
    classDef service fill:#2374ab
    classDef external fill:#57a773
    classDef auth fill:#ffc857
    classDef database fill:#484848
    classDef messaging fill:#ff8552
    classDef core fill:#2374ab,stroke-dasharray: 5 5
    classDef security fill:#ff6b6b
    classDef api fill:#4ecdc4
    classDef repo fill:#95a5a6

    %% Legend
    subgraph Legend
        direction TB
        L1["Service"]:::service
        L2["External System"]:::external
        L3["Authentication"]:::auth
        L4["Database"]:::database
        L5["Messaging"]:::messaging
        L6["Security"]:::security
        L7["API"]:::api
        L8["Repository"]:::repo
    end
```
