Eng. Domenico Alvaro
Eng. Domenico Alvaro

Starter Kit

React Lab Starter Kit

Educational Docker project: end-to-end JWT, a dashboard that verifies the session and a React/JS playground—not an enterprise template, a linear lab.

Built for students and juniors: the same API base and the same token for protected areas. After login you store the JWT in the browser, call protected endpoints with Bearer and handle logout or invalid tokens. Dashboard and Playground are two different ways to practise on the same frontend–backend “bridge”. For local study with Docker Compose; not as a production starting point. After purchase you receive the ZIP with README, FAQ, environment variables and sample credentials.

Stack and level

BeginnerNext.js 14React 18ExpressMongoDB 7DockerJWT

What it does and what it includes

Below is the content expected in the package: the concrete outcome you get, not the step-by-step guide (that lives in the README in the ZIP).

  • `web` (Next.js) and `api` (Express) structure linked by environment variables (e.g. `NEXT_PUBLIC_API_BASE_URL`)
  • JWT authentication: login, token in localStorage, protected requests with `Authorization: Bearer …`
  • Dashboard: session check, protected call `/api/v1/me`, `/health`, invalid or expired token handling, logout
  • Playground (after login): React mini-lab (`useState`, `useEffect`, `useMemo`), Function Runner, Type Inspector
  • MongoDB 7 via Docker; sample credentials documented in the ZIP README
  • Docker Compose to bring up frontend, API and database locally
  • README and FAQ in the ZIP (including a notice on the Function Runner: suitable for classroom/local use, not to expose in production)

Educational lab: the goal is to see JWT auth, API calls and React state clearly—not to clone an enterprise architecture. Operational details, ports and troubleshooting stay in the README in the ZIP.

How to read it (students / juniors)

Read the project as a simple pipeline: log in, receive a JWT, save the token in the browser (localStorage), use it to call protected endpoints; if the token is missing or no longer valid, go back to login. Dashboard and Playground are two practical exercises on the same authentication mechanism.

Dashboard (what it really teaches)

The dashboard is the “session check + backend status” page: it verifies that the auth bridge between browser and API works before you move on to experiments in the Playground.

Learning goal

  • Understand how the frontend checks whether you are authenticated
  • See a protected call (`/api/v1/me`)
  • See a public call (`/health`)
  • Handle logout and an invalid session

Mental flow step by step

  • Open `/dashboard`: the page looks for the token in the browser
  • If there is none, immediate redirect to `/login` (no point calling protected APIs without credentials)
  • If there is one, request `/api/v1/me` with `Authorization: Bearer …`
  • If the response is valid, show user data
  • Then call `/health` and show API status
  • If something fails (invalid or expired token), remove the token and send back to login

What you learn here

  • Difference between “logged-in user in the browser” and “token accepted by the server”
  • Basic UI state handling: loading, error, success
  • Minimal logout pattern: delete token and redirect

Playground (what it really teaches)

A three-module lab, always behind login: practise basic React, experiment with JS with real input/output and reason about types.

Section 1: React mini-lab

What you learn: render cycle, local state, side effects, memoization.

  • Counter with `useState`
  • Text input with live echo
  • Dynamic list with add/clear and rendering with `map`
  • Clock with `useEffect` and cleanup
  • “Heavy” value with `useMemo` to intuit memoization

Section 2: Function Runner

What you learn: JSON parsing and error handling, small functions on input, controlled `fetch` with helpers (`ctx.fetchJson`), quick debug with output and stack.

  • Choice of a template (sum, strings, arrays, objects, API health)
  • JSON input, JS code, Run: see logs (`ctx.log`), final output and parsing/runtime errors

Important teaching point (as in the README): execution uses `new Function`—great in class or locally for learning, not something to expose as-is in production.

Section 3: Type Inspector

What you learn: practical differences between JS types that often confuse beginners (e.g. `object` vs `null`, arrays, etc.).

  • Enter JSON and get type metadata (`typeof`, array/null, object tags)

Link between Dashboard and Playground

Both require login and a valid token; both use the same API base (`NEXT_PUBLIC_API_BASE_URL`, with a typical localhost fallback). If you break the auth contract (`Authorization: Bearer …`), both stop working.

In short: the Dashboard verifies that the frontend–backend–auth bridge is in place; the Playground uses that bridge for React/JS exercises safely on your machine.

Key message for beginners

The project does not aim for enterprise perfection: it shows in a linear way the building blocks of a modern web app—client and server JWT authentication, protected API calls, session handling in the frontend, solid React basics and debugging.

Technology stack

  • Frontend: Next.js 14 and React 18 (`web/package.json`).
  • Backend: Express, Mongoose, JWT, bcryptjs, cors, dotenv (`api/package.json`).
  • Database: MongoDB 7 (Docker).
  • Dev tooling: nodemon on the API; minimal Next config (`web/next.config.js`).

For a step-by-step path (exercise order, what to try on Dashboard and Playground), use the README in the ZIP together with this section.

Anteprima

Esempi visivi del pacchetto; le schermate definitive possono variare in base alla versione inclusa nello ZIP.

In arrivo
In arrivo
In arrivo

Quick start

ZIP download is not active yet. Here you see how startup is designed and what you will explore locally; README and FAQ will be in the package on release.

Bring up the stack with Docker Compose from the root of the repository extracted from the ZIP, then open the frontend, log in and walk Dashboard and Playground in the same mental order: first verify auth and API, then experiment in the React lab.

High-level steps

  1. With Docker installed, from the project root: `docker compose up --build` and wait until frontend, API and MongoDB are ready.
  2. Open the frontend in the browser (URL in the README), verify API health if indicated.
  3. Sign in with the sample credentials from the README (created on first start).
  4. Dashboard: check `/api/v1/me`, `/health`, invalid token and logout.
  5. Playground: React mini-lab, Function Runner (educational context only), Type Inspector.
  6. For CORS, API base URL, unreachable Mongo or busy ports, use the README and FAQ in the ZIP.

When download is active, the README in the ZIP will include commands, URLs, sample credentials and common questions: here only the high-level path remains.