# aws-samples/bobs-used-bookstore-classic architecture

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

- Interactive diagram: https://gitdiagram.com/aws-samples/bobs-used-bookstore-classic
- Repository: https://github.com/aws-samples/bobs-used-bookstore-classic

## Overview

##### Project type and purpose
- This is a full-stack ASP.NET MVC 5 web application targeting .NET Framework 4.8 (“Bob’s Used Books Classic”).
- It follows a layered architecture (Presentation → Domain → Data → Common) and can run locally (IIS Express + local DB/files) or be deployed to AWS via AWS CDK.

##### File structure
- Top-level “app” folder with four projects:
– Bookstore.Web: MVC presentation (Views, Controllers, Models, Middleware)
– Bookstore.Domain: business entities & services (service interfaces, DTOs, domain services)
– Bookstore.Data: EF DbContext, repositories, data services (local/S3 file services, Rekognition/validation)
– Bookstore.Common: shared constants, utilities
- AWS CDK project (Bookstore.Cdk) with four stacks: NetworkStack (VPC, subnets, ALB), DatabaseStack (RDS SQL Server), EcsStack (ECS Fargate cluster, task definitions), CoreStack (global IAM roles, S3 buckets, Cognito, CloudWatch LogGroups).
- Dockerfile for containerizing the .NET app, cdk.json for CDK context, LogMonitorConfig.json for logging setup.

##### Key points from the README
- The web.config toggles each service between “local” (in-process/local) and “aws” implementations.
- CDK stack “BobsUsedBooksClassicECS” builds a Windows container of the MVC app and deploys to ECS Fargate.
- AWS services used: Amazon Cognito, Amazon RDS (SQL Server), Amazon S3, Amazon Rekognition, Amazon CloudWatch.

a. Main components to represent
– User’s browser (HTTP(S) requests)
– Presentation layer (ASP.NET MVC app running in Windows container on ECS Fargate or locally in IIS Express)
– Domain layer (business logic services)
– Data layer (Entity Framework → RDS SQL Server or local DB)
– File service (local file system or Amazon S3)
– Image validation (local validators or Amazon Rekognition)
– Authentication (local store or Amazon Cognito user pool)
– Logging (local logs or Amazon CloudWatch)
– Infrastructure (VPC, public/private subnets, ALB, ECS cluster, RDS instance, S3 bucket, Cognito, CloudWatch).

b. Relationships and interactions
– Browser → ALB → ECS Fargate task → MVC Controllers
– Controllers → Domain services → Repositories → RDS (SQL)
– Controllers/Domain → FileService interface → S3 bucket (or local FS)
– Controller invoking AuthenticationController → Cognito User Pool (or local auth)
– Domain/ImageValidationService → Rekognition API (or local validation)
– Application → CloudWatch LogGroups/Streams via LoggingService interface
– CDK stacks interact to provision VPC → Subnets → RDS → ECS → supporting AWS services.

c. Architectural patterns & principles
– Layered architecture (Presentation, Domain, Data, Common)
– Repository pattern for data access
– Service interfaces for pluggable implementations (local vs. AWS)
– Dependency injection configured in Bookstore.Web/App_Start/DependencyInjectionSetup
– Infrastructure as Code via AWS CDK with separate stacks for networking, database, compute.

