# n0bcode/b3cbonsai architecture

> Architecture diagram of the GitHub repository n0bcode/b3cbonsai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/n0bcode/b3cbonsai
- Repository: https://github.com/n0bcode/b3cbonsai

## Overview

##### Primary components
- DataAccess Layer – Represented by the B3cBonsai.DataAccess project. It contains the DbContext (ApplicationDbContext) setup, migrations, and repository implementations (with clearly defined interfaces under the IRepository folder). This layer uses the Repository Pattern to encapsulate data persistence logic.
- Domain Models Layer – Represented by the B3cBonsai.Models project. It includes entity classes (e.g., SanPham, DonHang, BinhLuan etc.) and view models (in the ViewModels folder). These models represent the database schema as well as the objects used to present data.
- Utility Layer – Represented by the B3cBonsai.Utility project. It centralizes reusable code such as email functionality, helper classes, constants (e.g., SD.cs for static definitions of roles, order statuses, etc.), and extension methods.
- Presentation/Web Layer – Represented by the B3cBonsaiWeb project. Being an ASP.NET Core MVC web application, it includes:
- Areas: with separate sub-systems for Customer (with controllers like CartController, ClientProductController, ClientProfileController and corresponding views) and Employee (with further subdivisions for Admin and Staff functionalities).
- Identity: Dedicated Razor Pages for account access and management.
- wwwroot: Contains the static assets (scripts, css, fonts, images) distributed separately for customer and employee interfaces.

##### Inter-layer dependencies and interactions
- The Web project (B3cBonsaiWeb) depends on the Models, Utility, and DataAccess projects.
- DataAccess relies on the repository interfaces (from IRepository subfolder) to interact with application data through Entity Framework (via ApplicationDbContext).
- The presentation layer (Controllers and Razor Views) interacts with the domain models and utilizes utility classes (such as EmailSender or VnPayLibrary) to process user requests and business logic.
- The Areas structure under B3cBonsaiWeb enforces role-based separation of views and controllers for customers versus employees, while Identity handles the authentication/authorization features.

##### Architectural patterns and design principles
- Layered Architecture: Each project (DataAccess, Models, Utility, Web) serves a distinct purpose with minimal coupling.
- Repository Pattern: In the DataAccess project, repositories encapsulate data access logic, and interfaces ensure that the business logic is decoupled from the persistence mechanism.
- MVC Pattern: Within the B3cBonsaiWeb project, the separation of Controllers, Views, and (implicitly) Models (sometimes enhanced via ViewModels) adheres to the MVC design pattern.
- Area/Modular design: The use of separate Areas (Customer, Employee, Identity) in the Web project promotes an organized separation of different application domains and functionalities.

– DataAccess with its internal components like Data (DbContext), Migrations, Repository (and its IRepository interfaces).
– Models (with domain entities and view models).
– Utility (helper classes, email services, static definitions).
– Web (ASP.NET Core) which should be split further into:
▸ Areas: Customer (with controllers and views for shopping, order management, and profile) and Employee (with administrative interfaces and dashboards).
▸ Identity: For account management (Razor Pages for login, registration, password management).
– Static Assets (wwwroot): Separate parts for customer and employee user interfaces.
– From Web to DataAccess (when Controllers invoke repository methods).
– From DataAccess back to Web (passing results and domain entities).
– Utility components offering shared services to both Web and DataAccess when needed.
- That the Controllers in the Web layer render Views (Razor pages) that make up the user interface. Mark the typical flow from HTTP Request → Controller → DataAccess/Models → View.

##### Architectural details
- Zoning: Separate the full-stack responsibilities into clear layers with minimal cross-layer references.
- Communication: Illustrate how the front-end (customer and employee areas) interacts with business logic, which in turn uses repository patterns to connect with the database.
- Technologies: Note the use of ASP.NET Core MVC, Entity Framework Core (in DataAccess), and various client-side libraries (Bootstrap, jQuery, etc.) as seen in the wwwroot directory.
- Scalability Approaches: Though not explicitly detailed, the separation suggests that additional features or modules can be built into each layer without affecting others.

