# Microservice architecture
A bit of an oxymoron isn't it? If it needs an architecture diagram to explain it then how _micro_ can it be? The reality is that this microservice is actually several smaller services in a trenchcoat pretending to be one thing. I suppose that makes it just a service.

```mermaid
flowchart TB
    subgraph microservice["✌ 'Microservice' ✌"]
        subgraph rest[REST Interface]
            flask[Flask]
            swag[flasgger]
            swaggerui[Swagger UI]
            swag-->swaggerui
            flask-->swag
        end

        subgraph hw[Hardware Interface]
            soapy[SoapySDR]
            subgraph plugins[Vendor Plugins]
                soapysdrplay[SoapySDRPlay]
                soapyrtlsdr[SoapyRTLSDR]
            end
            soapy<-->plugins
        end

        %%soapy<-->flask
        rest-->hw
        hw-->rest


        subgraph radio["DSP Chain　　　　　　　　　　`"]
            demod["FM Demodulator\n(fm_demod.py)"]
            ffmpeg
        end
        mediamtx["RTSP Relay\n(MediaMTX)"]

        plugins-->|IQ samples|demod
        demod-->|PCM audio|ffmpeg
        ffmpeg-->|RTP stream|mediamtx

        subgraph proxy[Reverse Proxy]
            caddy[Caddy]
            l4[Caddy Layer 4 Plugin]
            %%le[Let's Encrypt]
            style l4 stroke-dasharray: 3 3,opacity: 0.5
            caddy-.->l4
            %%le-->caddy
        end

        flask<-->|HTTP:5000|caddy
        swaggerui<-->|HTTP:5000|caddy
        mediamtx-.->|RTSP:8554|l4
    end
    style microservice opacity: 0.5

    %%rtlsdr[RTL-SDR Driver]-->soapyrtlsdr
    %%sdrplay[SDRPlay Driver]-->soapysdrplay

    subgraph client["Client"]
        control["REST Client\n(Browser)"]
        rtsp["RTSP Renderer\n(VLC)"]
        rtp["RTP Sink\n(VLC/ffplay)"]
        style rtp stroke-dasharray: 3 3,opacity: 0.5
    end
    style client opacity: 0.5

    caddy<-->|HTTPS:443|control
    l4-.->|RTSPS|rtsp
    mediamtx-->|RTSP|rtsp
    ffmpeg-.->|RTP|rtp
```