How leyen1403/myapi works
Project type and purpose
• This is a backend RESTful API built with ASP .NET Core, following a Clean/Onion architecture.
• Purpose: expose endpoints for managing employees and fetching external data (JSONPlaceholder, jokes).
File structure
• Top-level project “MyApi.sln” containing four projects:
• MyApi.Api – ASP .NET Core Web API (Presentation layer)
• MyApi.Application – CQRS handlers (Application layer)
• MyApi.Core – Domain entities, interfaces, models, options (Core layer)
• MyApi.Infranstructure – EF Core DbContext, repositories, HTTP client services (Infrastructure layer)
• Each layer has its own DependencyInjection.cs to register services.
• Migrations under Infrastructure represent database schema evolution.
Main components
A. Presentation / API layer
• Controllers: EmployeesController, ExternalVendorsController
• Program.cs / Startup: configures middleware, routing, dependency injection
B. Application layer
• Command handlers (AddEmployeeCommand, UpdateEmployeeCommand, DeleteEmployeeCommand)
• Query handlers (GetAllEmployeesQuery, GetEmployeeByIdQuery, GetJsonplaceholderDataQuery, GetRandomJokeQuery, GetTenJokeQuery)
C. Core layer
• Entities (EmployeeEntity), Models (Joke, Jsonplaceholder)
• Interfaces (IEmployeeRepository, IExternalVendorRepository, IJokeHttpClientService, IJsonplaceholderHttpClientService)
• Options (ConnectionStringOptions)
D. Infrastructure layer
• EF Core AppDbContext & Migrations
• Repositories (EmployeeRepository, ExternalVendorRepository) implementing Core interfaces
• HTTP‐client services (JokeHttpClientService, JsonplaceholderHttpClientService) implementing Core interfaces
E. External systems
• SQL Database
• JSONPlaceholder REST API
• Joke API
Relationships and data flows
1. Client → HTTP request → API Controllers
2. Controller → calls Application layer (Command or Query handlers)
3. Handler → depends on Core interfaces (IEmployeeRepository, IJokeHttpClientService, etc.)
4. Interface implementations reside in Infrastructure
• Repositories → AppDbContext → Database
• HTTP‐client services → external REST APIs
5. Responses bubble back: external/DB → Infrastructure → Application handler → API → Client
Architectural patterns and design principles
• Clean or Onion architecture: strict dependency rule (outer layers depend on inner layers only via interfaces).
• CQRS pattern: split Commands (writes) and Queries (reads) to organize business logic.
• Dependency Injection in each layer to decouple implementation.
• EF Core Code-First migrations for schema management.
• HttpClient wrapper services for external API integration.