How littbarskiadeh/asset-ownership works
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)