# zrks/namedays architecture

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

- Interactive diagram: https://gitdiagram.com/zrks/namedays
- Repository: https://github.com/zrks/namedays

## Overview

##### Project Type and Purpose
- This is a Go-based application with its core business logic implemented in the pkg directory (specifically the "recipes" package containing namedayMemStore.go).
- The project appears to serve a specific “namedays” related functionality (possibly an API or service to deliver nameday information) and includes testing (main_test.go and JSON test data).
- Additionally, the project has infrastructure-as-code (Terraform files in the do-infra and k3d-infra directories) for deployment in different environments (DigitalOcean, K3d local cluster) and configuration for containerization (Dockerfile, fly.toml).
- There is also CI/CD support via the GitHub workflows directory.

##### File Structure
- Core Application:
- main.go and main_test.go: the starting point and testing entry.
- pkg/recipes: houses key business logic for processing or storing nameday data (e.g., in-memory store).
- Test and Data:
- testdata directory contains JSON files used either for seeding data or for testing purposes.
- Infrastructure/Deployment:
- Terraform directories (do-infra and k3d-infra): define and manage infrastructure on cloud (DigitalOcean) and local Kubernetes (k3d), including main.tf, variables.tf, outputs.tf.
- Dockerfile and fly.toml: indicate containerization and potential deployment on fly.io.
- CI/CD:
- .github/workflows for automated testing/build steps using Go.

a. Core Application Layer:
- Within this, show the “Business Logic Module” (pkg/recipes) including the Nameday Memory Store component.
- Testing and data loading (from testdata JSON) as supportive components.

b. Infrastructure & Deployment:
- A component for containerization (Docker image built from the Dockerfile).
- Nodes for deployment platforms:
- Cloud Infrastructure on DigitalOcean (illustrated with the "do-infra" Terraform configuration).
- Local Kubernetes cluster via K3d (illustrated with "k3d-infra" config files).
- Deployment on fly.io using fly.toml.
- To the Docker container to emphasize the deployment flow.

c. CI/CD Pipeline:
- CI/CD system using GitHub Actions (depicting the workflows in .github/workflows) which trigger builds and tests.

d. External Integrations:

##### Architectural Patterns & Design Principles
- The design suggests a separation between the business logic (in pkg) and the deployment/infrastructure configuration.
- The use of Terraform to provision and manage infrastructure hints at an Infrastructure-as-Code (IaC) paradigm.
- Test automation pathways (from main_test.go and testdata).

##### Elements
- "Main Application (main.go)"
- "Business Logic (pkg/recipes - Nameday Memory Store)"
- "Test Data (testdata JSON Files)"
- "Container (Docker)"
- "Deployment Platforms (DigitalOcean, K3d, Fly.io)"
- "CI/CD (GitHub Actions)"
- Data/instruction flow (e.g., from GitHub Actions triggering tests/builds, then building a Docker container).
- Deployment flow (from the Docker container to various infrastructure elements configured by Terraform).

##### Extra Details
- If possible, include notation for external monitoring tools or integration endpoints (like the SonarCloud badge in the README) to acknowledge quality checks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    subgraph "Application Layer"
        MA["Main Application (main.go)"]:::application
        TS["Tests (main_test.go)"]:::application
        BL["Business Logic (pkg/recipes - Nameday Memory Store)"]:::application
        MA -->|"calls"| BL
        TS -->|"uses"| TD1
        subgraph "Test Data"
            TD1["nameday_data.json"]:::application
            TD2["namedays.json"]:::application
            TD1 --> TD2
        end
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        CI["CI/CD (GitHub Actions)"]:::cicd
    end

    %% Containerization & Deployment Configuration
    subgraph "Containerization & Deployment Config"
        DF["Dockerfile"]:::container
        FLY["fly.toml"]:::container
        DF --> DI["Docker Image"]:::container
        FLY --> DI
    end

    %% Deployment Platforms
    subgraph "Deployment Platforms"
        subgraph "DigitalOcean Deployment"
            DO1["main.tf"]:::deployment
            DO2["variables.tf"]:::deployment
            DO1 --> DO2
        end
        subgraph "K3d Deployment"
            K31["k3d-default.yaml"]:::deployment
            K32["main.tf"]:::deployment
            K33["outputs.tf"]:::deployment
            K34["variables.tf"]:::deployment
            K31 --> K32 --> K33 --> K34
        end
        FL["Fly.io Deployment"]:::deployment
    end

    %% Connections from Application to CI/CD
    MA -->|"commit"| CI
    TS -->|"commit"| CI

    %% Connection from CI/CD to Containerization
    CI -->|"builds"| DF
    CI --> FLY

    %% Deployment from Docker Image
    DI -->|"deploys"| DO1
    DI -->|"deploys"| K31
    DI -->|"deploys"| FL

    %% Click Events
    click MA "https://github.com/zrks/namedays/blob/main/main.go"
    click TS "https://github.com/zrks/namedays/blob/main/main_test.go"
    click BL "https://github.com/zrks/namedays/blob/main/pkg/recipes/namedayMemStore.go"
    click TD1 "https://github.com/zrks/namedays/blob/main/testdata/nameday_data.json"
    click TD2 "https://github.com/zrks/namedays/blob/main/testdata/namedays.json"
    click CI "https://github.com/zrks/namedays/blob/main/.github/workflows/go.yml"
    click DF "https://github.com/zrks/namedays/tree/main/Dockerfile"
    click FLY "https://github.com/zrks/namedays/blob/main/fly.toml"
    click DO1 "https://github.com/zrks/namedays/blob/main/do-infra/main.tf"
    click DO2 "https://github.com/zrks/namedays/blob/main/do-infra/variables.tf"
    click K31 "https://github.com/zrks/namedays/blob/main/k3d-infra/k3d-default.yaml"
    click K32 "https://github.com/zrks/namedays/blob/main/k3d-infra/main.tf"
    click K33 "https://github.com/zrks/namedays/blob/main/k3d-infra/outputs.tf"
    click K34 "https://github.com/zrks/namedays/blob/main/k3d-infra/variables.tf"

    %% Styles
    classDef application fill:#ffdead,stroke:#333,stroke-width:2px;
    classDef cicd fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef container fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef deployment fill:#ffd700,stroke:#333,stroke-width:2px;
```
