Cogniva is a Learning-by-Teaching study platform where users learn by explaining a topic to an AI learner. The user prepares material in a workspace, teaches through a whiteboard and chat-based interaction, receives questions from the AI learner, and gets an evaluation of their explanation at the end of the session.
The application is built as a small monorepo with a React frontend and a
Fastify backend. The backend can use Gemini through the official
@google/genai SDK for real AI responses, while still supporting mock mode for
offline development and testing.
- Workspace creation and management
- Interactive whiteboard for writing and drawing teaching material
- AI learner persona that responds like a student
- Chat interaction for follow-up questions and clarification
- Teaching checkpoint submission with whiteboard and optional audio input
- Reference material for the evaluation — upload a PDF, paste your own notes, or let the reference agent search for sources and offer you a few options
- Spoken learner replies through ElevenLabs (optional)
- Session evaluation report after the learning session is completed
- Mock AI fallback when no Gemini API key is configured
- Frontend: React, TypeScript, Vite, Excalidraw
- Backend: Node.js, TypeScript, Fastify, Zod
- Database: PostgreSQL via Prisma
- AI provider: Gemini via
@google/genai - Voice: ElevenLabs over HTTP — optional
- Testing: Vitest
Cogniva/
|-- apps/
| |-- backend/
| | |-- src/
| | | |-- agents/ # Planner, learner, vision, ASR, evaluator agents
| | | |-- api/ # REST and WebSocket endpoints
| | | |-- config/ # Environment-based runtime config
| | | |-- contracts/ # Zod schemas and shared backend types
| | | |-- llm/ # Gemini client and prompts
| | | |-- modules/ # Workspace, session, topic, and storage logic
| | | |-- orchestrator/ # Teaching turn supervision (executes the planner's steps)
| | | |-- app.ts # Fastify app factory
| | | `-- main.ts # Backend entrypoint
| | |-- tests/ # Backend tests and demos
| | |-- .env.example
| | `-- package.json
| `-- frontend/
| |-- public/ # Static assets
| |-- src/
| | |-- bridge/ # Frontend bridge to real or mock backend
| | |-- dto/ # Frontend DTO types
| | |-- features/ # UI features
| | |-- routes/ # App routes
| | `-- main.tsx
| `-- package.json
|-- caddy/
| `-- Caddyfile # Reverse proxy and HTTPS configuration
|-- packages/
|-- scripts/
`-- README.md
Install these before running the project:
- Node.js 20 or newer
- npm
- PostgreSQL 14 or newer — or Docker, which brings its own (see Database)
- A Gemini API key, if you want to use real AI responses
You can still run the project without an API key. In that case, the backend uses mock AI responses. A database, however, is required.
Cogniva stores everything in PostgreSQL — workspaces, sessions, teaching
checkpoints, chat, transcripts, and the debrief report. The backend will not
start without a DATABASE_URL; there is no local-file or in-memory fallback.
The quickest way to get one is Docker Compose, which brings up Postgres, applies the migrations and starts the app together:
Copy-Item .env.example .env docker compose up -d --build
To run the backend directly instead, point it at a Postgres you already have and create the tables once:
cd apps/backend Copy-Item .env.example .env # then set DATABASE_URL npm install # also generates the Prisma client npm run db:migrate # create/update the tables
Useful commands:
npm run db:migrate— apply pending migrations (safe to re-run).npm run db:generate— regenerate the Prisma client after a schema change.npm run db:studio— browse the data in Prisma Studio.
Create the backend environment file:
cd apps/backend Copy-Item .env.example .env
Open apps/backend/.env and configure the values you need:
DATABASE_URL=postgresql://cogniva:cogniva@localhost:5432/cogniva?schema=public GEMINI_API_KEY=your_gemini_api_key_here USE_MOCK_AI=false COGNIVA_LEARNER_MODEL=gemini-2.5-flash PORT=8000
Important environment variables:
DATABASE_URL: PostgreSQL connection string. Required — see Database.GEMINI_API_KEY: Enables real Gemini-powered AI responses.USE_MOCK_AI: Set tofalseto use Gemini, ortrueto force mock AI.COGNIVA_LEARNER_MODEL: Gemini model used by the learner agent.PORT: Backend server port. The frontend expects8000by default.ELEVENLABS_API_KEY: Speak the learner's replies. Setting it turns the voice on; there is nothing else to run. See Learner voice.COGNIVA_ELEVENLABS_VOICE_ID: One voice for all three students, orCOGNIVA_ELEVENLABS_VOICE_YUZUKI/_REINA/_AKIRAfor one each. List the ids on your key withnpm run tts:voicesinapps/backend.COGNIVA_TTS_ENABLED: Follows the key above. Set it tofalseto silence the voice without unsetting the key.
Every other knob is listed with a comment in apps/backend/.env.example, and
they are all read in one place, apps/backend/src/config/index.ts.
If the backend starts on a different port, either change PORT=8000 in the
backend .env file or configure the frontend with VITE_API_BASE.
Optional frontend environment file:
cd apps/frontend New-Item .env.local
Example apps/frontend/.env.local:
VITE_API_BASE=http://localhost:8000 VITE_USE_MOCK=false
Two terminals are enough for the whole app. The learner's voice is an API key, not a third process.
There is no root package.json and no workspace tooling, so every npm command
has to run from inside apps/backend or apps/frontend.
See Database first — it needs DATABASE_URL and a migrated
database.
cd apps/backend
npm install
npm run db:migrate
npm run devRun npm run db:migrate again after pulling changes from someone else. It only
applies what is missing and is safe to re-run; skipping it leaves the schema
behind the code, which shows up as write failures rather than a startup error.
The backend should print:
Cogniva backend terhubung ke Postgres
Cogniva backend listening on http://localhost:8000
If it exits with DATABASE_URL belum diisi, the connection string is missing
from apps/backend/.env.
Check the backend health endpoint:
http://localhost:8000/health
cd apps/frontend
npm install
npm run devOpen the frontend in your browser:
http://localhost:5173
That is the app, fully working — whiteboard, learner, chat, reference material and the evaluation report. The learner is silent until you add a voice key below.
The student speaks through the ElevenLabs API. There is nothing to install and nothing to start: the backend calls it over HTTP, and the voice is best-effort — no key, a spent quota, a slow or broken call all mean "no audio this time" while the reply still arrives as text.
Put the key in apps/backend/.env:
ELEVENLABS_API_KEY=sk_...
Voice ids belong to your account, so there is no default to ship. List the ones on your key — it prints each id next to the variable it goes in:
cd apps/backend
npm run tts:voicesThen assign one per student (or COGNIVA_ELEVENLABS_VOICE_ID for all three) and
restart the backend:
COGNIVA_ELEVENLABS_VOICE_YUZUKI=... COGNIVA_ELEVENLABS_VOICE_REINA=... COGNIVA_ELEVENLABS_VOICE_AKIRA=...
That is the whole setup: with a key present the voice switches itself on, in
whichever language the session runs in. COGNIVA_TTS_ENABLED=false silences it
without unsetting the key, and every other knob (model, audio format, delivery
settings) is commented in apps/backend/.env.example.
There used to be a local voice service here (services/tts: Chatterbox and XTTS
behind FastAPI). It was removed — it needed a GPU to be worth using and could not
speak Indonesian, so the audience this product is built for could never hear it.
With the voice on, a reply is spoken one sentence at a time and its text appears in step: each sentence shows up as its clip starts playing, with nothing to press. If a clip takes longer than 8 seconds, the text is shown anyway.
From the repository root, this brings up Postgres, applies the migrations, and serves the frontend behind Caddy:
Copy-Item .env.example .env docker compose up -d --build
For the learner's voice, put ELEVENLABS_API_KEY and a voice id in the root
.env before bringing the stack up. There is no voice container: the backend
calls the API directly, so a host with no GPU is no obstacle.
To use real Gemini responses:
- Put a valid Gemini API key in
apps/backend/.env. - Set
USE_MOCK_AI=false. - Make sure the backend is running.
- Use the app from the frontend.
You can also test the learner agent directly from the backend:
cd apps/backend
npm run chat:learnerIf the AI is connected correctly, the command shows Gemini mode. If no API key is found, it falls back to mock mode.
Run backend tests. These use in-memory store doubles, so no database is needed:
cd apps/backend
npm testRun the database suite, which exercises the real PostgreSQL path. It needs a
DATABASE_URL pointing at a migrated database and cleans up its own rows:
cd apps/backend
npm run test:dbRun backend type checking:
cd apps/backend
npm run typecheckBuild the frontend:
cd apps/frontend
npm run buildThe backend includes a few demo scripts for testing individual AI features:
cd apps/backend npm run chat:learner npm run demo:learner npm run demo:vision -- ./gambar-uji/papan1.jpeg "Photosynthesis" npm run demo:asr -- ./path-to-audio.wav "Photosynthesis" npm run demo:referencer -- "Photosynthesis"
Some demos default to mock mode so they can run without an API key. Set
USE_MOCK_AI=false in .env when you want to call Gemini.
- Open the frontend.
- Create a new workspace and pick a student.
- Say what you are teaching. The same panel offers reference material for the evaluation — paste your own notes, upload a PDF, or let the agent search and choose from what it finds. This is optional; you can skip it and start.
- Add teaching material on the whiteboard.
- Submit a teaching checkpoint.
- Read the AI learner response — and hear it, if the voice service is running.
- Continue the discussion through chat.
- Finish the session.
- Review the generated evaluation report.
Reference material only ever reaches the evaluator, never the learner. The student you are teaching does not get to read the answer key.
Make sure the backend is running on the same port expected by the frontend. The default is:
http://localhost:8000
If the backend prints a different port, update PORT=8000 in
apps/backend/.env, restart the backend, and refresh the frontend.
This is normal if you open the backend root URL directly. Use the health endpoint instead:
http://localhost:8000/health
Check these values in apps/backend/.env:
GEMINI_API_KEY=your_gemini_api_key_here USE_MOCK_AI=false
Then restart the backend.
The schema is probably behind the code — a migration arrived with someone else's changes and was never applied. The backend only checks that it can connect at startup, so this surfaces as a failing request rather than a failed boot:
cd apps/backend
npm run db:migrateWork through these in order:
ELEVENLABS_API_KEYmust be inapps/backend/.env, with the backend restarted since you set it.- A voice id must be set for the student on screen — run
npm run tts:voicesinapps/backendto list the ids on your key and the variables they go in. Without one the backend logs exactly which variable is missing. - Check the mute toggle in the workspace header — it is remembered per browser.
- Out of characters on your plan is a 402 from the API;
npm run tts:voicesprints what the plan has left.
Silence is the designed failure mode: the backend never lets a voice problem cost you the reply, so nothing here shows up as an error in the UI. The backend log is where a failed synthesis is reported, with the reason.