How kerolesnabiel/socialmediaapi works
Purpose and entry point
This is a .NET REST backend for social-media accounts, posts, comments, likes, follows, search, and role-based administration. The executable API host starts in SocialMediaAPI/Program.cs; dependency registration and HTTP-pipeline setup are centralized in SocialMediaAPI/Extensions/WebApplicationBuilderExtension.cs. The solution boundary is SocialMediaAPI.sln.
HTTP API and request boundary
ASP.NET controllers expose the public REST surface and translate requests into application operations: SocialMediaAPI/Controllers/UsersController.cs, SocialMediaAPI/Controllers/PostsController.cs, and SocialMediaAPI/Controllers/CommentsController.cs. Administrative and search endpoints are isolated in SocialMediaAPI/Controllers/AdminController.cs and SocialMediaAPI/Controllers/SearchController.cs. Swagger is part of the API host per the README.
Application layer: CQRS orchestration
SocialMediaApplication implements feature-oriented CQRS with MediatR: controllers dispatch commands for mutation and queries for reads; handlers enforce use-case behavior and return DTOs. Representative flows are post creation (SocialMediaApplication/Posts/Commands/CreatePost/CreatePostCommandHandler.cs), followed-user feed retrieval (SocialMediaApplication/Posts/Queries/GetFeed/GetFeedQueryHandler.cs), and login/token issuance (SocialMediaApplication/Users/Commands/LoginUser/LoginUserCommandHandler.cs). Shared registration is in SocialMediaApplication/Extensions/ServiceCollectionExtensions.cs.
Validation, identity context, and authorization
MediatR validation is a cross-cutting pipeline stage in SocialMediaApplication/Behaviors/ValidationBehavior.cs, backed by per-command/query FluentValidation validators. The current authenticated principal is adapted for handlers through SocialMediaApplication/Users/CurrentUser.cs and SocialMediaApplication/Users/UserContext.cs. Ownership/permission checks sit behind domain contracts, with infrastructure implementations for posts and comments in SocialMediaInfrastructure/Services/PostAuthorizationService.cs and SocialMediaInfrastructure/Services/CommentAuthorizationService.cs; roles are defined by SocialMediaDomain/Constants/UserRoles.cs.
Domain model and dependency boundary
SocialMediaDomain contains persistence-agnostic entities, exceptions, constants, and interfaces. Core relational concepts are SocialMediaDomain/Entities/User.cs, SocialMediaDomain/Entities/Post.cs, and SocialMediaDomain/Entities/Comment.cs. Application handlers depend on repository/storage/authorization abstractions such as SocialMediaDomain/Interfaces/IUsersRepository.cs, SocialMediaDomain/Interfaces/IPostsRepository.cs, and SocialMediaDomain/Interfaces/IBlobStorageService.cs, rather than EF Core or Azure APIs directly.
Persistence and external services
Infrastructure implements domain interfaces using Entity Framework Core and SQL Server. SocialMediaInfrastructure/Persistence/SocialMediaDbContext.cs models database access; SocialMediaInfrastructure/Repositories/UsersRepository.cs, SocialMediaInfrastructure/Repositories/PostsRepository.cs, and SocialMediaInfrastructure/Repositories/CommentsRepository.cs provide data operations. Schema history is maintained under SocialMediaInfrastructure/Migrations/. ASP.NET Identity and JWT provide authentication per README. Profile/media storage is abstracted through SocialMediaInfrastructure/Storage/BlobStorageService.cs, requiring a blob-storage connection string.
Operational flow and deployment
Normal flow is HTTP request → controller → MediatR validation/handler → domain interfaces → EF repositories or blob storage → DTO/HTTP response. Domain exceptions cross the API boundary through SocialMediaAPI/Handlers/GlobalExceptionHandler.cs for consistent error responses. Configuration is supplied via SocialMediaAPI/appsettings.json and environment-specific development settings. The repository includes Azure-oriented service dependency metadata and a MonsterASP deployment workflow at .github/workflows/deploy-to-monster-asp.yml.
Main entry points: WebApplicationBuilderExtension.cs Host setup · CreatePostCommandHandler.cs Command/query handlers · IUsersRepository.cs Repository and service contracts · UsersController.cs REST controllers
Components 17
API Host
- API entry point
SocialMediaAPI/Program.cs - Host setup
SocialMediaAPI/Extensions/WebApplicationBuilderExtension.cs - REST controllers · Users, posts, comments, admin, and search endpoints.
SocialMediaAPI/Controllers/UsersController.cs - Global exception handler
SocialMediaAPI/Handlers/GlobalExceptionHandler.cs
Application CQRS
- MediatR dispatcher
SocialMediaApplication/Extensions/ServiceCollectionExtensions.cs - Validation pipeline · Runs FluentValidation validators before handlers.
SocialMediaApplication/Behaviors/ValidationBehavior.cs - Command/query handlers · Execute mutations and reads and return DTOs.
SocialMediaApplication/Posts/Commands/CreatePost/CreatePostCommandHandler.cs - Current user context
SocialMediaApplication/Users/CurrentUser.cs
Domain
- Social domain model · Users, posts, comments, follows, and likes.
SocialMediaDomain/Entities/User.cs - Repository and service contracts · Application depends on persistence, authorization, and blob abstractions.
SocialMediaDomain/Interfaces/IUsersRepository.cs - User roles
SocialMediaDomain/Constants/UserRoles.cs
Infrastructure
- Ownership authorization · Post and comment permission implementations.
SocialMediaInfrastructure/Services/PostAuthorizationService.cs - EF Core DbContext
SocialMediaInfrastructure/Persistence/SocialMediaDbContext.cs - EF repositories · User, post, and comment persistence.
SocialMediaInfrastructure/Repositories/PostsRepository.cs - SQL Server
- Blob storage · Stores profile and post media.
SocialMediaInfrastructure/Storage/BlobStorageService.cs - ASP.NET Identity and JWT
Connections 19
- API entry point → Host setup: configures
- Host setup → REST controllers: maps
- Host setup → MediatR dispatcher: registers
- Host setup → Global exception handler: uses
- Host setup → ASP.NET Identity and JWT: configures auth
- REST controllers → MediatR dispatcher: dispatches requests
- MediatR dispatcher → Validation pipeline: runs first
- Validation pipeline → Command/query handlers: continues valid requests
- Command/query handlers → Current user context: reads principal
- Command/query handlers → Repository and service contracts: depends on
- Command/query handlers → Social domain model: uses
- Command/query handlers → User roles: checks roles
- Repository and service contracts → EF repositories: implemented by
- Repository and service contracts → Ownership authorization: implemented by
- Repository and service contracts → Blob storage: implemented by
- EF repositories → EF Core DbContext: uses
- EF Core DbContext → SQL Server: persists to
- Ownership authorization → EF repositories: loads ownership data
- REST controllers → Global exception handler: domain errors handled by