FoxBerry.API: Robust ASP.NET Core 9 backend for a social media platform. Features include JWT Auth, user profiles, posts with images, likes, comments, and a follow system, all powered by PostgreSQL.
FoxBerry is a social media platform that allows users to share posts with images, like and comment on posts, and follow other users. This repository contains the backend API for the FoxBerry application, built using ASP.NET Core 9 and Entity Framework Core. It provides a robust and scalable foundation for managing user data, posts, interactions, and more.
This repository is the root of the FoxBerry
solution, which currently contains the backend API project (FoxBerry.API
).
The frontend web application (FoxBerry.Web
- Angular) will reside in a separate repository.
- User Authentication & Authorization: Secure JWT-based authentication (registration, login) and authorization for protected endpoints.
- User Profiles: Create, view, and update user profiles, including biography and profile pictures.
- Post Management: Create, view (individual and feed), update, and delete posts with image uploads.
- Likes: Like and unlike posts.
- Comments: Add, view, and delete comments on posts.
- Follow System: Follow and unfollow other users, view followers and following lists.
- Image Storage: Local file system storage for post and profile images (scalable to cloud storage for production).
- Database: PostgreSQL integration via Entity Framework Core.
- API Documentation: Self-documenting API with Swagger UI.
- Backend Framework: ASP.NET Core 9.0
- Language: C# 12
- Database: PostgreSQL
- ORM: Entity Framework Core 9.0 (via
Microsoft.EntityFrameworkCore
andNpgsql.EntityFrameworkCore.PostgreSQL
) - Authentication: JWT (JSON Web Tokens) with
Microsoft.AspNetCore.Authentication.JwtBearer
(v9.0.5) - Password Hashing: BCrypt.Net-Next (v4.0.3)
- API Documentation: Swashbuckle (Swagger/OpenAPI) (v8.1.4)
- .NET 9 SDK (or latest compatible)
- PostgreSQL (and optionally, pgAdmin)
- A code editor (e.g., Visual Studio Code, Visual Studio)
-
Clone the repository:
git clone https://github.com/abdullokhonz/FoxBerry.API.git cd FoxBerry.API # Navigate into the solution root directory
-
Configure Sensitive Data (Connection Strings & JWT Secret) using User Secrets:
- Sensitive information like database connection strings and JWT secret keys should not be committed to source control. ASP.NET Core provides a secure way to manage these for development using User Secrets.
- Navigate into the
FoxBerry.API
project directory (whereFoxBerry.API.csproj
is located):cd FoxBerry.API/
- Initialize User Secrets for the project (if not already done):
dotnet user-secrets init
- Add your database connection string:
Important: Replace
dotnet user-secrets set "ConnectionStrings:DefaultConnection" "Host=localhost;Port=5432;Database=FoxBerryDb;Username=your_username;Password=your_password"
your_username
andyour_password
with your actual PostgreSQL credentials. - Add your JWT secret key:
Important: Replace
dotnet user-secrets set "JwtSettings:Secret" "YourStrongAndUniqueJwtSecretKeyThatIsAtLeast32CharactersLong"
YourStrongAndUniqueJwtSecretKeyThatIsAtLeast32CharactersLong
with a secure, random string (minimum 32 characters). This should be the same key used during development of the Auth system. - You can verify your secrets are set by running
dotnet user-secrets list
.
-
Configure Database:
- Ensure your PostgreSQL server is running.
- Create a new database for this project (e.g.,
FoxBerryDb
). - From the
FoxBerry.API
project directory (whereFoxBerry.API.csproj
is), apply database migrations:This will create the necessary tables in yourdotnet ef database update
FoxBerryDb
database.
-
Create Image Folders:
- Manually create the following folders within the
wwwroot
directory of theFoxBerry.API
project:FoxBerry.API/wwwroot/images
FoxBerry.API/wwwroot/images/posts
FoxBerry.API/wwwroot/images/profiles
- This is where uploaded images will be stored locally.
- Manually create the following folders within the
-
Navigate back to the solution root directory:
cd .. # If you are in FoxBerry.API project directory, go up one level
-
Run the application (from solution root, for FoxBerry.API project):
dotnet run --project FoxBerry.API/FoxBerry.API.csproj
The API will typically run on
https://localhost:7001
(orhttp://localhost:5000
). -
Access Swagger UI:
- Open your browser and navigate to
https://localhost:7001/swagger
(replace port if different). - Here you can explore all API endpoints and test them.
- Open your browser and navigate to
-
Register a User:
- Navigate to
Auth
->POST /api/Auth/register
. - Provide
username
,email
, andpassword
. - Execute the request.
- Navigate to
-
Login and Get JWT Token:
- Navigate to
Auth
->POST /api/Auth/login
. - Provide
email
, andpassword
. - Execute the request. Copy the
token
from the response.
- Navigate to
-
Authorize in Swagger:
- Click the "Authorize" button at the top right of the Swagger UI.
- In the dialog, type
Bearer YourJWTToken
(replaceYourJWTToken
with the actual token you copied). - Click "Authorize".
-
Explore and Test Endpoints:
- Now you can use the various endpoints (e.g.,
Posts
,Likes
,Comments
,Follows
,Users
) to create, read, update, and delete data.
- Now you can use the various endpoints (e.g.,
Contributions are welcome! If you have suggestions or want to contribute, please feel free to open issues or pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.