Separate stacks, one set of rules.
Every product is a self-hosted Docker Compose stack: an nginx front door, a FastAPI service, PostgreSQL for every record and Redis for everything that may be lost. Only the proxy is published. Every AI call goes through one server-side gateway.
Decisions both products make the same way.
One origin
The compiled React app and the API are served from the same origin behind nginx, so session cookies stay same-site and no cross-origin access is needed.
PostgreSQL holds the truth
Every business record lives in PostgreSQL, and Alembic owns the schema: the application never creates tables behind its back. Redis holds sessions, rate-limit counters, caches and queues only.
Protected by construction
Every router except sign-in is mounted behind a session check, so a new route cannot be added unauthenticated. Tests walk the whole route table to prove it.
Blocking work off the event loop
Route handlers are synchronous and run in a thread pool; long jobs in cognita dev run in a separate Celery worker with progress streamed back.
Secrets as files
Keys are mounted as Docker secrets, never baked into images. cognita dev refuses to start in production with a missing secret or an unsafe setting.
Evidence by design
Exports carry hashes, uploads are typed by their content and stored under generated names, and downloads go through an authenticated route only.
Internal networks per role, one way in, one way out.
nginx is the only container with a published port: /api goes to the API, and /repository/, /v2/ (container images) and /service/rest/ to the artifact repository. Everything else sits on internal networks. Nothing reaches the internet directly: the worker, the repository, virus signature updates and sign-in each go out through one squid proxy on a network of their own, with an allowlist per service. A one-shot migrate service applies database changes, so the running API holds no owner password.
A request, step by step
- nginx terminates TLS, adds the security headers and a per-response CSP nonce, and forwards
/api, unbuffered for progress streams. - Middleware records metrics, adds a request ID, checks the CSRF header and origin, and applies rate limits.
- The protected router checks the session cookie against Redis; a Redis failure is a 503, never a pass.
- The endpoint checks its named permission, then whether the project is in the caller's scope.
- The service writes to PostgreSQL with the audit event in the same transaction. If the audit write fails, the change rolls back.
What runs in the background
- AI generation, reviews and rewrites, with progress over server-sent events
- Word, PDF and PowerPoint exports, rendered in the worker and stored with their hash
- Upload scanning and retries every 30 minutes when ClamAV is enabled
- Evidence pack builds with a verifiable manifest
- Audit chain verification every night at 02:00 UTC
- Provider status checks every 5 minutes, shown in the admin console
- Artifact repository: CISA KEV refresh, health check of what the proxies cache, release expiry; cleanup to the trash, blob compaction and container image scans with Trivy in
registry-jobs
A compact stack that degrades instead of failing.
In production, nginx serves the compiled app and proxies /api to FastAPI on the same origin. The API, PostgreSQL and Redis stay on the internal network. If Redis goes down, sessions survive and rate limiting falls back to in-process counting.
Each layer refuses on its own, so one miss is not a breach.
The controls below are built into both products and covered by tests that run on every merge. The security page has the detail, and how both products were tested and fixed.
| Layer | Controls |
|---|---|
| Edge | One published port; TLS 1.2+ and HSTS; content security policy (a per-response nonce in cognita dev), frame denial, nosniff and a strict referrer policy. |
| Identity | Cookie-only sessions that a server-side store can revoke; TOTP multi-factor sign-in; lockout and indistinguishable failures; LDAP, SAML and OpenID Connect with signature, audience and replay checks; break-glass for administrators. |
| Authorization | Every route checks a named permission (cognita dev) or view and edit per module (cognita grc); a test walks every route and fails the build if one has no check. |
| Requests | A custom header and matching origin on state-changing calls, rate limits by address, user and route, and generic errors with a request ID instead of internals. |
| Data | PostgreSQL holds every record; the audit event is written in the same transaction as the change (hash-chained in cognita dev); Redis holds no records. |
| Files | Typed by content, archive size and ratio caps, generated names, a SHA-256 per file, optional ClamAV scanning, and formula escaping in every spreadsheet export. |
| Network | Internal networks for the API and the data; outbound traffic only to allowlisted hosts (squid with a list per service in cognita dev; the enabled AI provider, sign-in providers and the vulnerability feeds in cognita grc). |
| Containers | Non-root; in cognita dev also read-only root filesystems, all capabilities dropped, no-new-privileges and images pinned by digest. |
| Secrets | Docker secret files; provider keys and identity-provider secrets encrypted at rest and never shown again; logs pass a redaction filter. |
| AI | One gateway, the platform-wide switch checked first, an allowlist of models, sanitised prompts, and provenance for every call. |
| Operations | Liveness and readiness endpoints, request IDs on every log line, encrypted backups with a restore drill or check. |
Every model call takes the same path, and can be stopped at one point.
In cognita dev, provider SDKs may be imported only inside one module, and CI fails the build if anything else tries. The API process never calls a model; the worker does.
- Checked. The job endpoint verifies the model key against the allowlist, the caller's role, the project's data classification, the emergency stop and the budgets. A refusal is audited and no provider is called.
- Queued. The job goes to the Celery worker; the browser follows its progress over server-sent events and can cancel it.
- Called. The gateway calls Claude or Gemini through the egress proxy, or vLLM on the internal network, with reference files passed as delimited data and no tools.
- Validated. Output is checked against the task's schema and retried once before failing with a clear message.
- Recorded. Model, prompt version, input hashes, tokens, cost and latency are stored with the job and in the audit log.
- Proposed. The result lands as a new draft version labelled AI-generated, and stays labelled until a person edits it.
cognita grc applies the same idea in one service: every AI request checks the database-held switch first (cached for 60 seconds, failing closed), then calls Gemini, Claude or a local Ollama model and validates the JSON it gets back.
A console that configures, a gateway that forwards, and keys neither can misuse.
cognita api is its own installation with two processes that trust each other as little as possible. The console stores configuration and shows the logs; the gateway carries the traffic. Each has its own database role, its own network and only the keys its job needs.
- Credentials sealed one wayThe console encrypts a vendor credential with the gateway's public key. Only the gateway process holds the private key, so the console that stores a credential cannot read it back.
- Payloads sealed the other wayKept payloads are encrypted by the gateway with the console's key, and opening one in the console needs a fresh authenticator code.
- A database role per processThe gateway role reads configuration and writes call rows; it cannot change configuration. The jobs role has only what retention, alerts and the export need.
- Logged before forwardedThe call row is written first. If the database cannot take it, the call is refused rather than sent unrecorded.
- Configuration by versionWorkers poll a version number and reload within seconds; a revoked key stops working without a restart.
- Two people for an internal addressMarking a service internal, which exempts it from the egress rules for private ranges, needs a second person to confirm its address.
Two origins: the application, and the course content kept away from it.
cognita lms is its own installation. Its nginx front end publishes two ports: one for the application and one for course packages, so a SCORM or cmi5 package runs on a separate origin with no session and cannot reach the application's pages or cookies. It shares no database with cognita grc; the organisation chart moves between them as a file.
| Piece | What it does |
|---|---|
| frontend (nginx, unprivileged) | The compiled React app on one port, course content on a second |
| backend | FastAPI on Python 3.13: courses, assignments, records, the course builder and its marking, and PowerPoint conversion with LibreOffice |
| content | The same image serving course packages to the content origin only |
| worker | A pass every quarter of an hour: assignments brought up to date, e-mail reminders and the managers' weekly digest |
| Data | PostgreSQL 17 for every record; Redis 7 |
| Optional | ClamAV upload scanning; an AI assistant that calls Gemini, off until an administrator switches it on and adds a key |
Outputs people already use, made safely.
Word, PDF, PowerPoint, Excel
cognita dev renders Word with python-docx and converts it to PDF with LibreOffice, builds decks with python-pptx, and stamps every page with the version hash. cognita grc builds PDFs with ReportLab and jsPDF, Excel with openpyxl and Word with python-docx.
Typed by content, not by name
File types are detected from their leading bytes, archives are read entry by entry with size, ratio and count limits, and files are stored under generated names outside any web-served path.
No formula injection
Every exported cell passes one escaping function, so text starting with =, +, - or @ can never run as a formula when someone opens the file.
Run on the analyst's machine, not on the platform.
cognita probe, cognita audit and cognita cap are Claude Code skills. Each is a set of instructions, a standard-library command-line tool that enforces its rules, and a locked-down container. They need nothing installed on the platforms and hand their results over as files.
One host, Docker Compose, your network.
Each product ships as a Compose file. Bring a Linux host with Docker, point DNS at it, add a certificate, and start the stack.
| cognita dev | cognita grc | |
|---|---|---|
| Services | proxy, migrate (one-shot), api, registry, worker, scheduler, registry-jobs, egress, PostgreSQL 16, Redis 7 | frontend (nginx), backend, PostgreSQL 15, Redis 7 |
| Optional profiles | ClamAV upload scanning, vLLM on a GPU host, LDAP relay for directory sign-in, backup service; a CA bundle overlay and a corporate parent proxy | ClamAV upload scanning, built-in HTTPS on the frontend; an Ollama host you run, reached by its address |
| Published ports | 443 and 80 on the proxy only | The nginx port only |
| First start | make up generates secrets and a certificate; make admin creates the first administrator | docker compose -f docker-compose.prod.yml up -d --build, then create the first administrator |
| Production guard rails | ENV=production refuses missing secrets, a non-HTTPS origin or test switches | Secure cookies and HSTS switched on together once served over HTTPS |
| Backups | Encrypted database and file backups, hourly WAL archiving, restore drill in CI | Nightly pg_dump snapshots with a verified manifest, an encrypted off-host copy and a restore check; export and import between environments |
| Migrations | Alembic in a one-shot migrate service, with grants for the application role in every migration | Alembic, applied once at start in production |
Two application nodes, two database nodes, one floating IP.
A single host is enough for a department. When the platform becomes the system of record for several teams, this is the layout we recommend on VMware for up to a few hundred users: four virtual machines and an optional GPU host at the main site, one standby at the recovery site. Nothing here needs Kubernetes.
| If this fails | What happens |
|---|---|
| One application node, or its upgrade | The floating IP moves to the other node in about a second. Rolling upgrades take one node out at a time, with no downtime. |
| The primary database | Patroni promotes the synchronous standby in about 30 seconds. No committed transaction is lost. |
| A physical host | vSphere HA restarts its virtual machines on another host within minutes; the pairs are on different hosts, so the service does not wait for it. |
| The GPU host | AI features degrade. Tasks that may only use the on-premises model fail closed; everything else keeps working. |
| The whole site | The recovery site takes over: RPO within 15 minutes, RTO 4 hours. |
Why four machines and not more
At this scale one application node and one database carry the load comfortably. The second application node exists for upgrades without downtime and a one-second failover. The second database node exists so that no committed write is lost. Further nodes add maintenance, not availability.
- Application nodes: 4 vCPU and 16 GB each, running the same Compose stack as a single host
- Database nodes: 4 vCPU and 32 GB each, PostgreSQL under Patroni with etcd for leader election
- Redis primary and replica on the application nodes; losing Redis costs sessions, never records
- Files on an existing NAS with snapshots, mounted by both application nodes
- Outbound AI calls through the egress proxy you already run, allowlisted to the enabled provider hosts
- Recovery site: one standby database receiving streaming replication, application nodes replicated by vSphere, a NAS replica
This is a reference design for your infrastructure team, not a product feature: Patroni, etcd and keepalived are installed and operated by you. The single-host layout above stays the default.
The same stack, pinned to exact versions.
| Layer | cognita dev | cognita grc |
|---|---|---|
| Language | Python 3.12, TypeScript 5.9 | Python 3.13, TypeScript 5.9 |
| API | FastAPI 0.141, Pydantic 2.13, gunicorn + uvicorn | FastAPI 0.141, Pydantic 2.14, uvicorn |
| Data | SQLAlchemy 2.0, Alembic 1.13, PostgreSQL 16, Redis 7 | SQLAlchemy 2.0, Alembic 1.13, PostgreSQL 15, Redis 7 |
| Background work | Celery 5.4 worker and beat | FastAPI background tasks, host scheduler for backups |
| Security libraries | argon2-cffi, PyJWT, slowapi, structlog, ldap3, signxml | bcrypt, PyJWT, cryptography, slowapi, defusedxml, ldap3, signxml |
| AI | anthropic, google-genai, OpenAI-compatible client for vLLM | anthropic, google-genai, Ollama over its HTTP API |
| Documents | python-docx, python-pptx, openpyxl, LibreOffice, Graphviz | ReportLab, python-docx, openpyxl, pypdf, pdfplumber, jsPDF |
| Frontend | React 19, Vite 7, MUI 7, React Router 7, TanStack Query, TipTap, React Flow | React 19, Vite 7, MUI 7 and MUI X DataGrid, React Router 7, Mermaid |
| Tests | pytest against PostgreSQL, Vitest, Playwright, axe | pytest with SQLite and an in-process Redis; migrations checked on PostgreSQL 15 in CI; a route walk that fails any route without an access check |
Walk your security architects through it.
We can run a technical session on the network layout, the AI gateway and the evidence model with your architecture and security teams.