# top-poop/top-of-the-poops-site architecture

> Architecture diagram of the GitHub repository top-poop/top-of-the-poops-site, 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/top-poop/top-of-the-poops-site
- Repository: https://github.com/top-poop/top-of-the-poops-site

## Overview

##### Main System Components

The system appears to be a microservices-based architecture with the following key components:

a. Core Services:
- Data Service (services/data)
- Badges Service (services/badges and services/badges-dynamic)
- Tiles Service (services/tiles)
- TLS Service (services/tls)
- Postgres Database (services/postgres)
- Monitoring Services (services/rainfall, services/thames)

b. Frontend Layer:
- Web Application (src/main/resources/templates)
- Static Assets (src/main/resources/assets)

c. Backend Layer:
- Kotlin-based API (src/main/kotlin)
- Data Processing Services

**[Frontend Layer]**
- ↓ ↑
**[TLS/Gateway Layer]**
- ↓ ↑
**[Backend Services Layer]**
- ↓ ↑
**[Data Layer]**

##### Key Relationships to Highlight

a. Data Flow:
- How data flows from external sources (Environment Agency, Thames Water) through the data processing services
- How processed data is stored in Postgres
- How the data is served to the frontend through the various services

b. Service Integration:
- How the badges service generates dynamic badges
- Tile service's role in map visualization
- Demonstrate the cron service's scheduled tasks

##### Specific Implementation Details

Technical elements:
- Kotlin/JVM backend (main application)
- Handlebars templating (templates directory)
- PostgreSQL database
- Nginx for serving static content
- Python services for data processing
- Docker containerization (multiple Dockerfiles present)

##### External Integrations

Connections to:
- Environment Agency data sources
- Thames Water data
- Tile services
- Social media sharing capabilities

##### Architectural Patterns

Highlight:
- Microservices architecture
- MVC pattern in the main application
- RESTful API design
- Event-driven data processing

##### External Services Layer

Use standardized symbols:
- Rectangles for services
- Hexagons for external systems

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef data fill:#f1c40f,stroke:#f39c12,color:black
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef database fill:#34495e,stroke:#2c3e50,color:white

    %% External Data Sources
    subgraph ExternalSources
        EA[Environment Agency]:::external
        TW[Thames Water]:::external
        MapService[Map Services]:::external
    end

    %% Frontend Layer
    subgraph Frontend
        Templates[Templates]:::frontend
        Assets[Static Assets]:::frontend
        FrontendTemplates[Page Templates]:::frontend
    end

    %% Gateway Layer
    subgraph Gateway
        TLS[TLS/Gateway]:::security
    end

    %% Backend Services
    subgraph BackendServices
        API[Kotlin API]:::backend
        PageHandlers[Page Handlers]:::backend
        ErrorHandling[Error Handler]:::backend
        APIModels[API Models]:::backend
    end

    %% Service Layer
    subgraph Services
        BadgesService[Badges Service]:::backend
        BadgesDynamic[Dynamic Badges]:::backend
        TilesService[Tiles Service]:::backend
        DataService[Data Service]:::data
        DataProcessing[Data Processing]:::data
    end

    %% Monitoring Services
    subgraph Monitoring
        RainfallMonitor[Rainfall Monitor]:::backend
        ThamesMonitor[Thames Monitor]:::backend
    end

    %% Data Layer
    subgraph DataStorage
        PostgreSQL[(PostgreSQL DB)]:::database
        DBViews[(Database Views)]:::database
        DBLookup[(Lookup Tables)]:::database
        DBModels[Database Models]:::backend
    end

    %% Relationships
    EA --> DataService
    TW --> DataService
    MapService --> TilesService
    
    DataService --> DataProcessing
    DataProcessing --> PostgreSQL
    
    PostgreSQL --> DBViews
    PostgreSQL --> DBLookup
    DBModels --> PostgreSQL
    
    API --> PageHandlers
    PageHandlers --> Templates
    ErrorHandling --> API
    APIModels --> API
    
    TLS --> API
    TLS --> Assets
    TLS --> Templates
    
    BadgesService --> BadgesDynamic
    BadgesDynamic --> PostgreSQL
    
    TilesService --> PostgreSQL
    
    RainfallMonitor --> PostgreSQL
    ThamesMonitor --> PostgreSQL
    
    Templates --> FrontendTemplates

    %% Click Events
    click DataService "https://github.com/top-poop/top-of-the-poops-site/tree/main/services/data/"
    click BadgesService "https://github.com/top-poop/top-of-the-poops-site/tree/main/services/badges/"
    click BadgesDynamic "https://github.com/top-poop/top-of-the-poops-site/tree/main/services/badges-dynamic/"
    click TilesService "https://github.com/top-poop/top-of-the-poops-site/tree/main/services/tiles/"
    click TLS "https://github.com/top-poop/top-of-the-poops-site/tree/main/services/tls/"
    click PostgreSQL "https://github.com/top-poop/top-of-the-poops-site/tree/main/services/postgres/"
    click DBViews "https://github.com/top-poop/top-of-the-poops-site/tree/main/db/views/"
    click DBLookup "https://github.com/top-poop/top-of-the-poops-site/tree/main/db/lookup/"
    click RainfallMonitor "https://github.com/top-poop/top-of-the-poops-site/tree/main/services/rainfall/"
    click ThamesMonitor "https://github.com/top-poop/top-of-the-poops-site/tree/main/services/thames/"
    click Templates "https://github.com/top-poop/top-of-the-poops-site/tree/main/src/main/resources/templates/"
    click Assets "https://github.com/top-poop/top-of-the-poops-site/tree/main/src/main/resources/assets/"
    click API "https://github.com/top-poop/top-of-the-poops-site/tree/main/src/main/kotlin/org/totp/"
    click DataProcessing "https://github.com/top-poop/top-of-the-poops-site/tree/main/services/data/lib/"
    click DBModels "https://github.com/top-poop/top-of-the-poops-site/tree/main/src/main/kotlin/org/totp/db/"
    click PageHandlers "https://github.com/top-poop/top-of-the-poops-site/tree/main/src/main/kotlin/org/totp/pages/"
    click FrontendTemplates "https://github.com/top-poop/top-of-the-poops-site/tree/main/src/main/resources/templates/page/org/totp/pages/"
    click APIModels "https://github.com/top-poop/top-of-the-poops-site/tree/main/src/main/kotlin/org/totp/model/"
    click ErrorHandling "https://github.com/top-poop/top-of-the-poops-site/tree/main/src/main/kotlin/org/totp/model/error/"
```
