HYDRA-AI is a modern AI chat application built with React, TypeScript, and Tailwind CSS. The project utilizes the latest web technology stack to provide a smooth, responsive user experience.
- 🔐 User authentication system
- 💬 Real-time AI chat functionality
- 🎨 Modern UI, using Tailwind CSS and Shadcn components
- 📱 Responsive design, compatible with various devices
- 🚀 Built with Vite, providing a fast development experience
- Framework: React 18
- Routing: React Router v7
- Styling: Tailwind CSS
- UI Components: Radix UI / Shadcn
- Build Tool: Vite
- Package Manager: pnpm
- Language: TypeScript
- Animation: Framer Motion
- Node.js (Recommended v18+)
- pnpm (v10+)
- Clone the repository
git clone https://your-repository-url/hydra-front.git
cd hydra-front- Install dependencies
pnpm install- Configure environment variables
Create a .env.local file (or edit the existing one):
VITE_API_BASE_URL=your_api_endpoint
- Start the development server
pnpm devThe application will run on http://localhost:5173.
pnpm buildThe built files will be located in the dist directory.
-
Install Caddy Server
Please refer to the Caddy official documentation for installation.
-
Configure Caddyfile
Create or edit the Caddyfile:
your-domain.com { root * /path/to/hydra-front/dist # Set up SPA routing try_files {path} {path}/ /index.html # Define static resource matcher @static { path *.css *.js *.ico *.gif *.jpg *.jpeg *.png *.svg *.webp *.woff *.woff2 } # Static resource cache settings header @static Cache-Control "public, max-age=31536000, immutable" # HTML file cache settings @html { path *.html } header @html Cache-Control "no-cache, no-store, must-revalidate" # API proxy settings (if needed) reverse_proxy /api/* your_backend_api_server # Enable file server file_server } -
Start Caddy Server
caddy run
-
Use Dockerfile
The project already includes a Dockerfile, which can be built directly:
docker build -t hydra-front . docker run -d -p 80:80 hydra-front -
Use docker-compose
The project provides a docker-compose.yml file, which can be used to deploy both the frontend and backend:
# Start the service docker-compose up -d # View logs docker-compose logs -f # Stop the service docker-compose down
Note: Please adjust the configuration in docker-compose.yml according to your actual situation before using it.
VITE_API_BASE_URL: API server base URLVITE_BASE_URL: Optional alternative API base URL (for development/testing)
src/
├── components/ # Reusable components
├── contexts/ # React contexts
├── hooks/ # Custom React hooks
├── layouts/ # Layout components
├── lib/ # General utility functions
├── pages/ # Page components
├── types/ # TypeScript type definitions
├── App.tsx # Main application component
├── Login.tsx # Login page
├── index.css # Global styles
└── main.tsx # Application entry point
- Create a new page component in the
src/pagesdirectory - Add a new route to
src/App.tsxfor the new page
The project uses Tailwind CSS, following these conventions:
- Use Tailwind classes for styling
- Use custom classes to extend Tailwind, such as
.text-shadow-whiteand.text-shadow-blue
Ensure your .env.local file has the correct API endpoint configuration. For development, you may need to resolve CORS issues.
If the build fails, please try the following steps:
- Delete the
node_modulesanddistdirectories - Reinstall dependencies:
pnpm install - Rebuild:
pnpm build
HYDRA-AI frontend uses the /agent/chat/completions API endpoint to interact with the AI assistant, implementing blockchain project analysis functionality. This API is similar to the structure of OpenAI's Chat Completions API, suitable for frontend developers familiar with LLM APIs. For the complete API documentation, please refer to API documentation.
POST /agent/chat/completions
- Requires an authenticated user session
- Uses JWT authentication (managed by the
get_current_active_userdependency)
{
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Analyze the project at address 0x123..."
}
],
"stream": true,
"temperature": 0.7,
"max_tokens": 1024,
"project_context": {
"additional_context": "any relevant context"
}
}API provides two response modes:
- Non-streaming response - Full response returned once
- Streaming response - Returned in Server-Sent Events (SSE) format, containing the following event types:
- Stage event - Represents different stages of the analysis process
- Content event - Passes actual content blocks
- Error event - Passes error information
- Done event - Represents the end of the stream
// Frontend code example using fetch
async function chatWithAgent(userMessage) {
const response = await fetch('/agent/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({
model: 'gpt-4',
messages: [
{ role: 'user', content: userMessage }
],
stream: true
})
});
// Process streaming response
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
// Process complete SSE messages
const lines = buffer.split('\n\n');
buffer = lines.pop();
for (const line of lines) {
if (line.trim() === '') continue;
const [eventType, eventData] = line.split('\n');
const type = eventType.replace('event: ', '');
const data = JSON.parse(eventData.replace('data: ', ''));
// Process different responses based on event type
if (type === 'stage') {
console.log(`Stage: ${data.stage} - Status: ${data.status}`);
updateProgressIndicator(data.stage, data.status);
} else if (type === 'content') {
if (data.choices[0].delta.content) {
appendToResponse(data.choices[0].delta.content);
}
} else if (type === 'error') {
console.error(data.error);
showError(data.error.message);
} else if (type === 'done') {
finishResponse();
}
}
}
}Welcome to contribute! Please follow the following steps:
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add some amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request