# danialtien/bookstore architecture

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

- Interactive diagram: https://gitdiagram.com/danialtien/bookstore
- Repository: https://github.com/danialtien/bookstore

## Overview

##### Project Type and Purpose
- This is a full-stack e-commerce application for managing and shopping a book store. It implements an N-Tier architecture, using ASP.NET Core (with both MVC and Razor Pages approaches) along with Identity for authentication/authorization, Stripe for payment processing, external authentication (Google/Facebook), and email notifications.
- The README confirms that the system is designed for both administrative and customer interactions, and uses modern ASP.NET Core practices, Entity Framework Core with the Repository Pattern, and dependency injection.

##### Analyzing the File Structure
- There are multiple projects in the solution:
- BookStore.DataAccess: Contains the EF Core ApplicationDBContext, all EF Migrations, and the Repository Pattern implementations (interfaces and concrete repository classes). This serves as the data layer.
- BookStore.Models: Contains the domain models (like ApplicationUser, Category, Company, Product, ShoppingCart, etc.) and view models for transferring UI data.
- BookStore.Utility: Provides utility classes such as EmailSender and application constants (SD.cs) that support other layers.
- BookStoreWeb: Implements the MVC style application for both Admin and Customer areas. It holds Controllers, Views, configuration files, and static assets (CSS, JS, images) and integrates identity and external authentication.
- BookStore_Razor: Offers an alternative implementation using Razor Pages following a similar pattern (pages for Categories, Home, Privacy, etc.).
- Key configuration and startup files (Program.cs, appsettings.json) indicate the use of ASP.NET Core’s dependency injection and middleware pipelines.

##### Main Components
a. Data Layer:
- BookStore.DataAccess: EF Core context, migrations, repositories, and unit of work. Use a database symbol (e.g., for SQL Server using EF Core).
b. Domain Models:
- BookStore.Models: Core domain entities (e.g., Product, Category, Company, ApplicationUser, ShoppingCart) used across the application.
c. Utility/Helper Classes:
- BookStore.Utility: Contains helper classes for emails and shared constants.
d. Presentation Layer:
- BookStoreWeb: Split into:
- Admin Area: Controllers and views for managing categories, companies, products.
- Customer Area: Controllers and views for home display, shopping cart, order summary.
- Identity and Authentication components – integration with external login providers.
- BookStore_Razor: Razor Pages implementation for similar functionalities but using a page-based approach.
e. External Services:
- Third-party services such as Stripe (for payments), Google/Facebook authentication, and email servers/SMTP for notifications.
- Hosting environment: Microsoft Azure for deployment.

##### Relationships and Data Flow
- The Presentation Layer (both MVC controllers in BookStoreWeb and Razor pages in BookStore_Razor) communicates with the Data Layer via repository interfaces.
- The Data Layer (BookStore.DataAccess) accesses the actual database.
- The Domain Models (BookStore.Models) are shared by both the Data and Presentation layers.
- Utility/helper functions (from BookStore.Utility) are used across various layers (e.g., EmailSender is invoked during user registration or order confirmation).
- External authentication and payment services interact with the Presentation layer through middleware and service integration.

##### Architectural Patterns and Critical Design Principles
- The system follows an N-Tier architecture with clear separation between data access, business/domain logic, and presentation.
- The Repository Pattern and Unit of Work are used to abstract database operations.
- ASP.NET Core Identity is integrated for robust user management.
- The use of MVC for one part of the project (BookStoreWeb) and Razor Pages in another (BookStore_Razor) demonstrates flexibility in the UI approach.
- Dependency injection is used extensively to decouple components.

##### Additional Elements for Maximum Detail
- Two implementations (MVC vs. Razor Pages) to show the parallel UI approaches in the overall system.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        subgraph "BookStoreWeb (MVC)"
            A1["Admin Controllers & Views"]:::mvc
            A2["Customer Controllers & Views"]:::mvc
            A3["Identity & Authentication"]:::mvc
            A4["BookStoreWeb Startup"]:::config
        end
        subgraph "BookStore_Razor (Razor Pages)"
            B1["Razor Pages Implementation"]:::razor
            B2["BookStore_Razor Startup"]:::config
        end
    end

    %% Domain Models
    D1["BookStore.Models (Domain Entities)"]:::domain

    %% Data Layer and Database
    D2["BookStore.DataAccess (EF Core & Repositories)"]:::data
    DB["SQL Server Database"]:::database

    %% Utility/Helper Classes
    U1["BookStore.Utility (Helpers & Constants)"]:::utility

    %% External Services
    ES1["Stripe Payment Integration"]:::external
    ES2["External Auth (Google/Facebook)"]:::external
    ES3["Email Notifications/SMTP"]:::external

    %% Relationships
    %% Presentation Layer uses Domain Models
    A1 -->|"uses"| D1
    A2 -->|"uses"| D1
    A3 -->|"uses"| D1
    B1 -->|"uses"| D1

    %% Domain Models communicate with Data Layer
    D1 -->|"calls"| D2
    D2 -->|"persists"| DB

    %% Utility interconnects with Presentation
    U1 -->|"helpers"| A1
    U1 -->|"helpers"| A2
    U1 -->|"helpers"| A3
    U1 -->|"helpers"| B1

    %% Startup nodes (Configuration)
    A4 -->|"configures"| D1
    B2 -->|"configures"| D1

    %% External Service interactions
    A3 -->|"authenticates"| ES2
    A2 -->|"payment"| ES1
    A2 -->|"emails"| ES3
    B1 -->|"payment"| ES1
    B1 -->|"emails"| ES3

    %% Click Events for Component Mappings
    click A1 "https://github.com/danialtien/bookstore/tree/master/BookStoreWeb/Areas/Admin"
    click A2 "https://github.com/danialtien/bookstore/tree/master/BookStoreWeb/Areas/Customer"
    click A3 "https://github.com/danialtien/bookstore/tree/master/BookStoreWeb/Areas/Identity"
    click A4 "https://github.com/danialtien/bookstore/blob/master/BookStoreWeb/Program.cs"
    click B1 "https://github.com/danialtien/bookstore/tree/master/BookStore_Razor"
    click B2 "https://github.com/danialtien/bookstore/blob/master/BookStore_Razor/Program.cs"
    click D1 "https://github.com/danialtien/bookstore/blob/master/BookStore.Models"
    click D2 "https://github.com/danialtien/bookstore/blob/master/BookStore.DataAccess"
    click U1 "https://github.com/danialtien/bookstore/blob/master/BookStore.Utility"

    %% Class Definitions for Colors
    classDef mvc fill:#FFCCCC,stroke:#000,stroke-width:2px;
    classDef razor fill:#FFE6E6,stroke:#000,stroke-width:2px;
    classDef config fill:#CCCCFF,stroke:#000,stroke-width:2px;
    classDef domain fill:#99CCFF,stroke:#000,stroke-width:2px;
    classDef data fill:#FFCC00,stroke:#000,stroke-width:2px;
    classDef utility fill:#CCFFCC,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef database fill:#F0E68C,stroke:#000,stroke-width:2px;
```
