|  | 
|  | 1 | +# GitHub Copilot Instructions for EssentialCSharp.Web | 
|  | 2 | + | 
|  | 3 | +## Project Overview & Core Purpose | 
|  | 4 | +This is a comprehensive ASP.NET Core 9.0 web application ecosystem for the **Essential C#** programming education platform. The project serves as the technical foundation for [essentialcsharp.com](https://essentialcsharp.com/), providing educational content, AI-powered chat assistance, and user management for C# learning resources. | 
|  | 5 | + | 
|  | 6 | +**Key Value**: Provides an interactive learning platform where developers can access Essential C# content, engage with AI-powered assistance for C# questions, and track their learning progress through a modern web interface. | 
|  | 7 | + | 
|  | 8 | +**Target Audience**: C# developers at all levels, students learning C#, and educators teaching C# programming concepts. | 
|  | 9 | + | 
|  | 10 | +## Project Structure & Architecture | 
|  | 11 | +This solution follows a modular architecture with clear separation of concerns: | 
|  | 12 | + | 
|  | 13 | +``` | 
|  | 14 | +EssentialCSharp.Web.sln | 
|  | 15 | +├── EssentialCSharp.Web/              # Main ASP.NET Core web application | 
|  | 16 | +│   ├── Areas/                        # Identity and feature-specific areas | 
|  | 17 | +│   ├── Controllers/                  # MVC controllers | 
|  | 18 | +│   ├── Views/                        # Razor views and layouts | 
|  | 19 | +│   ├── Models/                       # View models and data models | 
|  | 20 | +│   ├── Services/                     # Business logic services | 
|  | 21 | +│   ├── Migrations/                   # Entity Framework migrations | 
|  | 22 | +│   └── wwwroot/                      # Static assets (CSS, JS, images) | 
|  | 23 | +├── EssentialCSharp.Chat/             # Console application for AI chat | 
|  | 24 | +├── EssentialCSharp.Chat.Shared/      # Shared models and services | 
|  | 25 | +├── EssentialCSharp.Web.Tests/        # Integration tests for web app | 
|  | 26 | +└── EssentialCSharp.Chat.Tests/       # Unit tests for chat functionality | 
|  | 27 | +``` | 
|  | 28 | + | 
|  | 29 | +## Tech Stack & Core Technologies | 
|  | 30 | + | 
|  | 31 | +### Framework & Runtime | 
|  | 32 | +- **.NET 9.0** with **C# 13** language features | 
|  | 33 | +- **ASP.NET Core 9.0** for web application framework | 
|  | 34 | +- **Entity Framework Core 8.0.10** for data access with SQL Server | 
|  | 35 | +- **ASP.NET Core Identity** for user authentication and authorization | 
|  | 36 | + | 
|  | 37 | +### AI & Chat Integration | 
|  | 38 | +- **Microsoft Semantic Kernel 1.60.0** for AI orchestration | 
|  | 39 | +- **Azure OpenAI** integration for chat functionality | 
|  | 40 | +- **pgvector with PostgreSQL** for vector database operations | 
|  | 41 | +- **Model Context Protocol (MCP)** for AI agent integration | 
|  | 42 | + | 
|  | 43 | +### Authentication & Security | 
|  | 44 | +- **GitHub OAuth** integration for developer authentication | 
|  | 45 | +- **Microsoft Account** authentication support | 
|  | 46 | +- **HCaptcha** for bot protection | 
|  | 47 | +- **JWT tokens** for API authentication | 
|  | 48 | + | 
|  | 49 | +### Development & Deployment | 
|  | 50 | +- **Docker** containerization with multi-stage builds | 
|  | 51 | +- **Azure Application Insights** for telemetry and monitoring | 
|  | 52 | +- **Azure Monitor OpenTelemetry** for observability | 
|  | 53 | +- **Mailjet API** for email services | 
|  | 54 | + | 
|  | 55 | +### Package Management & Build | 
|  | 56 | +- **Central Package Management** via `Directory.Packages.props` | 
|  | 57 | +- **Private NuGet feed** from Azure DevOps for internal packages | 
|  | 58 | +- **Source Link** for debugging support | 
|  | 59 | +- **Build versioning** with continuous integration support | 
|  | 60 | + | 
|  | 61 | +## Coding Conventions & Development Patterns | 
|  | 62 | + | 
|  | 63 | +### Project Structure Conventions | 
|  | 64 | +- **Areas**: Use for Identity and distinct feature modules | 
|  | 65 | +- **Controllers**: Follow MVC pattern with async actions | 
|  | 66 | +- **Services**: Implement business logic with dependency injection | 
|  | 67 | +- **Models**: Separate view models from domain models | 
|  | 68 | +- **Extensions**: Place extension methods in dedicated Extension classes | 
|  | 69 | + | 
|  | 70 | +### Code Style & Patterns | 
|  | 71 | +- **Async/Await**: Use consistently for all I/O operations | 
|  | 72 | +- **Dependency Injection**: Register services in `Program.cs` | 
|  | 73 | +- **Repository Pattern**: Implement for data access abstraction | 
|  | 74 | +- **Error Handling**: Use structured logging and custom exceptions | 
|  | 75 | +- **Configuration**: Use strongly-typed configuration classes | 
|  | 76 | + | 
|  | 77 | +### File Naming & Organization | 
|  | 78 | +- **Controllers**: `{Feature}Controller.cs` (e.g., `HomeController.cs`) | 
|  | 79 | +- **Services**: `{Feature}Service.cs` and `I{Feature}Service.cs` | 
|  | 80 | +- **Models**: `{Entity}Model.cs` for view models, `{Entity}.cs` for domain | 
|  | 81 | +- **Extensions**: `{Type}Extensions.cs` | 
|  | 82 | +- **Tests**: `{ClassUnderTest}Tests.cs` | 
|  | 83 | + | 
|  | 84 | +## Testing Strategy & Frameworks | 
|  | 85 | + | 
|  | 86 | +### Test Organization | 
|  | 87 | +- **Integration Tests**: `EssentialCSharp.Web.Tests` using `Microsoft.AspNetCore.Mvc.Testing` | 
|  | 88 | +- **Unit Tests**: `EssentialCSharp.Chat.Tests` using `xUnit` and `Moq` | 
|  | 89 | +- **Test Structure**: Follow AAA pattern (Arrange, Act, Assert) | 
|  | 90 | + | 
|  | 91 | +### Testing Tools | 
|  | 92 | +- **xUnit 2.9.3** as the primary testing framework | 
|  | 93 | +- **Moq 4.20.72** for mocking dependencies | 
|  | 94 | +- **Coverlet** for code coverage collection | 
|  | 95 | +- **Microsoft.AspNetCore.Mvc.Testing** for integration testing | 
|  | 96 | + | 
|  | 97 | +### Test Conventions | 
|  | 98 | +```csharp | 
|  | 99 | +[Fact] | 
|  | 100 | +public async Task MethodName_Scenario_ExpectedBehavior() | 
|  | 101 | +{ | 
|  | 102 | +    // Arrange | 
|  | 103 | +    var service = new TestService(); | 
|  | 104 | +     | 
|  | 105 | +    // Act | 
|  | 106 | +    var result = await service.MethodAsync(); | 
|  | 107 | +     | 
|  | 108 | +    // Assert | 
|  | 109 | +    Assert.NotNull(result); | 
|  | 110 | +} | 
|  | 111 | +``` | 
|  | 112 | + | 
|  | 113 | +## Build & Development Commands | 
|  | 114 | + | 
|  | 115 | +### Essential Commands | 
|  | 116 | +```bash | 
|  | 117 | +# Restore all packages | 
|  | 118 | +dotnet restore | 
|  | 119 | + | 
|  | 120 | +# Build entire solution | 
|  | 121 | +dotnet build --configuration Release --no-restore | 
|  | 122 | + | 
|  | 123 | +# Run all tests | 
|  | 124 | +dotnet test --no-build --configuration Release | 
|  | 125 | + | 
|  | 126 | +# Run web application | 
|  | 127 | +dotnet run --project EssentialCSharp.Web | 
|  | 128 | + | 
|  | 129 | +# Run chat application | 
|  | 130 | +dotnet run --project EssentialCSharp.Chat | 
|  | 131 | + | 
|  | 132 | +# Entity Framework operations | 
|  | 133 | +dotnet ef migrations add MigrationName --project EssentialCSharp.Web | 
|  | 134 | +dotnet ef database update --project EssentialCSharp.Web | 
|  | 135 | +``` | 
|  | 136 | + | 
|  | 137 | +### Docker Operations | 
|  | 138 | +```bash | 
|  | 139 | +# Build Docker image | 
|  | 140 | +docker build -t essentialcsharp-web -f EssentialCSharp.Web/Dockerfile . | 
|  | 141 | + | 
|  | 142 | +# Run with Docker Compose (if available) | 
|  | 143 | +docker-compose up --build | 
|  | 144 | +``` | 
|  | 145 | + | 
|  | 146 | +## Configuration & Environment Setup | 
|  | 147 | + | 
|  | 148 | +### Required Secrets (Use dotnet user-secrets) | 
|  | 149 | +```bash | 
|  | 150 | +# Email configuration | 
|  | 151 | +dotnet user-secrets set "AuthMessageSender:SendFromName" "Essential C# Team" | 
|  | 152 | +dotnet user-secrets set "AuthMessageSender:SendFromEmail" "[email protected]" | 
|  | 153 | +dotnet user-secrets set "AuthMessageSender:SecretKey" "your-mailjet-secret" | 
|  | 154 | +dotnet user-secrets set "AuthMessageSender:APIKey" "your-mailjet-api-key" | 
|  | 155 | + | 
|  | 156 | +# OAuth providers | 
|  | 157 | +dotnet user-secrets set "Authentication:Microsoft:ClientSecret" "microsoft-oauth-secret" | 
|  | 158 | +dotnet user-secrets set "Authentication:Microsoft:ClientId" "microsoft-oauth-client-id" | 
|  | 159 | +dotnet user-secrets set "Authentication:github:clientSecret" "github-oauth-secret" | 
|  | 160 | +dotnet user-secrets set "Authentication:github:clientId" "github-oauth-client-id" | 
|  | 161 | + | 
|  | 162 | +# Security | 
|  | 163 | +dotnet user-secrets set "HCaptcha:SiteKey" "hcaptcha-site-key" | 
|  | 164 | +dotnet user-secrets set "HCaptcha:SecretKey" "hcaptcha-secret-key" | 
|  | 165 | + | 
|  | 166 | +# Application Insights | 
|  | 167 | +dotnet user-secrets set "APPLICATIONINSIGHTS_CONNECTION_STRING" "your-app-insights-connection" | 
|  | 168 | +``` | 
|  | 169 | + | 
|  | 170 | +### Package Feed Configuration | 
|  | 171 | +- Set `<AccessToNugetFeed>false</AccessToNugetFeed>` in `Directory.Packages.props` if you don't have access to private Azure DevOps feed | 
|  | 172 | +- Private feed contains `EssentialCSharp.Shared.Models` and content packages | 
|  | 173 | + | 
|  | 174 | +## AI Integration Patterns | 
|  | 175 | + | 
|  | 176 | +### Semantic Kernel Usage | 
|  | 177 | +- **Chat Services**: Implement AI chat functionality using Semantic Kernel | 
|  | 178 | +- **Vector Operations**: Use pgvector for semantic search and retrieval | 
|  | 179 | +- **Model Context Protocol**: Integrate with MCP for agent communication | 
|  | 180 | +- **Prompt Engineering**: Store prompts as structured templates | 
|  | 181 | + | 
|  | 182 | +### AI Service Patterns | 
|  | 183 | +```csharp | 
|  | 184 | +public interface IChatService | 
|  | 185 | +{ | 
|  | 186 | +    Task<ChatResponse> ProcessMessageAsync(string message, CancellationToken cancellationToken); | 
|  | 187 | +    Task<IEnumerable<SearchResult>> SearchContentAsync(string query, CancellationToken cancellationToken); | 
|  | 188 | +} | 
|  | 189 | +``` | 
|  | 190 | + | 
|  | 191 | +## Development Workflow & Best Practices | 
|  | 192 | + | 
|  | 193 | +### Code Review Guidelines | 
|  | 194 | +- Ensure all new code includes appropriate tests | 
|  | 195 | +- Follow established naming conventions and patterns | 
|  | 196 | +- Use async/await for all I/O operations | 
|  | 197 | +- Implement proper error handling and logging | 
|  | 198 | +- Add XML documentation for public APIs | 
|  | 199 | + | 
|  | 200 | +### Performance Considerations | 
|  | 201 | +- Use Entity Framework efficiently (avoid N+1 queries) | 
|  | 202 | +- Implement caching where appropriate | 
|  | 203 | +- Use async patterns for database and API calls | 
|  | 204 | +- Optimize Docker image size with multi-stage builds | 
|  | 205 | + | 
|  | 206 | +### Security Best Practices | 
|  | 207 | +- Never commit secrets to source control | 
|  | 208 | +- Use HTTPS for all external communications | 
|  | 209 | +- Implement proper input validation | 
|  | 210 | +- Follow OWASP security guidelines | 
|  | 211 | +- Use parameterized queries for database operations | 
|  | 212 | + | 
|  | 213 | +## Common Patterns & Utilities | 
|  | 214 | + | 
|  | 215 | +### Service Registration Pattern | 
|  | 216 | +```csharp | 
|  | 217 | +// In Program.cs | 
|  | 218 | +builder.Services.AddScoped<IFeatureService, FeatureService>(); | 
|  | 219 | +builder.Services.AddSingleton<ICacheService, CacheService>(); | 
|  | 220 | +``` | 
|  | 221 | + | 
|  | 222 | +### Configuration Pattern | 
|  | 223 | +```csharp | 
|  | 224 | +public class FeatureOptions | 
|  | 225 | +{ | 
|  | 226 | +    public const string SectionName = "Feature"; | 
|  | 227 | +    public string ApiKey { get; set; } = string.Empty; | 
|  | 228 | +    public int TimeoutSeconds { get; set; } = 30; | 
|  | 229 | +} | 
|  | 230 | + | 
|  | 231 | +// Registration | 
|  | 232 | +builder.Services.Configure<FeatureOptions>( | 
|  | 233 | +    builder.Configuration.GetSection(FeatureOptions.SectionName)); | 
|  | 234 | +``` | 
|  | 235 | + | 
|  | 236 | +### Error Handling Pattern | 
|  | 237 | +```csharp | 
|  | 238 | +public async Task<Result<T>> MethodAsync<T>() | 
|  | 239 | +{ | 
|  | 240 | +    try | 
|  | 241 | +    { | 
|  | 242 | +        var result = await SomeOperationAsync(); | 
|  | 243 | +        return Result<T>.Success(result); | 
|  | 244 | +    } | 
|  | 245 | +    catch (SpecificException ex) | 
|  | 246 | +    { | 
|  | 247 | +        logger.LogError(ex, "Operation failed"); | 
|  | 248 | +        return Result<T>.Failure(ex.Message); | 
|  | 249 | +    } | 
|  | 250 | +} | 
|  | 251 | +``` | 
|  | 252 | + | 
|  | 253 | +## Future Roadmap Considerations | 
|  | 254 | +- **Microservices Evolution**: Consider splitting into microservices as features grow | 
|  | 255 | +- **Performance Optimization**: Implement advanced caching and CDN strategies | 
|  | 256 | +- **AI Enhancement**: Expand AI capabilities with more sophisticated models | 
|  | 257 | +- **Mobile Support**: Potential mobile app integration | 
|  | 258 | +- **API Expansion**: RESTful API for third-party integrations | 
|  | 259 | + | 
|  | 260 | +## Anti-Patterns & Gotchas | 
|  | 261 | +- **Avoid**: Synchronous calls in async methods (use ConfigureAwait(false)) | 
|  | 262 | +- **Avoid**: Large Entity Framework queries without pagination | 
|  | 263 | +- **Avoid**: Hardcoded configuration values (use appsettings.json) | 
|  | 264 | +- **Avoid**: Missing error handling in async operations | 
|  | 265 | +- **Security**: Never expose sensitive configuration in client-side code | 
0 commit comments