comfyauthEXPLAINED
THE VISUAL GUIDE · PAGE 3 OF 3

A place for every app.
A reason for every file.

See how projects stay separate, how the dashboard checks access, and what we keep in the database.

A

Your workspace contains projects. Projects contain users.

A developer account is separate from every app’s users.
YOU · DEVELOPER ACCOUNT

Your ComfyAuth workspace

Ownership records connect your account to the projects you create.

↓ One developer can own many projects
EXAMPLE PROJECT A

Your shop

Its own users, password records, sessions, keys, and settings.

EXAMPLE PROJECT B

Your other app

A separate set of users, password records, sessions, keys, and settings.

Illustrative projects, not live customer data. The same email can belong to both apps as two separate accounts. A project ID identifies the app; it does not prove ownership.

B

Every project action goes through an ownership check.

“Am I signed in, and is this project mine?”
  1. Developer clicks

    Create a project, change a setting, view users, or manage a key.

  2. Check the session

    Read the protected cookie. For changes, require the exact trusted website origin.

  3. Check the owner

    Look up the project’s owner. For changes, recheck the developer session inside the transaction.

  4. Do the operation

    Only then read or change the project’s records. Record supported changes in the activity log.

Another developer’s project is returned as “not found.” Creating a project and saving its owner happen together: both succeed, or neither does.

What can I do in the portal?

Projects

Create projects. Edit names, verification/reset page URLs, exact allowed browser origins, and renewal time limits. Up to 100 projects per developer.

Users

Search users. Disable or enable an account. Revoke sessions. Disabling also cancels active sessions and email action links. Enabling does not verify an email.

Keys + activity

Create server keys, shown once; store only their hashes. Revoke a key to stop its use. Create up to 20 active keys per project. All active keys and 80 recent revoked keys stay visible. View the latest 100 activity events.

Developer account controls also list/revoke sessions, change password, and log out everywhere. Activity records are retained for 90 days. Team roles and project deletion are not implemented.

C

The database is just labelled drawers.

Each drawer has one clear responsibility.
projectsOne record per application: ID, name, URLs, allowed origins and session time limits.
↓ Related records carry the project ID
WHO BELONGS WHERE

People & ownership

project_owners
Which developer owns a project.
users
ID, email, optional name, verified/disabled state.
password_credentials
The user’s password hash.
WHO MAY ENTER

Passes & proofs

sessions
One stable record per login/device, with the current pass hash, time limits and revocation.
refresh_tokens
Current and spent renewal-token hashes. Reusing a spent token ends that session.
verification_tokens
Single-use email/reset token hashes.
api_keys
Server administration key hashes.
KEEP IT RUNNING

History & housekeeping

audit_events
Supported account/project activity.
email_outbox
Encrypted messages waiting to be sent.
rate_limits
Shared counters that slow repeated requests.
schema_migrations
Which database changes have been applied.

Related records use project + user references to prevent accidental cross-project links. Ownership can point only to a developer account in the reserved developer workspace. This is logical separation in one database; database administrators can access all projects.

D

Where does each piece of code live?

cmd/

Starts the server or runs an operator command.

internal/httpapi/

Receives requests and serves the website.

internal/auth/

Account rules, cryptography, and project ownership.

internal/database/

Database connections and numbered schema changes.

internal/mail/ + scheduled/

Message delivery, retries, and cleanup jobs.

scripts/ · docs/ · examples/

Checks, explanations, and an integration example.

Open the complete file-by-file map.

This index includes the source, tests, docs, and deployment files. Local credentials and generated files are deliberately excluded.

