Skip to content

punkouter26/PoJoker

Repository files navigation

Po.Joker - The Digital Jester πŸƒ

An autonomous AI comedy application that fetches multi-part jokes, predicts punchlines using Azure OpenAI, rates them across multiple dimensions, and delivers an immersive medieval-themed comedy showβ€”all without user input.

Status: Active Development
.NET 10 Blazor Azure Tests License

🎭 Features

  • Passive Comedy Loop: Autonomous, never-ending comedy show
  • AI Punchline Prediction: GPT-4 attempts to guess punchlines before reveal
  • Medieval Dark Theme: Immersive Gothic UI with custom fonts
  • Text-to-Speech: British male voice narration
  • Audio Effects: Drum roll before reveals, trombone on failures
  • Joke Ratings: Cleverness, Rudeness, Complexity, and Difficulty scores
  • Leaderboards: Browse historical jokes by rating category
  • Diagnostics: Health checks for all external dependencies

πŸš€ Quick Start

Prerequisites

Local Development with .NET Aspire (Recommended)

Single command to start everything:

dotnet run --project src/PoJoker.AppHost

This will:

  • πŸš€ Start the Aspire Dashboard for monitoring all services
  • πŸ“¦ Spin up Azurite container for local storage (persistent across restarts)
  • 🌐 Launch the Po.Joker Blazor application
  • πŸ”— Automatically wire up all service connections

The Aspire Dashboard will open automatically and show:

  • All running services and their status
  • Real-time logs from all services
  • Distributed traces across requests
  • Metrics and health checks

Configure AI Features (Optional)

cd src/PoJoker.AppHost
dotnet user-secrets set "Azure:OpenAI:Endpoint" "your-endpoint"

Alternative: Standalone Development

If you prefer not to use Aspire:

  1. Start Azurite manually

    azurite --silent --location ./azurite --debug ./azurite/debug.log
  2. Run the application directly

    dotnet run --project src/Po.Joker

Running Tests

# Unit tests
dotnet test tests/Po.Joker.Tests.Unit

# All tests with coverage
dotnet test --collect:"XPlat Code Coverage"

# E2E tests (requires browser)
dotnet test tests/Po.Joker.Tests.E2E

πŸ—οΈ Architecture

This application uses .NET Aspire for orchestration and service discovery.

PoJoker/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ PoJoker.AppHost/        # πŸš€ Aspire orchestrator (start here!)
β”‚   β”œβ”€β”€ PoJoker.ServiceDefaults/ # Shared service defaults (telemetry, resilience)
β”‚   β”œβ”€β”€ Po.Joker/               # Server-side Blazor + API endpoints
β”‚   β”‚   β”œβ”€β”€ Features/           # Vertical slice architecture
β”‚   β”‚   β”‚   β”œβ”€β”€ Jokes/          # Joke fetching from JokeAPI
β”‚   β”‚   β”‚   β”œβ”€β”€ Analysis/       # AI punchline prediction
β”‚   β”‚   β”‚   β”œβ”€β”€ Leaderboards/   # Historical joke rankings
β”‚   β”‚   β”‚   └── Diagnostics/    # Health checks
β”‚   β”‚   └── Infrastructure/     # Cross-cutting concerns
β”‚   β”œβ”€β”€ Po.Joker.Client/        # Client-side Blazor WASM
β”‚   └── Po.Joker.Shared/        # DTOs and contracts
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ Po.Joker.Tests.Unit/    # xUnit unit tests
β”‚   └── Po.Joker.Tests.E2E/     # Playwright E2E tests
β”œβ”€β”€ infra/                       # Bicep IaC templates
└── docs/                        # Documentation

Aspire Stack

Component Purpose
PoJoker.AppHost Orchestrates all services, manages Azurite container
PoJoker.ServiceDefaults OpenTelemetry, health checks, service discovery, resilience
Po.Joker Main Blazor Server + WASM application
Azurite Local Azure Table Storage emulator (Docker container)

☁️ Azure Deployment

