Getting Started

Project Structure

Understand the folder structure and virtual modules generated by an OmniSvelte application.

Project Structure

When you initialize an OmniSvelte application, you'll see a structure that resembles a standard SvelteKit project, but with a few powerful additions.

Here is what a typical OmniSvelte project looks like:

txt
my-app/
├── src/
│   ├── lib/
│   │   ├── *.schema.ts              # 1. Your OmniSvelte schema definitions
│   │   └── components/              # Shared UI components
│   │
│   ├── routes/                      # 2. SvelteKit file-based routing
│   │   ├── +layout.svelte
│   │   └── +page.svelte
│   │
│   └── app.html

├── .omni/                           # 3. OmniSvelte generated internals
├── omni.config.ts                   # 4. OmniSvelte configuration
├── svelte.config.js
├── vite.config.ts
└── package.json

1. Schema Definitions (*.schema.ts)

OmniSvelte relies on schema files ending in .schema.ts. You place these anywhere inside src/lib/ (or wherever configured).

The OmniSvelte Vite plugin watches these files. Whenever you save a schema, the framework automatically generates the underlying Drizzle tables, Zod validation logic, and your Active Record models.

2. Standard SvelteKit Routing

Everything inside src/routes/ is standard SvelteKit. You can use +page.svelte, +page.server.ts, +layout.svelte, and API endpoints just like you normally would.

3. Generated Internals (.omni/)

OmniSvelte generates files and types into the .omni/ directory. You should add this directory to your .gitignore.

The files here power OmniSvelte's Virtual Modules, allowing you to import your database, models, and auth clients cleanly across your project.

Virtual Modules

Instead of dealing with complex relative imports, you import your generated code via virtual aliases:

  • $db — The configured Drizzle database instance.
  • $models/* — Your generated Active Record models.
  • $validation/* — Your Zod schemas for form and API validation.
  • $auth/server & $auth/client — Your Better-Auth instances.
ts
import { db } from '$db';
import { Users } from '$models/users.model';
import { createUserSchema } from '$validation/users.validation';

4. Configuration (omni.config.ts)

The omni.config.ts file sits at the root of your project. This is where you configure your database provider, authentication settings, and plugin registrations.

ts
// omni.config.ts
import { defineConfig } from 'omni-svelte/config';
 
export default defineConfig({
  database: {
    provider: 'sqlite',
    url: process.env.DATABASE_URL
  },
  auth: {
    enabled: true
  }
});