From 388538605abe9cc8fc19a8ecda53215e1479b241 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Wed, 22 Apr 2026 09:26:09 -0700 Subject: [PATCH] improvements --- .devcontainer/post-create.sh | 14 ++++- README.md | 94 +++++++++++++++++---------------- apps/realtime/.env.example | 30 +++++++++++ apps/realtime/src/env.ts | 7 --- apps/realtime/src/index.test.ts | 2 - package.json | 4 +- packages/db/.env.example | 7 ++- 7 files changed, 99 insertions(+), 59 deletions(-) create mode 100644 apps/realtime/.env.example diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index f77473f3a8..c7ceff427e 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -71,7 +71,7 @@ fi # Set up environment variables if .env doesn't exist for the sim app if [ ! -f "apps/sim/.env" ]; then - echo "πŸ“„ Creating .env file from template..." + echo "πŸ“„ Creating apps/sim/.env from template..." if [ -f "apps/sim/.env.example" ]; then cp apps/sim/.env.example apps/sim/.env else @@ -79,6 +79,18 @@ if [ ! -f "apps/sim/.env" ]; then fi fi +# Set up env for the realtime server (must match the shared values in apps/sim/.env) +if [ ! -f "apps/realtime/.env" ] && [ -f "apps/realtime/.env.example" ]; then + echo "πŸ“„ Creating apps/realtime/.env from template..." + cp apps/realtime/.env.example apps/realtime/.env +fi + +# Set up packages/db/.env for drizzle-kit and migration scripts +if [ ! -f "packages/db/.env" ] && [ -f "packages/db/.env.example" ]; then + echo "πŸ“„ Creating packages/db/.env from template..." + cp packages/db/.env.example packages/db/.env +fi + # Generate schema and run database migrations echo "πŸ—ƒοΈ Running database schema generation and migrations..." echo "Generating schema..." diff --git a/README.md b/README.md index 57c0192825..e2489be54b 100644 --- a/README.md +++ b/README.md @@ -1,69 +1,55 @@ -

- - - - - Sim Logo - - -

-

The open-source platform to build AI agents and run your agentic workforce. Connect 1,000+ integrations and LLMs to orchestrate agentic workflows.

-

- Sim.ai - Discord - Twitter - Documentation -

+The open-source platform to build AI agents and run your agentic workforce. Connect 1,000+ integrations and LLMs to orchestrate agentic workflows. + + + -

- Ask DeepWiki Set Up with Cursor -

### Build Workflows with Ease + Design agent workflows visually on a canvasβ€”connect agents, tools, and blocks, then run them instantly. -

- Workflow Builder Demo -

+ ### Supercharge with Copilot + Leverage Copilot to generate nodes, fix errors, and iterate on flows directly from natural language. -

- Copilot Demo -

+ ### Integrate Vector Databases + Upload documents to a vector store and let agents answer questions grounded in your specific content. -

- Knowledge Uploads and Retrieval Demo -

