A comprehensive, enterprise-level Online Bookstore REST API built with .NET 10, SQL Server, and Clean Architecture principles.
- Book Management: CRUD operations, search, filtering, pagination
- Category Management: Organize books into categories
- User Authentication: JWT-based with secure password hashing (BCrypt)
- Role-Based Authorization: Admin and User roles
- Order Management: Create orders, track status, cancel orders
- Inventory Management: Stock management with transaction safety
- Global Exception Handling: Centralized error responses
- API Documentation: Interactive Swagger/OpenAPI
- Soft Delete: Logical deletion with audit trail
- Clean Architecture: Domain, Application, Infrastructure, API layers
- Repository Pattern: Abstraction over data access
- Unit of Work: Transaction management
- Service Layer: Business logic orchestration
- DTOs: Data Transfer Objects for API contracts
- Value Objects: ISBN and Money as domain-driven design values
- JWT Authentication: Stateless, token-based authentication
- Password Security: BCrypt hashing with adaptive work factor
- SQL Injection Prevention: Parameterized queries via EF Core
- HTTPS: Enforced in production
- CORS: Configurable cross-origin policies
- Role-Based Access Control: Fine-grained authorization
- SQL Server: Robust relational database
- Entity Framework Core: Code-First ORM
- Migrations: Version-controlled schema changes
- Soft Delete: Logical deletion support
- Optimistic Concurrency: RowVersion for conflict detection
- Comprehensive Indexing: Performance optimization
- Pagination: Efficient data retrieval
- Eager Loading: N+1 query prevention
- Indexing Strategy: Optimized database queries
- Connection Pooling: Efficient resource management
- Async/Await: Non-blocking I/O operations
- Caching Ready: Designed for Redis integration
Bookstore/
βββ Bookstore.Domain/ # Domain entities & value objects
β βββ Entities/
β β βββ BaseEntity.cs # Base class with audit fields
β β βββ Book.cs
β β βββ Category.cs
β β βββ User.cs
β β βββ Order.cs
β β βββ OrderItem.cs
β βββ ValueObjects/
β βββ ISBN.cs
β βββ Money.cs
β
βββ Bookstore.Application/ # Application services & DTOs
β βββ DTOs/
β β βββ BookDtos.cs
β β βββ CategoryDtos.cs
β β βββ UserDtos.cs
β β βββ OrderDtos.cs
β βββ Services/
β β βββ IServices.cs
β βββ Repositories/
β β βββ IRepositories.cs
β βββ Validators/
β β βββ DtoValidators.cs
β βββ Exceptions/
β β βββ CustomExceptions.cs
β βββ Common/
β βββ ApiResponse.cs
β
βββ Bookstore.Infrastructure/ # EF Core, repositories, services
β βββ Persistence/
β β βββ BookStoreDbContext.cs
β β βββ Configurations/
β β βββ Repositories/
β βββ Services/
β β βββ AuthenticationService.cs
β β βββ BookService.cs
β β βββ CategoryService.cs
β β βββ OrderService.cs
β βββ Middleware/
β β βββ GlobalExceptionMiddleware.cs
β βββ DependencyInjection.cs
β
βββ Bookstore.API/ # ASP.NET Core API
β βββ Controllers/
β β βββ AuthController.cs
β β βββ BooksController.cs
β β βββ CategoriesController.cs
β β βββ OrdersController.cs
β βββ Program.cs
β βββ appsettings.json
β
βββ docs/ # Project documentation
β βββ api/
β β βββ POSTMAN_COLLECTION.json # API testing collection
β βββ history/ # Historical records & reviews
β β βββ CODE_REVIEW_SENIOR_ENGINEER.md
β β βββ TEST_FAILURES_ANALYSIS_AND_FIXES.md
β βββ summaries/ # Feature and logic summaries
β β βββ SHOPPING_CART_FEATURE_SUMMARY.md
β βββ BEST_PRACTICES.md # Implementation best practices
β βββ DATABASE_MIGRATIONS.md # Migration guide
β βββ DEPLOYMENT_CHECKLIST.md # Deployment guide
β βββ NUGET_PACKAGES.md # Required NuGet packages
β βββ TESTING_GUIDE.md # Testing strategies
β βββ PROJECT_SPECIFICATION.md # Core project requirements
βββ .editorconfig # Code style & cleanup rules
- .NET 10 SDK
- SQL Server (or SQL Server Express)
- Visual Studio 2026 (or VS Code)
# Clone repository
git clone https://github.com/your-org/bookstore-api.git
cd bookstore-api
# Restore packages
dotnet restoreEdit Bookstore.API/appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(local)\\SQLEXPRESS;Database=BookstoreDb;Trusted_Connection=true;"
},
"JWT": {
"Key": "your-secure-key-minimum-32-characters-xxx",
"Issuer": "BookstoreAPI",
"Audience": "BookstoreClients"
}
}Option A: Using Package Manager Console
Add-Migration InitialCreate
Update-DatabaseOption B: Using .NET CLI
cd Bookstore.Infrastructure
dotnet ef migrations add InitialCreate
dotnet ef database updatecd Bookstore.API
dotnet run
# Application starts at: https://localhost:5001
# Swagger UI: https://localhost:5001/swagger/index.html# Register
POST /api/auth/register
Content-Type: application/json
{
"fullName": "John Doe",
"email": "john@example.com",
"password": "SecurePassword123",
"phoneNumber": "+1234567890"
}
# Login
POST /api/auth/login
{
"email": "john@example.com",
"password": "SecurePassword123"
}
# Response
{
"success": true,
"data": {
"userId": "guid",
"fullName": "John Doe",
"email": "john@example.com",
"role": "User",
"token": "eyJhbGciOiJIUzI1NiIs...",
"expiresAt": "2025-01-09T12:00:00Z"
},
"statusCode": 200
}# Get all books (paginated)
GET /api/books?pageNumber=1&pageSize=10
# Get book by ID
GET /api/books/{id}
# Search books
GET /api/books/search/gatsby
# Get books by category
GET /api/books/category/{categoryId}?pageNumber=1&pageSize=10
# Create book (Admin only)
POST /api/books
Authorization: Bearer {admin-token}
# Update book (Admin only)
PUT /api/books/{id}
# Delete book (Admin only)
DELETE /api/books/{id}# Get all categories
GET /api/categories
# Get category by ID
GET /api/categories/{id}
# Create category (Admin)
POST /api/categories
# Update category (Admin)
PUT /api/categories/{id}
# Delete category (Admin)
DELETE /api/categories/{id}# Create order
POST /api/orders
Authorization: Bearer {user-token}
# Get order by ID
GET /api/orders/{id}
# Get user's orders
GET /api/orders/my-orders?pageNumber=1&pageSize=10
# Update order status (Admin)
PUT /api/orders/{id}/status
# Cancel order
DELETE /api/orders/{id}/cancelImport POSTMAN_COLLECTION.json into Postman for API testing.
Setup Variables:
base_url: https://localhost:5001access_token: Token from login responseadmin_token: Admin user's tokencategory_id,book_id,order_id: IDs from responses
# Run tests
dotnet test
# With coverage
dotnet test /p:CollectCoverage=true /p:CoverageFormat=opencover- Users: Registered users with authentication
- Categories: Book categories
- Books: Book inventory with stock management
- Orders: Customer orders
- OrderItems: Individual items in orders
- β Referential integrity with foreign keys
- β Unique constraints (ISBN, Email, Category Name)
- β Soft delete with IsDeleted flag
- β Audit fields (CreatedAt, UpdatedAt, CreatedBy, UpdatedBy)
- β Optimistic concurrency with RowVersion
- β Strategic indexing for performance
- JWT tokens with 24-hour expiration
- Email and password validation
- Secure password hashing (BCrypt)
- Role-based access control
- Admin-only operations protected
- User resources isolated
- SQL injection prevention (parameterized queries)
- XSS protection (no inline scripts)
- CORS policy enforcement
- HTTPS enforced
- CreatedBy, UpdatedBy tracking
- CreatedAt, UpdatedAt timestamps
- Soft delete for data recovery
- API Response Time: < 2 seconds (target)
- Database Queries: < 500ms (P95)
- Pagination: 10-100 items per page
- Concurrent Users: 1000+ (with proper scaling)
- Order Processing: < 1 second
NuGet Restore Failed
dotnet nuget locals all --clear
dotnet restoreMissing Assembly References
# Verify packages installed
dotnet list packageConnection String Issues
- Verify SQL Server is running
- Check connection string in appsettings.json
- Ensure database exists or let EF Core create it
Migration Failures
- Check for pending migrations:
dotnet ef migrations list - Roll back if needed:
dotnet ef database update <PreviousMigration>
Authentication Issues
- Verify JWT Key is set in appsettings.json
- Check token hasn't expired
- Ensure token is in Authorization header:
Bearer {token}
- Database Migrations - Migration guide
- Best Practices - Implementation guidelines
- NuGet Packages - Required dependencies
- Testing Guide - Testing strategies
- Frontend Strategy - Modern frontend architecture
name: Build & Test
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '10.0.0'
- run: dotnet restore
- run: dotnet build
- run: dotnet test- Database backups configured
- Connection strings updated (no hardcoded values)
- JWT keys rotated and secured in Key Vault
- HTTPS certificate installed
- Logging configured (structured logging)
- Monitoring and alerting set up
- Load balancer configured
- Cache layer deployed (if using Redis)
- Firewall rules configured
- Database replicas set up
- Create feature branch:
git checkout -b feature/my-feature - Commit changes:
git commit -am 'Add my feature' - Push to branch:
git push origin feature/my-feature - Submit pull request
- Follow C# naming conventions
- Use async/await for I/O operations
- Add XML documentation for public APIs
- Write unit tests for new features
This project is licensed under the MIT License - see the LICENSE file for details.
For issues, questions, or suggestions:
- Open an issue on GitHub
- Check existing documentation
- Review troubleshooting guide
β Backend API: Full REST API implementation β Database: SQL Server with EF Core migrations β Authentication: JWT with role-based authorization β Error Handling: Global exception middleware β Logging: Structured logging throughout β Documentation: Comprehensive guides and API docs β Testing: Postman collection for API testing β Security: BCrypt passwords, SQL injection prevention β Performance: Pagination, indexing, lazy loading β Production Ready: Best practices implemented
Project Lead: Abdulmuheez Ogunrinde Email: abdulmuheezabiola@gmail.com GitHub: Abiola26
- Microsoft Entity Framework Core team
- ASP.NET Core community
- Security best practices from OWASP
Last Updated: January 2025
Version: 1.0.0
Status: β
Production Ready
Happy coding! π
