Update to use MySQL Database
This commit is contained in:
13
CLAUDE.md
13
CLAUDE.md
@@ -23,6 +23,7 @@ For a single Go package test: `go test ./internal/volunteer/...`
|
||||
## Architecture
|
||||
|
||||
### Go Backend
|
||||
|
||||
Domain-based packaging under `internal/` — each domain owns its models, store (DB queries), and HTTP handler in a single package:
|
||||
|
||||
| Package | Responsibility |
|
||||
@@ -43,23 +44,31 @@ Domain-based packaging under `internal/` — each domain owns its models, store
|
||||
All API routes are prefixed `/api/v1`. The Go binary serves the compiled React app from `STATIC_DIR` (default `./web/dist`) for all non-API routes.
|
||||
|
||||
### React Frontend
|
||||
|
||||
Standard CRA layout in `web/src/`:
|
||||
|
||||
- `api.ts` — typed fetch wrapper; reads JWT from `localStorage`, prefixes `BASE = '/api/v1'`
|
||||
- `auth.tsx` — `AuthProvider` context; decodes the JWT payload to expose `role` and `volunteerID`
|
||||
- `pages/` — one file per route (`Dashboard`, `Schedules`, `TimeOff`, `Volunteers`, `Login`)
|
||||
- `App.tsx` — `BrowserRouter` with a `ProtectedLayout` that redirects to `/login` when no token is present; admin-only nav links gated on `role === 'admin'`
|
||||
|
||||
### Data Storage
|
||||
SQLite via `modernc.org/sqlite` (pure Go, no CGO). Schema is defined inline in `internal/db/schema.go` and applied via `CREATE TABLE IF NOT EXISTS` on every startup. No migration framework — additive changes are safe; destructive changes require manual handling.
|
||||
|
||||
MySQL 8.0 via `github.com/go-sql-driver/mysql`. Schema is defined inline in `internal/db/schema.go` and applied via `CREATE TABLE IF NOT EXISTS` on every startup. No migration framework — additive changes are safe; destructive changes require manual handling.
|
||||
|
||||
### Auth
|
||||
|
||||
HS256 JWT signed with `JWT_SECRET`. Token payload: `{ volunteer_id, role, exp }`. Role is either `volunteer` or `admin`. The `RequireAdmin` middleware enforces admin-only routes server-side.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `DATABASE_DSN` | `walkies.db` | SQLite file path |
|
||||
| `DB_HOST` | `localhost` | MySQL host |
|
||||
| `DB_PORT` | `3306` | MySQL port |
|
||||
| `DB_USER` | `root` | MySQL username |
|
||||
| `DB_PASSWORD` | `` | MySQL password |
|
||||
| `DB_NAME` | `walkies` | MySQL database name |
|
||||
| `JWT_SECRET` | `change-me-in-production` | HMAC signing key |
|
||||
| `STATIC_DIR` | `./web/dist` | Path to compiled React app |
|
||||
| `PORT` | `8080` | HTTP listen port |
|
||||
|
||||
Reference in New Issue
Block a user