How mhkarami97/divarapi works
Main Components
• API Layer – Represented by the “MyApi” project and its Controllers inside MyApi/Controllers/v1. This layer receives client requests and delegates them to other parts of the system.
• Web Framework – The “WebFramework” project houses cross-cutting concerns such as custom controllers, middleware, filters, swagger configuration, and mapping configurations (AutoMapper). This can be depicted as a supporting infrastructure used by the API layer.
• Service Layer – The “Services” project contains the business logic, including functionalities like JWT token handling, data initialization, identity-related operations, scheduling cron jobs for notifications, and security operations. Use this to show where the application’s core logic lives.
• Repository/Data Access Layer – The “Data” and “Repositories” projects implement repository patterns to abstract data access. The “Data” folder with its ApplicationDbContext, migrations, and repository contracts, plus the “Repositories” project’s concrete implementations, indicate your data persistence strategy (likely using Entity Framework Core).
• Domain/Entities – The “Entities” project encapsulates the domain models (such as User, Post, Contact, Banner, etc.). These are the core business objects that are mapped to the database.
• Data Transfer Objects (DTOs) – The “Models” project holds DTOs that serve as the contracts between your API and its consumers. They ensure separation between internal data representations and external communication.
• Common Library – The “Common” project contains shared functionality (exceptions, settings, utilities, etc.), which are likely used across all layers for consistency and reducing code duplication.
• External Integrations – Although not explicitly a separate module, external services are present in the “Services/Notification” (e.g., Email and SMS notifications), as well as scheduled tasks (CronJob) that indicate integration with external email/SMS gateways.
• Testing – The “XUnitTest” project represents your testing layer to validate various components like controllers and utilities.
Relationships and Data Flow
• A client sends an HTTP request to the API layer.
• The API controllers (in MyApi/Controllers/v1) process the request, using components provided by the WebFramework (middleware, filters, etc.) to handle cross-cutting concerns (such as exception handling and security).
• The controllers call into the Service Layer (from Services) to execute business logic.
• The Service Layer in turn communicates with the Repository/Data Access Layer (Repositories and Data projects) to perform CRUD operations on the Domain Entities.
• The Domain Entities (in Entities) represent the persistent state and are connected to the database through the ApplicationDbContext.
• DTOs (from Models) are utilized to format and sanitize data as it moves between the client and the API.
• Additionally, aspects like identity management, notifications, and scheduled jobs are integrated within the Services layer interacting with external components.
• The Common library supports all these layers by providing shared utilities (for example, error handling and string operations).
Important Architectural Patterns and Principles
• Layered (or Onion/Clean Architecture) – You see distinct boundaries between the API, Service, Repository, and Domain layers.
• Repository Pattern – Abstracts database operations for a cleaner separation and easier testing.
• Dependency Injection – Evident from the configuration files and the modular structure, ensuring components are loosely coupled.
• Modular Design – Each project (Common, Data, Entities, Models, etc.) encapsulates a specific area of concern, promoting maintainability and extensibility.
Relevant Technologies and Frameworks
• .NET Core 3.1 – The framework underpinning the application.
• Entity Framework Core – Likely used for data persistence through the ApplicationDbContext and migrations.
• AutoMapper – For object mapping, as set in the WebFramework/CustomMapping directory.
• Logging and Configuration Tools – (nlog.config, appsettings.json files).
• Testing Framework – XUnit for unit tests.