Follow these instructions to set up the project on your local machine for development.
- Node.js installed (v16.0 or higher recommended).
- Optional: Python,
make, andg++for building native Node modules (e.g.,tree-sitter-java). Most platforms use prebuilt binaries; Alpine/Docker may require these for compilation. - Create an account for OpenRouter and Google Gemini APIs.
- Navigate to the Backend:
cd backend - Install Packages:
npm install
- Environment Variables:
Create a
.envfile within the/backenddirectory based on the following template:# Backend API details OPENROUTER_API_KEY=your_openrouter_api_key_here GEMINI_API_KEY=your_gemini_api_key_here TRANSLATOR_PROVIDER=openrouter # Options: 'openrouter' or 'mock' PORT=5000
- Start the Express Server:
The server runs at http://localhost:5000
npm start
- Navigate to the Frontend:
cd frontend - Install Packages:
npm install
- Environment Setup (Vite):
In your Vite environment, you can specify an API variable to override the
axiosbase backend connection endpoint, or Vite proxies. Ensure your code matches or defaults tolocalhost:5000. - Run Vite Development Server:
The client UI runs at http://localhost:5173
npm run dev
The backend enforces Java-only input via a three-layer validator:
- Layer 1: Sanity checks (empty, too short, non-code).
- Layer 2: Language detection (
program-language-detector) — rejects Python, JavaScript, etc. - Layer 3: Syntax validation (
tree-sitter-java) — rejects invalid Java, C#, Kotlin, Scala.
Validation runs on both /translate (typed/pasted code) and /upload (extracted image code).
Codemorpher supports containerized deployment using Docker. The backend image includes build tools for native modules (tree-sitter-java).
-
Build and Run the Backend Image:
cd backend docker build -t codemorpher-backend . docker run -p 8080:8080 --env-file .env codemorpher-backend
-
Build and Run the Frontend Image (with Nginx):
cd frontend docker build -t codemorpher-frontend . docker run -p 80:80 -e BACKEND_URL=http://localhost:8080 codemorpher-frontend
Note: The frontend uses an Nginx proxy to forward requests to the backend URL defined by the BACKEND_URL environment variable during container startup.