# hi-day/lisanai architecture

> Architecture diagram of the GitHub repository hi-day/lisanai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hi-day/lisanai
- Repository: https://github.com/hi-day/lisanai

## Overview

#### Purpose and Runtime
Lisan.ai is a multi-tenant Indonesian oral-assessment platform for teachers, students, and admins. It creates rubric-based assessments, collects spoken or typed responses, evaluates them through a trustworthy AI harness, and exposes operational and research dashboards. The runtime is Node.js with a static browser SPA, SQLite persistence, and Vercel-compatible serverless API routes.

#### Entry Points and Delivery
- Local bootstrapping and HTTP composition begin in `local-server.js` and `server/bootstrap.js`.
- The browser app starts from `src/js/main.js`, composes application state/UI in `src/js/app.js`, and is bundled to `public/js/app.bundle.js`.
- Vercel routes API requests through `api/v1.js` and feature handlers such as `api/assessment.js`; static delivery is handled by `server/static.js`.
- API documentation is served from `api/docs.js` and the generated contract `api/openapi.json`.

#### Identity, Tenancy, and Access Boundary
- Authentication, sessions, CSRF, password handling, and role authorization are centered in `server/auth-service.js` and `server/api-auth.js`.
- Teacher/student/admin workflows are represented client-side by `src/js/auth-ui.js`, `src/js/class-management.js`, and `src/js/student-flow.js`.
- Public API consumers use separately managed API keys through `server/api-key-service.js` and `api/apikeys.js`.
- Authorization is a critical boundary: tenant, class membership/approval, and role constraints must be enforced before assessment, submission, complaint, or research access.

#### Assessment Authoring and Submission Flow
- Teachers create and manage assessments through `server/assessment-service.js`, exposed by `api/assessment.js`; UI authoring is in `src/js/assessment-wizard.js` and `src/js/assessment-factory.js`.
- Question generation/alignment uses AI-provider abstractions in `server/ai/provider.js`, `server/ai/openrouter-provider.js`, and response normalization in `server/ai/response-parser.js`.
- Students enter an assessment flow, perform microphone checks, and submit recorded or manually transcribed answers via `src/js/student-flow.js`, `src/js/mic-check.js`, and `src/js/recorder.js`.
- Database schema evolution includes assessments, submissions, question banks, and evaluation intelligence in `server/migrations/001_initial_schema.sql`, `server/migrations/013_question_bank.sql`, and `server/migrations/014_evaluation_intelligence.sql`.

#### Trustworthy Evaluation Harness
- All AI scoring is orchestrated by `server/harness/harness.js` and `server/harness/pipeline.js`, rather than a direct evaluator path.
- The harness compiles rubrics, invokes plugins/evaluators, validates evidence, calculates reliability/risk, and records traceability through `server/harness/rubric-compiler.js`, `server/harness/evidence-validator.js`, and `server/harness/trace.js`.
- Verification and publication are distinct gates: failed results are withheld; review-required results require human approval. Related controls live in `server/harness/validator.js`, `server/evaluation/human-approval.js`, and `server/harness/reproducibility.js`.
- The provider boundary supports OpenRouter production calls and deterministic mock execution for CI/development: `server/ai/openrouter-provider.js`, `server/ai/mock-provider.js`.

#### Data, Observability, and Research
- SQLite access is centralized in `server/database.js`; local data is persisted under `data/`, with migrations in `server/migrations/`.
- AI telemetry, latency/token/cost semantics, and observability APIs are implemented in `server/ai/pricing.js`, `server/evaluation/trace-persister.js`, and `api/observability.js`.
- Research workflows compute AI-vs-human and experiment metrics through `server/evaluation/research.js`, `server/evaluation/metrics.js`, and `server/evaluation/benchmark/benchmark.js`; the UI is `src/js/research.js`.
- Benchmark inputs are file-based datasets, including `data/datasets/bench-mark-rater.json`.

