Skip to content

Gargera/DevPulse-WebAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DevPulse

.NET ASP.NET Core Entity Framework Core

A modern, fully-featured blogging platform built with Clean Architecture, ASP.NET Core, and Entity Framework Core. DevPulse demonstrates enterprise-grade API design with authentication, authorization, and comprehensive blog management capabilities.

Overview

DevPulse is a RESTful blogging platform that enables users to create, manage, and discover blog posts. The application leverages Clean Architecture principles to ensure separation of concerns, maintainability, and scalability. It is showcasing modern .NET development practices and design patterns.

Key Highlights:

  • πŸ—οΈ Clean Architecture with clear separation of concerns
  • πŸ” JWT-based authentication and role-based authorization
  • πŸ“ Full blog lifecycle management (Create, Read, Update, Delete)
  • 🏷️ Category-based blog organization and filtering
  • πŸ”’ User ownership authorization for blog content
  • πŸ› οΈ Enterprise design patterns (Generic Repository, Unit of Work, Dependency Injection)
  • πŸ“Š Global exception handling with standardized responses
  • πŸ”„ Automatic data seeding and database migrations

Key Features

Authentication & Authorization

  • User Registration & Login - Secure account creation with email verification
  • JWT Authentication - Token-based authentication for protected endpoints
  • Role-Based Authorization - Admin and User roles with granular access control
  • User Ownership Validation - Users can only modify their own blogs

Blog Management

  • Create Blogs - Authenticated users can publish blogs with title, content, category, and optional images
  • Read Blogs - Public access to browse all blogs or filter by category
  • Update Blogs - Users can edit only their own published blogs
  • Delete Blogs - Users can delete only their own blogs
  • User Blog Retrieval - Authenticated users can view their own blog collection

Category Management

  • Browse Categories - Public access to view all available categories
  • Admin Management - Admin users can create, update, and delete categories and update, delete any blog for any user

Data Validation & Security

  • Input Validation - Data Annotations for comprehensive validation rules
  • Global Exception Handling - Centralized error handling middleware
  • Standardized API Responses - Consistent response format across all endpoints

Architecture

DevPulse follows Clean Architecture principles with a layered approach:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              DevPulseApp (API Layer)                β”‚
β”‚        Controllers | Middleware | WebConfig         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
					 β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚          Application (Business Logic)               β”‚
β”‚  Services | DTOs | Interfaces | Dependency Setup   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
					 β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         Infrastructure (Data Access)                β”‚
β”‚  UnitOfWork | Repositories | DbContext | Services  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
					 β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Domain (Core Entities)                 β”‚
β”‚           ApplicationUser | Blog | Category         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Design Patterns Implemented

Pattern Purpose
Generic Repository Pattern Centralized data access logic with reusable CRUD operations
Unit of Work Pattern Transaction management and coordinated repository operations
Dependency Injection Loose coupling and easy testability
DTO Pattern Clean separation between API contracts and domain models
Middleware Pattern Cross-cutting concerns (exception handling, authentication)
Factory Pattern Service registration through extension methods

Project Structure

