Spaces:
Running
title: Alkabrain
emoji: π§
colorFrom: yellow
colorTo: red
sdk: docker
app_port: 8080
pinned: false
AI Router β Self-Deploying Claude-Style Workspace
A polished AI chat workspace that intelligently routes each prompt to the best of 20+ open-source Hugging Face models, with a built-in DevOps console that pushes the app to your own Hugging Face Space and watches the build live.
Features
- Claude.ai-style split workspace β chat on the left, an Artifacts viewer on the right for code, markdown, and Mermaid diagrams (syntax-highlighted, copy/download).
- Server-side intent router β picks a code, math, reasoning, summarization, translation, or general model based on the prompt. The pick + reason is shown above every assistant reply.
- Multi-language replies β the assistant always answers in the language the user wrote in (English, Hindi, Hinglish, etc.).
- DevOps Module β one-click push of a bundled FastAPI + Docker template to your Hugging Face
Space (
shrey77777/xyzzzby default), with live polling of the Space build stage and a deployment history. - Zero token leakage β
HF_TOKENis read only from the server-side environment. The frontend never sees it; the UI only shows whether it's configured.
Architecture
ββββββββββββββββββββββββββββ ββββββββββββββββββββββββ ββββββββββββββββββββββββββ
β React + Vite frontend β ββ β Express backend β ββ β HF Inference Router β
β (Claude-style UI) β β - intent router β β (chat completions) β
β - chat, artifacts β β - HF inference call β ββββββββββββββββββββββββββ
β - deploy console β β - git-push deployer β ββ β Hugging Face Space β
β - models catalog β β - status poller β β shrey77777/xyzzz β
ββββββββββββββββββββββββββββ ββββββββββββββββββββββββ ββββββββββββββββββββββββββ
The pushed Space contains a self-contained Python 3.11 + FastAPI + Docker version of the same
router with the same 20+ model catalog. See artifacts/api-server/src/hf-space-template/.
Required environment variables
| Variable | Required | Default | Notes |
|---|---|---|---|
HF_TOKEN |
yes | β | Hugging Face token with write scope |
HF_SPACE_REPO |
no | shrey77777/xyzzz |
<user>/<space-name> |
HF_SPACE_BRANCH |
no | main |
|
HF_USER |
no | first part of HF_SPACE_REPO |
username for the Git push URL |
The token is never read or rendered on the client. The
/api/deploy/configendpoint only reportshasToken: true|false.
Setting the token on Replit
HF_TOKEN is already requested as a Replit Secret β the agent will prompt you. Treat any token
that has ever been pasted into a chat as compromised: revoke it at
https://huggingface.co/settings/tokens and issue a fresh one.
Setting the token on Hugging Face
The pushed Space also needs HF_TOKEN so its /chat endpoint can call the Inference API. Add it
under Settings β Variables and secrets on the Space.
Running locally
pnpm install
# in three terminals:
pnpm --filter @workspace/api-server run dev
pnpm --filter @workspace/ai-router run dev
The frontend talks to the backend through the shared proxy at /api/....
Running in Docker
A single-container Dockerfile that builds the React frontend, runs the Express backend, and bundles
git + Python build deps for the deploy module:
docker build -t ai-router .
docker run --rm -p 8080:8080 \
-e HF_TOKEN="hf_xxx" \
-e HF_SPACE_REPO="your-username/your-space" \
ai-router
Deploying to your Hugging Face Space
- Make sure
HF_TOKENis set (Replit Secrets or.envfor Docker). - Open the Deploy page in the app.
- Optional: enter a commit message.
- Click Deploy to Hugging Face Space.
- Watch the live progress β
pending β pushing β building β success/failed. On success you get the commit SHA and a link to the live Space.
The deploy module clones the target Space, replaces the working tree with the bundled template,
commits, and pushes β then polls the HF Spaces API for runtime.stage until it's RUNNING (or an
error stage).
Security notes
- All secrets are read from
process.envon the server. They are never serialized to the client. - The frontend has no field for the HF token β it cannot be entered in the UI.
- The Docker container drops to a non-root user.
- The pushed Space's Dockerfile also runs as a non-root
appuser.
API (selected)
GET /api/modelsβ list of routable modelsPOST /api/chatβ{ messages, modelId? }β routed reply with model + intent + artifactGET /api/deploy/configβ{ spaceRepo, hasToken, defaultBranch }POST /api/deploy/pushβ start a deploy, returns the jobGET /api/deploy/statusβ current job + live HF runtime stageGET /api/deploy/historyβ last 20 jobs
Repo layout
artifacts/
ai-router/ # React + Vite frontend
api-server/ # Express backend
src/lib/models.ts # 20+ model catalog
src/lib/router.ts # intent classifier + model picker
src/lib/hf-inference.ts # Hugging Face Inference call
src/lib/deploy.ts # git-push + build poller
src/routes/{chat,deploy,models}.ts
src/hf-space-template/ # FastAPI + Docker bundle pushed to HF
lib/
api-spec/openapi.yaml # contract source of truth
api-client-react/ # generated React Query hooks
api-zod/ # generated Zod schemas
License
MIT