devjas1
Initial Release: Polymer Aging With ML [Standalone Appliance]
4a0e21d
|
Raw
History Blame Contribute Delete
2.89 kB
# Frontend React Application
This directory contains the React/TypeScript frontend for the Polymer Aging ML application.
## Architecture
The frontend is a modern React application with TypeScript:
```
frontend/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ components/ # React components
β”‚ β”‚ β”œβ”€β”€ Header.tsx
β”‚ β”‚ β”œβ”€β”€ SpectrumChart.tsx
β”‚ β”‚ β”œβ”€β”€ ResultsDisplay.tsx
β”‚ β”‚ └── ...
β”‚ β”œβ”€β”€ apiClient.ts # Centralized API client
β”‚ β”œβ”€β”€ types/
β”‚ β”‚ β”œβ”€β”€ api.ts # Auto-generated API types
β”‚ β”‚ └── index.ts # Custom types
β”‚ β”œβ”€β”€ App.tsx # Main application component
β”‚ └── index.tsx # Application entry point
β”œβ”€β”€ public/ # Static assets
β”œβ”€β”€ package.json # Dependencies and scripts
└── tsconfig.json # TypeScript configuration
```
## Key Features
- **Type Safety**: Full TypeScript integration with OpenAPI-generated types
- **Centralized API Client**: Single source for all backend communication
- **Component Architecture**: Modular, reusable React components
- **Responsive Design**: Works across desktop and mobile devices
- **Error Handling**: Graceful error handling with user feedback
## Setup and Development
### Prerequisites
- Node.js 16+ and npm 8+
- Backend API server running (for development)
### Installation
```bash
# Install dependencies
npm install --legacy-peer-deps
# Verify TypeScript types are up to date
npm run typegen:file
```
### Development Server
```bash
# Start development server with hot reload
npm start
# Opens http://localhost:3000
```
### Build for Production
```bash
# Create production build
npm run build
# Build files output to build/ directory
```
## API Integration
### Centralized API Client
All backend communication goes through `src/apiClient.ts`:
```typescript
import { ApiClient } from './apiClient';
const api = new ApiClient('http://localhost:8000');
// Example usage
const result = await api.analyzeSpectrum({
spectrum: spectrumData,
model_name: 'resnet',
modality: 'raman'
});
```
### Type Generation
API types are automatically generated from the OpenAPI schema:
```bash
# Generate types from running backend
npm run typegen
# Generate types from schema file
npm run typegen:file
```
## Scripts
Available npm scripts:
```bash
npm start # Development server
npm run build # Production build
npm test # Run tests
npm run lint # ESLint checking
npm run format # Prettier formatting
npm run typegen # Generate API types
```
## API Contract Adherence
The frontend strictly adheres to the OpenAPI contract:
- All requests/responses validated by TypeScript types
- Automatic type generation ensures contract compliance
- No direct backend imports or cross-boundary dependencies