DevPulse/
β”œβ”€β”€ DevPulseApp/                          # API Layer (ASP.NET Core Web API)
β”‚   β”œβ”€β”€ Controllers/
β”‚   β”‚   β”œβ”€β”€ AccountController.cs          # Authentication endpoints
β”‚   β”‚   β”œβ”€β”€ BlogController.cs             # Blog CRUD and filtering
β”‚   β”‚   └── CategoryController.cs         # Category management
β”‚   β”œβ”€β”€ Middlewares/
β”‚   β”‚   └── GlobalExceptionMiddleware.cs  # Centralized error handling
β”‚   β”œβ”€β”€ ExtensionMethods/
β”‚   β”‚   └── WebApplicationRegister.cs     # App configuration extensions
β”‚   β”œβ”€β”€ Program.cs                        # Application entry point
β”‚   β”œβ”€β”€ appsettings.json                  # Configuration
β”‚   └── Properties/
β”‚       └── launchSettings.json
β”‚
β”œβ”€β”€ Application/                          # Business Logic Layer
β”‚   β”œβ”€β”€ Services/
β”‚   β”‚   β”œβ”€β”€ BlogService.cs
β”‚   β”‚   └── CategoryService.cs
β”‚   β”œβ”€β”€ Interfaces/
β”‚   β”‚   β”œβ”€β”€ Services/
β”‚   β”‚   β”‚   β”œβ”€β”€ IAccountService.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ IBlogService.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ ICategoryService.cs
β”‚   β”‚   β”‚   └── IJwtService.cs
β”‚   β”‚   β”œβ”€β”€ Repositories/
β”‚   β”‚   β”‚   └── IGenericRepository.cs
β”‚   β”‚   β”œβ”€β”€ UnitOfWork/
β”‚   β”‚   β”‚   └── IUnitOfWork.cs
β”‚   β”‚   └── DataSeeding/
β”‚   β”‚       └── IDataInitializer.cs
β”‚   β”œβ”€β”€ DTOs/
β”‚   β”‚   β”œβ”€β”€ AccountDTOs/
β”‚   β”‚   β”‚   β”œβ”€β”€ RegisterDto.cs
β”‚   β”‚   β”‚   └── LoginDto.cs
β”‚   β”‚   β”œβ”€β”€ BlogDTOs/
β”‚   β”‚   β”‚   β”œβ”€β”€ CreateBlogDto.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ GetBlogDto.cs
β”‚   β”‚   β”‚   └── UpdateBlogDto.cs
β”‚   β”‚   β”œβ”€β”€ CategoryDTOs/
β”‚   β”‚   β”‚   β”œβ”€β”€ CreateCategoryDto.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ GetCategoryDto.cs
|   |   |   β”œβ”€β”€ GetCategoryWithoutBlogsDto.cs
β”‚   β”‚   β”‚   └── UpdateCategoryDto.cs
β”‚   β”‚   └── JwtDTOs/
β”‚   β”‚       └── JwtDto.cs
β”‚   β”œβ”€β”€ Mapper/
β”‚   β”‚   └── DomainProfile.cs              # AutoMapper configuration
β”‚   └── DependencyInjection/
β”‚       └── ApplicationServiceRegistration.cs
β”‚
β”œβ”€β”€ Infrastructure/                       # Data Access Layer
β”‚   β”œβ”€β”€ Database/
β”‚   β”‚   β”œβ”€β”€ ApplicationDbContext.cs       # Entity Framework Core context
β”‚   β”‚   └── Migrations/
β”‚   β”œβ”€β”€ Configurations/
β”‚   β”‚   β”œβ”€β”€ ApplicationUserConfiguration.cs
β”‚   β”‚   β”œβ”€β”€ BlogConfiguration.cs
β”‚   β”‚   └── CategoryConfiguration.cs
β”‚   β”œβ”€β”€ Repositories/
β”‚   β”‚   └── GenericRepository.cs
β”‚   β”œβ”€β”€ Services/
β”‚   β”‚   β”œβ”€β”€ AccountService.cs
β”‚   β”‚   └── JwtService.cs
β”‚   β”œβ”€β”€ UnitOfWork/
β”‚   β”‚   └── UnitOfWork.cs
β”‚   β”œβ”€β”€ DataSeeding/
β”‚   β”‚   └── DataInitializer.cs
β”‚   └── DependencyInjection/
β”‚       └── InfrastructureServiceRegistration.cs
β”‚
└── Domain/                               # Core Domain Layer
	β”œβ”€β”€ Entities/
	β”‚   β”œβ”€β”€ BaseEntity.cs                 # Base entity with generic Id
	β”‚   β”œβ”€β”€ ApplicationUser.cs            # User with Identity
	β”‚   β”œβ”€β”€ Blog.cs                       # Blog entity
	β”‚   └── Category.cs                   # Category entity
	└── Domain.csproj

Main Entities

ApplicationUser

Extends ASP.NET Core Identity User with profile information:

  • FirstName, LastName - User profile
  • Blogs - Collection of user's published blogs

Blog

Core blog entity with rich content:

  • Title - Blog title (3-200 characters)
  • Content - Blog body (20-10,000 characters)
  • ImageUrl - Optional featured image URL
  • CategoryId - Foreign key to Category
  • UserId - Foreign key to ApplicationUser (owner)
  • CreatedAt - Publication timestamp

Category

Content organization:

  • Name - Category name
  • Blogs - Collection of blogs in this category

Authentication & Authorization

JWT (JSON Web Tokens)

  • Token Generation - Issued upon successful login
  • Token Validation - Custom claims and signature verification
  • Configuration - Issuer, Audience, and expiration settings in appsettings.json
  • Duration - Configurable token lifetime (default: 30 days)

