An open API service indexing awesome lists of open source software.

https://github.com/nithinmohantk/genai-boilerplate-dotnet

.NET version of GenAI boilerplate with ASP.NET Core Web API backend, React frontend, multi-tenant architecture, JWT authentication, PostgreSQL/Redis integration, and AI chat capabilities using OpenAI API
https://github.com/nithinmohantk/genai-boilerplate-dotnet

boilerplate boilerplate-application boilerplate-front-end dotnet genai-chatbot llm multi-model reactjs

Last synced: 2 months ago
JSON representation

.NET version of GenAI boilerplate with ASP.NET Core Web API backend, React frontend, multi-tenant architecture, JWT authentication, PostgreSQL/Redis integration, and AI chat capabilities using OpenAI API

Awesome Lists containing this project

README

          

# πŸ€– GenAI Chatbot Boilerplate (.NET)

A production-ready, multi-tenant GenAI chatbot platform built with **ASP.NET Core**, **React**, and **PostgreSQL**. Features real-time chat, document processing, RAG capabilities, and comprehensive admin management.

## ✨ Key Features

### 🎯 **Core Functionality**
- **Real-time WebSocket Chat** with typing indicators and message broadcasting
- **Multi-tenant Architecture** with complete tenant isolation
- **Document Upload & RAG** with automatic text extraction and chunking
- **AI Model Integration** supporting OpenAI, Anthropic, Google, and custom models
- **Chat History Persistence** with full message search and session management

### πŸ” **Authentication & Security**
- **JWT Authentication** with refresh token rotation
- **OAuth Support** framework (Google, Microsoft, Apple ready)
- **Role-Based Access Control** (Super Admin, Tenant Admin, User, Viewer)
- **Multi-factor Security** with BCrypt password hashing
- **API Key Management** for tenant-specific AI provider keys

### πŸ‘‘ **Admin Center**
- **Tenant Management** - Create, configure, and monitor tenants
- **User Management** - Role assignment, activation/deactivation
- **System Statistics** - Usage metrics and analytics
- **API Key Configuration** - Secure AI provider key management
- **Real-time Monitoring** - Connection stats and system health

### πŸ—οΈ **Technical Excellence**
- **Clean Architecture** - Domain-driven design with proper layer separation
- **Entity Framework Core** - Code-first approach with PostgreSQL
- **Type Safety** - Full C# type safety and validation
- **Dependency Injection** - Built-in ASP.NET Core DI container
- **Health Checks & Metrics** - Kubernetes-ready with health endpoints

## πŸš€ Quick Start

### Prerequisites
- **.NET 9.0+** and **Node.js 18+**
- **PostgreSQL 13+** and **Redis 6+**
- **Git** for cloning

### 1. Clone & Setup
```bash
git clone https://github.com/nithinmohantk/genai-boilerplate-dotnet.git
cd genai-boilerplate-dotnet
```

### 2. Backend Setup
```bash
# Navigate to backend
cd backend

# Restore packages
dotnet restore

# Update database connection string in appsettings.json
# Then run the application
dotnet run --project GenAIBoilerplate.API
```
πŸŽ‰ **Backend running at https://localhost:5001**

### 3. Frontend Setup
```bash
# In a new terminal, navigate to frontend
cd frontend
npm install
npm start
```
πŸŽ‰ **Frontend running at http://localhost:3000**

### 4. Database Setup
The application will automatically create the database on first run. For production, use Entity Framework migrations:

```bash
# Add migration
dotnet ef migrations add InitialCreate --project GenAIBoilerplate.Infrastructure --startup-project GenAIBoilerplate.API

# Update database
dotnet ef database update --project GenAIBoilerplate.Infrastructure --startup-project GenAIBoilerplate.API
```

## πŸ“š API Documentation

### Authentication Endpoints
```bash
POST /api/v1/auth/login # User login
POST /api/v1/auth/register # User registration
POST /api/v1/auth/refresh # Token refresh
GET /api/v1/auth/me # Current user info
PUT /api/v1/auth/me # Update profile
POST /api/v1/auth/logout # User logout
```

### Chat Endpoints
```bash
POST /api/v1/chat/sessions # Create chat session
GET /api/v1/chat/sessions # List user sessions
GET /api/v1/chat/sessions/{id} # Get session with messages
POST /api/v1/chat/completions # Generate AI response
GET /api/v1/chat/models # Available AI models
GET /api/v1/chat/search # Search sessions
```

### Document Endpoints
```bash
POST /api/v1/documents/upload # Upload document
GET /api/v1/documents/ # List documents
POST /api/v1/documents/{id}/process # Process for RAG
GET /api/v1/documents/{id}/chunks # View document chunks
```

