This project is a simple real-time admin panel example that uses SignalR and Bogus. It demonstrates real-time updates within an admin panel, built on MVC architecture for simplicity.
- Real-time data updates via SignalR
- Mock data generation with Bogus
- Singleton pattern for the statistics service
- In-memory data storage (no database required)
- API endpoint testing with Swagger and Postman
The project follows the Model-View-Controller (MVC) architecture:
- Statistic Model: Stores admin data such as:
- Total users
- Active users
- New users today
- Total sales
- Errors reported
- Statistics Service: Manages statistics without a database. Uses a private
_currentStatistics
field for in-memory data persistence.- generateRandomStatistics(): Creates fake statistics using Bogus.
- updateStatistics(): Updates statistics based on client data and broadcasts changes to all connected users via SignalR.
- StatisticsHub: Facilitates real-time data sharing with clients.
- Sends current statistics upon user connection.
- Broadcasts updates to all connected clients in real-time.
- StatisticsController: Provides API endpoints for managing statistics:
GetCurrentStatistics()
: Retrieves current statistics.UpdateStatistics()
: Updates statistics with client data.ResetStatistics()
: Resets statistics with fresh random values, broadcasting the update in real-time.
- Configures Singleton for
StatisticsService
. - Initializes SignalR and maps endpoints for controllers and the SignalR hub.
- Swagger: Used for testing RESTful endpoints (not for WebSocket connections).
- Postman: Supports WebSocket testing. Uses a specific ASCII character sequence (
0x1e
) sent in Base64 format (eyJwcm90b2NvbCI6Impzb24iLCAidmVyc2lvbiI6MX0e
) to establish a WebSocket handshake.
- Clone the repository.
- Install dependencies.
- Start the project using your IDE or .NET CLI.
- Access the admin panel and API endpoints via Swagger.
- Test real-time updates in Postman using WebSocket connections.
Note: All data is stored in memory for simplicity. Real-time updates are facilitated by SignalR through HubContext
in StatisticsService
.
- C#
- ASP.NET Web API (MVC pattern)
- SignalR (real-time communication)
- Bogus (data mocking)
- Swagger (API testing)
- Postman (WebSocket testing)
This project uses GitHub Actions for CI/CD to automate build, test, and deployment steps.
-
Docker Compose Files:
docker-compose-prod
: Production deployment.docker-compose-test
: Testing environments.docker-file-prod
: Production build.docker-file-test
: Test build.
-
Pipeline Steps:
- Build: Runs on local setup with
docker-compose-prod
,docker-compose-test
, anddocker-compose-api
. - Test: Utilizes
docker-compose-test
for functionality validation. - Deploy: Deploys via
docker-compose-app
after successful tests.
- Build: Runs on local setup with
This CI/CD setup ensures streamlined building, testing, and deployment, enhancing development efficiency.