Merge branch 'main' of https://github.com/devaine/CodeRED-Astra
This commit is contained in:
commit
ddc99df369
24 changed files with 1228 additions and 391 deletions
117
DEVELOPMENT.md
117
DEVELOPMENT.md
|
|
@ -1,117 +0,0 @@
|
|||
# CodeRED-Astra Development Guide
|
||||
|
||||
## Project Structure
|
||||
|
||||
This is a hackathon-ready project with a clean separation between frontend and backend:
|
||||
|
||||
- **React Frontend** (`web-app/`): Modern React app with Vite and Tailwind CSS
|
||||
- **Rust Engine** (`rust-engine/`): High-performance backend API server
|
||||
- **Database**: MySQL 8.0 with phpMyAdmin for management
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Prerequisites
|
||||
- Docker & Docker Compose
|
||||
- Node.js 20+ (for local development)
|
||||
- Rust 1.82+ (for local development)
|
||||
|
||||
### Development Setup
|
||||
|
||||
1. **Clone and setup environment**:
|
||||
```bash
|
||||
cp .env.example .env
|
||||
# Edit .env with your database passwords and API keys
|
||||
```
|
||||
|
||||
2. **Start the entire stack**:
|
||||
```bash
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
3. **Access the application**:
|
||||
- Frontend: http://localhost (port 80)
|
||||
- Rust API: http://localhost:8000
|
||||
- phpMyAdmin: http://127.0.0.1:8080
|
||||
|
||||
### Local Development (Recommended for Hackathon)
|
||||
|
||||
**Frontend Development**:
|
||||
```bash
|
||||
cd web-app
|
||||
npm install
|
||||
npm run dev # Starts on http://localhost:5173
|
||||
```
|
||||
|
||||
**Backend Development**:
|
||||
```bash
|
||||
cd rust-engine
|
||||
cargo run # Starts on http://localhost:8000
|
||||
```
|
||||
|
||||
## Team Workflow
|
||||
|
||||
### Frontend Team (React)
|
||||
- Work in `web-app/src/`
|
||||
- Main entry: `src/App.jsx`
|
||||
- Add new components in `src/components/`
|
||||
- API calls go through `/api/*` (auto-proxied to Rust engine)
|
||||
- Use Tailwind CSS for styling
|
||||
- Hot reload enabled with Vite
|
||||
|
||||
### Backend Team (Rust)
|
||||
- Work in `rust-engine/src/`
|
||||
- Main server: `src/main.rs`
|
||||
- Add new modules in `src/`
|
||||
- API endpoints start with `/api/`
|
||||
- Database connection via SQLx
|
||||
- CORS enabled for frontend communication
|
||||
|
||||
## API Communication
|
||||
|
||||
The frontend communicates with the Rust engine via:
|
||||
```javascript
|
||||
// This automatically proxies to http://rust-engine:8000 in Docker
|
||||
// or http://localhost:8000 in local development
|
||||
fetch('/api/health')
|
||||
.then(response => response.json())
|
||||
.then(data => console.log(data));
|
||||
```
|
||||
|
||||
## Database Schema
|
||||
|
||||
Edit `rust-engine/src/main.rs` to add database migrations and models as needed.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
Required in `.env`:
|
||||
```
|
||||
MYSQL_DATABASE=astra
|
||||
MYSQL_USER=astraadmin
|
||||
MYSQL_PASSWORD=your_secure_password
|
||||
MYSQL_ROOT_PASSWORD=your_root_password
|
||||
GEMINI_API_KEY=your_gemini_key
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
The project is containerized and ready for deployment:
|
||||
- Frontend: Static files served via Vite preview
|
||||
- Backend: Optimized Rust binary
|
||||
- Database: Persistent MySQL data volume
|
||||
|
||||
## Hackathon Tips
|
||||
|
||||
1. **Frontend team**: Start with the existing App.jsx and build your UI components
|
||||
2. **Backend team**: Add new API endpoints in the Rust main.rs file
|
||||
3. **Database**: Use phpMyAdmin at http://127.0.0.1:8080 to manage data
|
||||
4. **Testing**: The app shows connection status between frontend and backend
|
||||
5. **Hot reload**: Both frontend and backend support hot reload during development
|
||||
|
||||
## Common Issues
|
||||
|
||||
- **CORS errors**: Already configured, but check Rust engine CORS settings if needed
|
||||
- **Database connection**: Engine gracefully handles DB offline state for initial development
|
||||
- **Port conflicts**: Web runs on 80, API on 8000, phpMyAdmin on 8080
|
||||
- **Build failures**: Check Node.js and Rust versions match requirements
|
||||
|
||||
Happy hacking! 🚀
|
||||
|
|
@ -1,22 +1,15 @@
|
|||
# web-app/Dockerfile
|
||||
FROM node:20-alpine
|
||||
FROM node:23-alpine
|
||||
|
||||
WORKDIR /app
|
||||
COPY . /codered-astra
|
||||
|
||||
# Copy package files first to leverage Docker's build cache
|
||||
COPY package*.json ./
|
||||
WORKDIR /codered-astra
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci --only=production=false
|
||||
RUN npm i
|
||||
|
||||
# Copy the rest of your application code
|
||||
COPY . .
|
||||
|
||||
# Build the React application
|
||||
RUN npm run build
|
||||
|
||||
# Expose the port
|
||||
EXPOSE 3000
|
||||
|
||||
# Use preview mode for production-like serving
|
||||
CMD ["npm", "run", "preview"]
|
||||
RUN npm run format
|
||||
|
||||
RUN npm run build
|
||||
|
||||
CMD ["npm", "run", "host"]
|
||||
|
|
|
|||
16
web-app/README.md
Normal file
16
web-app/README.md
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# React + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
|
||||
## React Compiler
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
|
||||
|
|
@ -1,29 +1,27 @@
|
|||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
import js from "@eslint/js";
|
||||
import globals from "globals";
|
||||
import { defineConfig, globalIgnores } from "eslint/config";
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
globalIgnores(["dist"]),
|
||||
{
|
||||
files: ['**/*.{js,jsx}'],
|
||||
files: ["**/*.{js,jsx}"],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
reactHooks.configs['recommended-latest'],
|
||||
reactHooks.configs["recommended-latest"],
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
ecmaVersion: "latest",
|
||||
ecmaFeatures: { jsx: true },
|
||||
sourceType: 'module',
|
||||
sourceType: "module",
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
|
||||
"no-unused-vars": ["error", { varsIgnorePattern: "^[A-Z_]" }],
|
||||
},
|
||||
},
|
||||
])
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link href="/src/index.css" rel="stylesheet" />
|
||||
<title>codered-astra</title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "web-app/src"
|
||||
"baseUrl": "./"
|
||||
},
|
||||
"include": [
|
||||
"web-app/src"
|
||||
]
|
||||
"include": ["src"]
|
||||
}
|
||||
|
|
|
|||
940
web-app/package-lock.json
generated
940
web-app/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,37 +1,45 @@
|
|||
{
|
||||
"name": "codered-astra",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"host": "vite --host 0.0.0.0 --port 3000",
|
||||
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
|
||||
"format": "prettier --write \"**/*.{js,jsx,md}\""
|
||||
"dev": "vite",
|
||||
"host": "vite host",
|
||||
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
|
||||
"clean-dist": "find apps/ -type d -name 'dist' -print0 | xargs -r0 -- rm -r",
|
||||
"clean-all": "find apps/ -type d -name 'dist' -print0 | xargs -r0 -- rm -r && find . -path ./node_modules -prune -o -name 'node_modules' | xargs rm -rf "
|
||||
},
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@google/generative-ai": "^0.21.0",
|
||||
"axios": "^1.7.7",
|
||||
"@google/genai": "^1.25.0",
|
||||
"@tailwindcss/postcss": "^4.1.14",
|
||||
"@tailwindcss/vite": "^4.1.14",
|
||||
"@vitejs/plugin-react": "^5.0.4",
|
||||
"bootstrap": "^5.3.8",
|
||||
"bootstrap-icons": "^1.13.1",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^17.2.3",
|
||||
"express": "^5.1.0",
|
||||
"helmet": "^8.1.0",
|
||||
"lucide-react": "^0.546.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-router-dom": "^6.28.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.3.12",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"@vitejs/plugin-react": "^4.3.3",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"eslint": "^9.14.0",
|
||||
"eslint-plugin-react": "^7.37.2",
|
||||
"eslint-plugin-react-hooks": "^5.0.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.14",
|
||||
"postcss": "^8.4.47",
|
||||
"prettier": "^3.3.3",
|
||||
"tailwindcss": "^3.4.14",
|
||||
"vite": "^5.4.10",
|
||||
"pg": "^8.16.3",
|
||||
"react": "^19.2.0",
|
||||
"react-bootstrap": "^2.10.10",
|
||||
"react-dom": "^19.2.0",
|
||||
"react-router": "^7.9.4",
|
||||
"react-router-dom": "^7.9.4",
|
||||
"vite-jsconfig-paths": "^2.0.1"
|
||||
},
|
||||
"packageManager": ">=npm@10.9.0",
|
||||
"devDependencies": {
|
||||
"eslint": "^9.38.0",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint-plugin-react": "^7.37.5",
|
||||
"eslint-plugin-react-hooks": "^7.0.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.24",
|
||||
"nodemon": "^3.1.10",
|
||||
"prettier": "^3.6.2",
|
||||
"tailwindcss": "^4.1.14",
|
||||
"vite": "^7.1.10"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { Cpu, Database, Zap, Activity } from "lucide-react";
|
||||
|
||||
function App() {
|
||||
const [engineStatus, setEngineStatus] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
checkEngineHealth();
|
||||
}, []);
|
||||
|
||||
const checkEngineHealth = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/health');
|
||||
const data = await response.json();
|
||||
setEngineStatus(data);
|
||||
} catch (error) {
|
||||
console.error('Engine health check failed:', error);
|
||||
setEngineStatus({ success: false, message: 'Engine offline' });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-gray-900 via-purple-900 to-violet-900">
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
{/* Header */}
|
||||
<header className="text-center mb-12">
|
||||
<div className="flex items-center justify-center mb-4">
|
||||
<Zap className="h-12 w-12 text-yellow-400 mr-3" />
|
||||
<h1 className="text-4xl font-bold text-white">
|
||||
CodeRED-Astra
|
||||
</h1>
|
||||
</div>
|
||||
<p className="text-gray-300 text-lg">
|
||||
Hackathon Project - React Frontend + Rust Engine
|
||||
</p>
|
||||
</header>
|
||||
|
||||
{/* Status Cards */}
|
||||
<div className="grid md:grid-cols-2 gap-6 mb-8">
|
||||
{/* React App Status */}
|
||||
<div className="bg-white/10 backdrop-blur-lg rounded-lg p-6 border border-white/20">
|
||||
<div className="flex items-center mb-4">
|
||||
<Activity className="h-8 w-8 text-blue-400 mr-3" />
|
||||
<h2 className="text-xl font-semibold text-white">React Frontend</h2>
|
||||
</div>
|
||||
<div className="text-green-400 font-medium">✓ Online</div>
|
||||
<p className="text-gray-300 text-sm mt-2">
|
||||
Vite + React development environment ready
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Rust Engine Status */}
|
||||
<div className="bg-white/10 backdrop-blur-lg rounded-lg p-6 border border-white/20">
|
||||
<div className="flex items-center mb-4">
|
||||
<Cpu className="h-8 w-8 text-orange-400 mr-3" />
|
||||
<h2 className="text-xl font-semibold text-white">Rust Engine</h2>
|
||||
</div>
|
||||
<div className={`font-medium ${loading ? 'text-yellow-400' : engineStatus?.success ? 'text-green-400' : 'text-red-400'}`}>
|
||||
{loading ? '⏳ Checking...' : engineStatus?.success ? '✓ Online' : '✗ Offline'}
|
||||
</div>
|
||||
<p className="text-gray-300 text-sm mt-2">
|
||||
{loading ? 'Connecting to engine...' :
|
||||
engineStatus?.success ? 'Engine responding normally' :
|
||||
'Engine may still be starting up'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Engine Details */}
|
||||
{engineStatus?.success && (
|
||||
<div className="bg-white/10 backdrop-blur-lg rounded-lg p-6 border border-white/20 mb-8">
|
||||
<div className="flex items-center mb-4">
|
||||
<Database className="h-6 w-6 text-purple-400 mr-3" />
|
||||
<h3 className="text-lg font-semibold text-white">Engine Status</h3>
|
||||
</div>
|
||||
<div className="grid md:grid-cols-2 gap-4 text-sm">
|
||||
<div>
|
||||
<span className="text-gray-400">Status:</span>
|
||||
<span className="text-white ml-2">{engineStatus.data?.status}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-gray-400">Last Check:</span>
|
||||
<span className="text-white ml-2">
|
||||
{engineStatus.data?.timestamp ? new Date(engineStatus.data.timestamp).toLocaleTimeString() : 'N/A'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{engineStatus.message && (
|
||||
<div className="mt-3 p-3 bg-yellow-500/20 border border-yellow-500/30 rounded">
|
||||
<span className="text-yellow-200 text-sm">{engineStatus.message}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Quick Actions */}
|
||||
<div className="bg-white/10 backdrop-blur-lg rounded-lg p-6 border border-white/20">
|
||||
<h3 className="text-lg font-semibold text-white mb-4">Quick Actions</h3>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<button
|
||||
onClick={checkEngineHealth}
|
||||
className="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition-colors"
|
||||
>
|
||||
Refresh Status
|
||||
</button>
|
||||
<button
|
||||
onClick={() => window.open('/api/health', '_blank')}
|
||||
className="px-4 py-2 bg-purple-600 hover:bg-purple-700 text-white rounded-lg transition-colors"
|
||||
>
|
||||
Test API Direct
|
||||
</button>
|
||||
<button
|
||||
onClick={() => alert('Add your hackathon features here!')}
|
||||
className="px-4 py-2 bg-green-600 hover:bg-green-700 text-white rounded-lg transition-colors"
|
||||
>
|
||||
Add Feature
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Development Notes */}
|
||||
<div className="mt-8 text-center text-gray-400 text-sm">
|
||||
<p>🚀 Ready for hackathon development!</p>
|
||||
<p className="mt-1">
|
||||
Frontend team: Work in <code className="bg-white/10 px-1 rounded">web-app/src/</code> |
|
||||
Backend team: Work in <code className="bg-white/10 px-1 rounded">rust-engine/src/</code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
12
web-app/src/app/index.jsx
Normal file
12
web-app/src/app/index.jsx
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import React from "react";
|
||||
import ChatLayout from "src/components/layouts/chat-layout";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-900 text-white flex items-center justify-center p-6">
|
||||
<ChatLayout />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
34
web-app/src/components/layouts/chat-layout.jsx
Normal file
34
web-app/src/components/layouts/chat-layout.jsx
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import React, { useState } from "react";
|
||||
import ChatHeader from "src/components/ui/chat/chat-header";
|
||||
import ChatWindow from "src/components/ui/chat/chat-window";
|
||||
import MessageInput from "src/components/ui/chat/message-input";
|
||||
|
||||
export default function ChatLayout() {
|
||||
const [messages, setMessages] = useState([
|
||||
{
|
||||
role: "assistant",
|
||||
content: "Hello — I can help you with code, explanations, and more.",
|
||||
},
|
||||
]);
|
||||
|
||||
function handleSend(text) {
|
||||
const userMsg = { role: "user", content: text };
|
||||
setMessages((s) => [...s, userMsg]);
|
||||
|
||||
// fake assistant reply after short delay
|
||||
setTimeout(() => {
|
||||
setMessages((s) => [
|
||||
...s,
|
||||
{ role: "assistant", content: `You said: ${text}` },
|
||||
]);
|
||||
}, 600);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-[80vh] w-full max-w-3xl mx-auto rounded-lg overflow-hidden shadow-lg border border-slate-700">
|
||||
<ChatHeader />
|
||||
<ChatWindow messages={messages} />
|
||||
<MessageInput onSend={handleSend} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
0
web-app/src/components/layouts/dashboard-layout.jsx
Normal file
0
web-app/src/components/layouts/dashboard-layout.jsx
Normal file
19
web-app/src/components/ui/Button/DeleteButton.jsx
Normal file
19
web-app/src/components/ui/Button/DeleteButton.jsx
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import Button from 'react-bootstrap/Button';
|
||||
|
||||
export default function DeleteButton({ onClick, variant = "outline-danger", children, ...props }) {
|
||||
return (
|
||||
<Button onClick={onClick} variant={variant} {...props}>
|
||||
{children || "Delete"}{" "}
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
fill="currentColor"
|
||||
className="bi bi-trash3"
|
||||
viewBox="0 0 16 16"
|
||||
>
|
||||
<path d="M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5M11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H1.5a.5.5 0 0 0 0 1h.538l.853 10.66A2 2 0 0 0 4.885 16h6.23a2 2 0 0 0 1.994-1.84l.853-10.66h.538a.5.5 0 0 0 0-1zm1.958 1-.846 10.58a1 1 0 0 1-.997.92h-6.23a1 1 0 0 1-.997-.92L3.042 3.5zm-7.487 1a.5.5 0 0 1 .528.47l.5 8.5a.5.5 0 0 1-.998.06L5 5.03a.5.5 0 0 1 .47-.53Zm5.058 0a.5.5 0 0 1 .47.53l-.5 8.5a.5.5 0 1 1-.998-.06l.5-8.5a.5.5 0 0 1 .528-.47M8 4.5a.5.5 0 0 1 .5.5v8.5a.5.5 0 0 1-1 0V5a.5.5 0 0 1 .5-.5"/>
|
||||
</svg>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
13
web-app/src/components/ui/Button/NewChatButton.css
Normal file
13
web-app/src/components/ui/Button/NewChatButton.css
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
.custom-btn {
|
||||
background-color: white !important;
|
||||
border: 2px solid #0F2862 !important;
|
||||
color: #0F2862 !important;
|
||||
transition: all 0.25s ease;
|
||||
}
|
||||
|
||||
.custom-btn:hover,
|
||||
.custom-btn:focus {
|
||||
background-color: #0F2862 !important;
|
||||
color: white !important;
|
||||
border-color: #0F2862 !important;
|
||||
}
|
||||
19
web-app/src/components/ui/Button/NewChatButton.jsx
Normal file
19
web-app/src/components/ui/Button/NewChatButton.jsx
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import Button from 'react-bootstrap/Button';
|
||||
import './NewChatButton.css'
|
||||
export default function NewChatButton({ onClick, variant = "outline-light", children, ...props }) {
|
||||
return (
|
||||
<Button onClick={onClick} className="custom-btn" {...props}>
|
||||
{children || "New Chat"}{" "}
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
fill="currentColor"
|
||||
className="bi bi-plus-lg"
|
||||
viewBox="0 0 16 16"
|
||||
>
|
||||
<path fillRule="evenodd" d="M8 2a.5.5 0 0 1 .5.5v5h5a.5.5 0 0 1 0 1h-5v5a.5.5 0 0 1-1 0v-5h-5a.5.5 0 0 1 0-1h5v-5A.5.5 0 0 1 8 2"/>
|
||||
</svg>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
19
web-app/src/components/ui/chat/chat-header.jsx
Normal file
19
web-app/src/components/ui/chat/chat-header.jsx
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import React from "react";
|
||||
|
||||
export default function ChatHeader({ title = "AI Assistant" }) {
|
||||
return (
|
||||
<header className="flex items-center justify-between px-4 py-3 bg-gradient-to-r from-slate-800 to-slate-900 text-white">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-indigo-500 rounded flex items-center justify-center font-bold">
|
||||
AI
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold">{title}</h1>
|
||||
<p className="text-sm text-slate-300">
|
||||
Ask anything — AI is listening
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
37
web-app/src/components/ui/chat/chat-window.jsx
Normal file
37
web-app/src/components/ui/chat/chat-window.jsx
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import React from "react";
|
||||
import { useRef } from "react";
|
||||
function MessageBubble({ message }) {
|
||||
const isUser = message.role === "user";
|
||||
return (
|
||||
<div
|
||||
className={`flex ${isUser ? "justify-end" : "justify-start"} px-4 py-2`}
|
||||
>
|
||||
<div
|
||||
className={`max-w-[70%] p-3 rounded-lg ${isUser ? "bg-indigo-600 text-white" : "bg-slate-700 text-slate-100"}`}
|
||||
>
|
||||
<div className="text-sm">{message.content}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ChatWindow({ messages }) {
|
||||
const chatRef = useRef(null);
|
||||
// Auto-scroll to bottom when new messages appear
|
||||
useEffect(() => {
|
||||
chatRef.current?.scrollTo({
|
||||
top: chatRef.current.scrollHeight,
|
||||
behavior: "smooth",
|
||||
});
|
||||
}, [messages]);
|
||||
|
||||
return (
|
||||
<main className="flex-1 overflow-auto p-2 bg-gradient-to-b from-slate-900 to-slate-800">
|
||||
<div className="space-y-2">
|
||||
{messages.map((m, i) => (
|
||||
<MessageBubble key={i} message={m} />
|
||||
))}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
31
web-app/src/components/ui/chat/message-input.jsx
Normal file
31
web-app/src/components/ui/chat/message-input.jsx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import React, { useState } from "react";
|
||||
|
||||
export default function MessageInput({ onSend }) {
|
||||
const [text, setText] = useState("");
|
||||
|
||||
function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
if (!text.trim()) return;
|
||||
onSend(text.trim());
|
||||
setText("");
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="p-3 bg-slate-900">
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
placeholder="Type a message..."
|
||||
className="flex-1 rounded-md bg-slate-800 border border-slate-700 px-3 py-2 text-white focus:outline-none focus:ring-2 focus:ring-indigo-500"
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-indigo-500 hover:bg-indigo-600 text-white px-4 py-2 rounded-md"
|
||||
>
|
||||
Send
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,33 +1,24 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
@import "tailwindcss/preflight";
|
||||
@import "tailwindcss/utilities";
|
||||
|
||||
:root {
|
||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
color-scheme: dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
--color-primary: 15 40 98;
|
||||
--color-secondary: 79 95 118;
|
||||
--color-accent: 158 54 58;
|
||||
--color-paragraph: 255 255 255;
|
||||
--color-background: 9 31 54;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
#root {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
|
||||
background-color: rgb(var(--color-background));
|
||||
color: rgb(var(--color-paragraph));
|
||||
font-family:
|
||||
ui-sans-serif,
|
||||
system-ui,
|
||||
-apple-system,
|
||||
"Segoe UI",
|
||||
Roboto,
|
||||
"Helvetica Neue",
|
||||
Arial;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.jsx'
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import "./index.css";
|
||||
import App from "./app/index.jsx";
|
||||
|
||||
createRoot(document.getElementById('root')).render(
|
||||
createRoot(document.getElementById("root")).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
</StrictMode>
|
||||
);
|
||||
|
|
|
|||
7
web-app/src/styles/theme.css
Normal file
7
web-app/src/styles/theme.css
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
@theme {
|
||||
--color-primary: rgba(15, 40, 98);
|
||||
--color-secondary: rgba(79, 95, 118);
|
||||
--color-accent: rgba(158, 54, 58);
|
||||
--color-paragraph: rgba(255, 255, 255);
|
||||
--color-background: rgba(9, 31, 54);
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ["./src/**/*.{html,js}"],
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
background: "rgba(var(--background))",
|
||||
paragraph: "rgba(var(--paragraph))",
|
||||
primary: "rgba(var(--primary))",
|
||||
secondary: "rgba(var(--secondary))",
|
||||
accent: "rgba(var(--accent))",
|
||||
},
|
||||
flex: {
|
||||
0: "0 0 100%",
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
||||
|
|
@ -1,26 +1,14 @@
|
|||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import jsconfigPaths from "vite-jsconfig-paths";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react(), jsconfigPaths()],
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
port: 3000,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: process.env.RUST_ENGINE_URL || 'http://localhost:8000',
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, '')
|
||||
}
|
||||
}
|
||||
plugins: [tailwindcss(), react(), jsconfigPaths()],
|
||||
resolve: {
|
||||
alias: {
|
||||
src: "/src",
|
||||
},
|
||||
preview: {
|
||||
host: '0.0.0.0',
|
||||
port: 3000
|
||||
},
|
||||
build: {
|
||||
outDir: 'dist'
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue