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.
- .NET 6.0 SDK
- Git
- Visual Studio Code (recommended) or Visual Studio 2022
- Clone the repository
git clone https://github.com/yourusername/TwitchAnalytics.git
cd TwitchAnalytics
- Create required mock data files:
mkdir -p src/TwitchAnalytics/Data
# Create twitch-mock-data.json, twitch-streams-mock.json, and twitch-users-mock.json
- Build the project:
dotnet build
- Run the project:
cd src/TwitchAnalytics
dotnet run
- Run code formatting:
dotnet format
- Run linting (StyleCop analysis):
dotnet build /p:TreatWarningsAsErrors=true
The API will be available at:
- Swagger UI: https://localhost:7059/swagger
- API Base URL: https://localhost:7059/analytics
This use case retrieves detailed information about a Twitch streamer by their ID.
- Client requests streamer information via GET endpoint
- Service validates the streamer ID
- Manager retrieves streamer data from
Data/twitch-mock-data.json
- Returns streamer information or appropriate error
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
This use case retrieves and enriches the top live streams from Twitch, combining stream data with broadcaster information.
- Get top streams from
Data/twitch-streams-mock.json
- Get user details from
Data/twitch-users-mock.json
- Combine both datasets
- Return enriched stream information
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
-
API Layer (Controllers)
- HTTP request/response handling
- Input validation
- Route definitions
- Error handling
-
Application Layer (Services)
- Use case orchestration
- Business logic coordination
- Input validation
-
Domain Layer (Managers)
- Business logic
- Domain models
- Interface definitions
-
Infrastructure Layer
- External service implementations
- Data access
- Mock data providers
- 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)
- 4 spaces indentation
- LF line endings
- Organized using directives
- Consistent C# code style rules
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