Simplified Instagram API clone made with .NET 9.0, .NET Aspire (orchestration, observability), MinIO (object storage) and PostgreSQL (DB).
InstagramClone.AppHost
: main entry point of the application, orchestrating other projects using .NET Aspire.InstagramClone.Api
: API project. Uses ASP.NET Core Identity to handle authentication, generates OpenAPI documents and has Scalar client.InstagramClone.ServiceDefaults
: class library that adds common .NET Aspire services. Used byInstagramClone.Api
.InstagramClone.DataSeeding
: console app for generating test data.
Please perform these steps in the sequence they are listed.
This command will create and use C:/docker-sandbox/minio
directory as a persistent storage for the container. You can use any other file path that you have read, write and delete access. More information can be found in MinIO documentation here.
docker run -p 9000:9000 -p 9001:9001 --name minio1 -v C:/docker-sandbox/minio:/data -e "MINIO_ROOT_USER=admin" -e "MINIO_ROOT_PASSWORD=min8chars" -d --rm quay.io/minio/minio:RELEASE.2024-12-18T13-15-44Z server data --console-address ":9001"
Once the container is running, you can use http://localhost:9001/ to access MinIO Console.
docker run --name postgres1 -e POSTGRES_PASSWORD=1234 -p 5432:5432 -d --rm postgres:17
To perform database migrations, you can use EF Core tools CLI and execute the following command from solution's root directory.
dotnet ef database update --project InstagramClone.Api
This is the main entry point of the application. You can run it from your favorite IDE or using dotnet
CLI with the following command from solution's root directory.
dotnet run --project InstagramClone.AppHost
Upon successful run, your console output should have the URL to login to the .NET Aspire dashboard. Open that URL and use token
from console output if prompted.
Login to the dashboard at https://localhost:17219/login?t=token
Once the API is running, you can generate some test users, images and user followings by executing the following command from solution's root directory.
dotnet run --project InstagramClone.DataSeeding
You can easily configure the amount of users, images and user followings by tweaking variables in InstagramClone.DataSeeding
project's Program.cs
.
Currently, the functionality is only contained within the API. You can find its URL by clicking on api
resource in .NET Aspire dashboard and then finding https target port
endpoint. Its port can change between different runs due to reverse proxy created by .NET Aspire. More inforamtion can be found here.
Following the image above:
- The API can be found at https://localhost:52213
- Scalar client can be found at https://localhost:52213/scalar/v1
- OpenAPI document can be found at https://localhost:52213/openapi/v1.json
API endpoints require authentication. In this solution, it is handled with ASP.NET Core Identity. You can find all of the authentication related endpoints in the documentation here.
One of the most basic ways to authenticate is to use /register
endpoint to register a user and then use /login
to login with that user. See example using cookie-based authentication below.
/register
{
"email": "[email protected]",
"password": "Abc123!"
}
/login?useCookies=true
{
"email": "[email protected]",
"password": "Abc123!"
}
HTTP POST /api/media
allows uploading images to the object storage. It conveniently creates a bucket for the user performing the request and all following user uploads will be performed to that bucket. On success, this endpoint returns an ID you can then query at api/media/{id}/preview
or api/media/{id}/
. Moreover, after a successful upload you can also view the image in MinIO Console.
HTTP POST /api/userFollowing
allows following other users.
HTTP GET /api/feed
returns the feed for user performing the request. It returns latest media from followed users.
- Error handling
- Request validation
- Move endpoint logic out of controllers
- Check generated EF Core queries and potential issues
- Add indexes
- Use Guid instead of default string for Identity PK
- Handle empty title search
- Detect and support multiple media types
- Token based authentication may not be represented correctly due to scalar/scalar#4055
- Use
TypedResults
when dotnet/aspnetcore#44988 is resolved