d. Key technologies/frameworks
– ASP.NET MVC 5 (.NET Framework 4.8)
– Entity Framework (Code First)
– AWS Cloud Development Kit (CDK) in .NET
– Docker Windows containers, ECS on Fargate
– Amazon RDS for SQL Server, Amazon S3, Amazon Rekognition, Amazon Cognito, Amazon CloudWatch.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    Browser["User Browser"]:::user

    %% AWS Infrastructure
    subgraph "AWS Infrastructure" 
        direction TB
        NS["NetworkStack"]:::infra
        NS --> VPC["VPC"]:::infra
        NS --> Subnets["Public/Private Subnets"]:::infra
        NS --> ALB["Application Load Balancer"]:::infra

        DBS["DatabaseStack"]:::infra
        DBS --> RDS["Amazon RDS (SQL Server)"]:::db

        ECSSt["EcsStack"]:::infra
        ECSSt --> ECS["ECS Fargate Cluster"]:::infra
        ECSSt --> TaskDef["Windows Container Task Definition"]:::infra

        CoreSt["CoreStack"]:::infra
        CoreSt --> IAM["IAM Roles"]:::infra
        CoreSt --> S3["Amazon S3 Bucket"]:::cloud
        CoreSt --> Cognito["Amazon Cognito"]:::cloud
        CoreSt --> Rekog["Amazon Rekognition"]:::cloud
        CoreSt --> CW["CloudWatch LogGroups"]:::cloud
    end

    %% Application Container
    subgraph "Application Container"
        direction TB
        WebApp["Bookstore.Web MVC App"]:::app
        DI["DependencyInjectionSetup"]:::app
        AuthSetup["AuthenticationSetup"]:::app
        LogSetup["LoggingSetup"]:::app
        Controllers["Controllers"]:::app
        Views["Views & ViewModels"]:::app
        Domain["Bookstore.Domain Services"]:::domain
        FileServiceIF["IFileService"]:::domain
        ImgResizeIF["IImageResizeService"]:::domain
        ImgValIF["IImageValidationService"]:::domain
        Data["Bookstore.Data"]:::data
        DbContext["ApplicationDbContext"]:::data
        Repos["Repositories"]:::data
        FileImpl["LocalFileService / S3FileService"]:::data
        ImgValImpl["LocalImageValidationService / RekognitionImageValidationService"]:::data
        Common["Bookstore.Common"]:::common
    end

    %% Local development mode
    FSLocal["Local File System"]:::infra
    LocalDB["Local SQL Server"]:::db

    %% Connections
    Browser -->|HTTPS| ALB
    ALB --> ECS
    ECS --> WebApp

    WebApp --> DI
    WebApp --> AuthSetup
    WebApp --> LogSetup
    WebApp --> Controllers
    WebApp --> Views

    Controllers --> Domain
    Domain --> FileServiceIF
    Domain --> ImgResizeIF
    Domain --> ImgValIF
    Domain --> Common
    Domain --> Data

    FileServiceIF --> FileImpl
    ImgValIF --> ImgValImpl
    Data --> DbContext
    Data --> Repos
    Repos --> RDS

    FileImpl --> S3
    FileImpl -->|Local FS| FSLocal

    ImgValImpl --> Rekog

    AuthSetup --> Cognito
    LogSetup --> CW

    DI -.-> FileServiceIF
    DI -.-> ImgValIF
    DI -.-> ImgResizeIF
    DI -.-> AuthSetup
    DI -.-> LogSetup

    WebApp -->|Local Mode| LocalDB
    LocalDB --> Repos

    %% Click Events
    click WebApp "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Web"
    click DI "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Web/App_Start/DependencyInjectionSetup.cs"
    click AuthSetup "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Web/App_Start/AuthenticationSetup.cs"
    click LogSetup "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Web/App_Start/LoggingSetup.cs"
    click Controllers "https://github.com/aws-samples/bobs-used-bookstore-classic/tree/main/app/Bookstore.Web/Controllers"
    click Views "https://github.com/aws-samples/bobs-used-bookstore-classic/tree/main/app/Bookstore.Web/Views"
    click Views "https://github.com/aws-samples/bobs-used-bookstore-classic/tree/main/app/Bookstore.Web/Models"
    click Domain "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Domain"
    click FileServiceIF "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Domain/IFileService.cs"
    click ImgResizeIF "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Domain/IImageResizeService.cs"
    click ImgValIF "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Domain/IImageValidationService.cs"
    click Data "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Data"
    click DbContext "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Data/ApplicationDbContext.cs"
    click Repos "https://github.com/aws-samples/bobs-used-bookstore-classic/tree/main/app/Bookstore.Data/Repositories"
    click FileImpl "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Data/FileServices/LocalFileService.cs"
    click FileImpl "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Data/FileServices/S3FileService.cs"
    click ImgValImpl "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Data/ImageValidationServices/LocalImageValidationService.cs"
    click ImgValImpl "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Data/ImageValidationServices/RekognitionImageValidationService.cs"
    click Common "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Common"
    click NS "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Cdk/NetworkStack.cs"
    click DBS "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Cdk/DatabaseStack.cs"
    click ECSSt "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Cdk/EcsStack.cs"
    click CoreSt "https://github.com/aws-samples/bobs-used-bookstore-classic/blob/main/app/Bookstore.Cdk/CoreStack.cs"

    %% Styles
    classDef app fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef domain fill:#87CEEB,stroke:#000,stroke-width:1px
    classDef data fill:#B0E0E6,stroke:#000,stroke-width:1px
    classDef common fill:#E0FFFF,stroke:#000,stroke-width:1px
    classDef infra fill:#F0E68C,stroke:#000,stroke-width:1px
    classDef db fill:#FFD700,stroke:#000,stroke-width:1px
    classDef cloud fill:#FFEFD5,stroke:#000,stroke-width:1px
    classDef user fill:#98FB98,stroke:#000,stroke-width:1px
```
