101 lines
4.3 KiB
Markdown
101 lines
4.3 KiB
Markdown
# Base Noter (Dockerized Next.js + Prisma)
|
||
|
||
This repository now contains a two-container stack:
|
||
|
||
- `frontend/` – a Next.js 14 web UI that reimplements the original single-page experience
|
||
- `backend/` – an Express API with Prisma + SQLite that provides authentication, base/category/defense CRUD, statistics, and image uploads
|
||
|
||
Everything runs via Docker so you can deploy directly to Dokploy (or any Docker-based host).
|
||
|
||
## Quick start (local Docker Compose)
|
||
|
||
The Dokploy-oriented compose files assume production domains. For a local smoke test you can temporarily override the variables at runtime:
|
||
|
||
```bash
|
||
JWT_SECRET=dev-secret docker compose -f docker-compose.backend.yml up --build -d
|
||
NEXT_PUBLIC_BACKEND_URL=http://localhost:4000 docker compose -f docker-compose.frontend.yml up --build -d
|
||
```
|
||
|
||
Then visit:
|
||
|
||
- Frontend UI: http://localhost:3000
|
||
- Backend API (optional): http://localhost:4000
|
||
|
||
Default environment variables ship in `backend/.env.example`. Copy it (e.g. to `backend/.env`) and update `JWT_SECRET`, `FRONTEND_ORIGIN`, and `COOKIE_SECURE` before deploying for real.
|
||
|
||
**Persistent data**
|
||
|
||
The compose file provisions two named volumes:
|
||
|
||
- `backend-data` – stores the Prisma SQLite database (`/app/dev.db`)
|
||
- `backend-uploads` – stores uploaded base layout images (`/app/uploads`)
|
||
|
||
## Backend details (`backend/`)
|
||
|
||
- Express 4 REST API
|
||
- Authentication via HTTP-only JWT cookie (`/auth/signup`, `/auth/login`, `/auth/logout`, `/auth/me`)
|
||
- CRUD-ish endpoints for army categories, bases (with upload-or-URL image support), defenses, and aggregated statistics (`/defenses`)
|
||
- Prisma schema lives in `prisma/schema.prisma`
|
||
- On container boot the schema is synced with `npx prisma db push`
|
||
- Dockerfile exposes port `4000`
|
||
|
||
Environment variables (see `.env.example`):
|
||
|
||
| Variable | Purpose |
|
||
|-------------------|----------------------------------------------|
|
||
| `DATABASE_URL` | Prisma connection string (default SQLite) |
|
||
| `JWT_SECRET` | Secret for signing JWT auth cookies |
|
||
| `FRONTEND_ORIGIN` | CORS allowlist (e.g. `http://localhost:3100`) |
|
||
| `COOKIE_SECURE` | Set to `true` when serving over HTTPS |
|
||
|
||
## Frontend details (`frontend/`)
|
||
|
||
- Next.js 14 App Router, React 18
|
||
- UI mirrors the earlier PHP page (auth tabs, dashboard, forms, base/category detail views)
|
||
- Global styling lives in `app/globals.css`
|
||
- All API calls are routed to `NEXT_PUBLIC_BACKEND_URL` (defaults to `http://localhost:4100` and configured in Docker compose)
|
||
- Dockerfile builds the production bundle and runs `next start`
|
||
|
||
## Deploying with Dokploy
|
||
|
||
Use the dedicated compose manifests so each service can be registered as its own Dokploy app with the correct domain routing:
|
||
|
||
- `docker-compose.backend.yml` – Express + Prisma API at `backend.basetracker.lona-development.org`
|
||
- `docker-compose.frontend.yml` – Next.js UI at `basetracker.lona-development.org`
|
||
|
||
Steps:
|
||
|
||
1. Push this repo to Git (commit the Dockerfiles and compose manifests).
|
||
2. In Dokploy create two Compose apps, each pointing to the respective file above.
|
||
3. Provide secrets for `JWT_SECRET` (backend) and any overrides you need; TLS-terminated installs should leave `COOKIE_SECURE` as `true`.
|
||
4. Dokploy's Traefik proxy will use the embedded labels to route the domains listed earlier. Adjust `entrypoints`/`certresolver` if your installation uses different names.
|
||
5. Configure persistent volumes for `/app/dev.db` and `/app/uploads`, or switch Prisma to an external database before deployment.
|
||
|
||
## Development without Docker
|
||
|
||
```bash
|
||
# Backend
|
||
yarn install # or npm install
|
||
npx prisma db push
|
||
npm run dev
|
||
|
||
# Frontend
|
||
npm install
|
||
npm run dev
|
||
```
|
||
|
||
Set `NEXT_PUBLIC_BACKEND_URL=http://localhost:4100` for the frontend.
|
||
|
||
## Image handling
|
||
|
||
Uploaded base images are saved to `/app/uploads` inside the backend container and served at `http://<backend>/uploads/<filename>`. You can switch to an object store by swapping the Multer storage in `src/server.js`.
|
||
|
||
## Testing
|
||
|
||
Automated tests are not yet included. Manual smoke testing is recommended:
|
||
|
||
1. Sign up and log in
|
||
2. Add army categories and bases (with/without image uploads)
|
||
3. Log defenses and confirm the dashboard, base detail, and category detail stats update
|
||
|
||
Feel free to extend the stack with migrations, tests, or alternative storage as your deployment requires.
|