+ ## Quickstart ### Cloud-hosted: [sim.ai](https://sim.ai) -Sim.ai + ### Self-hosted: NPM Package ```bash npx simstudio ``` -β†’ http://localhost:3000 + +β†’ [http://localhost:3000](http://localhost:3000) #### Note + Docker must be installed and running on your machine. #### Options -| Flag | Description | -|------|-------------| + +| Flag | Description | +| ------------------- | ----------------------------------- | | `-p, --port ` | Port to run Sim on (default `3000`) | -| `--no-pull` | Skip pulling latest Docker images | +| `--no-pull` | Skip pulling latest Docker images | + ### Self-hosted: Docker Compose @@ -89,7 +75,7 @@ bun install bun run prepare # Set up pre-commit hooks ``` -2. Set up PostgreSQL with pgvector: +1. Set up PostgreSQL with pgvector: ```bash docker run --name simstudio-db -e POSTGRES_PASSWORD=your_password -e POSTGRES_DB=simstudio -p 5432:5432 -d pgvector/pgvector:pg17 @@ -97,43 +83,61 @@ docker run --name simstudio-db -e POSTGRES_PASSWORD=your_password -e POSTGRES_DB Or install manually via the [pgvector guide](https://github.com/pgvector/pgvector#installation). -3. Configure environment: +1. Configure environment: ```bash +# Main app env (large, app-specific: OAuth secrets, LLM keys, etc.) cp apps/sim/.env.example apps/sim/.env -# Create your secrets perl -i -pe "s/your_encryption_key/$(openssl rand -hex 32)/" apps/sim/.env perl -i -pe "s/your_internal_api_secret/$(openssl rand -hex 32)/" apps/sim/.env perl -i -pe "s/your_api_encryption_key/$(openssl rand -hex 32)/" apps/sim/.env -# DB configs for migration + +# Realtime server env (small: just the ~6 shared values) +cp apps/realtime/.env.example apps/realtime/.env +# Copy DATABASE_URL, BETTER_AUTH_URL, BETTER_AUTH_SECRET, INTERNAL_API_SECRET, +# and NEXT_PUBLIC_APP_URL from apps/sim/.env into apps/realtime/.env so both +# services use the same auth secret and DB. + +# DB migration env cp packages/db/.env.example packages/db/.env -# Edit both .env files to set DATABASE_URL="postgresql://postgres:your_password@localhost:5432/simstudio" + +# Edit each .env to set DATABASE_URL="postgresql://postgres:your_password@localhost:5432/simstudio" ``` -4. Run migrations: +We use per-app `.env` files (the Turborepo-canonical pattern) rather than a +single root `.env`. This mirrors production β€” each service has its own env +block in Docker Compose / k8s β€” and keeps sim's app secrets (OAuth, LLM keys, +Stripe, etc.) out of the realtime server's process scope. The shared values +(DATABASE_URL, BETTER_AUTH_SECRET, INTERNAL_API_SECRET, etc.) are duplicated +across `apps/sim/.env` and `apps/realtime/.env`; that's the trade-off. + +Production uses env vars passed through Docker Compose / Kubernetes directly +and does not read any `.env` files. + +1. Run migrations: ```bash cd packages/db && bun run db:migrate ``` -5. Start development servers: +1. Start development servers: ```bash bun run dev:full # Starts Next.js app and realtime socket server ``` -Or run separately: `bun run dev` (Next.js) and `cd apps/sim && bun run dev:sockets` (realtime). +Or run separately: `bun run dev` (Next.js) and `bun run dev:sockets` (realtime). All scripts run from the repo root. ## Copilot API Keys Copilot is a Sim-managed service. To use Copilot on a self-hosted instance: -- Go to https://sim.ai β†’ Settings β†’ Copilot and generate a Copilot API key -- Set `COPILOT_API_KEY` environment variable in your self-hosted apps/sim/.env file to that value +- Go to [https://sim.ai](https://sim.ai) β†’ Settings β†’ Copilot and generate a Copilot API key +- Set `COPILOT_API_KEY` in `apps/sim/.env` to that value ## Environment Variables -See the [environment variables reference](https://docs.sim.ai/self-hosting/environment-variables) for the full list, or [`apps/sim/.env.example`](apps/sim/.env.example) for defaults. +See the [environment variables reference](https://docs.sim.ai/self-hosting/environment-variables) for the full list, or [`apps/sim/.env.example`](apps/sim/.env.example) (main app) and [`apps/realtime/.env.example`](apps/realtime/.env.example) (realtime server) for defaults. ## Tech Stack @@ -160,4 +164,4 @@ We welcome contributions! Please see our [Contributing Guide](.github/CONTRIBUTI This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details. -

Made with ❀️ by the Sim Team

+Made with ❀️ by the Sim Team \ No newline at end of file diff --git a/apps/realtime/.env.example b/apps/realtime/.env.example new file mode 100644 index 0000000000..26ef119c01 --- /dev/null +++ b/apps/realtime/.env.example @@ -0,0 +1,30 @@ +# Environment variables required by the @sim/realtime (Socket.IO) server. +# These MUST match the corresponding values in apps/sim/.env for auth to work. +# See apps/realtime/src/env.ts for the full zod schema. + +# Core +NODE_ENV=development +PORT=3002 + +# Database β€” must point at the same Postgres as the main app +DATABASE_URL=postgresql://postgres:postgres@localhost:5432/simstudio + +# Auth β€” shared with apps/sim (Better Auth "Shared Database Session" pattern) +BETTER_AUTH_URL=http://localhost:3000 +BETTER_AUTH_SECRET=your_better_auth_secret_min_32_chars + +# Internal RPC β€” shared with apps/sim +INTERNAL_API_SECRET=your_internal_api_secret_min_32_chars + +# Public app URL β€” used for CORS allow-list and base URL resolution +NEXT_PUBLIC_APP_URL=http://localhost:3000 + +# Optional: Redis for cross-pod room management +# Leave unset for single-pod / in-memory rooms +# REDIS_URL=redis://localhost:6379 + +# Optional: extra Socket.IO CORS allow-list (comma-separated) +# ALLOWED_ORIGINS=https://embed.example.com,https://admin.example.com + +# Optional: disable auth entirely for trusted private networks +# DISABLE_AUTH=true diff --git a/apps/realtime/src/env.ts b/apps/realtime/src/env.ts index 7794ef4115..91c7e4c648 100644 --- a/apps/realtime/src/env.ts +++ b/apps/realtime/src/env.ts @@ -8,12 +8,9 @@ const EnvSchema = z.object({ BETTER_AUTH_SECRET: z.string().min(32), INTERNAL_API_SECRET: z.string().min(32), NEXT_PUBLIC_APP_URL: z.string().url(), - INTERNAL_API_BASE_URL: z.string().url().optional(), ALLOWED_ORIGINS: z.string().optional(), - SOCKET_SERVER_URL: z.string().url().optional(), PORT: z.coerce.number().int().positive().default(3002), SOCKET_PORT: z.coerce.number().int().positive().optional(), - HOSTNAME: z.string().default('0.0.0.0'), DISABLE_AUTH: z .string() .optional() @@ -46,7 +43,3 @@ export const isAuthDisabled = env.DISABLE_AUTH === true && !isHosted export function getBaseUrl(): string { return env.NEXT_PUBLIC_APP_URL } - -export function getInternalApiBaseUrl(): string { - return env.INTERNAL_API_BASE_URL ?? env.NEXT_PUBLIC_APP_URL -} diff --git a/apps/realtime/src/index.test.ts b/apps/realtime/src/index.test.ts index 21d0decc77..c00592e0d6 100644 --- a/apps/realtime/src/index.test.ts +++ b/apps/realtime/src/index.test.ts @@ -45,7 +45,6 @@ vi.mock('@/env', () => ({ INTERNAL_API_SECRET: 'test-internal-api-secret-at-least-32-chars', NEXT_PUBLIC_APP_URL: 'http://localhost:3000', PORT: 3002, - HOSTNAME: '0.0.0.0', DISABLE_AUTH: false, }, isProd: false, @@ -54,7 +53,6 @@ vi.mock('@/env', () => ({ isHosted: false, isAuthDisabled: false, getBaseUrl: () => 'http://localhost:3000', - getInternalApiBaseUrl: () => 'http://localhost:3000', })) vi.mock('@/middleware/auth', () => ({ diff --git a/package.json b/package.json index 281a1daab1..b857f3c0f8 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "scripts": { "build": "turbo run build", "dev": "turbo run dev", - "dev:sockets": "bun --cwd apps/realtime run dev", - "dev:full": "bunx concurrently -n \"App,Realtime\" -c \"cyan,magenta\" \"bun --cwd apps/sim run dev\" \"bun --cwd apps/realtime run dev\"", + "dev:sockets": "cd apps/realtime && bun run dev", + "dev:full": "bunx concurrently -n \"App,Realtime\" -c \"cyan,magenta\" \"cd apps/sim && bun run dev\" \"cd apps/realtime && bun run dev\"", "test": "turbo run test", "format": "turbo run format", "format:check": "turbo run format:check", diff --git a/packages/db/.env.example b/packages/db/.env.example index bc06b7099c..14459e61f5 100644 --- a/packages/db/.env.example +++ b/packages/db/.env.example @@ -1,2 +1,5 @@ -# Database URL (Required for migrations and database operations) -DATABASE_URL="postgresql://postgres:your_password@localhost:5432/simstudio" \ No newline at end of file +# Database connection used by @sim/db scripts (drizzle-kit generate, +# db:migrate, register-sso-provider, etc.). Must match DATABASE_URL in +# apps/sim/.env and apps/realtime/.env. + +DATABASE_URL="postgresql://postgres:postgres@localhost:5432/simstudio"