# durundur/electro-app architecture

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

- Interactive diagram: https://gitdiagram.com/durundur/electro-app
- Repository: https://github.com/durundur/electro-app

## Overview

##### Major Components
a. Backend API:
- Two similar backend codebases are present (“electro.api.rest.new” and “electro.api.rest”) that implement the web API. These expose endpoints for key business functionality like authentication (login, register, refresh token), product catalog operations, cart management, orders, opinions, and product hierarchy.
- The backend is implemented in layered architecture:
– Application Layer: Contains “Features” such as Auth, Cart, Order, ProductCatalog, ProductHierarchy, and shared functionality. This layer handles commands, queries, mapping, handlers, and service orchestration.
– Domain Layer: Contains rich domain models (aggregates like CartAggregate, OrderAggregate, ProductCatalogAggregate, etc.), domain exceptions, repositories interfaces, and value objects.
– Infrastructure Layer: Provides ORM configurations (Entity Framework mappings, migrations), repository implementations, external services (identity, token, user context), and database context for Postgresql.
– Web API Layer: Includes controllers, middleware (for exception handling, authentication), DTO mappings, and API-specific configurations.
b. Database:
- Postgresql is used as a persistence store. The data model uses Entity Framework’s migration files to manage schema evolution.
c. Frontend Clients:
- The Vue3/Nuxt3 “electro.client” project is the primary storefront client based on the README. It covers pages for account management, shopping cart, checkout flows, product details, search, and admin panels.
- The “electro.client.react” project (using Next.js and React) adds another flavor of the client interface – possibly for a different user role or an alternative approach.
d. Additional/Supporting Services:
- “files.api.rest” appears to handle file operations (uploading, serving images, etc.) which might be integrated with the main API.
- There are shared API contracts, DTO mappings, and libraries (like the “nswag” generated stuff) that define the communication protocols between the frontend and backend.

##### Component Interactions
– The API controllers (in both “electro.api.rest.new” and “electro.api.rest”) forward requests into the application layer where business logic is processed.
– The Application layer interacts with the Domain layer for business rules and with the Infrastructure layer to manage persistence, identity, and external services.
– The Infrastructure layer then communicates with the Postgresql database (also shown as a distinct component) and with any external identity providers or file storage systems.
– In addition, the “files.api.rest” service should be depicted as a standalone or auxiliary service that the frontend or backend may call when handling file uploads/downloads.

##### Architectural Patterns and Design Principles
– Emphasize the layered architecture / Domain-Driven Design (DDD) pattern with clear separation between domain, application, and infrastructure.
– Note the usage of patterns like CQRS (Command/Query separation is visible in the “Features” by splitting commands, queries, handlers, and results).
– Mark the common structures like repositories (interfaces defined in Domain and implementations in Infrastructure) and identity/exception handling services.
– On the frontend side, the separation between admin and shop (user-facing) flows is clearly distinguished by folder structures (e.g., “(admin)” vs. “(shop)” in Nuxt).

##### Relevant Technology and Tools
– Backend: .NET 8, Entity Framework 8 for ORM, Postgresql as the database.
– Frontend: Vue3 with Nuxt3 for the Vue-based application and React with Next.js in the alternative client app.
– External tools: Docker (Dockerfiles in several projects), migration tools, and third-party libraries for state management (Redux in React, Vue/Nuxt store), authentication flows, etc.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Clients
    subgraph "Frontend Clients"
        Vue3["Vue3/Nuxt3 Storefront"]:::frontend
        React["React/Next.js Client"]:::frontend
    end

    %% Backend API Group
    subgraph "Backend API"
        %% Clean Architecture - New Codebase
        subgraph "Clean Architecture - New Codebase"
            WebAPI_New["Web API Layer (Controllers, Middleware)"]:::backend
            App_New["Application Layer (Features: Auth, Cart, Order, ProductCatalog, ProductHierarchy)"]:::backend
            Domain_New["Domain Layer (Aggregates, Domain Exceptions, Repositories Interfaces)"]:::backend
            Infra_New["Infrastructure Layer (EF Mappings, Repositories, External Services)"]:::backend
        end
        %% Original API Codebase
        subgraph "Original API Codebase"
            Controllers_Orig["Controllers"]:::backend
            DTOs_Orig["DTOs"]:::backend
        end
    end

    %% Supporting Services
    subgraph "Supporting Services"
        DB["Postgresql Database"]:::db
        Files["Files Service (File Uploads/Downloads)"]:::files
    end

    %% Connections from Frontend Clients to Backend API
    Vue3 -->|"HTTP/REST"| WebAPI_New
    React -->|"HTTP/REST"| Controllers_Orig

    %% Internal Backend Flow (New Clean Architecture)
    WebAPI_New -->|"calls"| App_New
    App_New -->|"invokes"| Domain_New
    App_New -->|"delegates"| Infra_New
    Infra_New -->|"persistsTo"| DB

    %% File Service interactions (dotted arrow for asynchronous/integrated calls)
    WebAPI_New -.->|"fileOps"| Files
    Controllers_Orig -.->|"fileOps"| Files

    %% Styling for clarity (colors)
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:1px;
    classDef backend fill:#F7D6AE,stroke:#333,stroke-width:1px;
    classDef db fill:#C1F7C1,stroke:#333,stroke-width:1px;
    classDef files fill:#F7C1F7,stroke:#333,stroke-width:1px;

    %% Click Events for Component Mappings
    click App_New "https://github.com/durundur/electro-app/tree/main/electro.api.rest.new/Application"
    click Domain_New "https://github.com/durundur/electro-app/tree/main/electro.api.rest.new/Domain"
    click Infra_New "https://github.com/durundur/electro-app/tree/main/electro.api.rest.new/Infrastructure"
    click WebAPI_New "https://github.com/durundur/electro-app/tree/main/electro.api.rest.new/WebAPI"
    click Controllers_Orig "https://github.com/durundur/electro-app/tree/main/electro.api.rest/Controllers"
    click DTOs_Orig "https://github.com/durundur/electro-app/tree/main/electro.api.rest/Dtos"
    click DB "https://github.com/durundur/electro-app/tree/main/electro.api.rest.new/Infrastructure/Migrations"
    click Vue3 "https://github.com/durundur/electro-app/blob/main/electro.client"
    click React "https://github.com/durundur/electro-app/blob/main/electro.client.react"
    click Files "https://github.com/durundur/electro-app/blob/main/files.api.rest"
```
