# littbarskiadeh/asset-ownership architecture

> Architecture diagram of the GitHub repository littbarskiadeh/asset-ownership, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/littbarskiadeh/asset-ownership
- Repository: https://github.com/littbarskiadeh/asset-ownership

## Overview

##### Project type and purpose
- From the folder names (`asset-factory` React app, `contracts`, `migrations`, `truffle-config.js`, `db/EthConnection.js`), this is a full-stack blockchain-enabled asset management application (a dApp).
- The backend is an Express.js REST API that exposes endpoints under `/api/Asset` to create, list and delete assets. It persists data in both a traditional database (via `DBConnection.js`) and on an Ethereum network (via Truffle smart contracts).
- The frontend is a React app (in `asset-factory/`) that consumes those APIs and allows users to log in, submit a form to add assets, and view asset listings.

##### File structure
Top-level directories and files:
- server.js – starts the Express server
- routes/AssetRoutes.js – defines HTTP routes for asset operations
- controller/AssetController.js – handles request/response orchestration
- services/AssetService.js – business logic for asset operations
- models/Asset.js – data model definition
- db/DBConnection.js – connects to the relational database
- db/EthConnection.js – connects to the Ethereum client
- contracts/ – Solidity smart contract definitions
- migrations/ – Truffle migrations for deploying contracts
- asset-factory/ – React frontend code (components, state management)
- logger.js & requestLogger.js – cross-cutting logging utilities
- test/Factory.test.js – unit tests for factory logic

##### README
- Provides only endpoint URLs and sample payloads for adding and deleting assets (`/api/Asset/list`, `/api/Asset/delete/:id`).

a. Main components to represent
- User’s browser (React UI)
- React application (`asset-factory/src`)
- Express.js API server (server.js, routes, controllers, services)
- Relational database (e.g., PostgreSQL/MySQL via `DBConnection.js`)
- Ethereum network (local or testnet) via Truffle and `EthConnection.js`
- Smart contracts (in `contracts/`)
- Logger subsystem (logger.js, requestLogger.js)

b. Relationships and data flows
1. UI → Express API: user actions in React trigger HTTP calls to `/api/Asset/*`.
2. Express `AssetRoutes` → `AssetController` routes requests.
3. `AssetController` → `AssetService`: business logic.
4. `AssetService` simultaneously:
– Persists/retrieves records in relational DB via `DBConnection`.
– Calls Ethereum smart contract methods via `EthConnection`.
5. Smart contracts are deployed on an Ethereum node configured in `truffle-config.js`.
6. Migrations folder holds Truffle scripts to deploy or update contract state.
7. Responses bubble back from service → controller → route → UI.
8. Logger components intercept and log requests/responses at various layers.

c. Architectural patterns
- Layered architecture (Routing → Controller → Service → Data access)
- MVC-like separation (models for data, services for logic, controllers for HTTP)
- Stateful React front end with a global state provider (`StateProvider.js`)
- Smart-contract integration for on-chain persistence

