Modern rewrite of the Predictions application using SvelteKit, TypeScript, and SQLite.
cd app
npm install# Generate the database schema
npm run db:pushThis will create predictions.db in the app directory.
npm run devVisit http://localhost:5173
app/
├── src/
│ ├── lib/
│ │ ├── db/ # Database (Drizzle ORM)
│ │ │ ├── schema.ts # Database schema
│ │ │ ├── index.ts # DB connection
│ │ │ └── migrations/ # SQL migrations
│ │ ├── server/ # Server-only code
│ │ │ └── auth.ts # Authentication
│ │ ├── components/ # Reusable Svelte components
│ │ └── utils/ # Utilities
│ │
│ ├── routes/ # Pages & API routes
│ │ ├── (auth)/ # Auth pages (login, register)
│ │ ├── +layout.svelte # Root layout
│ │ ├── +page.svelte # Homepage
│ │ └── +page.server.ts # Server load function
│ │
│ ├── hooks.server.ts # Server hooks (auth middleware)
│ ├── app.html # HTML template
│ ├── app.css # Global styles (Tailwind)
│ └── app.d.ts # TypeScript types
│
├── static/ # Static assets
├── drizzle.config.ts # Drizzle configuration
├── svelte.config.js # SvelteKit config
├── tailwind.config.js # Tailwind CSS config
└── package.json
- Framework: SvelteKit 2.x
- Language: TypeScript
- Database: SQLite (via better-sqlite3)
- ORM: Drizzle ORM
- Styling: Tailwind CSS
- Authentication: Custom (bcrypt + cookies)
- SvelteKit project setup
- TypeScript configuration
- Tailwind CSS
- Database schema (Drizzle ORM)
- Authentication system
- Password hashing (bcrypt)
- Login page
- Registration page
- Session management
- Auth middleware
- Group management
- Game creation & management
- Predictions submission
- Leaderboards
- Email notifications
- SMS integration (Twilio)
- Data migration from old SQLite DB
The new schema improves on the original:
- Security: Passwords are hashed with bcrypt
- Timestamps: All tables have created/updated timestamps
- Constraints: Unique constraints prevent duplicate predictions
- Indexes: Better query performance
- Soft Deletes: Can mark users as deleted without losing data
- Structured Data: Odds stored as separate fields, not HTML
users- User accounts (replacespeople)groups- Groups/leagues (replacesgroupplay)memberships- User group membershipsgames- Football gamesgroup_games- Which games belong to which groupspredictions- User predictionsin_game_scores- Live score updates & commentary
# Development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
# Type checking
npm run check
# Database commands
npm run db:generate # Generate migration SQL
npm run db:push # Push schema to database
npm run db:studio # Open Drizzle Studio (GUI)-
Registration:
/register- User provides name, email, password
- Password is hashed with bcrypt
- Session created and stored in cookie
-
Login:
/login- User provides email & password
- Password verified against hash
- Session created
-
Session Management:
- Session token stored in HTTP-only cookie
hooks.server.tschecks auth on every request- User info added to
event.locals.user
-
Logout:
/logout- Session cookie deleted
- Redirects to login
In any server file (+page.server.ts, +server.ts):
export const load = async ({ locals }) => {
const user = locals.user; // User object or undefined
// ...
};In Svelte components:
<script lang="ts">
export let data;
const user = data.user; // From page data
</script>
{#if user}
Welcome, {user.name}!
{/if}Visit http://localhost:5173/register and create an account.
npm run db:studioThis opens Drizzle Studio in your browser to view/edit data.
Follow the MIGRATION_PLAN.md to add:
- Group management
- Game creation
- Predictions
- Leaderboards
A migration script will be provided to:
- Read data from
../predictions.sqlite - Hash existing passwords
- Map old schema to new schema
- Import into new database
npm run buildThis creates a build/ directory with the production app.
node buildOr use a process manager:
npm install -g pm2
pm2 start build/index.js --name predictions-appCreate .env for production:
NODE_ENV=production
DATABASE_URL=file:./predictions.dbIf you need to reset the database:
rm predictions.db
npm run db:pushRegenerate types:
npm run checkChange the dev port:
npm run dev -- --port 3000This is a migration from the legacy Python app. See:
- MIGRATION_PLAN.md - Full migration roadmap
- DATABASE_ANALYSIS.md - Schema improvements
- SVELTEKIT_DETAILED.md - SvelteKit guide
Same as the original Predictions app.