- How the web application depends on the Models, DataAccess (with Repository pattern), and Utility libraries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Browser["Browser/Client"]:::client

    %% Web Application Node
    B3cBonsaiWeb["B3cBonsaiWeb (Web Application)"]:::frontend

    %% Presentation/Web Layer Subgraph
    subgraph "Presentation/Web Layer"
        Customer["Customer Area"]:::frontend
        Employee["Employee Area"]:::frontend
        Identity["Identity (Authentication)"]:::frontend
        StaticAssets["Static Assets (wwwroot)"]:::frontend
        AdditionalServices["Additional Services"]:::frontend
    end

    %% DataAccess Layer Subgraph
    subgraph "DataAccess Layer"
        DContext["ApplicationDbContext (DbContext)"]:::backend
        Migrations["Migrations"]:::backend
        Repository["Repository & Interfaces"]:::backend
    end

    %% Domain Models Subgraph
    subgraph "Domain Models"
        Entities["Entities (SanPham,DonHang,BinhLuan)"]:::backend
        ViewModels["ViewModels"]:::backend
    end

    %% Utility Layer Subgraph
    subgraph "Utility Layer"
        EmailSender["EmailSender"]:::backend
        VnPayLib["VnPayLibrary"]:::backend
        EmailSettings["EmailSettings"]:::backend
        SD["Static Definitions (SD)"]:::backend
        Extensions["Extension Methods"]:::backend
    end

    %% Connections
    Browser -->|"HTTPRequest"| B3cBonsaiWeb
    B3cBonsaiWeb --> Customer
    B3cBonsaiWeb --> Employee
    B3cBonsaiWeb --> Identity
    B3cBonsaiWeb --> StaticAssets
    B3cBonsaiWeb --> AdditionalServices

    Customer -->|"calls"| Repository
    Employee -->|"calls"| Repository
    Repository -->|"returns"| Entities
    Repository -->|"configures"| DContext
    DContext -->|"migrates"| Migrations
    Repository -->|"maps"| ViewModels

    B3cBonsaiWeb -->|"uses"| SD
    AdditionalServices -->|"utilizes"| VnPayLib
    Customer -.->|"notifies"| EmailSender
    B3cBonsaiWeb -->|"authenticates"| Identity

    %% Click Events for DataAccess Layer
    click DContext "https://github.com/n0bcode/b3cbonsai/blob/master/B3cBonsai.DataAccess/Data/ApplicationDbContext.cs"
    click Migrations "https://github.com/n0bcode/b3cbonsai/tree/master/B3cBonsai.DataAccess/Migrations"
    click Repository "https://github.com/n0bcode/b3cbonsai/tree/master/B3cBonsai.DataAccess/Repository"

    %% Click Events for Domain Models Layer
    click Entities "https://github.com/n0bcode/b3cbonsai/blob/master/B3cBonsai.Models/SanPham.cs"
    click ViewModels "https://github.com/n0bcode/b3cbonsai/tree/master/B3cBonsai.Models/ViewModels"

    %% Click Events for Utility Layer
    click EmailSender "https://github.com/n0bcode/b3cbonsai/blob/master/B3cBonsai.Utility/EmailSender.cs"
    click VnPayLib "https://github.com/n0bcode/b3cbonsai/blob/master/B3cBonsai.Utility/Helper/VnPayLibrary.cs"
    click EmailSettings "https://github.com/n0bcode/b3cbonsai/blob/master/B3cBonsai.Utility/Helper/EmailSettings.cs"
    click SD "https://github.com/n0bcode/b3cbonsai/blob/master/B3cBonsai.Utility/SD.cs"
    click Extensions "https://github.com/n0bcode/b3cbonsai/tree/master/B3cBonsai.Utility/Extentions"

    %% Click Events for Presentation/Web Layer
    click Customer "https://github.com/n0bcode/b3cbonsai/tree/master/B3cBonsaiWeb/Areas/Customer/Controllers"
    click Employee "https://github.com/n0bcode/b3cbonsai/tree/master/B3cBonsaiWeb/Areas/Employee/Controllers"
    click Identity "https://github.com/n0bcode/b3cbonsai/tree/master/B3cBonsaiWeb/Areas/Identity/Pages"
    click StaticAssets "https://github.com/n0bcode/b3cbonsai/tree/master/B3cBonsaiWeb/wwwroot"
    click AdditionalServices "https://github.com/n0bcode/b3cbonsai/tree/master/B3cBonsaiWeb/Services"
    click B3cBonsaiWeb "https://github.com/n0bcode/b3cbonsai/tree/master/B3cBonsaiWeb"

    %% Styles
    classDef backend fill:#fdd, stroke:#900, stroke-width:2px;
    classDef frontend fill:#ddf, stroke:#009, stroke-width:2px;
    classDef client fill:#dfd, stroke:#090, stroke-width:2px;
```