d. Key technologies & frameworks
- Frontend: React, Create-React-App, CSS modules in components
- Backend: Node.js, Express.js, body-parser, CORS, custom middleware (`requestLogger.js`)
- Database: any SQL DB (connection pooling in `DBConnection.js`)
- Blockchain: Truffle, Solidity contracts, Web3/EthConnection
- Testing: Mocha/Jest in `test/Factory.test.js`
- Logging: Winston or custom logger (`logger.js`)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "User Interface" 
        direction TB
        Browser["Browser"]:::client
        ReactIndex["React Entry (index.js)"]:::client
        StateProvider["Global State Provider"]:::client
        AssetsUI["Asset List Component"]:::client
        FormUI["Asset Form Component"]:::client
        LoginUI["Login Component"]:::client
    end

    Browser -->|"loads App"| ReactIndex
    ReactIndex --> StateProvider
    StateProvider --> AssetsUI
    StateProvider --> FormUI
    StateProvider --> LoginUI

    %% API Server Layer
    subgraph "API Server" 
        direction TB
        Express["Express Server"]:::server
        ReqLogger["Request Logging Middleware"]:::util
        LoggerUtil["Application Logger"]:::util
        Routes["Asset Routes"]:::server
        Controller["Asset Controller"]:::server
        Service["Asset Service"]:::server
        Model["Asset Data Model"]:::server
    end

    StateProvider -->|"HTTP calls /api/Asset/*"| Express
    Express --> ReqLogger
    Express --> LoggerUtil
    Express --> Routes
    Routes --> Controller
    Controller --> Service
    Service --> Model

    %% Data Layer
    subgraph "Relational Database" 
        direction TB
        DBConn["DB Connection"]:::data
        SQLDB["SQL Database"]:::data
    end

    Service -->|"SQL queries"| DBConn
    DBConn --> SQLDB

    %% Blockchain Layer
    subgraph "Blockchain" 
        direction TB
        EthConn["Ethereum Network Connection"]:::blockchain
        EthereumNode["Ethereum Node"]:::blockchain
        Contracts["Solidity Smart Contracts"]:::blockchain
        TruffleConfig["Truffle Configuration"]:::blockchain
        Migrations1["1_initial_migration.js"]:::blockchain
        Migrations2["2_factory_migration.js"]:::blockchain
    end

    Service -->|"web3.contract.method()"| EthConn
    EthConn --> EthereumNode
    EthereumNode --> Contracts
    EthereumNode --> TruffleConfig
    TruffleConfig --> Migrations1
    TruffleConfig --> Migrations2

    %% Testing
    Test["Unit Tests (Factory.test.js)"]:::test
    Migrations2 --> Test

    %% Click Events
    click ReactIndex "https://github.com/littbarskiadeh/asset-ownership/blob/main/asset-factory/src/index.js"
    click StateProvider "https://github.com/littbarskiadeh/asset-ownership/blob/main/asset-factory/src/StateProvider.js"
    click AssetsUI "https://github.com/littbarskiadeh/asset-ownership/blob/main/asset-factory/src/components/Assets/Assets.js"
    click FormUI "https://github.com/littbarskiadeh/asset-ownership/blob/main/asset-factory/src/components/Form/Form.js"
    click LoginUI "https://github.com/littbarskiadeh/asset-ownership/blob/main/asset-factory/src/components/Login/Login.js"
    click Express "https://github.com/littbarskiadeh/asset-ownership/blob/main/server.js"
    click Routes "https://github.com/littbarskiadeh/asset-ownership/blob/main/routes/AssetRoutes.js"
    click Controller "https://github.com/littbarskiadeh/asset-ownership/blob/main/controller/AssetController.js"
    click Service "https://github.com/littbarskiadeh/asset-ownership/blob/main/services/AssetService.js"
    click Model "https://github.com/littbarskiadeh/asset-ownership/blob/main/models/Asset.js"
    click DBConn "https://github.com/littbarskiadeh/asset-ownership/blob/main/db/DBConnection.js"
    click EthConn "https://github.com/littbarskiadeh/asset-ownership/blob/main/db/EthConnection.js"
    click Contracts "https://github.com/littbarskiadeh/asset-ownership/tree/main/contracts/"
    click TruffleConfig "https://github.com/littbarskiadeh/asset-ownership/blob/main/truffle-config.js"
    click Migrations1 "https://github.com/littbarskiadeh/asset-ownership/blob/main/migrations/1_initial_migration.js"
    click Migrations2 "https://github.com/littbarskiadeh/asset-ownership/blob/main/migrations/2_factory_migration.js"
    click ReqLogger "https://github.com/littbarskiadeh/asset-ownership/blob/main/requestLogger.js"
    click LoggerUtil "https://github.com/littbarskiadeh/asset-ownership/blob/main/logger.js"
    click Test "https://github.com/littbarskiadeh/asset-ownership/blob/main/test/Factory.test.js"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef server fill:#E6FFEA,stroke:#28A745,color:#28A745
    classDef data fill:#FFF5E6,stroke:#D66300,color:#D66300
    classDef blockchain fill:#F3E6FF,stroke:#8A2BE2,color:#8A2BE2
    classDef util fill:#F0F0F0,stroke:#6A737D,color:#6A737D
    classDef test fill:#FFEFE6,stroke:#DB1F48,color:#DB1F48
```
