# hoanvirtue/sammistoreecommerce architecture

> Architecture diagram of the GitHub repository hoanvirtue/sammistoreecommerce, 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/hoanvirtue/sammistoreecommerce
- Repository: https://github.com/hoanvirtue/sammistoreecommerce

## Overview

##### Project type and overall purpose
- This is a full-stack ecommerce platform that includes a web front end (built with Next.js), a back-end API (with a .NET Core-based API implementing domain-driven design principles), and a mobile application (likely built with React Native). There is also an Angular-based shared library (“thamkhao/base-angular”) that might be used for common utilities or micro-frontends.
- The system supports ecommerce activities such as managing products, orders, users, and payment processing (with integration to VNPay, ElasticSearch for search features, and external file storage via Cloudinary/FileStorage).

##### Analyzing the file structure
- At the top level, you see configuration files, SQL scripts (database.sql, database_mysql.sql), and documentation. This indicates that the database design has been carefully planned.
- Under the “source” directory, there are clear segregations:
– “SAMMI.ECOM.API”: contains the .NET backend API. Its structure follows a layered approach: Controllers for handling HTTP requests, an Application layer with Command Handlers that follow CQRS principles, Domain and Core projects (with domain models, enums, and responses), and Infrastructure (for EF Core configurations, migrations, external service integrations like ElasticSearch, caching with Redis, and more).
– “SammiMobile”: contains the mobile app code including API integrations, navigation, screens, components, and socket communications.
– “thamkhao”: contains a base Angular library that is likely used as a shared module or service library.
- There are docker-compose files and Dockerfiles that indicate containerization and preparation for deployment.

a. Frontend (Web Client):
– Component: Next.js based Frontend (source/FE)
– Sub-components: pages, layouts, components (auth guards, custom UI widgets), localization, theming, and state management (contexts/stores).
– Interactions: Communicates with backend API through REST/GraphQL endpoints.
b. Mobile Client:
– Component: SammiMobile (React Native based mobile app)
– Sub-components: Screens, Navigation, API clients, Socket integration, Redux/Context state.
– Interactions: Consumes backend API endpoints (similar to Web) for authentication, payment, orders, etc.
c. Backend API:
– Component: .NET Core API (SAMMI.ECOM.API)
– Layers:
- Controllers (presentation layer exposing endpoints)
- Application (Command Handlers, Mediator patterns, transaction/validation behaviors)
- Domain (aggregates for products, orders, user, payment, shipping, etc.)
- Infrastructure (Entity Framework Core configurations, repositories, external integrations such as for ElasticSearch, caching with Redis, file/media storage, third-party payment services like VNPay and GHN)
- Cross-cutting concerns: AutoMapper, FluentValidation, and logging (SysLog)
– Interactions: Communicates with the database (using SQL scripts), consumes external services, and is consumed by the Frontend and Mobile.
d. Database:
– Component: SQL Database (as defined by database.sql)
– Represents storage for ecommerce data – product catalog, user data, orders, payments, reviews, etc.
e. Shared Libraries/Services:
– “thamkhao/base-angular”: A reusable Angular-based collection of models/services/components that might be used by parts of the system or provide guidelines for structuring code.
– Additional cross-cutting services (such as caching, logging, and messaging via Redis or other patterns).

##### Relationships and interactions
- Backend’s interaction with the SQL database (using Entity Framework Core and migrations) and external services (ElasticSearch for search capabilities, VNPay for payment processing, Cloudinary/FileStorage for media, and Redis for caching).
- Internal layers within the Backend API (Controllers → Application Layer (commands/handlers) → Domain Models → Infrastructure/Repositories).
- If needed, show integration with shared libraries (e.g., “thamkhao/base-angular”) as a component that may wrap certain common functions or data models.

##### Architectural patterns & design principles
- That the backend adheres to Domain-Driven Design (DDD) patterns such as separation of concerns (Controllers vs. Application vs. Domain vs. Infrastructure), use of Command Handler (CQRS) patterns, and an emphasis on scalability (with Docker Compose support and containerized services).
- For the UI, the design separates presentation (pages and layouts) from business logic (hooks, context) and is built as a Single-Page Application (SPA) using Next.js.
- The mobile app typically uses similar separation between view components, API services, and state management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interfaces
    subgraph "User Interfaces"
        FE["Next.js Web Client (Frontend)"]:::frontend
        Mobile["React Native Mobile App"]:::mobile
    end

    %% Backend API with internal layers
    subgraph "Backend API (.NET Core)"
        Controllers["Controllers\n(HTTP Endpoints)"]:::backend
        Application["Application Layer\n(Command Handlers,CQRS)"]:::backend
        Domain["Domain Models\n(Entities,Aggregates)"]:::backend
        Infrastructure["Infrastructure\n(Repositories,EF Core,External Integrations)"]:::backend
        Controllers -->|"calls"| Application
        Application -->|"processes"| Domain
        Domain -->|"persists"| Infrastructure
    end

    %% External and Data Services
    subgraph "External & Data Services"
        DB["SQL Database"]:::database
        DB1["database.sql"]:::database
        DB2["database_mysql.sql"]:::database
        Elastic["ElasticSearch\n(Search Service)"]:::external
        VNPay["VNPay\n(Payment Gateway)"]:::external
        Cloudinary["Cloudinary/FileStorage\n(Media Storage)"]:::external
        Redis["Redis\n(Caching)"]:::external
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        AngularLib["Shared Angular Library"]:::library
    end

    %% Relationships
    FE -->|"HTTP/REST"| Controllers
    Mobile -->|"HTTP/REST"| Controllers

    Infrastructure -->|"ORMqueries"| DB
    Infrastructure -->|"DBmigrations"| DB1
    Infrastructure -->|"DBmigrations"| DB2
    Infrastructure -->|"search"| Elastic
    Infrastructure -->|"payment"| VNPay
    Infrastructure -->|"storage"| Cloudinary
    Infrastructure -->|"cache"| Redis

    AngularLib -.->|"utilities"| FE
    AngularLib -.->|"utilities"| Mobile

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#1F78B4,stroke-width:2px;
    classDef mobile fill:#C2F0C2,stroke:#2CA02C,stroke-width:2px;
    classDef backend fill:#F7D6AE,stroke:#FF7F0E,stroke-width:2px;
    classDef database fill:#F7A8A8,stroke:#D62728,stroke-width:2px;
    classDef external fill:#E7E7E7,stroke:#636363,stroke-width:2px;
    classDef library fill:#D4B3FF,stroke:#6A5ACD,stroke-width:2px;

    %% Click Events
    click FE "https://github.com/hoanvirtue/sammistoreecommerce/tree/main/source/FE"
    click Mobile "https://github.com/hoanvirtue/sammistoreecommerce/tree/main/source/SammiMobile"
    click Controllers "https://github.com/hoanvirtue/sammistoreecommerce/blob/main/source/SAMMI.ECOM.API"
    click DB1 "https://github.com/hoanvirtue/sammistoreecommerce/blob/main/database.sql"
    click DB2 "https://github.com/hoanvirtue/sammistoreecommerce/blob/main/database_mysql.sql"
    click AngularLib "https://github.com/hoanvirtue/sammistoreecommerce/tree/main/thamkhao/base-angular"
```