#### Infrastructure and External Services
- OpenRouter is the external AI gateway, configured through environment variables and mediated by `server/openrouter.js`.
- Security and abuse controls are server-level middleware concerns: `server/rate-limit.js` and `server/security-headers.js`.
- Deployment configuration is `vercel.json`; frontend assets are built from `src/js/` into `public/`.

Main entry points: [`server/database.js`](https://github.com/hi-day/lisanai/blob/master/server/database.js) (SQLite persistence), [`src/js/app.js`](https://github.com/hi-day/lisanai/blob/master/src/js/app.js) (Application SPA), [`server/assessment-service.js`](https://github.com/hi-day/lisanai/blob/master/server/assessment-service.js) (Assessment service), [`api/assessment.js`](https://github.com/hi-day/lisanai/blob/master/api/assessment.js) (Assessment API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser SPA"]
  node_spa["Application SPA<br/>browser app<br/>[app.js]"]
  node_client_auth["Auth &amp; role UI<br/>client workflow<br/>[auth-ui.js]"]
  node_authoring_ui["Assessment authoring<br/>client workflow"]
  node_student_ui["Student response flow<br/>client workflow<br/>[student-flow.js]"]
  node_research_ui["Research dashboard<br/>client workflow<br/>[research.js]"]
end

subgraph group_api["Delivery &amp; API"]
  node_api_router{{"Vercel API router<br/>serverless entry<br/>[v1.js]"}}
  node_assessment_api["Assessment API<br/>API handler<br/>[assessment.js]"]
  node_observability_api["Observability API<br/>API handler<br/>[observability.js]"]
end

subgraph group_core["Core services"]
  node_auth_boundary{{"Auth &amp; tenancy boundary<br/>access control<br/>[api-auth.js]"}}
  node_api_keys["API key service<br/>access service<br/>[api-key-service.js]"]
  node_assessment_service["Assessment service<br/>domain service"]
  node_ai_provider["AI provider boundary<br/>provider abstraction<br/>[provider.js]"]
end

subgraph group_evaluation["Evaluation &amp; research"]
  node_harness_pipeline{{"Evaluation harness<br/>scoring pipeline<br/>[pipeline.js]"}}
  node_evidence_gate["Evidence &amp; validation<br/>verification gate"]
  node_approval_gate["Human approval<br/>publication gate<br/>[human-approval.js]"]
  node_trace_persister["Trace &amp; telemetry<br/>observability service<br/>[trace-persister.js]"]
  node_research_metrics["Research metrics<br/>analysis service<br/>[research.js]"]
end

subgraph group_data["Data &amp; external"]
  node_sqlite[("SQLite persistence<br/>database access<br/>[database.js]")]
  node_migrations["Schema migrations<br/>schema evolution"]
  node_benchmark_data["Benchmark dataset<br/>file dataset"]
  node_openrouter["OpenRouter gateway<br/>external AI<br/>[openrouter.js]"]
end

node_spa --> node_client_auth
node_spa --> node_authoring_ui
node_spa --> node_student_ui
node_spa --> node_research_ui
node_client_auth -->|"authenticated requests"| node_api_router
node_authoring_ui -->|"author assessments"| node_assessment_api
node_student_ui -->|"submit responses"| node_assessment_api
node_research_ui -->|"view metrics"| node_observability_api
node_api_router -->|"protect routes"| node_auth_boundary
node_auth_boundary -->|"authorized access"| node_assessment_api
node_auth_boundary -->|"public consumer access"| node_api_keys
node_assessment_api --> node_assessment_service
node_assessment_service -->|"assessments and submissions"| node_sqlite
node_assessment_service -->|"generate questions"| node_ai_provider
node_assessment_service -->|"evaluate submissions"| node_harness_pipeline
node_harness_pipeline -->|"verify evidence"| node_evidence_gate
node_evidence_gate -->|"review-required results"| node_approval_gate
node_evidence_gate -->|"record trace"| node_trace_persister
node_approval_gate -->|"publish outcome"| node_sqlite
node_trace_persister -->|"persist telemetry"| node_sqlite
node_observability_api -->|"query telemetry"| node_trace_persister
node_research_ui -->|"analyze studies"| node_research_metrics
node_research_metrics -->|"evaluation data"| node_sqlite
node_research_metrics -->|"benchmark inputs"| node_benchmark_data
node_ai_provider -->|"production inference"| node_openrouter
node_migrations -.->|"evolve schema"| node_sqlite

click node_spa "https://github.com/hi-day/lisanai/blob/master/src/js/app.js"
click node_client_auth "https://github.com/hi-day/lisanai/blob/master/src/js/auth-ui.js"
click node_authoring_ui "https://github.com/hi-day/lisanai/blob/master/src/js/assessment-wizard.js"
click node_student_ui "https://github.com/hi-day/lisanai/blob/master/src/js/student-flow.js"
click node_research_ui "https://github.com/hi-day/lisanai/blob/master/src/js/research.js"
click node_api_router "https://github.com/hi-day/lisanai/blob/master/api/v1.js"
click node_assessment_api "https://github.com/hi-day/lisanai/blob/master/api/assessment.js"
click node_observability_api "https://github.com/hi-day/lisanai/blob/master/api/observability.js"
click node_auth_boundary "https://github.com/hi-day/lisanai/blob/master/server/api-auth.js"
click node_api_keys "https://github.com/hi-day/lisanai/blob/master/server/api-key-service.js"
click node_assessment_service "https://github.com/hi-day/lisanai/blob/master/server/assessment-service.js"
click node_ai_provider "https://github.com/hi-day/lisanai/blob/master/server/ai/provider.js"
click node_harness_pipeline "https://github.com/hi-day/lisanai/blob/master/server/harness/pipeline.js"
click node_evidence_gate "https://github.com/hi-day/lisanai/blob/master/server/harness/evidence-validator.js"
click node_approval_gate "https://github.com/hi-day/lisanai/blob/master/server/evaluation/human-approval.js"
click node_trace_persister "https://github.com/hi-day/lisanai/blob/master/server/evaluation/trace-persister.js"
click node_research_metrics "https://github.com/hi-day/lisanai/blob/master/server/evaluation/research.js"
click node_sqlite "https://github.com/hi-day/lisanai/blob/master/server/database.js"
click node_migrations "https://github.com/hi-day/lisanai/blob/master/server/migrations/014_evaluation_intelligence.sql"
click node_benchmark_data "https://github.com/hi-day/lisanai/blob/master/data/datasets/bench-mark-rater.json"
click node_openrouter "https://github.com/hi-day/lisanai/blob/master/server/openrouter.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spa,node_client_auth,node_authoring_ui,node_student_ui,node_research_ui toneBlue
class node_api_router,node_assessment_api,node_observability_api toneAmber
class node_auth_boundary,node_api_keys,node_assessment_service,node_ai_provider toneMint
class node_harness_pipeline,node_evidence_gate,node_approval_gate,node_trace_persister,node_research_metrics toneRose
class node_sqlite,node_migrations,node_benchmark_data,node_openrouter toneIndigo
```

## Components

### Browser SPA

- [Application SPA](https://github.com/hi-day/lisanai/blob/master/src/js/app.js): browser app · `src/js/app.js`
- [Auth & role UI](https://github.com/hi-day/lisanai/blob/master/src/js/auth-ui.js): client workflow · `src/js/auth-ui.js`
- [Assessment authoring](https://github.com/hi-day/lisanai/blob/master/src/js/assessment-wizard.js): client workflow · `src/js/assessment-wizard.js`
- [Student response flow](https://github.com/hi-day/lisanai/blob/master/src/js/student-flow.js): client workflow · Includes microphone checks and recording. · `src/js/student-flow.js`
- [Research dashboard](https://github.com/hi-day/lisanai/blob/master/src/js/research.js): client workflow · `src/js/research.js`

### Delivery & API

- [Vercel API router](https://github.com/hi-day/lisanai/blob/master/api/v1.js): serverless entry · `api/v1.js`
- [Assessment API](https://github.com/hi-day/lisanai/blob/master/api/assessment.js): API handler · `api/assessment.js`
- [Observability API](https://github.com/hi-day/lisanai/blob/master/api/observability.js): API handler · `api/observability.js`

### Core services

- [Auth & tenancy boundary](https://github.com/hi-day/lisanai/blob/master/server/api-auth.js): access control · Enforces sessions, CSRF, roles, tenant and membership constraints. · `server/api-auth.js`
- [API key service](https://github.com/hi-day/lisanai/blob/master/server/api-key-service.js): access service · `server/api-key-service.js`
- [Assessment service](https://github.com/hi-day/lisanai/blob/master/server/assessment-service.js): domain service · `server/assessment-service.js`
- [AI provider boundary](https://github.com/hi-day/lisanai/blob/master/server/ai/provider.js): provider abstraction · Selects OpenRouter or deterministic mock execution. · `server/ai/provider.js`

### Evaluation & research

- [Evaluation harness](https://github.com/hi-day/lisanai/blob/master/server/harness/pipeline.js): scoring pipeline · Compiles rubrics, invokes evaluators, and produces traceable results. · `server/harness/pipeline.js`
- [Evidence & validation](https://github.com/hi-day/lisanai/blob/master/server/harness/evidence-validator.js): verification gate · Withholds failed evaluations before publication. · `server/harness/evidence-validator.js`
- [Human approval](https://github.com/hi-day/lisanai/blob/master/server/evaluation/human-approval.js): publication gate · Publishes review-required results only after approval. · `server/evaluation/human-approval.js`
- [Trace & telemetry](https://github.com/hi-day/lisanai/blob/master/server/evaluation/trace-persister.js): observability service · `server/evaluation/trace-persister.js`
- [Research metrics](https://github.com/hi-day/lisanai/blob/master/server/evaluation/research.js): analysis service · Computes AI-vs-human and experiment metrics. · `server/evaluation/research.js`

### Data & external

- [SQLite persistence](https://github.com/hi-day/lisanai/blob/master/server/database.js): database access · Stores tenant, assessment, submission, and evaluation data. · `server/database.js`
- [Schema migrations](https://github.com/hi-day/lisanai/blob/master/server/migrations/014_evaluation_intelligence.sql): schema evolution · `server/migrations/014_evaluation_intelligence.sql`
- [Benchmark dataset](https://github.com/hi-day/lisanai/blob/master/data/datasets/bench-mark-rater.json): file dataset · `data/datasets/bench-mark-rater.json`
- [OpenRouter gateway](https://github.com/hi-day/lisanai/blob/master/server/openrouter.js): external AI · `server/openrouter.js`

## Connections

- Application SPA → Auth & role UI
- Application SPA → Assessment authoring
- Application SPA → Student response flow
- Application SPA → Research dashboard
- Auth & role UI → Vercel API router: authenticated requests
- Assessment authoring → Assessment API: author assessments
- Student response flow → Assessment API: submit responses
- Research dashboard → Observability API: view metrics
- Vercel API router → Auth & tenancy boundary: protect routes
- Auth & tenancy boundary → Assessment API: authorized access
- Auth & tenancy boundary → API key service: public consumer access
- Assessment API → Assessment service
- Assessment service → SQLite persistence: assessments and submissions
- Assessment service → AI provider boundary: generate questions
- Assessment service → Evaluation harness: evaluate submissions
- Evaluation harness → Evidence & validation: verify evidence
- Evidence & validation → Human approval: review-required results
- Evidence & validation → Trace & telemetry: record trace
- Human approval → SQLite persistence: publish outcome
- Trace & telemetry → SQLite persistence: persist telemetry
- Observability API → Trace & telemetry: query telemetry
- Research dashboard → Research metrics: analyze studies
- Research metrics → SQLite persistence: evaluation data
- Research metrics → Benchmark dataset: benchmark inputs
- AI provider boundary → OpenRouter gateway: production inference
- Schema migrations → SQLite persistence: evolve schema
