CotaDocs

Host and contribute

Self-hosting

Cota has two parts:

PartFolderNeeded for
Web appservices/webEverything you draw. It is a static single-page app that runs in the browser
API server (optional)services/apiUser accounts, drawings stored in a database, DWG conversion, natural-language modeling

Without the server, Cota saves drawings as .cota files (download, or a folder on your disk). Pick the setup that fits you.

Option 1 — Static site, no server#

Build the web app with the server features turned off:

Terminal
cd services/web
npm ci
VITE_CLOUD=off npm run build

Upload services/web/dist/ to any static host (GitHub Pages, Netlify, Cloudflare Pages, an Nginx or Apache folder, an S3 bucket…). Serve index.html for unknown paths. Serve it over HTTPS (or from localhost): browsers only offer to install the app and enable offline use on secure origins. The build includes the web app manifest and a service worker (sw.js) that caches that version's files. It also includes this documentation as static pages under docs/ (built from the Markdown in the repository's docs/ folder); the DOCS command opens them. The Docker image below is built from services/web alone and has no copy of the docs: there, DOCS opens the published documentation instead.

If the site lives in a subfolder (for example https://user.github.io/cota/), set the base path when building:

Terminal
VITE_CLOUD=off COTA_BASE=/cota/ npm run build

GitHub Pages: the repository includes .github/workflows/pages.yml. In your fork go to Settings ▸ Pages, choose GitHub Actions as the source and push to main: the site is published at https://<user>.github.io/<repo>/.

Option 2 — Full stack with Docker#

Requires Docker with Compose. The stack runs the web app (Nginx), the API and PostgreSQL.

  1. Generate the secrets:

    Terminal
    openssl rand -hex 32        # use it as JWT_SECRET
    openssl rand -hex 16        # use it as POSTGRES_PASSWORD
    python3 -c "import base64,os;print(base64.urlsafe_b64encode(os.urandom(32)).decode())"   # SECRETS_ENCRYPTION_KEY
  2. Export them in your shell (or put them in a file that Docker Compose reads, outside version control):

    Terminal
    export JWT_SECRET=…  POSTGRES_PASSWORD=…  SECRETS_ENCRYPTION_KEY=…
  3. Start it:

    Terminal
    docker compose up -d --build

Open http://localhost:8080. Click Login to create an account. The API applies the database migrations every time it starts.

To serve it on a domain, put it behind a reverse proxy with HTTPS (Caddy, Traefik, Nginx…) and set APP_BASE_URL=https://cad.example.com and ALLOWED_HOSTS=cad.example.com. In production the session cookie is marked Secure, so the browser only sends it over HTTPS (or to localhost).

The bundled Nginx limits login and sign-up attempts per IP address, refuses to be embedded in other sites' frames and sends the usual security headers. For a server only your team uses, set ALLOW_REGISTRATION=false once your accounts exist.

Option 3 — Development#

With hot reload, SQLite and development defaults:

Terminal
docker compose -f docker-compose.dev.yml up --build

Web at http://localhost:5173, API at http://localhost:8000 (interactive docs at /docs). Both listen only on this machine: the development secrets are public, so do not expose these ports to a network.

Without Docker:

Terminal
# API (Python 3.12, using uv: https://docs.astral.sh/uv/)
cd services/api
uv venv --python 3.12 .venv
uv pip install --python .venv -e ".[dev]"
.venv/bin/uvicorn app.main:app --reload

# Web, in another terminal (Node.js 20+)
cd services/web
npm install
npm run dev

The web dev server proxies /api to http://localhost:8000.

DWG support#

Opening and saving DWG files does not need the server: the browser reads and writes them with acad-ts (MIT), loaded only when the first .dwg is used. The server is only a fallback for files the browser cannot read or write.

DWG is converted on the server with the dwg2dxf and dxf2dwg programs of GNU LibreDWG. They are not bundled with Cota: install them in the API machine or image (for example apt-get install libredwg-tools where available, or build LibreDWG from source). Cota runs them as separate programs. Without them, OPEN and EXPORT simply report that DWG is not available; DXF always works in the browser.

The converters parse files uploaded by your users. Cota runs them without the server's secrets in their environment, with CPU, memory and output-size limits and at most two at a time, but on a server open to the public consider running the API (or the whole converter) in a separate, unprivileged container.

Configuration reference#

API server#

All settings are read from environment variables (names are case-insensitive).

VariableDefaultDescription
COTA_ENVdevdev, qa or prod. Outside dev (or with a public APP_BASE_URL), the secrets below must be your own, the API docs are hidden and cookies are Secure. prod also requires PostgreSQL and ALLOWED_HOSTS
DATABASE_URLsqlite:///./data/cota.dbSQLAlchemy URL. postgres:// and postgresql:// URLs are accepted and use the bundled psycopg 3 driver
JWT_SECRETdevelopment valueSecret that signs the sessions. At least 32 characters outside dev
SECRETS_ENCRYPTION_KEYdevelopment valueFernet key that encrypts the users' LLM keys. Must be your own outside dev
JWT_EXPIRE_MINUTES30Session length (5–1440)
JWT_ALGORITHMHS256HS256, HS384 or HS512
JWT_ISSUER / JWT_AUDIENCEcota / cota-webToken issuer and audience
SESSION_COOKIE_NAMEcota_sessionName of the session cookie
APP_BASE_URLhttp://localhost:5173Public URL of the web app. A URL that is not localhost also enforces your own secrets
API_CORS_ORIGINShttp://localhost:5173Comma-separated origins allowed to call the API from another origin
ALLOWED_HOSTSlocalhost,127.0.0.1Comma-separated host names accepted in production (* is rejected)
ALLOW_REGISTRATIONtruefalse closes sign-up: only existing accounts can log in (a private server for your team)
MAX_DOCUMENT_BYTES5242880Largest drawing that can be stored (bytes)
MAX_UPLOAD_BYTES10485760Largest file accepted for conversion (bytes)
AI_ALLOWED_BASE_URLSemptyComma-separated HTTPS base URLs that users may set for OpenAI-compatible LLM providers. Empty: only the official OpenAI and Google endpoints. The agent's presets need their base: https://api.deepseek.com/v1 (DeepSeek), https://api.moonshot.ai/v1 (Kimi), https://api.z.ai/api/paas/v4 (GLM) and https://openrouter.ai/api/v1 (OpenRouter); see below
AGENT_RATE_PER_MINUTE30Agent model calls per user and clock minute in server mode; above it /agent/step answers 429 with X-Agent-Error: limit and Retry-After. 0 turns it off
AGENT_DAILY_TOKEN_BUDGET0 (off)Agent tokens (input + output) per user and UTC day in server mode; the call that crosses it finishes, the next ones wait until 00:00 UTC
AGENT_MAX_CONVERSATIONS200Agent conversations saved per user; saving one more answers 409 (updating an existing one always works)
DWG2DXF_CMD / DXF2DWG_CMDdwg2dxf / dxf2dwgLibreDWG programs used for DWG

To enable every preset of the agent panel:

Command line
AI_ALLOWED_BASE_URLS=https://api.deepseek.com/v1,https://api.moonshot.ai/v1,https://api.z.ai/api/paas/v4,https://openrouter.ai/api/v1

Anthropic, OpenAI and Gemini send no base (they use the SDK's). OpenAI-compatible sends the base the user types (for example https://api.z.ai/api/coding/paas/v4 for Z.ai's Coding Plan), which must be on the list too.

Run the migrations with alembic upgrade head before starting a prod server (the Docker stack does it for you). In dev, the API creates the tables itself.

The agent limits are counted in the database (table agent_usage, migration cota_004), so they hold with several API instances. The web container's nginx also limits /api/agent/ per IP address (60 requests per minute, bursts of 30; zone agent in services/web/nginx.conf) and answers the excess with the same 429 and X-Agent-Error: limit. Logs never include API keys or the content of the conversations.

Each agent step in server mode logs one line on the cota.agent logger, whether it succeeds or not: agent_step user_id=… provider=… model=… latency_ms=… input_tokens=… output_tokens=… outcome=…. outcome is ok or the kind of failure (auth, limit with limit=rate|budget, quota, context_overflow, network, provider); ok, limit and auth are INFO, provider failures WARNING. The same fields are in the record's agent_step attribute for a JSON formatter. The line never carries the conversation, the tool calls, the answer, the API key or the base URL. GET /agent/usage returns the signed-in user's steps and tokens today and in the last 30 days (UTC, today included) with rate_per_minute and daily_token_budget (0 = no limit); the agent settings show it. It needs no new migration.

Web app#

These are read when building or running the dev server.

VariableDefaultDescription
VITE_CLOUDonoff hides login and cloud storage and builds a server-less app
COTA_BASE/Base path when the app is served from a subfolder
API_PROXY_TARGEThttp://localhost:8000Where the dev server proxies /api
VITE_API_BASE_URL/apiAbsolute API URL, only if the API is on another origin (requires CORS)

Backups#

Everything a user saves to the server is in the database: back up the PostgreSQL volume (db_data), for example with docker compose exec db pg_dump -U cota cota > cota.sql. Drawings saved as files are already on the users' disks.

Visit statistics (optional)#

Builds send no statistics unless you configure them at build time. Cota supports Umami, an open-source, cookieless analytics service (Umami Cloud has a free plan, or you can host Umami yourself):

VariableValue
VITE_ANALYTICS_UMAMIThe website id from Umami (a UUID)
VITE_ANALYTICS_UMAMI_HOSTOptional: your Umami server, e.g. https://stats.example.com (default: Umami Cloud)

No third-party script is loaded: Cota sends one request when the page opens and one when the visitor leaves (so Umami can measure how long the visit lasted). Drawings, commands and anything typed are never sent, and visitors with "Do Not Track" are not counted. On GitHub Pages, set the repository variables ANALYTICS_UMAMI (and optionally ANALYTICS_UMAMI_HOST) in Settings ▸ Secrets and variables ▸ Actions ▸ Variables; the Pages workflow passes them to the build.