fix(00_ProjectStructure): modified the details and formattings

This commit is contained in:
2025-03-13 17:50:27 +03:30
parent 20d08cab8d
commit f9163fb61c
1316 changed files with 26 additions and 27 deletions
@@ -1,283 +0,0 @@
# Overview of Clean Architecture in an ASP.NET Core Project
Clean Architecture is a software design pattern that promotes separation of concerns, testability, and maintainability. It structures an application into layers, ensuring dependencies flow inwards (towards business logic) and that the core logic is independent of frameworks and external dependencies.
---
## **Clean Architecture Layers**
Clean Architecture consists of **four main layers**:
1. **Domain Layer (Core Business Rules)**
2. **Application Layer (Use Cases)**
3. **Infrastructure Layer (External Services & Data Access)**
4. **Presentation Layer (UI & API)**
### **1. Domain Layer (Enterprise Business Rules)**
- **Purpose**: Contains core business logic and rules that should be independent of frameworks and external systems.
- **Key Components**:
- **Entities** (Aggregates, Value Objects) → Represent business models.
- **Domain Events** → Events triggered by business logic.
- **Domain Services** → Logic that spans multiple entities.
- **Dependencies**: No external dependencies (completely independent).
- **Example**:
```csharp
public class Product
{
public int Id { get; private set; }
public string Name { get; private set; }
public decimal Price { get; private set; }
public Product(string name, decimal price)
{
Name = name;
Price = price;
}
}
```
---
### **2. Application Layer (Use Cases & Business Logic)**
- **Purpose**: Implements application-specific business logic, coordinating workflows, and executing use cases.
- **Key Components**:
- **Use Cases (Application Services)** → Define what the application does.
- **Commands & Queries** → For operations (CQRS pattern).
- **DTOs (Data Transfer Objects)** → Pass data without exposing domain models.
- **Interfaces for Repositories & Services** → Abstract dependencies (repositories, external APIs).
- **Dependencies**:
- Can reference **Domain Layer**.
- No dependency on Infrastructure or Presentation layers.
- **Example (Use Case)**:
```csharp
public class CreateProductCommand
{
public string Name { get; set; }
public decimal Price { get; set; }
}
public class ProductService
{
private readonly IProductRepository _productRepository;
public ProductService(IProductRepository productRepository)
{
_productRepository = productRepository;
}
public async Task<int> CreateProduct(CreateProductCommand command)
{
var product = new Product(command.Name, command.Price);
await _productRepository.AddAsync(product);
return product.Id;
}
}
```
---
### **3. Infrastructure Layer (Data & External Services)**
- **Purpose**: Provides implementations for repositories, external APIs, database access, logging, and file storage.
- **Key Components**:
- **Repositories (EF Core, Dapper, etc.)** → Implement database operations.
- **External Service Integrations** → Calls to third-party APIs.
- **Logging, Email, File Storage** → External services.
- **Dependencies**:
- References **Application Layer** (implementing interfaces).
- No direct reference to **Presentation Layer**.
- **Example (EF Core Repository)**:
```csharp
public class ProductRepository : IProductRepository
{
private readonly ApplicationDbContext _context;
public ProductRepository(ApplicationDbContext context)
{
_context = context;
}
public async Task AddAsync(Product product)
{
_context.Products.Add(product);
await _context.SaveChangesAsync();
}
}
```
---
### **4. Presentation Layer (UI & API)**
- **Purpose**: Handles HTTP requests, user interactions, and returns responses.
- **Key Components**:
- **Controllers (Web API in ASP.NET Core)** → Handle HTTP requests.
- **Views (Razor Pages, React, Blazor, etc.)** → UI rendering.
- **DTO Mapping (AutoMapper, MediatR, etc.)** → Maps domain models to response objects.
- **Dependencies**:
- References **Application Layer** (calls use cases).
- Should not directly reference **Infrastructure Layer**.
- **Example (Controller in ASP.NET Core)**:
```csharp
[ApiController]
[Route("api/products")]
public class ProductController : ControllerBase
{
private readonly ProductService _productService;
public ProductController(ProductService productService)
{
_productService = productService;
}
[HttpPost]
public async Task<IActionResult> CreateProduct([FromBody] CreateProductCommand command)
{
var productId = await _productService.CreateProduct(command);
return CreatedAtAction(nameof(CreateProduct), new { id = productId });
}
}
```
---
## **Dependencies Flow**
- **Presentation Layer** depends on **Application Layer**.
- **Application Layer** depends on **Domain Layer**.
- **Infrastructure Layer** depends on **Application Layer**.
- **Domain Layer** has NO dependencies.
This ensures the **business logic is central** and **not coupled** to frameworks, databases, or UI.
---
## **Example ASP.NET Core Clean Architecture Folder Structure**
```
/src
/Domain
/Entities
/ValueObjects
/DomainServices
/Application
/Interfaces
/Services
/DTOs
/UseCases
/Infrastructure
/Persistence
/Repositories
/ExternalServices
/Presentation
/Controllers
/Views (if MVC)
/ReactApp (if using React)
```
---
### **Summary**
- **Domain Layer**: Core business logic (Entities, Domain Events, Domain Services).
- **Application Layer**: Use cases (Application Services, CQRS, DTOs).
- **Infrastructure Layer**: External dependencies (Repositories, External APIs, Logging).
- **Presentation Layer**: UI & API (Controllers, Views, Frontend).
Would you like a more detailed breakdown for a specific area? 🚀
![[Pasted image 20250306182113.png]]
![[Pasted image 20250306182209.png]]
![[Pasted image 20250306182246.png]]
![[Pasted image 20250306182324.png]]
# Backend Project Structure
## **Solution Name: MyApp (or your project name)**
📂 **MyApp.sln** (Solution file)
### **1. Presentation Layer** (📂 `MyApp.WebAPI`)
- **Purpose:** Exposes the application via a web API.
📂 `MyApp.WebAPI`
- 📂 **Controllers** Defines API endpoints.
- 📂 **Middlewares** Implements custom middleware (logging, exception handling).
### Dependencies:
> Projects: ApplicationProject, DomainProject
> Packages: AutoMapper, Microsoft.EntityFrameworkCore.Design, Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.Tools, Newtonsoft.Json
---
### **2. Application Layer** (📂 `MyApp.Application`)
- **Purpose:** Contains the application logic, use cases, and service abstractions.
📂 `MyApp.Application`
- 📂 **Interfaces** Defines services like `IUserService`, `IOrderService`, etc.
- 📂 **Services** Defines services like `IUserService`, `IOrderService`, etc.
- 📂 **DTOs** Data Transfer Objects for input/output models.
- 📂 **Mappers** Maps domain models to DTOs (using AutoMapper or manual mapping).
- 📂 **Validators** Contains validation rules using FluentValidation.
### Dependencies:
>Projects: DomainProjec
>Packages: AutoMapper, Microsoft.Extensions.DependencyInjection
---
### **3. Core Domain Layer** (📂 `MyApp.Domain`)
- **Purpose:** Represents the core business logic and entities without dependencies on infrastructure or frameworks.
📂 `MyApp.Domain`
- 📂 **Aggregates** Groups related entities following DDD principles.
- 📂 **Framework** - **Interfaces** Contains domain-level abstractions like repository interfaces and entity interface.
- 📂 **Framework** - **Interfaces** **Repositories**
- 📂 **Framework** - **Base**
- 📂 **Enums** Defines domain-specific enumerations.
- 📂 **Factories**
### Dependencies:
>Packages: Microsoft.Extensions.DependencyInjection
---
### **4. Infrastructure Layer** (📂 `MyApp.Infrastructure`)
- **Purpose:** Implements external dependencies such as databases, logging, APIs, and caching.
📂 `MyApp.Infrastructure`
- 📂 **Framework** - **Base** Implements `IRepository<TEntity>` for data access.
- 📂 **Configurations** Stores EF Core entity configurations.
- 📂 **Services** - Repositories
- 📂 **Migrations** - Auto Created
- **DB-Context**
### Dependencies:
>Projects: DomainProjec
>Packages: Microsoft.EntityFrameworkCore.SqlServer
---
### **Additional Projects (Optional)**
- 📂 `MyApp.Tests` Unit and integration tests.
- 📂 `MyApp.Shared` Shared utilities (cross-cutting concerns like constants, helpers).
Check the structure and git and stuff
# Frontend Project Structure
```shell
npx create-react-app alibabaclone-frontend --use-npm --template typescript cd alibabaclone-frontend npm start
```
-113
View File
@@ -1,113 +0,0 @@
# Domain
> subject area in which we build an application
> We have some core domains and some sub domains
> Working out all domains is an iterative process
Bounded Context -> Each subdomain has its own bounded context so that they can each have their own "language"
Context Map -> outlines which domains communicate with each other and how
Anti-Corruption Level
Tactical Design
Domain Objects -> 1. Entity Objects 2. Value Objects
![[Pasted image 20250306182113.png]]
![[Pasted image 20250306182209.png]]
![[Pasted image 20250306182246.png]]
![[Pasted image 20250306182324.png]]
## **Solution Name: MyApp (or your project name)**
📂 **MyApp.sln** (Solution file)
### **1. Presentation Layer** (📂 `MyApp.WebAPI`)
- **Purpose:** Exposes the application via a web API.
📂 `MyApp.WebAPI`
- 📂 **Controllers** Defines API endpoints.
- 📂 **Middlewares** Implements custom middleware (logging, exception handling).
### Dependencies:
> Projects: ApplicationProject, DomainProject
> Packages: AutoMapper, Microsoft.EntityFrameworkCore.Design, Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.Tools, Newtonsoft.Json
---
### **2. Application Layer** (📂 `MyApp.Application`)
- **Purpose:** Contains the application logic, use cases, and service abstractions.
📂 `MyApp.Application`
- 📂 **Interfaces** Defines services like `IUserService`, `IOrderService`, etc.
- 📂 **Services** Defines services like `IUserService`, `IOrderService`, etc.
- 📂 **DTOs** Data Transfer Objects for input/output models.
- 📂 **Mappers** Maps domain models to DTOs (using AutoMapper or manual mapping).
- 📂 **Validators** Contains validation rules using FluentValidation.
>- 📂 **Queries** Handles read operations (CQRS pattern).
>- 📂 **Commands** Handles write operations (CQRS pattern).
>- 📂 **Exceptions** Defines application-layer exceptions.
>- 📂 **UseCases** Implements application logic (e.g., `CreateOrderHandler`).
### Dependencies:
>Projects: DomainProjec
>Packages: AutoMapper, Microsoft.Extensions.DependencyInjection
---
### **3. Core Domain Layer** (📂 `MyApp.Domain`)
- **Purpose:** Represents the core business logic and entities without dependencies on infrastructure or frameworks.
📂 `MyApp.Domain`
- 📂 **Aggregates** Groups related entities following DDD principles.
- 📂 **Framework** - **Interfaces** Contains domain-level abstractions like repository interfaces and entity interface.
- 📂 **Framework** - **Interfaces** **Repositories**
- 📂 **Framework** - **Base**
- 📂 **Enums** Defines domain-specific enumerations.
- 📂 **Factories**
>- 📂 **ValueObjects** Defines immutable objects that dont have an identity.
>- 📂 **Exceptions** Custom exceptions related to domain logic.
>- 📂 **Specifications** Encapsulates domain rules and query logic.
### Dependencies:
>Packages: Microsoft.Extensions.DependencyInjection
---
### **4. Infrastructure Layer** (📂 `MyApp.Infrastructure`)
- **Purpose:** Implements external dependencies such as databases, logging, APIs, and caching.
📂 `MyApp.Infrastructure`
- 📂 **Framework** - **Base** Implements `IRepository<TEntity>` for data access.
- 📂 **Configurations** Stores EF Core entity configurations.
- 📂 **Services** - Repositories
- 📂 **Migrations** - Auto Created
- **DB-Context**
>- 📂 **Persistence** Implements repositories and EF Core DbContext.
>- 📂 **Logging** Implements logging strategies (e.g., Serilog, NLog).
>- 📂 **Identity** Manages authentication and authorization.
>- 📂 **Caching** Implements caching strategies (Redis, MemoryCache).
>- 📂 **Email** Handles email services (SMTP, SendGrid).
>- 📂 **ExternalServices** Integrations with third-party APIs.
### Dependencies:
>Projects: DomainProjec
>Packages: Microsoft.EntityFrameworkCore.SqlServer
---
### **Additional Projects (Optional)**
- 📂 `MyApp.Tests` Unit and integration tests.
- 📂 `MyApp.Shared` Shared utilities (cross-cutting concerns like constants, helpers).
Check the structure and git and stuff
-116
View File
@@ -1,116 +0,0 @@
# Name: alibaba.ir
## Stack
> .NET 8 (LTS) - Domain Driven Design (DDD)
> Database: MS SQL Server - Code First - EF Core
> Front: React with TS
## Entities
### Person
id
firstname
lastname
...
### Role
Id
Title (User, Admin, Emp)
### Account
PersonId
RoleId
password
### Company
id
title
### Transportation
id
srcId
destId
startTime
endTime
capacity
remainingPlaces
vehicleId
price
companyId
### City
id
title
### Location
id
location
type
cityId
### Vehicle
id
typeId
### LocationType
id
typeId
### Ticket
tranportationId
seatId
buyerId
travellerId
cancelled
### Seat
vehicleId
row
column
vipFlag
### Transaction
buyerId
amount?
ticketId
couponId
serialNo
Not Mapped
### Search
###
###
## Phases
## Questions
### Authentication and Authorization
### Roles in database, how to handle multiple roles
### DB Management of person sub classes
### Should we complete the whole db
### How to handle tickets
## Tasks
- [x] Review ERD
- [x] Create a Project
- [x] Name + Structure
- [x] Talk about the privacy
- [x] Should we all fork the structure?
- [x] We should keep the site and keep it running
- [x] Picking the react course
- [x] A quick talk about the plans and timing.
[https://www.youtube.com/watch?v=SqcY0GlETPk](https://www.youtube.com/watch?v=SqcY0GlETPk)
[https://www.youtube.com/watch?v=g3is3wQK70Q](https://www.youtube.com/watch?v=g3is3wQK70Q)
-6
View File
@@ -1,6 +0,0 @@
# Plan
## Talking about clean architecture
## Talking about project structure
## Talking about plan and time
## Talking about ERD
## Talking about Class Time