Automated Action 3ef47ed096 Rebuild platform with Node.js, Express.js and TypeScript
Complete rewrite from Python/FastAPI to Node.js stack:

Features implemented:
- User authentication with JWT tokens and role-based access (DEVELOPER/BUYER)
- Blockchain wallet linking and management with Ethereum integration
- Carbon project creation and management for developers
- Marketplace for browsing and purchasing carbon offsets
- Transaction tracking with blockchain integration
- Comprehensive input validation with Joi
- Advanced security with Helmet, CORS, and rate limiting
- Error handling and logging middleware
- Health check endpoint with service monitoring

Technical stack:
- Node.js with Express.js and TypeScript
- Prisma ORM with SQLite database
- Web3.js and Ethers.js for blockchain integration
- JWT authentication with bcrypt password hashing
- Comprehensive validation and security middleware
- Production-ready error handling and logging

Database schema:
- Users with wallet linking capabilities
- Carbon projects with verification status
- Carbon offsets with blockchain token tracking
- Transactions with confirmation details

Environment variables required:
- JWT_SECRET (required)
- DATABASE_URL (optional, defaults to SQLite)
- BLOCKCHAIN_RPC_URL (optional, defaults to localhost)
- NODE_ENV, PORT, CORS_ORIGIN (optional)

Run with: npm install && npm run db:generate && npm run db:migrate && npm run dev
2025-06-20 17:14:37 +00:00

143 lines
3.8 KiB
Plaintext

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
password String
fullName String @map("full_name")
userType UserType @map("user_type")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// Blockchain wallet information
walletAddress String? @unique @map("wallet_address")
walletPublicKey String? @map("wallet_public_key")
// Relationships
projects CarbonProject[] @relation("ProjectDeveloper")
transactions Transaction[] @relation("TransactionBuyer")
@@map("users")
}
model CarbonProject {
id Int @id @default(autoincrement())
title String
description String
location String
projectType String @map("project_type")
methodology String
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// Carbon offset details
totalCreditsAvailable Int @map("total_credits_available")
creditsSold Int @default(0) @map("credits_sold")
pricePerCredit Float @map("price_per_credit")
// Project timeline
startDate DateTime @map("start_date")
endDate DateTime @map("end_date")
// Verification and status
verificationStatus VerificationStatus @default(PENDING) @map("verification_status")
verificationDocumentUrl String? @map("verification_document_url")
isActive Boolean @default(true) @map("is_active")
// Blockchain information
contractAddress String? @map("contract_address")
tokenId String? @map("token_id")
// Foreign keys
developerId Int @map("developer_id")
// Relationships
developer User @relation("ProjectDeveloper", fields: [developerId], references: [id])
offsets CarbonOffset[]
@@map("carbon_projects")
}
model CarbonOffset {
id Int @id @default(autoincrement())
serialNumber String @unique @map("serial_number")
vintageYear Int @map("vintage_year")
quantity Int
status OffsetStatus @default(AVAILABLE)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// Blockchain information
tokenId String? @unique @map("token_id")
blockchainHash String? @map("blockchain_hash")
// Foreign keys
projectId Int @map("project_id")
// Relationships
project CarbonProject @relation(fields: [projectId], references: [id])
transactions Transaction[]
@@map("carbon_offsets")
}
model Transaction {
id Int @id @default(autoincrement())
transactionHash String @unique @map("transaction_hash")
quantity Int
pricePerCredit Float @map("price_per_credit")
totalAmount Float @map("total_amount")
createdAt DateTime @default(now()) @map("created_at")
// Transaction status
status TransactionStatus @default(PENDING)
confirmedAt DateTime? @map("confirmed_at")
// Blockchain information
blockNumber Int? @map("block_number")
gasUsed Int? @map("gas_used")
// Foreign keys
buyerId Int @map("buyer_id")
offsetId Int @map("offset_id")
// Relationships
buyer User @relation("TransactionBuyer", fields: [buyerId], references: [id])
offset CarbonOffset @relation(fields: [offsetId], references: [id])
@@map("transactions")
}
enum UserType {
DEVELOPER
BUYER
}
enum VerificationStatus {
PENDING
VERIFIED
REJECTED
}
enum OffsetStatus {
AVAILABLE
SOLD
RETIRED
}
enum TransactionStatus {
PENDING
CONFIRMED
FAILED
}