# gilmae/maat architecture

> Architecture diagram of the GitHub repository gilmae/maat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gilmae/maat
- Repository: https://github.com/gilmae/maat

## Overview

##### Main Components

a. Core Components:
- Micropub Endpoint (Central Component)
- MicropubController
- QueryController
- MediaEndpoint
- IndieAuth Authentication System
- AccessTokenStore
- AuthenticationRequestStore
- TokenSigning

b. Domain Components:
- Entry Management
- EntryController
- EntryProjection
- Command System
- CommandHandler
- Various Commands (CreateEntry, PublishEntry, etc.)
- Event System
- Event Store
- Event Handlers
- Projections

c. External Integration Components:
- Syndication System
- Multiple Network Support (Twitter, Mastodon, Pinboard)
- SyndicationController
- SyndicationStore
- Webmention System
- WebmentionSender

d. Storage Components:
- PostgreSQL Database (indicated by PgStore)
- File Storage System (FSStore)
- Memory Store

##### Relationship Flows

- Client requests → Micropub Endpoint
- Micropub Endpoint → Command System
- Command System → Event System
- Event System → Projections
- Projections → Storage Components
- Authentication Requests → IndieAuth System
- Syndication System → External Networks

##### Implementation Details

Technical annotations for:
- .NET Core as the primary framework
- PostgreSQL as the database
- IndieAuth authentication protocol
- Supported syndication networks (Twitter, Mastodon, Pinboard)

##### Architectural Patterns to Highlight

- Event Sourcing (shown by Events structure)
- CQRS (Command/Query separation)
- Repository Pattern (various stores)
- Middleware Pipeline Pattern
- Microformat Parsing

##### External Services (Side)

Remember to show the clear separation between write operations (commands) and read operations (queries) as this appears to be a fundamental aspect of the system's design.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        C[Client Requests]:::client
    end

    subgraph "API Layer"
        ME["Media Endpoint"]:::api
        MC["Micropub Controller"]:::api
        QC["Query Controller"]:::api
        click ME "https://github.com/gilmae/maat/blob/main/SV.Maat/Micropub/MediaEndpoint.cs"
        click MC "https://github.com/gilmae/maat/blob/main/SV.Maat/Micropub/MicropubController.cs"
        click QC "https://github.com/gilmae/maat/blob/main/SV.Maat/Micropub/QueryController.cs"
    end

    subgraph "Authentication"
        IAC["IndieAuth Controller"]:::auth
        ATS["Access Token Store"]:::auth
        AURS["Auth Request Store"]:::auth
        TS["Token Signing"]:::auth
        click IAC "https://github.com/gilmae/maat/blob/main/SV.Maat/IndieAuth/IndieAuthController.cs"
        click ATS "https://github.com/gilmae/maat/blob/main/SV.Maat/IndieAuth/AccessTokenStore.cs"
        click AURS "https://github.com/gilmae/maat/blob/main/SV.Maat/IndieAuth/AuthenticationRequestStore.cs"
        click TS "https://github.com/gilmae/maat/blob/main/SV.Maat/IndieAuth/TokenSigning.cs"
    end

    subgraph "Domain Layer"
        EC["Entry Controller"]:::domain
        EP["Entry Projection"]:::domain
        EM["Entry Model"]:::domain
        click EC "https://github.com/gilmae/maat/blob/main/SV.Maat/Entry/EntryController.cs"
        click EP "https://github.com/gilmae/maat/blob/main/SV.Maat/Projections/EntryProjection.cs"
        click EM "https://github.com/gilmae/maat/blob/main/SV.Maat/Entry/Models/Entry.cs"
    end

    subgraph "Command System"
        CH["Command Handler"]:::command
        CE["Create Entry"]:::command
        PE["Publish Entry"]:::command
        click CH "https://github.com/gilmae/maat/blob/main/SV.Maat/CommandHandler.cs"
        click CE "https://github.com/gilmae/maat/blob/main/SV.Maat/Commands/CreateEntry.cs"
        click PE "https://github.com/gilmae/maat/blob/main/SV.Maat/Commands/PublishEntry.cs"
    end

    subgraph "Event System"
        ES["Event Store"]:::event
        EH["Event Handlers"]:::event
        EE["Entry Events"]:::event
        click ES "https://github.com/gilmae/maat/blob/main/Events/IEventStore.cs"
        click EE "https://github.com/gilmae/maat/tree/main/StrangeVanilla.Blogging.Events/Entries/Events/"
    end

    subgraph "External Integration"
        SC["Syndication Controller"]:::external
        SS["Syndication Store"]:::external
        WS["Webmention Sender"]:::external
        MI["Mastodon Integration"]:::external
        TI["Twitter Integration"]:::external
        click SC "https://github.com/gilmae/maat/blob/main/SV.Maat/Syndications/SyndicationController.cs"
        click SS "https://github.com/gilmae/maat/blob/main/SV.Maat/Syndications/SyndicationStore.cs"
        click WS "https://github.com/gilmae/maat/blob/main/SV.Maat/Webmention/WebmentionSender.cs"
        click MI "https://github.com/gilmae/maat/blob/main/SV.Maat/Mastodon/Mastodon.cs"
        click TI "https://github.com/gilmae/maat/blob/main/SV.Maat/ExternalNetworks/Twitter.cs"
    end

    subgraph "Storage Layer"
        PG[(PostgreSQL)]:::storage
        FS[(File Storage)]:::storage
        MS[(Memory Store)]:::storage
        click PG "https://github.com/gilmae/maat/blob/main/SV.Maat/lib/PgStore.cs"
        click FS "https://github.com/gilmae/maat/blob/main/SV.Maat/lib/FileStore/FSStore.cs"
        click MS "https://github.com/gilmae/maat/blob/main/Events/MemoryStore.cs"
    end

    C --> MC & ME & QC
    MC & ME & QC --> IAC
    IAC --> ATS & AURS
    ATS & AURS --> TS
    
    MC --> CH
    CH --> CE & PE
    CE & PE --> ES
    ES --> EH
    EH --> EP
    EP --> EC
    EC --> EM
    
    MC --> SC
    SC --> SS
    SS --> MI & TI
    EC --> WS
    
    EP --> PG & FS
    ES --> MS

    classDef client fill:#e1f5fe,stroke:#01579b
    classDef api fill:#bbdefb,stroke:#1976d2
    classDef auth fill:#c8e6c9,stroke:#388e3c
    classDef domain fill:#fff9c4,stroke:#fbc02d
    classDef command fill:#ffccbc,stroke:#e64a19
    classDef event fill:#ffe0b2,stroke:#f57c00
    classDef external fill:#e1bee7,stroke:#7b1fa2
    classDef storage fill:#fff3e0,stroke:#ef6c00
```
