How imshivendra29/shopnext works
1. This is a single ASP.NET Core 8 Web API organized as a layered e-commerce backend. The primary runtime path is HTTP request → middleware → controller → service → repository → EF Core DbContext → relational database.
2. The API layer is split into feature controllers: Auth, User, Product, Category, Cart, Order, Review, Address, Banner, OTP, and Payment. Controllers stay thin and primarily translate HTTP requests into DTOs and delegate all business rules to services.
3. The service layer is the main business boundary. Each domain area has an interface and implementation pair, which keeps controllers isolated from persistence and external integrations. This layer contains the core rules for login/register, profile management, cart merging, checkout, review ownership, default address logic, OTP verification, and payment lifecycle checks.
4. Persistence is handled by a repository + Unit of Work pattern on top of Entity Framework Core. The database context is ShopNextDbContext, with repositories for each aggregate area such as users, products, categories, carts, orders, reviews, banners, and OTP records. The Unit of Work acts as the transaction/cohesion boundary for multi-entity operations like checkout and order creation.
5. The domain model is centered on commerce entities: User, Product, Category, Cart, CartItem, Order, OrderItem, Review, Address, Banner, Payment, and OtpVerification. DTOs are used heavily to separate API contracts from persistence models, especially for create/update inputs and response shaping.
6. Authentication and authorization are JWT-based. JwtHelper is responsible for token creation/claims, while protected endpoints use bearer auth and role-based checks. The README and code structure indicate user/admin distinctions, with admin-only write access for catalog and banner operations.
7. Several external integrations materially shape the architecture:
- Cloudinary for server-side image uploads for products, categories, banners, and user profile photos.
- Razorpay for online payment initiation and signature verification.
- Redis for caching/rate-limit/OTP-related workflows.
- SMS/OTP delivery is represented by the OTP module, with rate-limited verification behavior.
8. OTP and rate limiting are first-class security subsystems. The repo includes dedicated rate-limit policy constants, rate-limiter extensions, and Redis-backed cache services. OTP verification is stored hashed, time-limited, and request-capped, and checkout requires phone verification before order placement.
9. Order and payment flow is intentionally server-authoritative. Cart contents are converted into order snapshots at checkout so pricing cannot be manipulated from the client. Payment initiation pulls the amount from persisted order data, not from the request, and payment verification validates the Razorpay signature before updating payment/order state.
10. The API is hardened with centralized exception handling via ErrorHandlingMiddleware, producing consistent error responses. This middleware sits early in the pipeline so failures from controllers, services, repositories, or external services are normalized before reaching clients.
11. The repository also includes docs/deployment.md and docs/ratelimit.md, plus a Dockerfile, which indicates the app is designed to be containerized and deployed as a standalone backend service. Swagger/OpenAPI is part of the delivery surface for manual testing and API discovery.
12. One architecture note for diagram accuracy: the README says SQL Server, but the migration names and compiled dependencies show PostgreSQL/Npgsql artifacts as well. So the safest diagram is “EF Core-backed relational database” with provider-specific configuration likely present or having changed over time, rather than hard-coding only one database vendor.
Main entry points: Controllers Feature controllers · UnitOfWork.cs Unit of Work · Program.cs Program · AuthService.cs Auth & OTP
Components 21
Host
Application startup and composition root
- Program · Composes DI, middleware, auth, rate limits, and endpoint pipeline
Program.cs
API
HTTP entrypoints and request translation
- Feature controllers · Thin HTTP controllers for auth, catalog, cart, order, review, address, banner, OTP, and payment
Controllers - DTO contracts · Request and response shapes that decouple HTTP contracts from persistence models
DTOs
Application
Business services and workflow orchestration
- Auth & OTP · Login/register, JWT issuance, OTP verification, and security rules
Services/Implementations/AuthService.cs - Catalog · Product, category, and banner workflows including image handling
Services/Implementations/ProductService.cs - Cart · Cart merge, item updates, and shopping cart rules
Services/Implementations/CartService.cs - Orders · Checkout, snapshot creation, order lifecycle, and payment coordination
Services/Implementations/OrderService.cs - Users & address · Profile updates, password changes, default address logic, and address management
Services/Implementations/UserService.cs - Reviews · Review ownership and product feedback rules
Services/Implementations/ReviewService.cs - Payments · Razorpay initiation and signature verification for server-authoritative payment flow
Infrastructure/Payment/Implementations/RazorpayService.cs
Persistence
EF Core data access and transaction boundary
- Unit of Work · Cohesion and transaction boundary across repositories
Data/UnitOfWork.cs - Repositories · Aggregate repositories for users, products, categories, carts, orders, reviews, banners, and OTP records
Repositories/Implementations - DbContext · ShopNextDbContext persistence model and change tracking
Data/ShopNextDbContext.cs - Relational DB · EF Core-backed relational store with provider-specific configuration
Domain
Core commerce entities and contracts
- Domain models · User, product, cart, order, review, address, banner, payment, and OTP entities
Models
Integrations
External services and platform adapters
- Cloudinary · Server-side image uploads for products, categories, banners, and profiles
Infrastructure/Cloudinary/Implementations/CloudinaryService.cs - Razorpay · Online payment provider for initiation and verification
Infrastructure/Payment/Implementations/RazorpayService.cs - Redis cache · Caching, OTP, and rate-limit backing store
Infrastructure/Redis/RedisCacheService.cs
Cross-cutting
Shared security, caching, and runtime concerns
- Error middleware · Normalizes exceptions into consistent API responses
Middleware/ErrorHandlingMiddleware.cs - Rate limiting · Policy constants and limiter extensions for request caps
Extensions/RateLimiterExtensions.cs - JWT helper · Creates bearer tokens and claims for authenticated users
Helpers/JwtHelper.cs
Connections 31
- Program → Error middleware: adds · Registers centralized exception handling
- Program → Rate limiting: configures · Adds request limiting policies and extensions
- Program → JWT helper: wires · Registers authentication/token services
- Program → Feature controllers: maps · Exposes API endpoints through the HTTP pipeline
- Feature controllers → DTO contracts: uses · Accepts and returns typed request/response contracts
- Feature controllers → Auth & OTP: calls · Delegates auth and OTP workflows
- Feature controllers → Catalog: calls · Delegates product, category, and banner operations
- Feature controllers → Cart: calls · Delegates cart operations
- Feature controllers → Orders: calls · Delegates checkout and order placement
- Feature controllers → Users & address: calls · Delegates profile and address operations
- Feature controllers → Reviews: calls · Delegates review operations
- Feature controllers → Payments: calls · Delegates payment initiation and verification
- Auth & OTP → JWT helper: issues · Builds bearer tokens and claims
- Auth & OTP → Redis cache: stores · Uses cache for OTP and request-capped flows
- Auth & OTP → Unit of Work: persists · Reads/writes user and OTP state through repositories
- Catalog → Cloudinary: uploads · Stores product, category, banner, and profile images
- Catalog → Unit of Work: persists · Coordinates catalog writes and reads
- Cart → Unit of Work: persists · Updates cart aggregates and items
- Orders → Unit of Work: persists · Creates order snapshots and commits multi-entity changes
- Orders → Razorpay: verifies · Initiates and verifies payment lifecycle state
- Orders → Redis cache: checks · Relies on verification and throttling related cache state
- Users & address → Cloudinary: uploads · Handles profile photo updates
- Users & address → Unit of Work: persists · Updates user and address records
- Reviews → Unit of Work: persists · Stores and validates review ownership
- Payments → Razorpay: integrates · Uses gateway client for payment operations
- Unit of Work → Repositories: coordinates · Provides transaction and cohesion boundary
- Repositories → DbContext: uses · Implements data access on top of EF Core
- DbContext → Relational DB: writes · Persists commerce data to relational storage
- DbContext → Domain models: maps · Tracks entity sets and relationships
- Repositories → Domain models: queries · Reads and mutates domain entities
- Feature controllers → Error middleware: fails through · Unhandled errors are normalized by middleware