A modern, real-time chat application built with ASP.NET Core, SignalR, React, and PostgreSQL. Features include real-time messaging, online status tracking, JWT authentication with automatic token refresh, and a beautiful dark mode UI.
- π JWT Authentication with automatic token refresh
- π¬ Real-Time Messaging using SignalR
- π’ Online/Offline Status tracking
- π₯ User Discovery with live registration notifications
- π¨ Modern Dark Mode UI with gradient accents
- π± Fully Responsive - works on desktop, tablet, and mobile
- π Auto-Reconnection with exponential backoff
- π― Optimistic UI Updates for better UX
- ASP.NET Core 9.0 - Web API framework
- SignalR - Real-time communication
- Entity Framework Core - ORM
- PostgreSQL - Database
- JWT Bearer Authentication - Security
- React 18+ - UI library
- Vite - Build tool and dev server
- Axios - HTTP client with interceptors
- @microsoft/signalr - SignalR client
- React Router - Client-side routing
git clone <your-repo-url>
cd ChatAsp- Navigate to the backend folder:
cd MyApp- Copy the example configuration:
cp appsettings.Example.json appsettings.json- Edit
appsettings.jsonwith your settings:
{
"ConnectionStrings": {
"Default": "Host=localhost;Port=5432;Database=asp_chat_db;Username=your_username;Password=your_password"
},
"AppSettings": {
"Token": "your-super-secret-jwt-key-minimum-32-characters-long",
"Issuer": "YourAppIssuer",
"Audience": "YourAppAudience"
},
"Cors": {
"AllowedOrigins": "http://localhost:5173"
}
}- Create a PostgreSQL database:
createdb asp_chat_db- Run migrations:
dotnet ef database updateOr if you don't have EF tools installed:
dotnet tool install --global dotnet-ef
dotnet ef database updatedotnet runBackend will start on http://localhost:5000
- Navigate to the frontend folder:
cd frontend- Copy the example environment file:
cp .env.example .env- The
.envfile should contain:
VITE_API_BASE_URL=http://localhost:5000/api
VITE_SIGNALR_HUB_URL=http://localhost:5000/hub/chatnpm installnpm run devFrontend will start on http://localhost:5173
ChatAsp/
βββ MyApp/ # Backend (ASP.NET Core)
β βββ Controllers/
β β βββ AuthController.cs # Authentication endpoints
β βββ Hubs/
β β βββ ChatHub.cs # SignalR hub for real-time communication
β βββ Infrastructure/
β β βββ PasswordHasher.cs # Password hashing utilities
β βββ Migrations/ # EF Core migrations
β βββ Models/
β β βββ AppDbContext.cs # Database context
β β βββ AppUser.cs # User entity
β β βββ AppRoom.cs # Chat room entity
β β βββ AppMessage.cs # Message entity
β β βββ AppUserConnection.cs # SignalR connection tracking
β βββ Services/
β β βββ AuthService.cs # Authentication logic
β β βββ UserService.cs # User management
β β βββ RealtimeService.cs # SignalR data access
β β βββ DTOS/ # Data transfer objects
β βββ appsettings.Example.json # Example configuration
β βββ Program.cs # Application entry point
β
βββ frontend/ # Frontend (React)
βββ src/
β βββ components/
β β βββ auth/ # Authentication components
β β βββ home/ # Main app components
β β βββ Home.jsx # Main layout
β β βββ ChatModal.jsx # Chat interface
β β βββ ConversationsSidebar.jsx # Active chats
β β βββ UserList.jsx # User discovery
β βββ services/
β β βββ AxiosProvider.js # HTTP client with auth
β β βββ SignalRService.js # SignalR client
β βββ App.jsx # Root component
βββ .env.example # Example environment variables
βββ package.json
- Access tokens (short-lived, ~15min)
- Refresh tokens (long-lived, ~7 days)
- Automatic token refresh on 401 errors
- Secure password hashing with BCrypt
- JWT authentication for WebSocket connections
- User-scoped message delivery
- Connection tracking per user
- Modern slate/navy color scheme
- Purple/pink gradient accents
- High contrast for readability
- Custom scrollbars
- Desktop (1200px+): Two-column layout with sidebar
- Tablet (768px-1199px): Stacked layout, compact header
- Mobile (< 768px): Single column, touch-optimized
- Small Mobile (< 480px): Ultra-compact, icon-only buttons
- Smooth transitions and micro-interactions
- Slide-in modals and messages
- Fade effects for status changes
- Loading spinners
{
"ConnectionStrings": {
"Default": "PostgreSQL connection string"
},
"AppSettings": {
"Token": "JWT secret key (min 32 chars)",
"Issuer": "JWT issuer",
"Audience": "JWT audience"
},
"Cors": {
"AllowedOrigins": "Comma-separated list of allowed origins"
}
}VITE_API_BASE_URL=http://localhost:5000/api
VITE_SIGNALR_HUB_URL=http://localhost:5000/hub/chatPOST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/auth/refresh-token?token=...- Refresh access token
GET /api/user/users- List all users (authenticated)
GET /api/chat/messages/{roomId}- Get message historyGET /api/chat/rooms/{userId}- Get user's chat rooms
CreateOrJoinChatRoom(int otherUserId)- Start/join chatSendMessage(int roomId, string messageContent)- Send message- Events:
ReceiveMessage,UserJoined,UserStatusChanged,UserRegistered
- Update
appsettings.jsonwith production database and secrets - Set
ASPNETCORE_ENVIRONMENT=Production - Build the app:
dotnet publish -c Release- Run with Kestrel or deploy to Azure/AWS/Docker
- Update
.envwith production API URL:
VITE_API_BASE_URL=https://your-api.com/api
VITE_SIGNALR_HUB_URL=https://your-api.com/hub/chat- Build:
npm run build- Deploy the
dist/folder to Vercel, Netlify, or any static host
If you encounter HotReloadException errors:
# Stop dotnet watch and restart
dotnet run- Verify JWT token is valid
- Check CORS configuration matches frontend URL
- Ensure WebSocket support is enabled
# Reset database (WARNING: deletes all data)
dotnet ef database drop
dotnet ef database updateThis project is open source and available under the MIT License.
Built as a learning project to explore SignalR, real-time web applications, and modern React patterns.
- ASP.NET Core Team for SignalR
- React Team for the amazing framework
- Tailwind inspiration for the color scheme



