# 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 + PostgreSQL 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 \ DATABASE_URL="postgresql://basenoter:basenoter@localhost:5432/basenoter?schema=public" \ 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_ORIGINS`, and `COOKIE_SECURE` before deploying for real. **Persistent data** The compose file provisions a single named volume: - `backend-uploads` – stores uploaded base layout images (`/app/uploads`) Because the API now targets PostgreSQL, you must supply an external database connection string via the `DATABASE_URL` environment variable (e.g., through Dokploy secrets pointing at your managed Postgres instance). ## 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 (PostgreSQL) | | `JWT_SECRET` | Secret for signing JWT auth cookies | | `FRONTEND_ORIGINS` | Comma-delimited list of allowed frontend origins | | `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 the `DATABASE_URL` secret to point at your managed Postgres instance and mount the `backend-uploads` volume, or adjust the compose file to include a local Postgres service for testing. ## 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. For the backend, provide a PostgreSQL connection string such as: ``` DATABASE_URL="postgresql://basenoter:basenoter@localhost:5432/basenoter?schema=public" ``` When developing locally you can point this URL at any Postgres instance you manage (Docker Desktop, remote cloud database, etc.). ## Image handling Uploaded base images are saved to `/app/uploads` inside the backend container and served at `http:///uploads/`. 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.