Merge branch 'cloud-prep'
This commit is contained in:
commit
5eb64cf775
26 changed files with 3321 additions and 61 deletions
39
.dockerignore
Normal file
39
.dockerignore
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# Node modules
|
||||
node_modules
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Build outputs
|
||||
dist
|
||||
build
|
||||
target
|
||||
|
||||
# Environment files
|
||||
.env
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
# IDE
|
||||
.vscode
|
||||
.idea
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
# Documentation
|
||||
README.md
|
||||
DEVELOPMENT.md
|
||||
*.md
|
||||
|
||||
# Scripts
|
||||
setup-check.ps1
|
||||
14
.env.example
Normal file
14
.env.example
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# .env.example
|
||||
|
||||
# --- PLEASE FILL THIS OUT WITH THE SECURELY PROVIDED CREDENTIALS ---
|
||||
|
||||
# Application Database Credentials
|
||||
MYSQL_DATABASE=astra
|
||||
MYSQL_USER=astraadmin
|
||||
MYSQL_PASSWORD=
|
||||
|
||||
# MySQL Container Root Password (for first-time setup only, not used by the app)
|
||||
MYSQL_ROOT_PASSWORD=
|
||||
|
||||
# API Keys
|
||||
GEMINI_API_KEY=
|
||||
110
.github/workflows/build-and-deploy.yml
vendored
110
.github/workflows/build-and-deploy.yml
vendored
|
|
@ -1,56 +1,96 @@
|
|||
# For information on GITHUB_TOKEN: https://docs.github.com/en/actions/concepts/security/github_token
|
||||
# For information on github.actor: https://github.com/orgs/community/discussions/62108
|
||||
# .github/workflows/build-and-deploy.yml
|
||||
|
||||
name: Build and Deploy
|
||||
|
||||
# This workflow runs only on pushes to the 'main' branch
|
||||
on:
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
push:
|
||||
branches: ["main"]
|
||||
|
||||
env:
|
||||
CONTAINER_NAME: codered-astra
|
||||
CONTAINER_TAG: ghcr.io/${{ github.repository_owner }}/codered-astra:latest
|
||||
|
||||
jobs:
|
||||
# Set permissions for the job
|
||||
build:
|
||||
build-and-deploy:
|
||||
# Set permissions for the job to read contents and write to GitHub Packages
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
attestations: write
|
||||
id-token: write
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
name: Build Docker Image
|
||||
name: Build Images and Deploy to Server
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v5
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Login to Docker Hub
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }} # User that commits
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
tags: ${{ env.CONTAINER_TAG }}
|
||||
images: |
|
||||
ghcr.io/${{ github.repository }}/frontend
|
||||
ghcr.io/${{ github.repository }}/nodejs-backend
|
||||
ghcr.io/${{ github.repository }}/rust-engine
|
||||
|
||||
# WIP: For deployment
|
||||
deploy:
|
||||
name: Deploy Docker Image to Server
|
||||
runs-on: self-hosted
|
||||
needs: build
|
||||
steps:
|
||||
# --- Build and push one image for each service ---
|
||||
- name: Build and push frontend image 🚀
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ./frontend
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags_frontend }}
|
||||
labels: ${{ steps.meta.outputs.labels_frontend }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Build and push Node.js backend image 🚀
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ./nodejs-backend
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags_nodejs-backend }}
|
||||
labels: ${{ steps.meta.outputs.labels_nodejs-backend }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Build and push Rust engine image 🚀
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ./rust-engine
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags_rust-engine }}
|
||||
labels: ${{ steps.meta.outputs.labels_rust-engine }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
# --- Deploy the new images to your server ---
|
||||
- name: Deploy to server via SSH ☁️
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.SERVER_HOST }}
|
||||
username: ${{ secrets.SERVER_USERNAME }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
script: |
|
||||
# Navigate to your project directory on the server
|
||||
cd /var/www/codered-astra
|
||||
|
||||
# Export secrets as environment variables for Docker Compose
|
||||
export GEMINI_API_KEY='${{ secrets.GEMINI_API_KEY }}'
|
||||
export MYSQL_DATABASE='${{ secrets.MYSQL_DATABASE }}'
|
||||
export MYSQL_USER='${{ secrets.MYSQL_USER }}'
|
||||
export MYSQL_PASSWORD='${{ secrets.MYSQL_PASSWORD }}'
|
||||
export MYSQL_ROOT_PASSWORD='${{ secrets.MYSQL_ROOT_PASSWORD }}'
|
||||
|
||||
# Set the image tag to the specific commit SHA for a precise deployment
|
||||
export IMAGE_TAG=${{ github.sha }}
|
||||
|
||||
# Pull the new images you just pushed to the registry
|
||||
docker-compose pull
|
||||
|
||||
# Stop the old containers and start new ones with the updated images
|
||||
docker-compose up -d --force-recreate
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -21,6 +21,9 @@ dist
|
|||
turbo-build.log
|
||||
turbo-host.log
|
||||
|
||||
# rust
|
||||
rust-engine/target
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
|
|
|
|||
117
DEVELOPMENT.md
Normal file
117
DEVELOPMENT.md
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
# 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! 🚀
|
||||
15
Dockerfile
15
Dockerfile
|
|
@ -1,15 +0,0 @@
|
|||
FROM node:23-alpine
|
||||
|
||||
COPY . /codered-astra
|
||||
|
||||
WORKDIR /codered-astra
|
||||
|
||||
RUN npm i
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
RUN npm run format
|
||||
|
||||
RUN npm run build
|
||||
|
||||
CMD ["npm", "run", "host"]
|
||||
77
README.md
77
README.md
|
|
@ -1,16 +1,75 @@
|
|||
# React + Vite
|
||||
# CodeRED-Astra 🚀
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
A hackathon-ready project with React frontend and Rust backend engine.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
## Quick Start
|
||||
|
||||
- [@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
|
||||
```bash
|
||||
# 1. Setup environment
|
||||
cp .env.example .env
|
||||
# Edit .env with your credentials
|
||||
|
||||
## React Compiler
|
||||
# 2. Start everything with Docker
|
||||
docker-compose up --build
|
||||
|
||||
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).
|
||||
# 3. Access your app
|
||||
# Frontend: http://localhost
|
||||
# API: http://localhost:8000
|
||||
# Database Admin: http://127.0.0.1:8080
|
||||
```
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
## Development
|
||||
|
||||
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.
|
||||
**Frontend (React + Vite)**:
|
||||
```bash
|
||||
cd web-app
|
||||
npm install
|
||||
npm run dev # http://localhost:5173
|
||||
```
|
||||
|
||||
**Backend (Rust)**:
|
||||
```bash
|
||||
cd rust-engine
|
||||
cargo run # http://localhost:8000
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
- **Frontend**: React 18 + Vite + Tailwind CSS
|
||||
- **Backend**: Rust + Warp + SQLx
|
||||
- **Database**: MySQL 8.0 + phpMyAdmin
|
||||
- **API**: RESTful endpoints with CORS enabled
|
||||
- **Docker**: Full containerization for easy deployment
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
├── web-app/ # React frontend
|
||||
│ ├── src/
|
||||
│ │ ├── App.jsx # Main component
|
||||
│ │ └── main.jsx # Entry point
|
||||
│ └── Dockerfile
|
||||
├── rust-engine/ # Rust backend
|
||||
│ ├── src/
|
||||
│ │ └── main.rs # API server
|
||||
│ └── Dockerfile
|
||||
├── docker-compose.yml # Full stack orchestration
|
||||
└── .env.example # Environment template
|
||||
```
|
||||
|
||||
## Team Workflow
|
||||
|
||||
- **Frontend devs**: Work in `web-app/src/`, use `/api/*` for backend calls
|
||||
- **Backend devs**: Work in `rust-engine/src/`, add endpoints to main.rs
|
||||
- **Database**: Access phpMyAdmin at http://127.0.0.1:8080
|
||||
|
||||
## Features
|
||||
|
||||
✅ Hot reload for both frontend and backend
|
||||
✅ Automatic API proxying from React to Rust
|
||||
✅ Database connection with graceful fallback
|
||||
✅ CORS configured for cross-origin requests
|
||||
✅ Production-ready Docker containers
|
||||
✅ Health monitoring and status dashboard
|
||||
|
||||
Ready for your hackathon! See `DEVELOPMENT.md` for detailed setup instructions.
|
||||
|
|
|
|||
53
docker-compose.yml
Normal file
53
docker-compose.yml
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
# docker-compose.yml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
web-app:
|
||||
build:
|
||||
context: ./web-app
|
||||
restart: always
|
||||
ports:
|
||||
- "80:3000"
|
||||
environment:
|
||||
# The connection string remains the same, but points to the 'mysql' service
|
||||
- DATABASE_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@mysql:3306/${MYSQL_DATABASE}
|
||||
- RUST_ENGINE_URL=http://rust-engine:8000
|
||||
- GEMINI_API_KEY=${GEMINI_API_KEY}
|
||||
depends_on:
|
||||
- mysql # <-- Updated dependency
|
||||
- rust-engine
|
||||
|
||||
rust-engine:
|
||||
build:
|
||||
context: ./rust-engine
|
||||
restart: always
|
||||
environment:
|
||||
- DATABASE_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@mysql:3306/${MYSQL_DATABASE}
|
||||
depends_on:
|
||||
- mysql # <-- Updated dependency
|
||||
|
||||
# --- Key Changes are in this section ---
|
||||
mysql: # <-- Renamed service for clarity
|
||||
image: mysql:8.0 # <-- CHANGED: Using the official MySQL 8.0 image
|
||||
restart: always
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
|
||||
- MYSQL_DATABASE=${MYSQL_DATABASE}
|
||||
- MYSQL_USER=${MYSQL_USER}
|
||||
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
|
||||
volumes:
|
||||
- mysql-data:/var/lib/mysql
|
||||
|
||||
phpmyadmin:
|
||||
image: phpmyadmin/phpmyadmin
|
||||
restart: always
|
||||
ports:
|
||||
# CHANGED: Binds port 8080 to localhost ONLY.
|
||||
- "127.0.0.1:8080:80"
|
||||
environment:
|
||||
- PMA_HOST=mysql
|
||||
depends_on:
|
||||
- mysql
|
||||
|
||||
volumes:
|
||||
mysql-data: # Renamed volume for clarity (optional but good practice)
|
||||
2390
rust-engine/Cargo.lock
generated
Normal file
2390
rust-engine/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
17
rust-engine/Cargo.toml
Normal file
17
rust-engine/Cargo.toml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "rust-engine"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
warp = { version = "0.4.2", features = ["server"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
sqlx = { version = "0.8.6", features = ["runtime-tokio-rustls", "mysql", "chrono"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.3"
|
||||
dotenv = "0.15"
|
||||
cors = "0.1.0"
|
||||
anyhow = "1.0"
|
||||
30
rust-engine/Dockerfile
Normal file
30
rust-engine/Dockerfile
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# rust-engine/Dockerfile
|
||||
# --- Stage 1: Builder ---
|
||||
FROM rust:1.82-slim AS builder
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Install build dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
pkg-config \
|
||||
libssl-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy Cargo files for dependency caching
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
# Create a dummy src/main.rs for dependency build
|
||||
RUN mkdir src && echo "fn main() {}" > src/main.rs
|
||||
RUN cargo build --release && rm src/main.rs
|
||||
|
||||
# Copy source code and build
|
||||
COPY src ./src
|
||||
RUN cargo build --release
|
||||
|
||||
# --- Stage 2: Final Image ---
|
||||
FROM debian:bookworm-slim
|
||||
RUN apt-get update && apt-get install -y \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=builder /usr/src/app/target/release/rust-engine /usr/local/bin/rust-engine
|
||||
EXPOSE 8000
|
||||
CMD ["rust-engine"]
|
||||
132
rust-engine/src/main.rs
Normal file
132
rust-engine/src/main.rs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
use std::env;
|
||||
use warp::Filter;
|
||||
use sqlx::mysql::MySqlPool;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::{info, warn};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct HealthResponse {
|
||||
status: String,
|
||||
timestamp: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct ApiResponse<T> {
|
||||
success: bool,
|
||||
data: Option<T>,
|
||||
message: Option<String>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Initialize tracing
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
// Load environment variables
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
let database_url = env::var("DATABASE_URL")
|
||||
.unwrap_or_else(|_| "mysql://astraadmin:password@mysql:3306/astra".to_string());
|
||||
|
||||
info!("Starting Rust Engine...");
|
||||
info!("Connecting to database: {}", database_url);
|
||||
|
||||
// Connect to database
|
||||
let pool = match MySqlPool::connect(&database_url).await {
|
||||
Ok(pool) => {
|
||||
info!("Successfully connected to database");
|
||||
pool
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to connect to database: {}. Starting without DB connection.", e);
|
||||
// In a hackathon setting, we might want to continue without DB for initial testing
|
||||
return start_server_without_db().await;
|
||||
}
|
||||
};
|
||||
|
||||
// CORS configuration
|
||||
let cors = warp::cors()
|
||||
.allow_any_origin()
|
||||
.allow_headers(vec!["content-type", "authorization"])
|
||||
.allow_methods(vec!["GET", "POST", "PUT", "DELETE", "OPTIONS"]);
|
||||
|
||||
// Health check endpoint
|
||||
let health = warp::path("health")
|
||||
.and(warp::get())
|
||||
.map(|| {
|
||||
let response = HealthResponse {
|
||||
status: "healthy".to_string(),
|
||||
timestamp: chrono::Utc::now().to_rfc3339(),
|
||||
};
|
||||
warp::reply::json(&ApiResponse {
|
||||
success: true,
|
||||
data: Some(response),
|
||||
message: None,
|
||||
})
|
||||
});
|
||||
|
||||
// API routes - you'll expand these for your hackathon needs
|
||||
let api = warp::path("api")
|
||||
.and(
|
||||
health.or(
|
||||
// Add more routes here as needed
|
||||
warp::path("version")
|
||||
.and(warp::get())
|
||||
.map(|| {
|
||||
warp::reply::json(&ApiResponse {
|
||||
success: true,
|
||||
data: Some("1.0.0"),
|
||||
message: Some("Rust Engine API".to_string()),
|
||||
})
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
let routes = api
|
||||
.with(cors)
|
||||
.with(warp::log("rust_engine"));
|
||||
|
||||
info!("Rust Engine started on http://0.0.0.0:8000");
|
||||
|
||||
warp::serve(routes)
|
||||
.run(([0, 0, 0, 0], 8000))
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn start_server_without_db() -> Result<(), Box<dyn std::error::Error>> {
|
||||
info!("Starting server in DB-less mode for development");
|
||||
|
||||
let cors = warp::cors()
|
||||
.allow_any_origin()
|
||||
.allow_headers(vec!["content-type", "authorization"])
|
||||
.allow_methods(vec!["GET", "POST", "PUT", "DELETE", "OPTIONS"]);
|
||||
|
||||
let health = warp::path("health")
|
||||
.and(warp::get())
|
||||
.map(|| {
|
||||
let response = HealthResponse {
|
||||
status: "healthy (no db)".to_string(),
|
||||
timestamp: chrono::Utc::now().to_rfc3339(),
|
||||
};
|
||||
warp::reply::json(&ApiResponse {
|
||||
success: true,
|
||||
data: Some(response),
|
||||
message: Some("Running without database connection".to_string()),
|
||||
})
|
||||
});
|
||||
|
||||
let routes = warp::path("api")
|
||||
.and(health)
|
||||
.with(cors)
|
||||
.with(warp::log("rust_engine"));
|
||||
|
||||
info!("Rust Engine started on http://0.0.0.0:8000 (DB-less mode)");
|
||||
|
||||
warp::serve(routes)
|
||||
.run(([0, 0, 0, 0], 8000))
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
62
setup-check.ps1
Normal file
62
setup-check.ps1
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env pwsh
|
||||
|
||||
Write-Host "🚀 CodeRED-Astra Setup Verification" -ForegroundColor Green
|
||||
Write-Host "=================================" -ForegroundColor Green
|
||||
|
||||
# Check if Docker is available
|
||||
Write-Host "`n📦 Checking Docker..." -ForegroundColor Yellow
|
||||
try {
|
||||
$dockerVersion = docker --version
|
||||
Write-Host "✅ Docker found: $dockerVersion" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "❌ Docker not found. Please install Docker Desktop." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if .env exists
|
||||
Write-Host "`n🔧 Checking environment setup..." -ForegroundColor Yellow
|
||||
if (Test-Path ".env") {
|
||||
Write-Host "✅ .env file exists" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "⚠️ .env file not found. Creating from template..." -ForegroundColor Yellow
|
||||
Copy-Item ".env.example" ".env"
|
||||
Write-Host "✅ Created .env file. Please edit it with your credentials!" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Check Node.js (for local development)
|
||||
Write-Host "`n📱 Checking Node.js..." -ForegroundColor Yellow
|
||||
try {
|
||||
$nodeVersion = node --version
|
||||
Write-Host "✅ Node.js found: $nodeVersion" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "⚠️ Node.js not found (needed for local frontend development)" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Check Rust (for local development)
|
||||
Write-Host "`n🦀 Checking Rust..." -ForegroundColor Yellow
|
||||
try {
|
||||
$rustVersion = rustc --version
|
||||
Write-Host "✅ Rust found: $rustVersion" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "⚠️ Rust not found (needed for local backend development)" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Write-Host "`n🎯 Setup Summary:" -ForegroundColor Cyan
|
||||
Write-Host "=================" -ForegroundColor Cyan
|
||||
Write-Host "• Frontend: React + Vite + Tailwind CSS" -ForegroundColor White
|
||||
Write-Host "• Backend: Rust + Warp + SQLx + MySQL" -ForegroundColor White
|
||||
Write-Host "• Docker: Full stack containerization" -ForegroundColor White
|
||||
|
||||
Write-Host "`n🚀 Quick Start Commands:" -ForegroundColor Magenta
|
||||
Write-Host "========================" -ForegroundColor Magenta
|
||||
Write-Host "1. Start full stack: docker-compose up --build" -ForegroundColor White
|
||||
Write-Host "2. Frontend dev: cd web-app && npm install && npm run dev" -ForegroundColor White
|
||||
Write-Host "3. Backend dev: cd rust-engine && cargo run" -ForegroundColor White
|
||||
|
||||
Write-Host "`n📍 Access URLs:" -ForegroundColor Cyan
|
||||
Write-Host "===============" -ForegroundColor Cyan
|
||||
Write-Host "• Web App: http://localhost (Docker) or http://localhost:5173 (local)" -ForegroundColor White
|
||||
Write-Host "• Rust API: http://localhost:8000" -ForegroundColor White
|
||||
Write-Host "• phpMyAdmin: http://127.0.0.1:8080" -ForegroundColor White
|
||||
|
||||
Write-Host "`n✨ Your hackathon project is ready! Happy coding! ✨" -ForegroundColor Green
|
||||
22
web-app/Dockerfile
Normal file
22
web-app/Dockerfile
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# web-app/Dockerfile
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files first to leverage Docker's build cache
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci --only=production=false
|
||||
|
||||
# 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"]
|
||||
29
web-app/eslint.config.js
Normal file
29
web-app/eslint.config.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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";
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(["dist"]),
|
||||
{
|
||||
files: ["**/*.{js,jsx}"],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
reactHooks.configs["recommended-latest"],
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
parserOptions: {
|
||||
ecmaVersion: "latest",
|
||||
ecmaFeatures: { jsx: true },
|
||||
sourceType: "module",
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
"no-unused-vars": ["error", { varsIgnorePattern: "^[A-Z_]" }],
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src"
|
||||
"baseUrl": "web-app/src"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
"web-app/src"
|
||||
]
|
||||
}
|
||||
0
package-lock.json → web-app/package-lock.json
generated
0
package-lock.json → web-app/package-lock.json
generated
37
web-app/package.json
Normal file
37
web-app/package.json
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"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}\""
|
||||
},
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@google/generative-ai": "^0.21.0",
|
||||
"axios": "^1.7.7",
|
||||
"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",
|
||||
"vite-jsconfig-paths": "^2.0.1"
|
||||
}
|
||||
}
|
||||
6
web-app/postcss.config.js
Normal file
6
web-app/postcss.config.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
137
web-app/src/App.jsx
Normal file
137
web-app/src/App.jsx
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
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;
|
||||
33
web-app/src/index.css
Normal file
33
web-app/src/index.css
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
10
web-app/src/main.jsx
Normal file
10
web-app/src/main.jsx
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import "./index.css";
|
||||
import App from "./app/index.jsx";
|
||||
|
||||
createRoot(document.getElementById("root")).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>
|
||||
);
|
||||
19
web-app/tailwind.config.js
Normal file
19
web-app/tailwind.config.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ["./src/**/*.{js,ts,jsx,tsx}"],
|
||||
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: [],
|
||||
};
|
||||
26
web-app/vite.config.js
Normal file
26
web-app/vite.config.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import jsconfigPaths from "vite-jsconfig-paths";
|
||||
|
||||
// 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/, '')
|
||||
}
|
||||
}
|
||||
},
|
||||
preview: {
|
||||
host: '0.0.0.0',
|
||||
port: 3000
|
||||
},
|
||||
build: {
|
||||
outDir: 'dist'
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue