Everything you need to build a Svelte project, powered by sv.
If you're seeing this, you've probably already done this step. Congrats!
# create a new project in the current directory
# Movie DB (SvelteKit)
Lightweight movie database demo built with SvelteKit and SQLite/PostgresQL.
**Status:** Prototype / local demo
**What this repo contains:**
- **Frontend:** SvelteKit app in `src/routes` and `src/lib`.
- **Server / DB:** lightweight SQLite DB and helper scripts in `src/lib/server`.
**Quick Links:**
- **DB file (dev):** `src/lib/server/movie.db`
- **DB helpers:** `src/lib/server/createDb.js`, `src/lib/server/createTable.js`, `src/lib/server/sql.js`
- **Config:** `.env.local` (Supabase keys for production)
**Tech stack:**
- **SvelteKit** (UI)
- **Node.js** (server-side routes)
- **SQLite** (local database via `sqlite3` – **development only**)
- **Supabase** (PostgreSQL backend – **production only**)
**Database Strategy:**
- **Development:** SQLite at `src/lib/server/movie.db` for fast local iteration.
- **Production:** Supabase PostgreSQL with environment variables (`PUBLIC_SUPABASE_URL`, `PUBLIC_SUPABASE_PUBLISHABLE_KEY`).
**Features:**
- Movie, director, actor, user and rating tables.
- Many-to-many relation between movies and actors (`movie_actor`).
**Prerequisites**
- Node.js (v16+ recommended)
- npm (or pnpm/yarn)
**Install & Run (Windows bash / WSL)**
```bash
git clone <repo-url>
cd movie_db_sveltekit
npm install
npm run dev
Open http://localhost:5173 (or the port shown by the dev server).
Build / Preview
npm run build
npm run preview
Database
src/lib/server/movie.db (created by createDb.js).src/lib/server/createTable.js.movie.db does not exist, it is created automatically when server-side code runs..db file and restart the dev server.Production (Supabase)
.env.local (or production environment variables):PUBLIC_SUPABASE_URL – Supabase project URLPUBLIC_SUPABASE_PUBLISHABLE_KEY – Supabase anon key@supabase/supabase-js) to sign up and sign in users; server-side verification is recommended for sensitive operations..env.local; keep any service-role keys or other secrets in your hosting provider's secure environment variables.Schema summary (columns shown with primary keys and foreign keys):
user
user_id INTEGER PRIMARY KEY AUTOINCREMENTusername VARCHAR(50) NOT NULL UNIQUEemail VARCHAR(100) NOT NULL UNIQUEfirst_name, last_name VARCHAR(50)created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMPis_active BOOLEAN DEFAULT 1password_hash VARCHAR(255) NOT NULLrating
rating_id INTEGER PRIMARY KEY AUTOINCREMENTcomment TEXTrate INTEGER CHECK(rate >= 1 AND rate <= 5)user_id INTEGER REFERENCES user(user_id)director
director_id INTEGER PRIMARY KEY AUTOINCREMENTfirst_name, last_name VARCHAR(100) NOT NULLactor
actor_id INTEGER PRIMARY KEY AUTOINCREMENTfirst_name, last_name VARCHAR(100) NOT NULLmovie
movie_id INTEGER PRIMARY KEY AUTOINCREMENTtitle VARCHAR(100) NOT NULLsynopsis TEXTrelease_date DATEgenre, country_of_origin, language VARCHAR(50)img_url VARCHAR(255)rating_id INTEGER REFERENCES rating(rating_id)director_id INTEGER REFERENCES director(director_id)movie_actor (join table)
movie_id INTEGER REFERENCES movie(movie_id)actor_id INTEGER REFERENCES actor(actor_id)movie_id, actor_id)ER Diagram (Mermaid) This diagram can be rendered on GitHub or with Mermaid-enabled renderers.
erDiagram
USER {
INTEGER user_id PK
VARCHAR username
VARCHAR email
VARCHAR first_name
VARCHAR last_name
TIMESTAMP created_at
BOOLEAN is_active
VARCHAR password_hash
}
RATING {
INTEGER rating_id PK
TEXT comment
INTEGER rate
INTEGER user_id FK
}
DIRECTOR {
INTEGER director_id PK
VARCHAR first_name
VARCHAR last_name
}
ACTOR {
INTEGER actor_id PK
VARCHAR first_name
VARCHAR last_name
}
MOVIE {
INTEGER movie_id PK
VARCHAR title
TEXT synopsis
DATE release_date
VARCHAR genre
VARCHAR country_of_origin
VARCHAR language
VARCHAR img_url
INTEGER rating_id FK
INTEGER director_id FK
}
MOVIE_ACTOR {
INTEGER movie_id FK
INTEGER actor_id FK
}
USER ||--o{ RATING : "writes"
RATING }o--|| USER : "belongs_to"
DIRECTOR ||--o{ MOVIE : "directs"
MOVIE ||--o{ RATING : "has"
MOVIE ||--o{ MOVIE_ACTOR : "cast_in"
ACTOR ||--o{ MOVIE_ACTOR : "acts_in"
Notes / maintenance
src/lib/server/movie.db does not exist, the createDb.js script opens/creates it automatically when server-side code runs.createTable.js script (it executes on import). Be careful: repeated runs are guarded with CREATE TABLE IF NOT EXISTS but manual DB resets require removing the .db file.LICENSE file in this repo (checked src/lib/server for license; none found). Add a LICENSE to the repo root if you want to publish with a specific license.Deployment
vercel --prod or similar for production builds (see vite.config.js and svelte.config.js).Further work / suggestions