πΈ InstagramAPI - ASP.NET Core 8 + Onion Architecture
A full-featured Instagram clone REST API built with ASP.NET Core 8 , SQL Server , Onion Architecture , and Generic Repository Pattern .
InstagramApi/
βββ src/
β βββ Core/ β Domain + Application (innermost layers)
β β βββ InstagramApi.Domain/ β Entities, Enums, Common base classes
β β βββ InstagramApi.Application/ β DTOs, Interfaces, Validators, AutoMapper
β β
β βββ Infrastructure/ β External concerns
β β βββ InstagramApi.Infrastructure/ β Repositories, Services (Auth, Email, File, Cache)
β β βββ InstagramApi.Persistence/ β EF Core DbContext, Configurations, Migrations
β β
β βββ Presentation/
β βββ InstagramApi.API/ β Controllers, Middleware, Program.cs
β
βββ tests/
βββ InstagramApi.UnitTests/
βββ InstagramApi.IntegrationTests/
Dependency Rule (Onion Architecture)
API β Application β Infrastructure
β
Domain
Domain has no dependencies
Application depends only on Domain
Infrastructure depends on Application
API depends on Application + Infrastructure
Feature
Details
π Authentication
JWT Access Token + Refresh Token
π§ Email
Confirmation, Password Reset, Welcome Email (MailKit)
πΌοΈ Media
Upload images/videos with ImageSharp processing
π± Posts
Create, Edit, Delete, Like, Save, Share
π¬ Comments
Nested replies, likes
π Stories
24h expiry, view tracking
π₯ Follow System
Public/Private accounts, follow requests
π Search
Users, hashtags
π© Direct Messages
1:1 conversations, unsend
π Notifications
Like, comment, follow, DM
π‘οΈ Admin Panel
Dashboard, user management, reports
π« Block/Report
Block users, report content
β»οΈ Soft Delete
All entities support soft delete
π Pagination
Generic paged results
ποΈ Generic Repository
Full CRUD + paged query
π Unit of Work
Transaction management
β
Validation
FluentValidation
πΊοΈ AutoMapper
Full mapping profiles
.NET 8 SDK
SQL Server (LocalDB works)
(Optional) Redis for distributed caching
git clone < repo>
cd InstagramApi
Edit src/Presentation/InstagramApi.API/appsettings.json:
{
"ConnectionStrings" : {
"DefaultConnection" : " Server=localhost;Database=InstagramApiDb;..."
},
"Jwt" : {
"Secret" : " YourSecretKeyMin32Chars!"
},
"Email" : {
"SmtpHost" : " smtp.gmail.com" ,
"Username" : " you@gmail.com" ,
"Password" : " your-app-password"
}
}
cd src/Presentation/InstagramApi.API
dotnet ef migrations add InitialCreate --project ../../Infrastructure/InstagramApi.Persistence
dotnet ef database update --project ../../Infrastructure/InstagramApi.Persistence
dotnet run --project src/Presentation/InstagramApi.API
Open https://localhost:7001 β Swagger UI
π Default Admin Account
Email: admin@instagramapi.com
Password: Admin@123456
Role: SuperAdmin
Method
Endpoint
Description
POST
/api/auth/register
Register new user
POST
/api/auth/login
Login
POST
/api/auth/refresh-token
Refresh JWT
POST
/api/auth/logout
Logout
POST
/api/auth/forgot-password
Send reset email
POST
/api/auth/reset-password
Reset password
GET
/api/auth/confirm-email
Confirm email
POST
/api/auth/change-password
Change password
GET
/api/auth/me
Current user info
Method
Endpoint
Description
GET
/api/users/{username}
Get profile
PUT
/api/users/profile
Update profile
POST
/api/users/profile/avatar
Upload avatar
GET
/api/users/search?q=
Search users
GET
/api/users/suggestions
Suggested users
POST
/api/users/{userId}/follow
Follow user
DELETE
/api/users/{userId}/follow
Unfollow
GET
/api/users/{userId}/followers
Followers list
GET
/api/users/{userId}/following
Following list
POST
/api/users/{userId}/block
Block user
POST
/api/users/follow-requests/{id}/accept
Accept request
Method
Endpoint
Description
GET
/api/posts/feed
Home feed
GET
/api/posts/explore
Explore page
POST
/api/posts
Create post
GET
/api/posts/{postId}
Get post
PUT
/api/posts/{postId}
Update post
DELETE
/api/posts/{postId}
Delete post
POST
/api/posts/{postId}/like
Like post
DELETE
/api/posts/{postId}/like
Unlike post
POST
/api/posts/{postId}/save
Save post
GET
/api/posts/saved
Saved posts
GET
/api/posts/hashtag/{tag}
Posts by hashtag
Comments
Method
Endpoint
Description
GET
/api/posts/{postId}/comments
Get comments
POST
/api/posts/{postId}/comments
Add comment
DELETE
/api/comments/{commentId}
Delete comment
POST
/api/comments/{commentId}/like
Like comment
GET
/api/comments/{commentId}/replies
Get replies
Method
Endpoint
Description
GET
/api/stories/feed
Story feed
POST
/api/stories
Create story
DELETE
/api/stories/{storyId}
Delete story
POST
/api/stories/{storyId}/view
View story
Method
Endpoint
Description
GET
/api/messages/conversations
All conversations
GET
/api/messages/conversations/{id}/messages
Messages
POST
/api/messages/send
Send message
DELETE
/api/messages/{messageId}
Unsend message
Method
Endpoint
Description
GET
/api/notifications
Get notifications
PATCH
/api/notifications/read-all
Mark all read
GET
/api/notifications/unread-count
Unread count
Method
Endpoint
Description
GET
/api/admin/dashboard
Dashboard stats
GET
/api/admin/users
All users
PATCH
/api/admin/users/{id}
Update user
POST
/api/admin/users/{id}/ban
Ban user
GET
/api/admin/reports
Pending reports
PATCH
/api/admin/reports/{id}
Resolve report
GET
/api/admin/settings
App settings
AutoMapper + AutoMapper.Extensions.Microsoft.DependencyInjection
FluentValidation + FluentValidation.DependencyInjectionExtensions
MediatR
Microsoft.AspNetCore.Identity.EntityFrameworkCore
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.IdentityModel.Tokens + System.IdentityModel.Tokens.Jwt
MailKit β Email sending
SixLabors.ImageSharp β Image processing
StackExchange.Redis β Distributed caching
Microsoft.AspNetCore.Authentication.JwtBearer
Swashbuckle.AspNetCore + Annotations
Serilog.AspNetCore + Sinks (Console, File, MSSqlServer)
AspNetCoreRateLimit
Key tables: Users, Posts, PostMedia, Comments, Likes, CommentLikes, Follows, Stories, StoryViews, Hashtags, PostHashtags, PostTags, SavedPosts, Messages, Conversations, Notifications, Reports, BlockedUsers, AppSettings
JWT with short-lived access tokens (1h) + long-lived refresh tokens (30d)
Password hashing via ASP.NET Core Identity (PBKDF2)
Account lockout after 5 failed attempts
Soft delete for all data (GDPR-friendly)
Input validation with FluentValidation
Global exception handling middleware