SnakeAid (Nền tảng hỗ trợ sơ cứu & cứu hộ rắn cắn ứng dụng AI) is a comprehensive backend API infrastructure powering the SnakeAid platform. Designed and built with ASP.NET Core 8, it connects users with experts, rescuers, and community resources related to snake identification, capturing missions, and emergency first aid response.
The backend supports a multi-actor ecosystem defined by four primary modules:
- SOS Setup: Integrates directly with GPS to provide real-time location sharing and emergency dialing (e.g., configuring webhook alerts or SMS).
- First Aid Guidance: Serves step-by-step instructions and warnings against prohibited actions (
SymptomConfig,SnakebiteIncident). - AI-Powered Identification: Endpoints connecting to AI models to analyze images of snakes/bites to determine species, toxicity, and severity (
SnakeAIRecognitionResult.cs). - Facility Locator: Geospatial queries using PostGIS (
NetTopologySuite) to find nearby antivenom treatment centers.
- Live Mission Allocation: Routes rescue requests to nearby rescuers based on proximity (e.g., 5km, 10km radius) and expertise.
- Tracking & Environment Tracking: Domains for
CatchingEnvironmentandCatchingMissionDetailto record specific capture scenarios and ensure rescuer safety. - SignalR Hub Notifications: Real-time
/rescuer-huband/mission-hubcommunication matching victims to respondents and streaming location updates. - Rescue Fee Management: Handles transactional status via the PayOS gateway once a mission completes.
- Online Booking System: API endpoints to schedule video or text consultations with verified snake experts.
- Transactional Integrity: Uses strict database transactions to lock time slots and prevent double-booking.
- Payment Gateway Flow: Generates a secure PayOS checkout link, keeping funds in escrow pending completion, and processes webhooks to
ConfirmorCancelbookings interactively. - Species Verification: Expert portals to manually verify or correct AI-identified snake instances.
- Data Management: Aggregates reporting metrics for community safety, manages treatment facility data, and handles user role permissions.
- Financial Reconciliation: Tracks total platform revenue, processes rescue and consultation splits, and calculates insurance payouts and net income.
This project strictly adheres to Clean Architecture / Onion Architecture principles with distinct layers:
- SnakeAid.Core: Domain models, Entities, Enums, DTOs (Requests/Responses), mappings, and exceptions.
- SnakeAid.Repository: Data access layer via Entity Framework Core, implementing the Generic Repository Pattern and
IUnitOfWork. - SnakeAid.Service: Business logic encapsulation interacting with Repositories.
- SnakeAid.Api: ASP.NET Core Controllers, Swagger integrations, SignalR Hubs, and Razor Pages UI.
- Framework: .NET 8 SDK
- Database: PostgreSQL hosted on Supabase (with Npgsql & NetTopologySuite for spatial data).
- ORM: Entity Framework Core.
- Mapping: Mapster for DTO to Entity conversions.
- Real-Time Communication: SignalR (
/chat-hub,/rescuer-hub,/mission-hub). - Payment Gateway: PayOS integration (
SnakeAid.Service.Services.PayOs). - Configuration Management: Doppler Cloud.
- Logging & Monitoring: Serilog with SQLite storage, Health Checks
/health. - Email Providers: Resend & SMTP configured via factory pattern.
[HttpPost("payment-callback")]
public async Task<IActionResult> HandleCallback([FromBody] PayOsWebhookData webhook)
{
await ExecuteInTransactionAsync(async () => {
var booking = await Context.Bookings.FindAsync(webhook.OrderCode);
if (webhook.Success) {
booking.Status = BookingStatus.Confirmed;
} else {
booking.Status = BookingStatus.Cancelled;
await RollbackAsync();
}
});
return Ok();
}- .NET 8 SDK
- PostgreSQL Database (with PostGIS extensions for spatial queries)
- Docker (Optional)
- Clone the repository.
- Create
.envor properly duplicateappsettings.Example.jsonintoappsettings.json. - Provide essential external keys:
SupabaseConnectionPayOSintegration keys (ClientId,ApiKey,ChecksumKey)DopplerCloud(Optional based on local execution)
# Navigate to API project
cd SnakeAid.Api
# Restore workloads
dotnet restore
# Run API (Listens on ports 8080/8081 locally)
dotnet runAccess Swagger UI: http://localhost:8080 / https://localhost:8081
SnakeAid.Backend/
├── SnakeAid.Api/ # Controllers, Middlewares, SignalR Hubs, Webhooks
├── SnakeAid.Core/ # Interfaces, DTOs, Entities, Constants, Enums
├── SnakeAid.Repository/ # AppDbContext, Migrations, Repositories, Seeds
├── SnakeAid.Service/ # Business Layer, Third-party service integrations
├── File configurations # Dockerfile, Jenkinsfile, docker-compose.yml
└── README.md
Maintain standard pull-request policies. Verify code formatting and CI/CD pipelines before integration.