A modern, real-time chat REST API built with ASP.NET Core 9, SignalR, MongoDB, and Redis caching.
Quick Start β’ Documentation β’ Architecture β’ Contributing
- π Real-time Messaging - WebSocket support via SignalR
- π Secure Authentication - JWT tokens with BCrypt hashing
- πΎ Flexible Database - MongoDB with in-memory fallback
- β‘ Performance - Redis caching (optional)
- π File Storage - Local blob storage for media
- π API Documentation - Swagger UI included
- ποΈ Clean Architecture - Repository + UoW + MediatR CQRS pattern
- π Graceful Degradation - Works without external services
| Component | Technology |
|---|---|
| Framework | ASP.NET Core 9 |
| Architecture | Repository + Unit of Work + MediatR (CQRS) |
| Real-time | SignalR WebSockets |
| Database | MongoDB (with in-memory fallback) |
| Caching | Redis (optional) |
| Authentication | JWT Bearer + BCrypt |
| API Docs | Swagger/OpenAPI |
| Storage | Local file system |
- Click the Replit badge above
- Click "Run" button
- Access API at the provided URL
git clone https://github.com/Mostafa-SAID7/Chat-Api.git
cd Chat-Api/apiContact
dotnet restore
dotnet runThe API will start on http://localhost:5000
Access Swagger UI: http://localhost:5000/swagger
Full documentation is available in the /docs directory:
- ARCHITECTURE.md - System design and components
- API.md - API endpoints and usage
- SETUP.md - Detailed setup instructions
- DEVELOPMENT.md - Development guide
- DATABASE.md - Database schema and models
- TROUBLESHOOTING.md - Common issues and fixes
Base URL: ws://localhost:5000/hubs/chat
POST /api/auth/register Register new user
POST /api/auth/login Login and get JWT
GET /api/contacts Get all contacts
POST /api/contacts Create new contact
GET /api/messages Get conversation history
POST /api/messages Send message
See API Documentation for complete endpoint reference.
apiContact/
βββ Controllers/ # API endpoints
βββ Features/ # Feature-specific logic (CQRS)
βββ Hubs/ # SignalR WebSocket hubs
βββ Services/ # Business logic services
βββ Models/ # Data models/entities
βββ Data/ # Database context & repositories
βββ Middleware/ # Custom middleware
βββ Mappings/ # AutoMapper profiles
βββ Utilities/ # Helper utilities
βββ Properties/ # Project properties
βββ appsettings.json # Configuration
βββ Program.cs # Application startup
The API uses JWT Bearer tokens for authentication:
- Register or login to get a token
- Include token in request header:
Authorization: Bearer <token> - Token expires after 24 hours
Example:
curl -H "Authorization: Bearer eyJhbGc..." http://localhost:5000/api/contacts# Register
curl -X POST http://localhost:5000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"SecurePass123"}'
# Login
curl -X POST http://localhost:5000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"SecurePass123"}'const connection = new signalR.HubConnectionBuilder()
.withUrl("http://localhost:5000/hubs/chat")
.withAutomaticReconnect()
.build();
connection.start();
connection.invoke("SendMessage", {
contactId: "123",
text: "Hello!",
timestamp: new Date()
});cd apiContact
dotnet testdotnet builddotnet watch runSee DEVELOPMENT.md for more details.
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see LICENSE.txt for details.
Q: Do I need MongoDB to run this?
A: No, it includes an in-memory fallback. MongoDB is optional.
Q: Can I use this in production?
A: Yes, with proper MongoDB and Redis setup. See SETUP.md.
Q: How do I enable real-time chat?
A: Connect to the SignalR hub at /hubs/chat for real-time messaging.
For issues, questions, or suggestions:
- π Open an Issue
- π¬ Start a Discussion
Made with β€οΈ by the Chat API team