# alan2207/e-shop-with-mf architecture

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

- Interactive diagram: https://gitdiagram.com/alan2207/e-shop-with-mf
- Repository: https://github.com/alan2207/e-shop-with-mf

## Overview

##### Main Components
- Main Application Shell – Acts as the central container. It “glues” all the micro frontends together. It is built with Next.js and handles routing and layout.
- Products Application – Manages and displays the products list and product detail pages with functionality to add products.
- Cart Application – Manages user cart state and related interactions.
- Checkout Application – Handles the user checkout process.
- Home Application – Displays the e-commerce home page with a Vue.js-based UI.
- Shared Package – Contains utilities, API clients (for example, the API client for the FakeStore API), state management helpers, and other shared functionality available to all micro frontends.
- External API Layer – The FakeStore API (https://fakestoreapi.com/) which supplies product data.

##### Relationships and Interactions
- The Main application acts as the shell that loads the individual micro frontends via Webpack Module Federation.
- Each micro frontend (Products, Cart, Checkout, Home) is an independent module running on a distinct port during development and deployed separately in production.
- A shared library/package is used by the micro frontends to centralize common code, which may include API communications (like API client calls to FakeStore API), utility functions, and even state management hooks.
- Data flows from the external FakeStore API into the Products app, and then through interactions (e.g., “add to cart”) into the Cart and Checkout applications.
- Communication between these micro frontends might be handled via public APIs exposed through Module Federation and by leveraging the shared library.

##### Architectural Patterns and Design Principles
- Micro Frontend Architecture: Each application (or microservice) is developed, built, and deployed independently yet composed together at runtime.
- Module Federation: Uses Webpack Module Federation to share code and load remote modules dynamically.
- Separation of Concerns: The monorepo structure clearly separates each application’s code with its own configuration, pages, and components – while also sharing common code via the “packages/shared” module.
- Technology Stack: Next.js is used for most apps (Main, Products, Cart, Checkout) while Vue.js is used for the Home app; TypeScript underpins the code for type safety; styling is consistent with Tailwind CSS.

##### Final Detailing
- Configuration or deployment notes (like how production assets might be hosted on a CDN) if relevant to the overall system design.
- Mention that each micro frontend is self-contained with its own ESLint configurations, TailwindCSS, and build scripts, reinforcing the independence of each module.
- Optionally, include a small inset showing the overall deployment strategy (as depicted by the Deployment Overview in the README) which indicates the server for Main, cloud storage/CDN for micro frontends, and how the shared library could be deployed via NPM or included in the monorepo.

## Diagram (Mermaid)

```mermaid
graph TD
    M["Main Application Shell (Next.js)"]:::shell
    P["Products Application (Next.js)"]:::next
    C["Cart Application (Next.js)"]:::next
    CO["Checkout Application (Next.js)"]:::next
    H["Home Application (Vue.js)"]:::vue
    S["Shared Package (Utilities, API Clients)"]:::shared
    E["FakeStore API (External)"]:::external

    %% Main Application federates micro frontends
    M -->|"federates"| P
    M -->|"federates"| C
    M -->|"federates"| CO
    M -->|"federates"| H

    %% Micro frontends and Main use Shared Package
    M -->|"uses"| S
    P -->|"uses"| S
    C -->|"uses"| S
    CO -->|"uses"| S
    H -->|"uses"| S

    %% External API supplies data to Products Application
    E -->|"supplies"| P

    %% Click Events
    click M "https://github.com/alan2207/e-shop-with-mf/tree/main/apps/main"
    click P "https://github.com/alan2207/e-shop-with-mf/tree/main/apps/products"
    click C "https://github.com/alan2207/e-shop-with-mf/tree/main/apps/cart"
    click CO "https://github.com/alan2207/e-shop-with-mf/tree/main/apps/checkout"
    click H "https://github.com/alan2207/e-shop-with-mf/tree/main/apps/home"
    click S "https://github.com/alan2207/e-shop-with-mf/tree/main/packages/shared"

    %% Styles
    classDef shell fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef next fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef vue fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef shared fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#333,stroke-width:2px;
```