Role-Based Access Control (RBAC)

  • Admin Role - Category management, administrative operations
  • User Role - Default role for registered users
  • Public Access - Endpoints for anonymous users (blog browsing, category listing)

Endpoint Authorization Examples

[AllowAnonymous]                      // Public endpoint
[Authorize]                           // Authenticated
[Authorize(Roles = "Admin")]          // Admin users only

Technologies Used

Core Framework

  • ASP.NET Core 9 - High-performance web framework
  • .NET 9 - Latest .NET runtime

Data Access & ORM

  • Entity Framework Core - Object-relational mapping
  • SQL Server - Relational database
  • LINQ - Data queries and operations

Authentication & Security

  • ASP.NET Core Identity - User management and authentication
  • JWT Bearer Authentication - Token-based security
  • SymmetricSecurityKey - Token encryption/decryption

Dependency Injection & Mapping

  • Microsoft Dependency Injection - Service registration and resolution
  • AutoMapper - Object-to-object mapping for DTOs

API Documentation

  • Swagger/OpenAPI - Interactive API documentation
  • Swagger UI - Web-based API testing interface

Data Validation

  • System.ComponentModel.DataAnnotations - Declarative validation rules
  • Custom Validation - Email, StringLength, Required attributes

Middleware & Error Handling

  • Global Exception Middleware - Centralized error handling
  • Custom Response Format - Standardized API responses

Local Setup

Prerequisites

  • .NET 9 SDK - Download
  • SQL Server - Any version (LocalDB, Developer Edition, or Express)
  • Visual Studio 2022 or VS Code with C# extension

Installation Steps

  1. Clone the Repository

    git clone https://github.com/Gargera/DevPulse-WebAPI.git
    cd DevPulse
  2. Configure Database Connection

    • Open DevPulseApp/appsettings.json
    • Update ConnectionStrings:DefaultConnection with your SQL Server connection string:
      "ConnectionStrings": {
        "DefaultConnection": "Server=.;Database=DevPulseDb;Trusted_Connection=true;TrustServerCertificate=true;"
      }
  3. Configure JWT Settings

    • Update JWT settings in appsettings.json:
      "JWT": {
        "Key": "your-secret-key-here-minimum-64-characters",
        "Issuer": "DevPulseAPI",
        "Audience": "DevPulseClient",
        "DurationInDays": 30
      }
    • Security Note: Use dotnet user-secrets for sensitive configuration in production
  4. Restore Dependencies

    dotnet restore
  5. Apply Migrations

    dotnet ef database update --project Infrastructure --startup-project DevPulseApp
  6. Run the Application

    dotnet run --project DevPulseApp
  7. Access the API

    • API: https://localhost:5001
    • Swagger UI: https://localhost:5001/swagger

User Secrets Setup (Production Recommended)

Instead of hardcoding sensitive data in appsettings.json, use User Secrets:

# Initialize user secrets
dotnet user-secrets init --project DevPulseApp

# Set connection string
dotnet user-secrets set "ConnectionStrings:DefaultConnection" "Your_Connection_String" --project DevPulseApp

# Set JWT key
dotnet user-secrets set "JWT:Key" "Your_JWT_Secret_Key" --project DevPulseApp

API Endpoints Overview

Authentication

  • POST /api/account/register - Create new user account
  • POST /api/account/login - Authenticate and receive JWT token

Blogs

  • GET /api/blog - Get all blogs (public)
  • GET /api/blog/{id} - Get blog by ID (public)
  • GET /api/blog/category/{categoryId} - Filter blogs by category (public)
  • GET /api/blog/my-blogs - Get current user's blogs (authenticated)
  • POST /api/blog - Create new blog (authenticated)
  • PUT /api/blog/{id} - Update blog (authenticated, owner and admins only)
  • DELETE /api/blog/{id} - Delete blog (authenticated, owner and admins only)

Categories

  • GET /api/category - Get all categories (public)
  • GET /api/category/{id} - Get category by ID (admin)
  • POST /api/category - Create category (admin)
  • PUT /api/category/{id} - Update category (admin)
  • DELETE /api/category/{id} - Delete category (admin)

Author

Gargera


DevPulse Β© 2024. modern ASP.NET Core development practices and Clean Architecture principles.

About

A modern blogging platform for developers built with ASP.NET Core 9 and Entity Framework Core following Clean Architecture. Features complete JWT authentication, full blog management (CRUD operations), category organization, and role-based authorization (Admin/User). A professional application with Generic Repository and Unit of Work patterns.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages