Skip to content

A full-stack web application (NextJS + FastAPI) for RDF data generation, validation, and SHACL shape constraint checking.

Notifications You must be signed in to change notification settings

teman67/IUC02_NextJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

IUC02: Framework for Curation and Distribution of Reference Datasets

A full-stack web application for RDF data generation, validation, and SHACL shape constraint checking, focusing on reference material datasets for creep properties of single crystal Ni-based superalloys.

🎯 Project Overview

This project develops a framework for reference material data sets using creep properties of single crystal Ni-based superalloy as an example. The framework provides:

  • (i) Tools for evaluating and validating experimental/modeling methods and their uncertainties
  • (ii) Systems for assessing the performance of analysis, modeling, and simulation tools
  • (iii) Comprehensive material descriptions through metadata schemas and ontologies

The application implements community-driven processes for the definition, identification, and curation of reference material data sets, including metadata, raw data, processed data, and quality assessment routines.

πŸ—οΈ Architecture

This is a monorepo containing:

  • Frontend: Next.js 14 (React 18) with TypeScript and Tailwind CSS
  • Backend: FastAPI (Python) with RDF/SHACL validation capabilities
  • Data: Sample datasets, schemas, and mapping documents
IUC02_NextJS/
β”œβ”€β”€ frontend/          # Next.js web application
β”œβ”€β”€ backend/           # FastAPI REST API
β”œβ”€β”€ data/              # Sample data files and schemas
└── README.md          # This file

Application Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         User Interface                          β”‚
β”‚                    (Next.js 14 + React 18)                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚                                    β”‚
             β”‚ HTTP/REST API                      β”‚ WebSocket (Future)
             β”‚                                    β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Frontend Layer                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Components β”‚  β”‚  API Routes  β”‚  β”‚   Chat Assistant    β”‚   β”‚
β”‚  β”‚             β”‚  β”‚              β”‚  β”‚   (OpenAI GPT-4o)   β”‚   β”‚
β”‚  β”‚  - Navigationβ”‚  β”‚ - /api/chat  β”‚  β”‚                     β”‚   β”‚
β”‚  β”‚  - ChatBox  β”‚  β”‚              β”‚  β”‚  β€’ Rate Limiting    β”‚   β”‚
β”‚  β”‚  - Workflow β”‚  β”‚              β”‚  β”‚  β€’ Response Cache   β”‚   β”‚
β”‚  β”‚  - Validationβ”‚  β”‚              β”‚  β”‚  β€’ Topic Filtering  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β”‚ Axios HTTP Client
             β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Backend Layer                              β”‚
β”‚                     (FastAPI + Python)                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”‚
β”‚  β”‚   RDF Processor  β”‚  β”‚  File Manager    β”‚                    β”‚
β”‚  β”‚   (rdflib)       β”‚  β”‚                  β”‚                    β”‚
β”‚  β”‚                  β”‚  β”‚  β€’ Serve Files   β”‚                    β”‚
β”‚  β”‚  β€’ Parse Turtle  β”‚  β”‚  β€’ List Files    β”‚                    β”‚
β”‚  β”‚  β€’ Validate      β”‚  β”‚  β€’ Download      β”‚                    β”‚
β”‚  β”‚  β€’ JSON-LD       β”‚  β”‚                  β”‚                    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚
β”‚           β”‚                                                     β”‚
β”‚           β”‚ pyshacl                                             β”‚
β”‚           β”‚                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚  β”‚    SHACL Validation Engine              β”‚                   β”‚
β”‚  β”‚    (pyshacl 0.25.0)                     β”‚                   β”‚
β”‚  β”‚                                          β”‚                   β”‚
β”‚  β”‚  β€’ Constraint Checking                  β”‚                   β”‚
β”‚  β”‚  β€’ Validation Reports                   β”‚                   β”‚
β”‚  β”‚  β€’ Conformance Testing                  β”‚                   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β”‚ File System Access
             β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       Data Layer                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚  RDF Graphs β”‚  β”‚ SHACL Shapes β”‚  β”‚  Metadata Schemas  β”‚    β”‚
β”‚  β”‚  (.ttl)     β”‚  β”‚  (.ttl)      β”‚  β”‚  (.json)           β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚         Creep Experiment Data (.LIS)                    β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

External Services:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   OpenAI API         β”‚
β”‚   (GPT-4o-mini)      β”‚
β”‚                      β”‚
β”‚  β€’ Natural Language  β”‚
β”‚  β€’ Context-Aware     β”‚
β”‚  β€’ Rate Limited      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

Validation Workflow:

User Upload β†’ Frontend Validation β†’ Backend API β†’ RDF Parser
                                                      ↓
                                              SHACL Validator
                                                      ↓
                                         Validation Report (JSON)
                                                      ↓
                                         Frontend Display

Chat Assistant Workflow:

User Question β†’ ChatBox Component β†’ Rate Limiter β†’ Cache Check
                                                         ↓
                                                    Cache Miss?
                                                         ↓
                                                   OpenAI API
                                                         ↓
                                              Store in Cache (5 min TTL)
                                                         ↓
                                                 Return Response

✨ Features

Frontend Features

  • πŸ“Š Interactive Workflow Visualization - Visual representation of the data generation and validation workflow
  • πŸ“ File Management - Browse and download example datasets, schemas, and mapping documents
  • βœ… RDF/SHACL Validation - Upload or use example RDF data graphs and SHACL shapes for validation
  • πŸ€– AI Chat Assistant - OpenAI-powered chatbot to help with RDF, SHACL, and workflow questions
  • 🎨 Modern UI - Responsive design with Tailwind CSS and smooth animations
  • πŸ“± Mobile Friendly - Fully responsive interface

Backend Features

  • πŸ” RDF Validation - Validate RDF data against SHACL shapes using pyshacl
  • πŸ“„ File API - Serve example data files from the data directory
  • πŸ”„ JSON-LD Conversion - Convert RDF graphs to JSON-LD format
  • πŸš€ Fast & Async - Built with FastAPI for high performance
  • πŸ“‘ CORS Enabled - Configured for frontend integration

πŸš€ Getting Started

Prerequisites

  • Node.js 18.x or higher
  • Python 3.9 or higher
  • npm or yarn package manager
  • Git

Installation

1. Clone the Repository

git clone https://github.com/teman67/IUC02_NextJS.git
cd IUC02_NextJS

2. Backend Setup

# Navigate to backend directory
cd backend

# Create and activate virtual environment
python -m venv backend
.\backend\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Run the backend server
uvicorn main:app --reload --port 8000

The backend API will be available at http://localhost:8000

3. Frontend Setup

# Navigate to frontend directory (in a new terminal)
cd frontend

# Install dependencies
npm install

# Configure OpenAI API (for AI chat assistant)
# Create .env.local file and add your OpenAI API key:
# OPENAI_API_KEY=your_openai_api_key_here
# Get your key from: https://platform.openai.com/api-keys

# Run the development server
npm run dev

The frontend application will be available at http://localhost:3000

πŸ“– Usage

AI Chat Assistant

  1. Click the chat icon (blue button) in the bottom-right corner
  2. Ask questions about:
    • RDF data generation and concepts
    • SHACL validation and shapes
    • Application workflow and navigation
    • Schema requirements and metadata
  3. Features:
    • Context-aware responses about IUC02 framework
    • Rate limiting (5 messages per 2 minutes)
    • Response caching for instant repeated answers
    • Focused on semantic web and materials science topics

Data Generation Workflow

  1. Navigate to Data Generation page
  2. Browse available files:
    • Creep experiment input files (.LIS)
    • Metadata schemas (.json)
    • RDF graphs (.ttl)
    • SHACL shapes (.ttl)
    • Mapping documents
  3. Preview and download files as needed

Data Validation

  1. Navigate to Data Validation page
  2. Choose either:
    • Upload your own files (RDF Data Graph and SHACL Shape Graph)
    • Use example files from the data directory
  3. Click Validate to run SHACL validation
  4. View validation results:
    • Conformance status (βœ… Valid / ❌ Invalid)
    • Detailed validation report
    • JSON-LD representation of the data graph

API Documentation

Visit http://localhost:8000/docs for interactive API documentation (Swagger UI)

Available endpoints:

  • GET / - API health check
  • GET /api/health - Detailed health status
  • POST /api/validate - Validate RDF against SHACL shapes
  • GET /api/files/{filename} - Retrieve file content from data directory
  • GET /api/files - List all available files

πŸ› οΈ Technology Stack

Frontend

  • Framework: Next.js 14 (App Router)
  • Language: TypeScript
  • Styling: Tailwind CSS
  • HTTP Client: Axios
  • AI Integration: OpenAI API (GPT-4o-mini)
  • UI Components: Custom React components

Backend

  • Framework: FastAPI
  • Language: Python 3.9+
  • RDF Processing: rdflib 7.0.0
  • SHACL Validation: pyshacl 0.25.0
  • Data Validation: Pydantic
  • Server: Uvicorn