Using GitHub Actions (Recommended)

  1. Configure OIDC authentication (recommended)

    • Create an Azure AD App Registration
    • Add Federated Credentials for your GitHub repository
    • Set repository secrets:
      • AZURE_CLIENT_ID
      • AZURE_TENANT_ID
      • AZURE_SUBSCRIPTION_ID
      • OPENAI_API_KEY
  2. (Alternative) Use a Service Principal secret

    • Create a Service Principal and a client secret in Azure AD.
    • Add a repository secret named AZURE_CREDENTIALS with a JSON value like:
{
  "clientSecret":"<client-secret>",
  "subscriptionId":"<subscription-id>",
  "tenantId":"<tenant-id>",
  "clientId":"<client-id>"
}
  • The workflow should use the azure/login@v2 action with:
with:
  creds: ${{ secrets.AZURE_CREDENTIALS }}
  • Ensure the secret value is valid JSON and contains these keys exactly (case-sensitive): clientId, clientSecret, tenantId, subscriptionId.
  • After adding the secret, the workflow includes a verification step (az account show and azd --version) that will fail early if login doesn't succeed.
  1. Deploy via workflow
    • Push to main branch for automatic deployment
    • Use manual workflow dispatch for specific environments

Manual Deployment with Azure Developer CLI (azd)

# Login to Azure
azd auth login

# Initialize environment (first time only)
azd init

# Provision infrastructure and deploy to Azure Container Apps
azd up

This will:

  • Create Azure Container Registry, Container App Environment, and Container App
  • Build and push the Docker image
  • Deploy the application to Azure Container Apps

πŸ“Š Monitoring

Application Insights

The application includes comprehensive monitoring:

  • Request/response logging
  • AI latency tracking
  • Error rate monitoring
  • Custom metrics for joke analysis

KQL Queries

See docs/kql/ for monitoring queries:

  • error-rates.kql - Error monitoring and anomaly detection
  • ai-latency.kql - AI service performance tracking

πŸ”§ Configuration

Environment Variables

Variable Description Required
OpenAI__ApiKey OpenAI API key for punchline prediction No*
Azure__StorageConnectionString Azure Table Storage connection No*
APPLICATIONINSIGHTS_CONNECTION_STRING App Insights connection No

*Uses mock/local services when not configured

App Settings

{
  "JokeSettings": {
    "CacheEnabled": true,
    "RateLimitPerMinute": 60,
    "SafeMode": true
  }
}

οΏ½ Documentation & Architecture

Comprehensive documentation with visual diagrams is available in the /docs folder:

High-Signal Documentation

  • ProductSpec.md – Business logic, features, success metrics, and scope
  • DevOps.md – CI/CD pipeline, environment secrets, deployment strategies
  • LocalSetup.md – Day 1 onboarding guide, Docker Compose, troubleshooting

Architecture Diagrams (View in Mermaid)

Full Detail Diagrams:

  • Architecture.mmd – C4 System Context: Azure services, Managed Identity, all connections
  • ApplicationFlow.mmd – User journey: Auth β†’ Comedy loop β†’ Leaderboard navigation
  • DataModel.mmd – Entity Relationship Diagram: Joke, Performance Score, Leaderboard entities
  • ComponentMap.mmd – Component tree: Frontend hierarchy + Backend service dependencies
  • DataPipeline.mmd – CRUD workflow: Fetch β†’ Predict β†’ Rate β†’ Store β†’ Display

Simplified Diagrams (High-level Overview):

View Diagrams:

  1. Copy .mmd file content
  2. Paste into Mermaid Live Editor
  3. Or use VS Code Markdown Preview Mermaid Support

Visual Assets

πŸ—οΈ System Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ User Browser (WebSocket/HTTP)                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚ Blazor Web App     β”‚
                    β”‚ (.NET 10)          β”‚
                    β”‚ β€’ JesterStage      β”‚
                    β”‚ β€’ Leaderboard      β”‚
                    β”‚ β€’ Diagnostics      β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                   β”‚                   β”‚
   β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
   β”‚ JokeAPI β”‚      β”‚ Azure OpenAI β”‚    β”‚  Storage β”‚
   β”‚ Public  β”‚      β”‚ (GPT-4)      β”‚    β”‚ (Tables) β”‚
   β”‚ REST    β”‚      β”‚ + Key Vault  β”‚    β”‚ + Azuriteβ”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

See Architecture.mmd for detailed C4 diagram

οΏ½πŸ“ API Endpoints

Endpoint Method Description
/api/jokes/fetch GET Fetch a random joke from JokeAPI
/api/jokes/analyze POST Get AI punchline prediction and ratings
/api/leaderboard GET Retrieve joke leaderboard
/api/diagnostics GET Health check status
/health GET Simple health probe

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors