Backend part of a social network built on .NET 8 using Clean Architecture principles.
- Project Description
- Architecture
- Technologies
- Features
- Installation & Setup
- API Documentation
- Project Structure
- Database
- Authentication
- Real-time Chat
This project is the backend part of a social network that provides APIs for managing users, posts, comments, and real-time chat. The system is built using Clean Architecture, ensuring flexibility, testability, and ease of code maintenance.
The project uses Clean Architecture with the following layers:
π SocialNetwork.API (Presentation Layer)
βββ Controllers/ - API Controllers
βββ Hubs/ - SignalR Hubs for real-time communication
βββ Middleware/ - Custom middleware
βββ Extensions/ - Configuration extensions
π SocialNetwork.Application (Application Layer)
βββ DTO/ - Data Transfer Objects
βββ Interfaces/ - Service contracts
βββ Service/ - Business logic
βββ Mappings/ - AutoMapper profiles
π SocialNetwork.Domain (Domain Layer)
βββ Entities/ - Domain models
βββ Enums/ - Enumerations
βββ Interfaces/ - Domain contracts
π SocialNetwork.Infrastructure (Infrastructure Layer)
βββ Repos/ - Repositories
βββ Configurations/ - EF Core configurations
βββ Security/ - JWT providers
βββ SocialDbContext.cs - Database context
- .NET 8 - Main framework
- Entity Framework Core 9.0 - ORM for database operations
- SQL Server - Database
- SignalR - Real-time communication
- JWT - Authentication and authorization
- AutoMapper - Object mapping
- Swagger/OpenAPI - API documentation
- xUnit - Testing
- User registration
- Login with JWT tokens
- User profile management
- User ban system
- Create, view and edit posts
- Comment on posts
- Post ban system
- Display all posts and comments
- Private chats between users
- Group chats
- Channels
- Real-time messaging via SignalR
- User and post banning
- Access rights management
- .NET 8 SDK
- SQL Server (local or Azure)
- Visual Studio 2022 or VS Code
- Clone the repository
git clone <repository-url>
cd SocialNetwork_Server- Install dependencies
dotnet restore-
Configure database
- Update connection string in
appsettings.json:
"ConnectionStrings": { "DefaultConnection": "Data Source=YOUR_SERVER;Initial Catalog=SocialNetworkDb;Integrated Security=True;TrustServerCertificate=True" }
- Update connection string in
-
Apply migrations
dotnet ef database update --project SocialNetwork.Infrastructure --startup-project SocialNetwork.API- Run the application
dotnet run --project SocialNetwork.APIThe application will be available at: https://localhost:7000
After running the application, Swagger documentation is available at:
- Swagger UI:
https://localhost:7000/swagger
POST /api/auth/register- User registrationPOST /api/auth/login- User login
GET /api/post- Get all postsGET /api/post/{id}- Get post by IDPOST /api/post- Create new post (requires authentication)DELETE /api/post/{id}- Ban post (admin only)
GET /api/user- Get all usersGET /api/user/{id}- Get user by ID
GET /api/comment- Get all commentsPOST /api/comment- Create comment (requires authentication)
POST /chatHub- SignalR hub for real-time communication
SocialNetwork_Server/
βββ SocialNetwork.API/ # Web API project
β βββ Controllers/ # API Controllers
β βββ Hubs/ # SignalR Hubs
β βββ Middleware/ # Custom middleware
β βββ Extensions/ # Extensions
β βββ Program.cs # Entry point
βββ SocialNetwork.Application/ # Business logic
β βββ DTO/ # Data Transfer Objects
β βββ Interfaces/ # Service contracts
β βββ Service/ # Service implementations
β βββ Mappings/ # AutoMapper profiles
βββ SocialNetwork.Domain/ # Domain layer
β βββ Entities/ # Domain models
β βββ Enums/ # Enumerations
β βββ Interfaces/ # Domain contracts
βββ SocialNetwork.Infrastructure/ # Infrastructure layer
β βββ Repos/ # Repositories
β βββ Configurations/ # EF Core configurations
β βββ Security/ # JWT providers
β βββ SocialDbContext.cs # Database context
βββ SocialNetwork.Tests/ # Tests
- User - System users
- Post - User posts
- Comment - Post comments
- Chat - Chats (private, group, channels)
- Message - Chat messages
- UserChat - User-Chat relationship
The project uses Entity Framework Core migrations for database schema management. All migrations are located in the SocialNetwork.Infrastructure/Migrations/ folder.
The system uses JWT (JSON Web Tokens) for authorization:
- Secret Key: Configured in
appsettings.json - Expiration: 12 hours (configurable)
- Claims: User ID, Email, Role
The chat system is built on SignalR and supports:
- Private chats - one-on-one
- Group chats - multiple users
- Channels - public channels
const connection = new signalR.HubConnectionBuilder()
.withUrl("/chatHub")
.build();
// Join chat
await connection.invoke("JoinChat", chatId, userId);
// Send message
await connection.invoke("SendMessage", chatId, "Hello!");The project uses the built-in .NET logging system with different levels:
- Information - General information
- Warning - Warnings
- Error - Errors
This project is developed for educational purposes.