Internal AI operations workspace for authenticated support chat, document ingestion, admin observability, and Gemini-powered responses with persistent state.
Description Sankhya is a production-style AI support console. Users sign in with seeded local identities, open a live chat workspace, stream answers from Gemini over SSE, persist conversations in PostgreSQL, and manage privileged operations through an admin dashboard protected by RBAC, session-backed auth, and audit logging.
Sankhya is not just a chat page. It is a full-stack internal operations product that combines:
- a user workspace for authenticated AI conversations
- a FastAPI backend for chat orchestration, persistence, security, and metrics
- a PostgreSQL data layer for users, conversations, messages, auth sessions, token usage, and audit logs
- an admin console for metrics, document ingestion, and operational visibility
- a Gemini integration for text generation and embeddings
- an optional Redis-backed queue path for background embedding and tool workflows
In practice, this means you can:
- sign into the main app as a user
- send a prompt and watch the answer stream live
- come back later and see persisted conversation history
- sign into the admin area as an admin
- ingest documents into the system
- inspect token usage, queue depth, and audit-aware operational views
The current repository is stronger than a typical demo because it already includes:
- session-backed login instead of anonymous chat access
- role-based access control for privileged routes
- audit logging for sensitive actions like login, logout, admin reads, and document creation
- durable storage for conversations, messages, token usage, auth sessions, and metrics
- SSE streaming for a responsive operator experience
- graceful degradation when Redis-backed embedding queue infrastructure is unavailable locally
- a monorepo structure that keeps UI, API, workers, models, and docs aligned
This makes Sankhya a good base for:
- internal support copilots
- operations assistant dashboards
- retrieval-enabled service tools
- secure local demos of a production-style AI product
Open http://localhost:3000.
You will see:
- a sign-in panel for the user workspace
- a conversation sidebar
- a live message area
- a streaming composer that sends prompts to the backend over SSE
After login, the UI automatically uses the session token returned by /api/v1/auth/login.
Open http://localhost:3000/admin.
You will see:
- an admin sign-in form
- dashboard metrics
- document ingestion controls
- token usage data
- system log views
Admin-only endpoints are protected by RBAC permissions, and sensitive actions are recorded in the audit log.
Open http://localhost:8000/docs.
You can inspect and test:
/api/v1/auth/login/api/v1/auth/me/api/v1/auth/logout/api/v1/chat/stream/api/v1/conversations/{user_id}/api/v1/admin/dashboard/api/v1/admin/audit-logs
These screenshots are taken from the current local build and show the live UI after the latest auth, RBAC, and admin updates.
This is the main operator view after session login. It shows the signed-in identity, active conversation history, and a live streamed assistant response in progress or already persisted.
Why it matters:
- proves the user session is active
- shows the actual chat surface people will use every day
- demonstrates conversation persistence and streamed response rendering in the same screen
This is the top-level admin surface after an admin signs in. It highlights the role-aware session, granted permissions, and the operational summary cards used to monitor platform health.
Why it matters:
- shows that admin access is not anonymous anymore
- makes the RBAC model visible through the permission badges
- gives operators a quick read on platform-level usage and queue state
This view focuses on model usage records coming from the backend. It helps explain that Sankhya is not only a chat frontend, but also an observable AI system with latency and token reporting.
Why it matters:
- surfaces real Gemini usage information
- helps teams understand performance and cost patterns
- supports admin-side operational review
This admin view shows how documents are created and tracked through the retrieval pipeline. The form on the left queues ingestion, and the table on the right shows the indexed document inventory and status.
Why it matters:
- shows the retrieval side of the platform, not just chat
- demonstrates a privileged write flow protected by admin permissions
- makes the RAG/document pipeline visible to reviewers and operators
This component diagram shows the current runtime boundaries, including the new session auth and audit path.
This sequence view explains how login, permission checks, session resolution, and audit logging work together.
This sequence diagram captures the main user action: authenticated streaming chat from UI to Gemini and back.
This deployment view shows the local stack and the boundaries between frontend, backend, Postgres, Redis, and Gemini.
This domain view includes the latest persisted control-plane objects such as auth_sessions and audit_logs.
- A user signs in with
email + api_key. - The backend verifies the credentials against the
userstable. - A session token is issued and stored in
auth_sessions. - The frontend stores that session token in browser session storage.
- The user sends a prompt.
- The backend resolves the principal, checks access scope, and streams the answer over SSE.
- Conversation history and token usage are persisted in PostgreSQL.
- An admin signs in with an admin identity.
- The backend issues a session and permission-aware principal.
- Admin-only endpoints require permissions such as
admin:access,documents:write, andaudit:read. - Sensitive actions are written to
audit_logs. - The admin can inspect metrics, queue status, and privileged views from the dashboard.
.
|-- .env.example
|-- docker-compose.yml
|-- README.md
|-- docs
| `-- diagrams
|-- backend
| |-- Dockerfile
| |-- requirements.txt
| |-- alembic.ini
| |-- alembic
| |-- scripts
| `-- app
`-- frontend
|-- Dockerfile
|-- package.json
|-- app
|-- components
|-- hooks
`-- lib
-
backend/app/apiFastAPI route composition for auth, chat, conversations, documents, admin, and health endpoints. -
backend/app/coreConfiguration, structured logging, runtime validation, request IDs, and security helpers. -
backend/app/modelsSQLAlchemy entities for users, conversations, messages, token usage, auth sessions, audit logs, metrics, and queue tasks. -
backend/app/servicesGemini integration, audit logging, agent orchestration, queueing, metrics, memory, and retrieval services. -
backend/app/repositoriesDatabase access boundaries for conversations, tasks, and documents. -
backend/app/workersBackground processing entry points for embedding and tool-task execution. -
frontend/appNext.js App Router pages for user and admin experiences. -
frontend/libAPI helpers, SSE streaming helpers, and the new login/session client.
Copy-Item .env.example .env
Copy-Item backend\.env.example backend\.envMinimum local setup:
- PostgreSQL on
localhost:5432 - Node.js for the frontend
- Python for the backend
- a valid Gemini API key in backend/.env
Optional but recommended:
- Redis on
localhost:6379
cd backend
python -m alembic upgrade head
$env:PYTHONPATH='.'
python scripts\seed.pyThe seed script creates or updates:
demo@sankhya.localadmin@sankhya.local
If a user does not already have an API key, the script prints it to the console. If the users already exist, their API keys remain in the database.
cd backend
python -m uvicorn app.main:app --host 127.0.0.1 --port 8000In a second terminal:
cd frontend
npm install
npm.cmd run dev- Open
http://localhost:3000 - Sign in with:
- email: your seeded user email
- api key: the API key stored for that user
- Choose a conversation or start a new one
- Send a support-style prompt
- Watch the response stream into the chat area
- Open
http://localhost:3000/admin - Sign in with the seeded admin account
- Review dashboard metrics
- Create a document from the document manager
- Inspect token usage and system logs
- Query audit activity through
/api/v1/admin/audit-logs
If the seed script does not print keys because the users already exist, inspect the current local DB values directly:
select email, api_key
from users
where email in ('demo@sankhya.local', 'admin@sankhya.local');This is meant for local development only. In a production deployment, do not expose or document secrets this way.
- Frontend:
http://localhost:3000 - Admin:
http://localhost:3000/admin - FastAPI docs:
http://localhost:8000/docs - Backend root:
http://localhost:8000 - Health live:
http://localhost:8000/api/v1/health/live - Health ready:
http://localhost:8000/api/v1/health/ready
POSTGRES_DBPOSTGRES_USERPOSTGRES_PASSWORDPOSTGRES_PORTREDIS_PORTBACKEND_PORTFRONTEND_PORTGEMINI_API_KEYGEMINI_MODELGEMINI_EMBEDDING_MODELAPP_ENVLOG_LEVEL
APP_DATABASE_URLAPP_REDIS_URLAPP_GEMINI_API_KEYAPP_GEMINI_MODELAPP_GEMINI_FALLBACK_MODELAPP_GEMINI_EMBEDDING_MODELAPP_RATE_LIMIT_REQUESTSAPP_RATE_LIMIT_WINDOW_SECONDSAPP_MAX_AGENT_STEPSAPP_MAX_TOOL_WAIT_SECONDSAPP_EMBEDDING_DIMENSIONAPP_CORS_ORIGINSAPP_SSE_HEARTBEAT_SECONDSAPP_AUTH_SESSION_TTL_HOURS
What is implemented now:
- session-backed login
- RBAC permissions mapped by role
- tenant-aware conversation access
- admin-only document and audit routes
- persisted audit logs
- request IDs and structured logging
- security headers and fail-fast runtime checks
What still strengthens it further:
- replace plaintext API-key login with password-based auth or external identity
- hash stored login secrets instead of storing raw API keys
- rotate keys automatically
- install Redis locally for the full queue path
- add persisted audit log views directly in the admin UI
- If Redis is unavailable locally, the app still runs, but queue-backed background work degrades.
- If
APP_GEMINI_API_KEYis missing, chat can fall back instead of returning a live Gemini answer. - If you change database schema or auth behavior, rerun migrations before testing the UI.
Sankhya is already structured like a serious internal platform:
- the security model now covers login, session identity, permissions, auditability, and scoped access
- the product experience spans both end-user chat and admin operations
- the data model supports future reporting, retention, and governance work
- the architecture is ready for additional hardening in workers, observability, and production deployment
That makes it useful both as:
- a working local product
- a showcase of full-stack AI product engineering
- a foundation for a more production-hardened enterprise assistant
This repository is currently documented as an implementation-oriented project workspace. Add an explicit license and contribution policy before public distribution.



