Skip to content

540/twitch-analytics-c-sharp-testing

Repository files navigation

TwitchAnalytics

TwitchAnalytics is a .NET 6 Web API project that provides analytics and insights for Twitch streamers. The project follows Clean Architecture principles and uses modern .NET practices.

🚀 Getting Started

Prerequisites

  • .NET 6.0 SDK
  • Git
  • Visual Studio Code (recommended) or Visual Studio 2022

Installation

  1. Clone the repository
git clone https://github.com/yourusername/TwitchAnalytics.git
cd TwitchAnalytics
  1. Create required mock data files:
mkdir -p src/TwitchAnalytics/Data
# Create twitch-mock-data.json, twitch-streams-mock.json, and twitch-users-mock.json

Development

  1. Build the project:
dotnet build
  1. Run the project:
cd src/TwitchAnalytics
dotnet run
  1. Run code formatting:
dotnet format
  1. Run linting (StyleCop analysis):
dotnet build /p:TreatWarningsAsErrors=true

The API will be available at:

🎯 Current Features

1. Get Streamer Information

This use case retrieves detailed information about a Twitch streamer by their ID.

Flow

  1. Client requests streamer information via GET endpoint
  2. Service validates the streamer ID
  3. Manager retrieves streamer data from Data/twitch-mock-data.json
  4. Returns streamer information or appropriate error

API Details

Endpoint: GET /analytics/streamer?id={streamerId}

Example Request:

curl -X GET "https://localhost:7059/analytics/streamer?id=12345"

Success Response (200 OK):

{
    "id": "12345",
    "login": "ninja",
    "displayName": "Ninja",
    "type": "",
    "broadcasterType": "partner",
    "description": "Professional Gamer and Streamer",
    "profileImageUrl": "https://example.com/ninja.jpg",
    "offlineImageUrl": "https://example.com/ninja-offline.jpg",
    "viewCount": 500000,
    "createdAt": "2011-11-20T00:00:00Z"
}

Data source: Data/twitch-mock-data.json

Error Responses:

  • 400 Bad Request: Invalid or empty streamer ID
  • 404 Not Found: Streamer not found
  • 500 Internal Server Error: Server-side error

2. Get Enriched Top Streams

This use case retrieves and enriches the top live streams from Twitch, combining stream data with broadcaster information.

Flow

  1. Get top streams from Data/twitch-streams-mock.json
  2. Get user details from Data/twitch-users-mock.json
  3. Combine both datasets
  4. Return enriched stream information

API Details

Endpoint: GET /analytics/streams/enriched?limit={limit}

Parameters:

  • limit (optional): Number of streams to return (default: 3, max: 100)

Example Request:

curl -X GET "https://localhost:7059/analytics/streams/enriched?limit=3"

Success Response (200 OK):

[
   {
      "stream_id": "12345",
      "user_id": "12345",
      "title": "Playing Fortnite!",
      "viewer_count": 20000,
      "game_name": "Fortnite",
      "started_at": "2024-03-20T10:00:00Z",
      "user_display_name": "Ninja",
      "profile_image_url": "https://example.com/ninja.jpg",
      "broadcaster_type": "partner"
   }
]

Data sources:

  • Stream data: Data/twitch-streams-mock.json
  • User data: Data/twitch-users-mock.json

Error Responses:

  • 400 Bad Request: Invalid limit parameter
  • 500 Internal Server Error: Server-side error

🏛️ Architecture

Clean Architecture Layers

  1. API Layer (Controllers)

    • HTTP request/response handling
    • Input validation
    • Route definitions
    • Error handling
  2. Application Layer (Services)

    • Use case orchestration
    • Business logic coordination
    • Input validation
  3. Domain Layer (Managers)

    • Business logic
    • Domain models
    • Interface definitions
  4. Infrastructure Layer

    • External service implementations
    • Data access
    • Mock data providers

🛠️ Code Quality Tools

StyleCop

  • Configuration in StyleCop.ruleset
  • Enforces consistent code style
  • Rules configured:
    • XML documentation requirements disabled (CS1591, SA1600)
    • File headers not required (SA1633)
    • this. prefix optional (SA1101)
    • Trailing commas optional (SA1413)

EditorConfig

  • 4 spaces indentation
  • LF line endings
  • Organized using directives
  • Consistent C# code style rules

Husky.Net

Pre-commit checks:

  • Code formatting: dotnet format TwitchAnalytics.sln
  • StyleCop analysis: dotnet build TwitchAnalytics.sln --no-restore /warnaserror
  • Runs against entire solution to ensure consistency

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published