File Its job
cmd/comfyauth/main.goServer lifecycle, graceful shutdown, operator commands, one-time key output
cmd/api/main.goVercel Go entrypoint, production configuration, small connection pool, finite email work
internal/config/config.goEnvironment configuration, verified database TLS requirement, callback/origin validation
internal/config/config_test.goProduction configuration and unsafe URL tests
internal/config/limits.goConfigurable public API capacity budgets and conservative defaults
internal/config/limits_test.goPublic capacity configuration validation and default tests
internal/database/database.goConnection limits/timeouts, migration lock, embedded SQL, checksum validation
internal/database/migrations/001_initial.sqlTables, indexes, tenant constraints, retention-related fields
internal/database/migrations/002_developer_portal.sqlReserved developer workspace and constrained ownership table
internal/database/migrations/003_session_renewal.sqlAdditive renewable-session deadlines and tenant-scoped refresh-token history
internal/auth/portal_integration_test.goCloud database tests for ownership, cookie/CSRF boundaries, revocation, and secret redaction
internal/auth/key_visibility_test.goEnsures active keys stay visible and revocable after many rotations
internal/auth/http_limits_test.goDatabase tests for shared-backend capacity, account limits, and error handling
internal/httpapi/portal_test.goEmbedded page routes, security headers, callback validation
internal/auth/portal.goOwnership-scoped project, user, key, and activity operations
internal/auth/models.goPublic response types, project/principal types, controlled service errors
internal/auth/crypto.goArgon2id, random IDs/tokens, hashes, AES-GCM, input normalization
internal/auth/service.goAccount/session operations, atomic recovery, shared limits, key administration, cleanup
internal/auth/renewal.goOpt-in renewable login, atomic refresh rotation and replay revocation
internal/auth/renewal_integration_test.goDatabase tests for rotation, replay, expiry, concurrency and revocation
internal/auth/crypto_test.goPassword policy/hash, token format, ciphertext tampering and identity-binding tests
internal/auth/integration_test.goIsolated PostgreSQL lifecycle, isolation, concurrency, expiry, outbox, and HTTP tests
internal/httpapi/portal.goEmbedded website, exact-origin cookie authentication, portal HTTP routes
internal/httpapi/web/guide-system.htmlVisual guide 1: people, hosting, request/code flow, deployment
internal/httpapi/web/guide-accounts.htmlVisual guide 2: signup, email, login, identity checks, recovery and revocation
internal/httpapi/web/guide-workspace.htmlVisual guide 3: ownership, portal controls, database and full file map
internal/httpapi/web/guide.cssResponsive HTML flowcharts, connected boxes, expandable explanations and print layout
internal/httpapi/web/index.htmlPublic product website with a visual system overview
internal/httpapi/web/auth.htmlDeveloper signup, login, verification, recovery screens
internal/httpapi/web/dashboard.htmlAccessible developer console shell and dialogs
internal/httpapi/web/docs.htmlPublic quickstart, API reference, and security explanation
internal/httpapi/web/style.cssResponsive dark visual system, layouts, focus and reduced motion states
internal/httpapi/web/app.jsPortal forms and real project/user/key/session controls; no persisted browser tokens
internal/httpapi/web/mark.svgLocal ComfyAuth brand mark and favicon
internal/httpapi/api.goRouting, strict JSON, status codes, CORS, bearer credentials, proxy handling
internal/httpapi/api_test.goMalformed input, origin, bearer parsing, and proxy spoofing tests
internal/httpapi/limits.goSeparates public project capacity and account limits from portal IP controls
internal/mail/mail.goBounded SMTP delivery, required production STARTTLS, retries, queue cleanup
internal/scheduled/handler.goInline project-scoped delivery and authenticated, bounded email/cleanup jobs
internal/scheduled/handler_test.goJob authorization, finite work, error privacy, and inline response preservation tests
examples/bff/server.mjsCustomer-owned browser backend; server-held tokens, secure cookies, CSRF checks
examples/bff/server.test.mjsToken isolation, CSRF, cookies, safe retry metadata and bounded upstream deadline tests
scripts/init_dev.pyPrivate, non-overwriting development secret/config generation
scripts/portal_ui.test.mjsEscaping, token removal, final verification password, credentials and secret-dialog tests
scripts/check_docs.pyEnforces matching README/HTML file maps, local links, HTTP routes and OpenAPI references
scripts/vercel_build.shRequires a separate test database, runs Go checks, builds Vercel binary
scripts/smoke_vercel.pyHTTPS live health/auth rejection checks and optional test-account login/revocation
docs/portal.mdPortal setup, ownership boundaries, browser security, limits and full route inventory
docs/openapi.jsonVersioned HTTP API schema, request/response definitions, security schemes
docs/openapi.goEmbeds the same API contract for the public /openapi.json route
docs/integration.mdCustomer integration and credential-handling guide
docs/security.mdThreat model, implemented safeguards, limitations, production requirements
docs/deployment.mdSetup, production environment, testing, migrations, backups and restore
docs/vercel.mdVercel Hobby configuration, setup sequence, live verification and retry limitations
docs/domain-setup.mdNamecheap domain connection, canonical portal origin and separate sender-domain setup
docs/verification.mdObserved checks and explicit environment blockers
.github/workflows/ci.ymlGo/PostgreSQL race tests, browser tests, build, and vulnerability scan
go.modGo version and pinned direct dependencies
go.sumDependency checksums verified against Go's signed checksum database
DockerfileMulti-stage nonroot runtime image
compose.yamlLocal database, migrations, API, and captured email
vercel.jsonGo framework, build gate, function duration, daily cleanup cron
.vercelignoreExcludes development secrets and local/generated files from uploads
MakefileBuild/test/format/check shortcuts
.env.exampleConfiguration names and placeholders; never real shared secrets
.gitignore
.dockerignore
Exclude local secrets and generated files
README.mdThis living architecture and file map