Skip to content

NotiFi

NotiFi is a multi-tenant platform for resource-based, traceable communication. The first product, Visitor Incident Management, manages visitor presence and SMS-based emergency dispatches.

Foundation and architecture decisions. No production service is deployed.

  • docs/architecture.md — boundaries between product, Core and channels.
  • docs/core/ — developer guide, implemented interfaces and proposed designs.
  • docs/visitor-incident-drafts.md — current Visitor draft backend contract.
  • docs/adr/ — short, immutable architectural decision records.
  • Future application code will live in apps/ and deployment material in infra/.
  • main must always be understandable and runnable.
  • No secrets, credentials, exports or production data are committed.
  • Deployments are manual and documented initially; CI/CD will be added once the delivery path is stable enough to automate.
  1. Copy .env.example to .env and replace the development database password.
  2. Set distinct random hexadecimal passwords for both NOTIFI_APP_PASSWORD and NOTIFI_MIGRATOR_PASSWORD in .env (for example, generate each with openssl rand -hex 32).
  3. Run the database setup below, then docker compose up --build.
  4. Visit http://127.0.0.1:3001/up for the Rails health endpoint.

PostgreSQL and Redis are internal Docker services and have no host ports. The web process is bound to loopback only; it is not publicly reachable. Stop the local stack with docker compose down. Use docker compose down -v only when you intentionally want to discard local NotiFi database and Redis data.

The development css service rebuilds Tailwind when source files change. The fictional design preview at /design-preview is available without signing in only in development; it does not expose product data.

Database setup, for a new installation or the existing development database:

Terminal window
docker compose up -d postgres
set -a; . ./.env; set +a
docker compose exec -T -e NOTIFI_APP_PASSWORD -e NOTIFI_MIGRATOR_PASSWORD postgres \
sh -c 'psql -X -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -v app_password="$NOTIFI_APP_PASSWORD" -v migrator_password="$NOTIFI_MIGRATOR_PASSWORD"' \
< infra/docker/postgres/provision.sql
./bin/dev-migrate

Run ./bin/dev-migrate whenever the development schema changes. It uses the migration role and restarts any running web and worker processes, including after a failed migration, so they do not retain an outdated schema cache. It does not start services that were stopped. The web and worker services connect as notifi_app, not as the migration role. This command is for the local development Compose stack, not production or test databases. To verify RLS on an initialized database, run:

Terminal window
docker compose exec -T postgres sh -c 'psql -X -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB"' < infra/docker/postgres/verify_rls.sql
docker compose run --rm --no-deps web bin/rails runner script/verify_tenant_context.rb

The verification uses a transaction that is rolled back. RLS is a database boundary; authentication and tenant authorization still need implementation before tenant data can be exposed to users.

Provisioning reserves the notifi_dispatch schema for future frozen dispatch data. It preserves current application grants on public, but does not grant app writes or sequence access in the reserved schema; rerunning provisioning revokes those direct grants and rejects unsafe effective or default privileges. It does not create dispatch tables or enable delivery. Run tests/dispatch_schema_privileges_test.sh to exercise provisioning in an isolated disposable PostgreSQL container. SQL schema restore for the reserved schema runs atomically and leaves routine execution fail-closed; tests/dispatch_schema_roundtrip_test.sh verifies it. Before adding dispatch functions, design explicit grant reconciliation after restore, migration ownership and retention access. Provisioning revokes default PUBLIC EXECUTE for new functions created by notifi_migrator in all schemas; future callable functions require explicit reviewed grants. Provisioning only protects the reserved schema; it does not make arbitrary SQL under the app role tenant-safe.

Rails tests require TEST_DATABASE_URL pointing to a dedicated database whose name ends in _test. Prepare its schema with the migration role and give the runtime role access to the application tables, sequences and Rails metadata before running the tests as the runtime role. Never point this variable at development or production data.

To check the development migration wrapper without changing a database, run tests/dev_migrate_test.sh.

The inactive development discovery role is provisioned separately as a PostgreSQL administrator, then verified with:

Terminal window
docker compose exec -T postgres sh -c 'psql -X -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB"' < infra/docker/postgres/provision_discovery_role.sql
docker compose exec -T postgres sh -c 'psql -X -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB"' < infra/docker/postgres/verify_discovery_role.sql

This NOLOGIN role has no application table access and is not assigned to any worker. See docs/core/tenant-work-discovery-design.md before enabling any future discovery capability.