# antkaynak/keyist-ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/antkaynak/keyist-ecommerce
- Repository: https://github.com/antkaynak/keyist-ecommerce

## Overview

##### High-Level Components
- Client Application (Angular Frontend)
- Authorization Server (OAuth2)
- Resource Server (Backend API)
- MySQL Database

##### Client Application (Angular) Layer
Following components:
- Store Module (using NgRx for state management)
- Auth Store
- Cart Store
- Order Store
- Product Store
- Core Modules:
- Account
- Auth
- Browse
- Cart
- Checkout
- Product
- Services Layer:
- Account Service
- Auth Guard
- Cart Service
- Order Service
- Product Service
- Token Service

##### Authorization Server
OAuth2 components:
- Auth Server Config
- Security Config
- User Repository
- Token Management

##### Resource Server
Components:
- REST Controllers Layer
- Service Layer:
- Product Service
- Cart Service
- Order Service
- User Service
- Cache Services
- Repository Layer
- Model Layer:
- Entities
- DTOs
- Request/Response objects

##### Database Layer
Main database tables:
- Users
- Products
- Orders
- Cart
- Categories
- Variants

##### Integration Points
- Client → Authorization Server (OAuth2 flow)
- Client → Resource Server (Protected API calls)
- Authorization Server → Database
- Resource Server → Database
- Resource Server → Authorization Server (Token validation)

##### Additional Elements
Include:
- Cache layer for products
- Email service integration
- CORS filter
- Security boundaries

Styling Guidelines:
- Blue: Frontend components
- Green: Authorization server
- Orange: Resource server
- Gray: Database
- Purple: External services

- Double lines: Data synchronization

- Security boundaries
- Cache mechanisms

Important Architectural Notes:

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef auth fill:#2ecc71,stroke:#27ae60,color:white
    classDef resource fill:#e67e22,stroke:#d35400,color:white
    classDef database fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef service fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        F[Frontend]:::frontend
        A[Auth Server]:::auth
        R[Resource Server]:::resource
        D[(Database)]:::database
        S[Services]:::service
    end

    %% Client Application Layer
    subgraph "Client Application"
        %% Store Module
        subgraph "Store Module"
            AuthStore["Auth Store"]:::frontend
            CartStore["Cart Store"]:::frontend
            OrderStore["Order Store"]:::frontend
            ProductStore["Product Store"]:::frontend
        end

        %% Core Modules
        subgraph "Core Modules"
            Account["Account Module"]:::frontend
            Auth["Auth Module"]:::frontend
            Cart["Cart Module"]:::frontend
            Checkout["Checkout Module"]:::frontend
        end

        %% Services
        subgraph "Services Layer"
            AccountService["Account Service"]:::frontend
            AuthGuard["Auth Guard"]:::frontend
            CartService["Cart Service"]:::frontend
            OrderService["Order Service"]:::frontend
            ProductService["Product Service"]:::frontend
            TokenService["Token Service"]:::frontend
        end
    end

    %% Authorization Server
    subgraph "Authorization Server"
        AuthConfig["Auth Server Config"]:::auth
        SecurityConfig["Security Config"]:::auth
        UserRepo["User Repository"]:::auth
        TokenManagement["Token Management"]:::auth
        AuthCORS["CORS Filter"]:::auth
    end

    %% Resource Server
    subgraph "Resource Server"
        Controllers["REST Controllers"]:::resource
        ResourceServices["Service Layer"]:::resource
        Repositories["Repository Layer"]:::resource
        Models["Model Layer"]:::resource
        CacheServices["Cache Services"]:::resource
        ResourceCORS["CORS Filter"]:::resource
    end

    %% Database Layer
    subgraph "Database"
        DB[(MySQL Database)]:::database
        Users[("Users")]:::database
        Products[("Products")]:::database
        Orders[("Orders")]:::database
        CartDB[("Cart")]:::database
    end

    %% Relationships
    Client --> |OAuth2 Flow| AuthConfig
    Client --> |API Calls| Controllers
    AuthConfig --> DB
    Controllers --> ResourceServices
    ResourceServices --> Repositories
    Repositories --> DB
    Controllers --> |Token Validation| AuthConfig

    %% Click events
    click AuthStore "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/client/src/app/store/auth/"
    click CartStore "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/client/src/app/store/cart/"
    click OrderStore "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/client/src/app/store/order/"
    click ProductStore "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/client/src/app/store/showcase/"
    click Account "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/client/src/app/account/"
    click Auth "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/client/src/app/auth/"
    click Cart "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/client/src/app/cart/"
    click Checkout "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/client/src/app/checkout/"
    click TokenService "https://github.com/antkaynak/Keyist-Ecommerce/blob/master/client/src/app/services/token.service.ts"
    click AuthConfig "https://github.com/antkaynak/Keyist-Ecommerce/blob/master/authorization_server/src/main/java/com/commerce/oauth/config/AuthServerOAuth2Config.java"
    click SecurityConfig "https://github.com/antkaynak/Keyist-Ecommerce/blob/master/authorization_server/src/main/java/com/commerce/oauth/config/ServerSecurityConfig.java"
    click UserRepo "https://github.com/antkaynak/Keyist-Ecommerce/blob/master/authorization_server/src/main/java/com/commerce/oauth/dao/UserRepository.java"
    click Controllers "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/resource_server/src/main/java/com/commerce/backend/api/"
    click ResourceServices "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/resource_server/src/main/java/com/commerce/backend/service/"
    click Repositories "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/resource_server/src/main/java/com/commerce/backend/dao/"
    click Models "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/resource_server/src/main/java/com/commerce/backend/model/"
    click CacheServices "https://github.com/antkaynak/Keyist-Ecommerce/tree/master/resource_server/src/main/java/com/commerce/backend/service/cache/"
    click AuthCORS "https://github.com/antkaynak/Keyist-Ecommerce/blob/master/authorization_server/src/main/java/com/commerce/oauth/config/SimpleCORSFilter.java"
    click ResourceCORS "https://github.com/antkaynak/Keyist-Ecommerce/blob/master/resource_server/src/main/java/com/commerce/backend/config/SimpleCORSFilter.java"
    click DB "https://github.com/antkaynak/Keyist-Ecommerce/blob/master/sql/script.sql"
```
