How merttmetinn/smartsyncapi works
Main Components
• Presentation Layer (SmartSyncAPI.API):
• Contains the API controllers (AdminController, CartController, CustomerController, LogController, OrderController, ProductController) that expose HTTP endpoints.
• Includes middleware such as the TokenMiddleware for handling authentication issues.
• Holds configuration files (appsettings.json, launchSettings.json) which set up the runtime environment.
• Application Layer (SmartSyncAPI.Application):
• Implements use-case-specific features via Command and Query sub-folders (e.g., CreateAdmin, LoginAdmin, AddProduct, UpdateCart, etc.).
• Defines abstractions for repositories (read/write repository interfaces) and services (password hashing, token service) to ensure loose coupling.
• Centralizes business logic and mediates requests coming in from the API layer.
• Domain Layer (SmartSyncAPI.Domain):
• Contains core business entities (Admin, Cart, Customer, Log, Order, OrderProduct, Product) and DTOs.
• Defines common base classes and enumerations (e.g., BaseEntity, OrderStatus) that capture the domain’s rules and behaviour.
• Acts as the central point of the business logic without any dependencies on external components.
• Infrastructure/Persistence Layer (SmartSyncAPI.Persistance):
• Provides concrete implementations of the repository interfaces defined in the Application Layer.
• Manages data access through the SmartSyncDbContext (the Entity Framework Core context) along with corresponding migrations.
• Contains service registrations for integration (e.g., dependency injection configuration for repositories and services).
Relationships & Interactions
• The Presentation layer (API controllers) accepts HTTP requests, forwards them to the Application layer where the corresponding Command or Query handlers process the requests.
• The Application layer executes business logic and then interacts with the Infrastructure/Persistence layer through repository interfaces for data storage and retrieval.
• The Domain layer supplies the fundamental business models that are used across both Application and Infrastructure layers.
• Middleware (e.g., TokenMiddleware) and service implementations (TokenService, PasswordHasher) are cross-cutting concerns that ensure security and authentication.
Architectural Patterns and Design Principles
• Clean Architecture: The separation into Presentation, Application, Domain, and Infrastructure encourages a loosely coupled, easily maintainable structure.
• Repository Pattern: Both read and write repositories are abstracted in the Application layer and implemented concretely in the Infrastructure layer.
• Command-Query Responsibility Segregation (CQRS): Commands (for changes) and Queries (for data retrieval) are organized into distinct folders to separate mutating from querying operations.
• Dependency Injection: Evident in the service registrations for repositories and services, allowing easier testing and management of dependencies.