Data Formats

  • RDF: Turtle (.ttl)
  • Metadata: JSON Schema
  • Validation: SHACL shapes
  • Serialization: JSON-LD

πŸ“‚ Project Structure

Frontend (/frontend)

frontend/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                    # Next.js App Router pages
β”‚   β”‚   β”œβ”€β”€ page.tsx           # Home page
β”‚   β”‚   β”œβ”€β”€ about/             # About page
β”‚   β”‚   β”œβ”€β”€ data-generation/   # Data generation workflow
β”‚   β”‚   β”œβ”€β”€ data-validation/   # Validation interface
β”‚   β”‚   └── api/
β”‚   β”‚       └── chat/          # AI chat API route
β”‚   β”œβ”€β”€ components/            # Reusable React components
β”‚   β”‚   β”œβ”€β”€ Navigation.tsx     # Navigation bar
β”‚   β”‚   β”œβ”€β”€ ChatBox.tsx        # AI chat assistant
β”‚   β”‚   β”œβ”€β”€ WorkflowDiagram.tsx
β”‚   β”‚   β”œβ”€β”€ BackgroundLogo.tsx
β”‚   β”‚   └── WarningMessage.tsx
β”‚   └── lib/
β”‚       └── chatCache.ts       # Caching & rate limiting
β”œβ”€β”€ public/                    # Static assets
β”œβ”€β”€ CHATBOX_SETUP.md          # AI chat setup guide
β”œβ”€β”€ CHAT_PROTECTION.md        # Protection features docs
└── package.json              # Dependencies and scripts

Backend (/backend)

backend/
β”œβ”€β”€ main.py                   # FastAPI application
β”œβ”€β”€ requirements.txt          # Python dependencies
└── backend/                  # Virtual environment

Data (/data)

data/
β”œβ”€β”€ 2024-09_Schema_IUC02_v1.json          # Metadata schema
β”œβ”€β”€ mapping document.json                  # Mapping document
β”œβ”€β”€ rdfGraph_smallExample.ttl             # Example RDF data
β”œβ”€β”€ shaclShape_smallExample.ttl           # Example SHACL shapes
β”œβ”€β”€ Vh5205_C-95.LIS                       # Creep experiment data
└── Vh5205_C-95_translated.json          # Translated metadata

πŸ”§ Development

Frontend Scripts

npm run dev      # Start development server
npm run build    # Build for production
npm run start    # Start production server
npm run lint     # Run ESLint

Backend Development

# Run with auto-reload
uvicorn main:app --reload

# Run on specific port
uvicorn main:app --port 8000

# Run with custom host
uvicorn main:app --host 0.0.0.0 --port 8000

Environment Variables

Create .env.local in the frontend directory:

NEXT_PUBLIC_API_URL=http://localhost:8000
OPENAI_API_KEY=your_openai_api_key_here

Note:

  • The OPENAI_API_KEY is required for the AI chat assistant feature
  • Get your API key from OpenAI Platform
  • Keep this file private and never commit it to version control

πŸ§ͺ Testing

Testing AI Chat Assistant

  1. Rate Limiting Test:

    • Send 6 messages rapidly
    • 6th message should trigger rate limit error
    • Wait 2 minutes for reset
  2. Cache Test:

    • Ask "What is RDF?" (takes 1-2 seconds)
    • Ask the exact same question (instant response)
    • Check browser console for cache indicators
  3. Topic Enforcement Test:

    • Ask off-topic question (e.g., "What's the weather?")
    • Should politely redirect to IUC02 topics

Testing RDF Validation

You can test the validation endpoint using curl:

curl -X POST "http://localhost:8000/api/validate" \
  -H "Content-Type: application/json" \
  -d '{
    "rdf_content": "@prefix ex: <http://example.org/> . ex:subject ex:predicate ex:object .",
    "shacl_content": "@prefix sh: <http://www.w3.org/ns/shacl#> ..."
  }'

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is part of the NFDI-MatWerk initiative.

πŸ”— Related Links

πŸ“§ Contact

For questions and support, please refer to the main IUC02 repository.

πŸ™ Acknowledgments

This project uses data from:

  • PP18 BAM: Bundesanstalt fΓΌr Materialforschung und -prΓΌfung
  • PP01 SFB/TR103: Collaborative Research Centre on Ni-based superalloys

Built with ❀️ for materials science research and data standardization

About

A full-stack web application (NextJS + FastAPI) for RDF data generation, validation, and SHACL shape constraint checking.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published