### Admin Endpoints
```bash
GET /api/v1/admin/tenants # Manage tenants (Super Admin)
GET /api/v1/admin/users # Manage users (Tenant Admin)
GET /api/v1/admin/api-keys # Manage API keys
GET /api/v1/admin/system/stats # System statistics
```

### Health Check Endpoints
```bash
GET /health # Application health
GET /api/v1/health/live # Liveness probe
GET /api/v1/health/ready # Readiness probe
```

## πŸ—οΈ Architecture Overview

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ React SPA β”‚ β”‚ ASP.NET Core β”‚ β”‚ PostgreSQL β”‚
β”‚ β”‚ β”‚ Web API β”‚ β”‚ β”‚
β”‚ β€’ Chat UI │◄──►│ β€’ REST API │◄──►│ β€’ Multi-tenant β”‚
β”‚ β€’ Admin Panel β”‚ β”‚ β€’ SignalR Hub β”‚ β”‚ β€’ Chat History β”‚
β”‚ β€’ Auth Flow β”‚ β”‚ β€’ Auth & RBAC β”‚ β”‚ β€’ Documents β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β€’ Document RAG β”‚ β”‚ β€’ Users/Tenants β”‚
β”‚ β€’ AI Integrationβ”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Redis β”‚ β”‚ AI Providers β”‚
β”‚ β”‚ β”‚ β”‚
β”‚ β€’ Sessions β”‚ β”‚ β€’ OpenAI β”‚
β”‚ β€’ Cache β”‚ β”‚ β€’ Anthropic β”‚
β”‚ β€’ SignalR β”‚ β”‚ β€’ Google β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β€’ Custom APIs β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

## πŸ› οΈ Project Structure

```
genai-boilerplate-dotnet/
β”œβ”€β”€ backend/
β”‚ β”œβ”€β”€ GenAIBoilerplate.API/ # Web API project
β”‚ β”‚ β”œβ”€β”€ Controllers/ # API controllers
β”‚ β”‚ β”œβ”€β”€ Program.cs # Application entry point
β”‚ β”‚ └── appsettings.json # Configuration
β”‚ β”œβ”€β”€ GenAIBoilerplate.Core/ # Domain layer
β”‚ β”‚ β”œβ”€β”€ Entities/ # Domain entities
β”‚ β”‚ β”œβ”€β”€ Enums/ # Domain enums
β”‚ β”‚ β”œβ”€β”€ Interfaces/ # Repository interfaces
β”‚ β”‚ └── Common/ # Base classes
β”‚ β”œβ”€β”€ GenAIBoilerplate.Application/ # Application layer
β”‚ β”‚ β”œβ”€β”€ Services/ # Application services
β”‚ β”‚ β”œβ”€β”€ DTOs/ # Data transfer objects
β”‚ β”‚ └── Mappings/ # Object mappings
β”‚ └── GenAIBoilerplate.Infrastructure/ # Infrastructure layer
β”‚ β”œβ”€β”€ Persistence/ # Database context & repositories
β”‚ β”œβ”€β”€ Services/ # External service implementations
β”‚ └── Migrations/ # EF Core migrations
β”œβ”€β”€ frontend/ # React frontend (same as Python version)
β”‚ β”œβ”€β”€ src/
β”‚ β”‚ β”œβ”€β”€ components/
β”‚ β”‚ β”œβ”€β”€ pages/
β”‚ β”‚ └── contexts/
β”‚ └── package.json
β”œβ”€β”€ data/ # Data directories
β”‚ β”œβ”€β”€ documents/
β”‚ β”œβ”€β”€ embeddings/
β”‚ └── uploads/
└── GenAIBoilerplate.sln # Solution file
```

## πŸ”§ Configuration

### Environment Variables
```bash
# Database
ConnectionStrings__DefaultConnection="Host=localhost;Database=genai_chatbot;Username=genai_user;Password=genai_password"

# JWT
JwtSettings__SecretKey="your-super-secret-key-here-change-in-production"
JwtSettings__Issuer="GenAIBoilerplateAPI"
JwtSettings__Audience="GenAIBoilerplateClient"

# Redis
RedisSettings__ConnectionString="localhost:6379"

# AI Providers
AIProviders__OpenAI__ApiKey="sk-your-openai-key"
AIProviders__Anthropic__ApiKey="claude-your-key"
```

### Multi-Model Configuration
Each tenant can configure their own AI provider keys through the admin panel with support for the latest AI models:

#### **OpenAI Models**
- **GPT-4 Series**: GPT-4, GPT-4 Turbo, GPT-4o, GPT-4o Mini, GPT-4.1, GPT-4.1 Mini, GPT-4.1 Nano
- **GPT-3.5 Series**: GPT-3.5 Turbo, GPT-3.5 Turbo 16K
- **GPT-5 Series**: GPT-5, GPT-5.0 Mini, GPT-5.0 Nano ✨ **Latest Release**

#### **Anthropic Models**
- **Claude 3 Series**: Claude 3 Haiku, Claude 3 Sonnet, Claude 3 Opus
- **Claude 3.5 Series**: Claude 3.5 Sonnet, Claude 3.5 Haiku
- **Claude 4.0 Series**: Claude 4.0 Opus, Claude 4.0 Sonnet ✨ **Latest Release**

## 🎭 User Roles & Permissions

### Role Hierarchy
```
Super Admin πŸ† Full system access, manage all tenants
β”‚
Tenant Admin πŸ‘‘ Manage tenant users, settings, API keys
β”‚
Tenant User πŸ‘€ Chat, upload documents, personal settings
β”‚
Tenant Viewer πŸ‘οΈ Read-only access to tenant resources
```

## 🐳 Docker Deployment

### Quick Docker Setup
```bash
# Build and run with docker-compose
docker-compose up --build

# Or run individual services
docker build -t genai-backend ./backend
docker build -t genai-frontend ./frontend

docker run -p 5000:8080 genai-backend
docker run -p 3000:3000 genai-frontend
```

## πŸ§ͺ Testing

### Backend Tests
```bash
cd backend

# Run tests
dotnet test

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"
```

### Frontend Tests
```bash
cd frontend

# Run component tests
npm test

# Run E2E tests
npm run test:e2e
```

## πŸ” Monitoring & Observability

### Health Checks
- `GET /health` - Application health
- `GET /api/v1/health/live` - Liveness probe
- `GET /api/v1/health/ready` - Readiness probe

### Swagger Documentation
- Development: `https://localhost:5001/swagger`
- Comprehensive API documentation with authentication support

## 🚨 Security Features

### Authentication Security
- **JWT with configurable algorithms** (HS256, RS256)
- **Refresh Token Rotation** - Automatic token renewal
- **Session Management** - Device tracking and revocation
- **Rate Limiting** - Built-in ASP.NET Core rate limiting

### Data Protection
- **Tenant Isolation** - Complete data separation with EF Core
- **Encrypted Storage** - Passwords with BCrypt
- **Input Validation** - Model validation and sanitization
- **HTTPS Enforcement** - Production security headers

## 🀝 Contributing

### Development Setup
```bash
# Backend development
cd backend
dotnet restore
dotnet build

# Frontend development
cd frontend
npm install
npm run dev
```

### Code Standards
- **C#**: .NET coding standards, nullable reference types
- **JavaScript**: Prettier, ESLint, TypeScript
- **Commits**: Conventional commits format
- **Testing**: Unit + integration test coverage

## πŸ“ž Support & Documentation

- **πŸ› Issues**: [GitHub Issues](https://github.com/nithinmohantk/genai-boilerplate-dotnet/issues)
- **πŸ’¬ Discussions**: [GitHub Discussions](https://github.com/nithinmohantk/genai-boilerplate-dotnet/discussions)
- **πŸ“– Wiki**: [Project Wiki](https://github.com/nithinmohantk/genai-boilerplate-dotnet/wiki)
- **πŸš€ Releases**: [Release Notes](https://github.com/nithinmohantk/genai-boilerplate-dotnet/releases)

## πŸ“„ License

This project is licensed under the **MIT License** - see [LICENSE](LICENSE) file for details.

---

## 🎯 What's Next?

This boilerplate provides a solid foundation for building production GenAI applications with .NET. Here are some potential enhancements:

### Immediate Extensions
- **SignalR Integration** for real-time chat
- **Vector Database Integration** (Pinecone, Weaviate, Chroma)
- **Advanced RAG** with semantic chunking and reranking
- **Background Jobs** with Hangfire or Quartz.NET

### Advanced Features
- **Multi-language Support** with localization
- **Custom Model Fine-tuning** workflows
- **Analytics Dashboard** with usage insights
- **gRPC Services** for high-performance APIs

### Enterprise Features
- **Azure AD / Identity Server** integration
- **Audit Logging** with compliance reports
- **Multi-database Support** (SQL Server, MySQL)
- **Microservices Architecture** with service mesh

---

**πŸš€ Ready to build the next generation of AI-powered applications with .NET!**

*Built with ❀️ by [Nithin Mohan](https://github.com/nithinmohantk)*