152 lines
3.7 KiB
Markdown
152 lines
3.7 KiB
Markdown
# 💤 SlaapKampioen
|
||
|
||
Slaaptracker voor jou en je Discord vrienden. Log elke nacht je slaap, bekijk wie het meeste slaapt in verschillende periodes, en vergelijk optioneel je slaapfases (diepe slaap, REM, lichte slaap).
|
||
|
||
## Features
|
||
|
||
- 🔐 Login via Discord
|
||
- ➕ Slaap loggen — bedtijd + wektijd invullen, totaal wordt automatisch berekend
|
||
- 🧠 Optionele slaapfases (diepe slaap, lichte slaap, REM, wakker momenten)
|
||
- 🏆 Klassement per periode: Gisternacht / Deze week / Deze maand / Dit jaar
|
||
- 📅 Persoonlijke geschiedenis met grafiekje en fase-visualisatie
|
||
- 🎨 Dark mode, mobielvriendelijk
|
||
- 🐳 Docker Compose + nginx ready
|
||
|
||
---
|
||
|
||
## 1. Discord OAuth app aanmaken
|
||
|
||
1. Ga naar https://discord.com/developers/applications
|
||
2. Klik **New Application** → geef het een naam (bv. "SlaapKampioen")
|
||
3. Ga naar **OAuth2** → **General**
|
||
4. Kopieer **Client ID** en **Client Secret**
|
||
5. Voeg onder **Redirects** toe:
|
||
```
|
||
https://slaap.jouwdomein.be/api/auth/callback/discord
|
||
```
|
||
*(of `http://localhost:3000/api/auth/callback/discord` voor lokaal testen)*
|
||
|
||
---
|
||
|
||
## 2. Configuratie
|
||
|
||
```bash
|
||
cp .env.example .env
|
||
```
|
||
|
||
| Variabele | Waarde |
|
||
|-----------|--------|
|
||
| `POSTGRES_PASSWORD` | Sterk wachtwoord voor de DB |
|
||
| `NEXTAUTH_URL` | Jouw publieke URL, bv. `https://slaap.jouwdomein.be` |
|
||
| `NEXTAUTH_SECRET` | Output van `openssl rand -base64 32` |
|
||
| `DISCORD_CLIENT_ID` | Van stap 1 |
|
||
| `DISCORD_CLIENT_SECRET` | Van stap 1 |
|
||
|
||
---
|
||
|
||
## 3. Docker Compose starten
|
||
|
||
De app luistert op `127.0.0.1:3010` — alleen bereikbaar via nginx.
|
||
|
||
```bash
|
||
docker compose up -d
|
||
docker compose logs -f app
|
||
```
|
||
|
||
Bij de eerste start worden migrations automatisch uitgevoerd:
|
||
```
|
||
🔄 Running database migrations...
|
||
🚀 Starting SlaapKampioen...
|
||
```
|
||
|
||
---
|
||
|
||
## 4. Nginx instellen
|
||
|
||
Zie `nginx.example.conf`. Pas de domeinnaam aan en kopieer naar `/etc/nginx/sites-available/`:
|
||
|
||
```bash
|
||
sudo cp nginx.example.conf /etc/nginx/sites-available/slaapkampioen
|
||
sudo ln -s /etc/nginx/sites-available/slaapkampioen /etc/nginx/sites-enabled/
|
||
sudo nginx -t && sudo systemctl reload nginx
|
||
```
|
||
|
||
SSL via certbot:
|
||
```bash
|
||
sudo certbot --nginx -d slaap.jouwdomein.be
|
||
```
|
||
|
||
---
|
||
|
||
## 5. Gitea setup
|
||
|
||
```bash
|
||
git init
|
||
git remote add origin https://jouw-gitea.be/username/slaapkampioen.git
|
||
git add .
|
||
git commit -m "feat: initial SlaapKampioen"
|
||
git push -u origin main
|
||
```
|
||
|
||
### Gitea Actions CI/CD (optioneel)
|
||
|
||
Het workflow bestand staat al in `.gitea/workflows/deploy.yml`.
|
||
Voeg deze secrets toe in je Gitea repo settings:
|
||
|
||
| Secret | Waarde |
|
||
|--------|--------|
|
||
| `DEPLOY_HOST` | IP of hostnaam van je server |
|
||
| `DEPLOY_USER` | SSH gebruiker |
|
||
| `DEPLOY_KEY` | Privé SSH sleutel |
|
||
|
||
Zorg dat de repo op de server staat in `/opt/slaapkampioen` (of pas het pad aan in het workflow bestand).
|
||
|
||
---
|
||
|
||
## 6. Lokaal ontwikkelen
|
||
|
||
```bash
|
||
npm install
|
||
|
||
# Lokale postgres
|
||
docker run -d --name sleep-pg \
|
||
-e POSTGRES_DB=sleep \
|
||
-e POSTGRES_USER=sleep \
|
||
-e POSTGRES_PASSWORD=dev \
|
||
-p 5432:5432 \
|
||
postgres:16-alpine
|
||
|
||
# .env voor lokaal:
|
||
# DATABASE_URL=postgresql://sleep:dev@localhost:5432/sleep
|
||
# NEXTAUTH_URL=http://localhost:3000
|
||
# NEXTAUTH_SECRET=$(openssl rand -base64 32)
|
||
# DISCORD_CLIENT_ID=...
|
||
# DISCORD_CLIENT_SECRET=...
|
||
|
||
npx prisma migrate dev --name init
|
||
npm run dev
|
||
```
|
||
|
||
---
|
||
|
||
## Slaapfase referentiewaarden
|
||
|
||
| Fase | Normaal bereik |
|
||
|------|---------------|
|
||
| Diepe slaap | 13–25% van totaal |
|
||
| Lichte slaap | 45–65% van totaal |
|
||
| REM | 15–25% van totaal |
|
||
| Wakker | < 5% van totaal |
|
||
|
||
De app berekent automatisch of je waarden "Normaal", "Lang" of "Kort" zijn — zoals de OnePlus Health app.
|
||
|
||
---
|
||
|
||
## Tech stack
|
||
|
||
- **Next.js 14** (App Router)
|
||
- **NextAuth v4** (Discord OAuth)
|
||
- **Prisma** + **PostgreSQL**
|
||
- **Tailwind CSS**
|
||
- **Docker Compose** + **nginx**
|