Live: https://dz-legal-assistant-ai.onrender.com
The product is an offline desktop app: the lawyer’s case data never leaves the computer (OFFLINE.md). The web demo exists so that anyone, a judge of a competition for example, can use the real product from a link without installing anything. It runs the same engine, the same law library and the same screen logic. The one difference is where the AI model runs:
| Desktop app | Web demo | |
|---|---|---|
| Form, formal check, legal points, templates, PDF/Word | on the laptop | on the demo server |
| Model for the analysis and the drafting | Gemma 3 4B, local (Ollama); about 2 minutes per draft on a laptop CPU | Nemotron 3 Ultra hosted on OpenRouter first (much larger than the desktop’s model, said on the page), then Gemma 4 26B on Google AI Studio, then Groq |
| Case data | never leaves the computer | sent to the hosted model: fictitious cases only |
| Screen logic (view models, strings) | DzLegal.Presentation |
DzLegal.Presentation (the same code) |
The app bar says “Demo · fictitious cases only”, and the details under the disclosure line explain that the product runs the model offline.
The website at the same address
The public website (site/, Astro, static HTML) is served by the same app, so one address carries both: the site at
/ar/ and /en/ (Arabic first, the product’s language), with its guide, download, law library, privacy and about pages
(/<lang>/try/, /download/, /law/, /privacy/, /about/), and the demo at /app. The guide (“Test it in 5 minutes”) and
the demo’s own guide take the same five steps with the same button names: the website reads them from
Strings.resx, WebText.cs and the sample files at build time. The demo’s guide shows one step at a time: a gold ring
marks the field or button to use next, the gold-bordered card stands beside it (in the middle when there is nothing to
point at, at the bottom on a phone), and both pulse a few times at each new step. It never presses anything; it moves
on once the step is done, and Next stays locked until then (a step done before can be passed again); when the model
fails, it says so and asks to try again
(Home.Guide.cs, reading the view model’s state). /app?guide=1 opens it, as the try page’s button does; its step is
remembered for the visit. Nothing is loaded from another origin,
the page’s Content Security Policy stays as strict as the demo’s (no inline scripts), and the fonts and icons are the
desktop’s own, bundled with their licences.
- Language: a remembered choice (
/lang/{code}sets the first-party cookiedzlegal.langand comes back), then?lang=, then the browser (an Arabic browser gets Arabic, every other one English)./appfollows the same rule, so the page is already in the right language and direction before the circuit connects. - Theme: dark unless the visitor chose light (cookie
dzlegal.theme, shared by the site and the demo). The browser’s own dark preference is not consulted. - Design tokens:
site/scripts/tokens.mjsgeneratessite/src/styles/tokens.cssandsrc/DzLegal.Web/wwwroot/tokens.cssfrom the desktop theme (App.axaml,Styles/Workbench.axaml); the build fails when they are stale, so the website never drifts from the product. /: the home page in the visitor’s language (thedzlegal.langcookie, then the browser’s Accept-Language, then English), served at the address itself, no redirect; the demo lives at/app. The switch isSite:ServeRootinappsettings.json: set it tofalseand the demo answers at/again (rewritten internally to/app), which is also what happens when the site folder is missing from the image. Unknown paths get the site’s own not-found page.- Compression: the site leaves the server compressed (Brotli, else gzip: the Arabic home is 22 KB instead of 104 KB), as the host already does in front of it, so a local Lighthouse run sees what a visitor gets. Only the site is compressed; the demo page carries the antiforgery token, which compressing would expose (BREACH), and is left as it is, like the circuit. Fonts and images are compressed formats already.
- Documentation pages: six documents of
docs/(PRODUCT-DETAILS,ARCHITECTURE,OFFLINE,LAW-LIBRARY,HIDDEN-SET,WEB-DEMO) are rendered as pages at/<lang>/docs/<name>/from the Markdown at build time (site/src/content.config.tsreads them from../docs;site/src/content/docs-pages.tsadapts their links: a sibling of the six goes to its page, any other file of the repository to GitHub). They are English on both pages, the Arabic page says so in one line. The Dockerfile copies exactly these files and the pictures they embed (.dockerignorelets them through). Astro caches the rendered documents insite/node_modules/.astro/: after a change to the plugin, delete that folder beforenpm run build, or the old HTML is reused. - Pictures:
site/src/assets/shots/holds the PNG crops the pages show (the build makes WebP renditions).node scripts/crops.mjs --desktop <folder>cuts the desktop app’s frames (rendered by the headless UI tests withDZLEGAL_SCREENSHOTS) and the live recording’s frames;node tests/guide-shots.mjs --base <instance>captures the five steps of the guide from the demo, and its AI steps must run against an instance with real keys, never the stand-in model, since those pictures show model output. - Build: the
Dockerfilebuilds the site in a Node stage (npm ci --omit=dev && npm run build, about two minutes) and copiessite/distnext to the app; the app finds it at<base>/site(settingSite:Root). Without the folder the app behaves exactly as before. - Local run with the site:
cd site && npm ci && npm run build, thendotnet run --project src/DzLegal.Web --launch-profile http+site(setsSite__Root=../../site/dist). - Checks, run locally (GitHub Actions are off):
npm test(Playwright: the routes, the switch, the headers, the demo shell; axe on every page;tests/guide.spec.tsfollows the five-step guide in the demo against an instance whose AI is the local stand-intests/mock-model.mjs, started as its header says, withGUIDE_BASE_URLset),npm run shots -- --out ../docs/website/<phase>,npm run lighthouse -- --out ../docs/website/<phase>,npm run budget(what each page loads and the Lighthouse scores againstsite/budget.json) andnpm run links(a private window opens every page and follows every link). Each phase’s reports live indocs/website/.
How it is built
Browser ──SignalR──► DzLegal.Web (ASP.NET Core, Blazor Server, one instance)
├─ one MainWindowViewModel per visitor (DzLegal.Presentation, shared with the desktop)
├─ FormEngine · Law (official texts) · Drafting · Documents (QuestPDF) · Storage
└─ every model call goes through ProtectedModelProvider:
per-visitor and per-network hourly limits (charged per call)
→ the shared queue (ModelGate, 2 calls at a time)
→ the engine chain (FallbackModelProvider, one set of engines for everyone):
Nemotron 3 Ultra on OpenRouter (when OPENROUTER_API_KEY is set; reasoning switched off)
→ Gemma 4 on Google AI Studio (when GOOGLE_API_KEY is set; models Google still serves, 26B first)
→ Groq (optional)
Nemotron 3 Ultra answers first because, on 31 October 2026, it matched or beat Gemma 4 26B on every test set, faster and with no failed call, while Google returned “internal error” on up to a third of its calls. (Before that, Gemma 4 26B led the chain: in the October audit OpenRouter’s Gemma 3 4B left every argued paragraph of the live sample blank.) The page says the demo runs a larger hosted model than the desktop, lists the services the form may be sent to (Google, OpenRouter, Groq), and shows under the draft which engine answered. Each switch down the chain is logged:
Engine … skipped (…); the next engine in the chain answers instead.The visitor’s case is kept in the browser as a recovery copy for at most a day; «امسح نسخة المتصفح» deletes it and stops keeping one.
- Failures never end a visitor’s session.
- A dropped connection, an unreadable event, or an answer silent for 45 seconds becomes a model error.
- A service that is busy, refuses the key or has no credit left (401/402/403/404/429/5xx, or an error inside the stream) hands the request to the next engine, as long as it has not written anything yet.
- The visitor sees a plain message; the service’s raw error goes to the server log only.
- AI buttons run one task at a time per visitor. Closing the tab cancels running work.
- The case is kept in the visitor’s browser (
localStorage) every few seconds. After a server restart (the free plan sleeps after 15 minutes) or a closed tab, the page offers to restore it. Nothing is stored on the server. - The official law texts (
data/law/codes) and the PDFs they come from (docs/official-law-texts, served at/law-sources/…) ship with the image. Every article card links to its page. - Security headers: a Content Security Policy with no inline scripts and no framing,
nosniff, and no referrer. /healthzsays only whether the server is up and whether AI is configured. The engines in use are logged at start-up.
Run it locally
# Without any key: everything works except the AI steps, which use fill-in templates.
dotnet run --project src/DzLegal.Web # http://localhost:5080
# With the hosted model:
OPENROUTER_API_KEY=... dotnet run --project src/DzLegal.Web
PowerShell: $env:OPENROUTER_API_KEY = "..." in the window that runs dotnet run.
To try the AI flow without any key, point the Groq slot at any OpenAI-compatible server, for example a local mock:
GROQ_API_KEY=x Engines__GroqEndpoint=http://127.0.0.1:5090/v1/ Engines__GroqModel=mock dotnet run --project src/DzLegal.Web.
Settings (src/DzLegal.Web/appsettings.json, section Engines; any of them can be overridden by an environment variable such as Engines__MaxConcurrentCalls=3):
| Setting | Default | Meaning |
|---|---|---|
Order |
openrouter, google, groq | which service is tried first; a service without a key is skipped |
OpenRouterModel |
nvidia/nemotron-3-ultra-550b-a55b |
the online model chosen on 31 Oct 2026; reasoning is switched off for Nemotron ids |
GoogleModels |
Gemma 4 26B A4B, Gemma 4 31B, then Gemma 3 | tried in order; models Google no longer serves are dropped at start-up |
MaxConcurrentCalls |
2 | model calls running at once, all visitors together |
CallsPerSessionPerHour |
60 | model calls per browser session per hour (a full run is about six) |
CallsPerAddressPerHour |
150 | model calls per hour for all sessions from one network address |
MaxTokens, Temperature |
1000, 0.2 | same as the desktop defaults |
Keys come only from environment variables (OPENROUTER_API_KEY, GOOGLE_API_KEY, GROQ_API_KEY), set in the host’s secret settings. They never go into appsettings.json, a commit, a chat or a screenshot.
Deploy it (Render)
The repository root has a Dockerfile (ready-to-run build, workstation GC for a 512 MB instance) and a render.yaml blueprint.
- On render.com: New → Web Service, connect the repository, language Docker, region Frankfurt.
- Environment variables:
PORT=7860,OPENROUTER_API_KEY, optionallyGOOGLE_API_KEY. Health check path:/healthz. - Every push to the deployed branch redeploys.
The free plan sleeps after 15 minutes without visitors and takes about a minute to wake. For judging week, switch the service to the smallest paid plan (always on, five times the CPU), then back.
OpenRouter:
- Add a few dollars of credit and set a credit limit on the key.
- Use the paid
nvidia/nemotron-3-ultra-550b-a55brather than the:freevariant. Free variants are capped at about 50 requests a day for accounts that never bought $10 of credit. - When the credit runs out, the demo falls back to Google’s free Gemma 4.
Other hosts (Google Cloud Run: deploy/cloud-run.sh and .ps1; a paid Hugging Face Space: the deploy-web-demo workflow) run the same image.
Visit counting (anonymous)
The server can count visits to the website and steps in the demo, to see when and how the site is used. It is off until
a database is configured, and the privacy page says what is counted (privacy.site.5 and privacy.demo.6 in
site/src/i18n/site.*.json).
What is recorded, one row per event (src/DzLegal.Web/Services/Visits.cs):
| Event | Kept |
|---|---|
A page viewed (page) |
time, page path without its query, language, the referring site’s host only, and the browser’s Sec-Fetch-Site (an arrival from another site, a typed address, or a click inside the site) |
| In the demo | a sample opened (sample, its id), a guide step reached (guide, 1 to 5, then finished), an AI call admitted (ai, its kind: grounds.reading for an analysis, grounds-argued for a draft), an export (export, pdf or word, refused when the review blocked it) |
What is never recorded: the IP address, the browser string (read only to leave out bots), cookies or any other
identifier, and anything typed. VisitEvent has no field for them, and a test fails if one is added. Not counted at all:
our uptime checks, bots, link previews, headless test browsers, prefetches, assets, /healthz and /stats.
Setting it up on Render (the host restarts often and its disk is wiped, so the counts need a database):
- New → PostgreSQL, plan Free, region Frankfurt (the web service’s). Render’s free databases expire after a limited time (30 days when this was written): enough for an evaluation period, then delete it or move to a paid plan.
- In the web service’s Environment:
DATABASE_URL= the database’s Internal Database URL, andSTATS_TOKEN= a long random password (for example the output ofopenssl rand -base64 24). Neither goes in the repository. - Save: the service redeploys, creates its table and logs «Visit counting: the database is ready.»
Reading it: open /stats (the browser asks for a user name, any, and the password: STATS_TOKEN). It shows the totals,
a table by day, the referring sites of arrivals, the pages, and the demo’s steps, in Algeria time; ?days=30 widens it (at
most 60). /stats.csv downloads every event. Without STATS_TOKEN both addresses answer 404.
The owner’s own visits are left out. Opening /stats or /stats.csv with the password marks that browser with a
cookie (dzlegal.owner, HttpOnly, a year): from then on, nothing it does on the site or in the demo is counted. Its value
is derived from STATS_TOKEN (it neither reveals nor stands for it), so a new token unmarks every browser. Open /stats
once on each browser or phone you use. A visitor never receives this cookie, so the privacy page’s list of cookies stays
true for them.
If the database fails, pages are served as usual: counting happens after the page is sent, the events wait in a
bounded queue, and a failed write is dropped with one warning a minute in the server log. Locally, Visits:Store=memory
counts in memory without a database.
No wake-up wait: the options (checked 20 Oct 2026)
Vercel cannot run this demo as it is built. The demo is Blazor Server: one long-running .NET process keeps each visitor’s screen state in memory and talks to the browser over a WebSocket (SignalR). Vercel runs static files and short functions (Node.js, Python), not a .NET process or a Docker image, and a function, WebSocket or not, ends after at most 300 s on the free plan, which would cut every visitor’s session. Moving to Vercel means rewriting the page as Blazor WebAssembly with the model calls behind a separate function, and the PDF engine (QuestPDF, native code) does not run in the browser, so preview and PDF export would need a server again. Not before 31 October.
What works with the current image, cheapest first:
| Option | Cost | Wake-up wait | Effort |
|---|---|---|---|
Render free + an external monitor pinging /healthz every 5 minutes (e.g. UptimeRobot’s free plan) |
free | none while the pings run | 5 minutes, no code |
| Render Starter plan | about $7 a month | none | one click in the dashboard |
| Fly.io, one shared-CPU 512 MB machine left running | about $3–4 a month | none | a fly.toml and fly deploy |
Google Cloud Run, MIN_INSTANCES=1 ./deploy/cloud-run.sh |
a few dollars a month | none | the script exists |
Notes on the free option: Render counts any inbound HTTP request as activity, so a ping every 5 minutes keeps the 15-minute idle timer from running out. One service running all month uses about 744 of the workspace’s 750 free hours, so it only fits if no other free Render service runs in the same workspace. Don’t use a GitHub workflow for the pings: this repository is private, and a run every 10 minutes would take more than its 2,000 free Actions minutes a month.
Setting up the free keep-awake ping (UptimeRobot)
- Create a free account on uptimerobot.com.
- New monitor → type HTTP(s), URL
https://dz-legal-assistant-ai.onrender.com/healthz, interval 5 minutes (the free plan’s shortest)./healthzanswers GET and HEAD, so either method the monitor uses works. - Optional: as alert contact, your e-mail; the monitor then also tells you when the demo is down.
- Check that it works:
powershell -ExecutionPolicy Bypass -File tools\web\Watch-DemoAwake.ps1visits the demo every 20 minutes for 3 hours (longer than Render’s 15 idle minutes, so the script alone cannot keep it awake) and reports whether the server’s start time (startedin/healthz) ever changed. A redeploy also changes it once.
Uptime
The web-demo-uptime workflow checks DEMO_URL/healthz and the page every 30 minutes. It needs the repository variable
DEMO_URL, and GitHub runs scheduled workflows only on the default branch. A failed check sends GitHub’s usual failure
e-mail.
Limits, stated plainly
- AI quality: the desktop’s Gemma 3 4B is a small model, and even the demo’s larger one makes mistakes. That is why the checks matter:
- the articles a claim type requires are always proposed;
- the program writes each ticked article’s rule from the catalog’s one-line wording, one paragraph per part of the claim; the AI only writes how the facts meet it, and an application that cites or quotes an article is rejected;
- a paragraph that keeps attributing wrong content to an article is removed, and the lawyer sees what was removed;
- the legal points flag a wrong basis, interest on a private loan, damages without formal notice, and an article from an unrelated area of law;
- export is refused while the notes contain text addressed to an AI, a request line not in Arabic, or a prison sentence asked in a civil case.
- Law texts: 1,361 articles are loaded: the complete Family Code and the complete CPCA (with the 2022 amendment applied), and the articles of the Civil, Commercial and Labour texts that the claim types rely on (LAW-LIBRARY.md). Each was checked against its official source by a build script or read against the Journal Officiel page; that is not a lawyer’s review. None is yet marked “checked by a lawyer”; that review is under way.
- Speed depends on the hosted service and on Render’s small CPU. The status bar shows the queue when visitors wait.
- The demo saves nothing on the server: Open and Save read and write a draft file (
.dzdraft.json) on the visitor’s own disk, and the case is otherwise kept only as a recovery copy in the browser.