How madcoderzx/forms works
1. System purpose and entry points
This is a containerized form-builder system: authenticated users create and manage forms, anonymous users submit published forms, and owners review responses. Its primary architectural objective is also demonstrating a React/Express/PostgreSQL Docker deployment.
Runtime entry points are the React bootstrap at frontend/src/main.jsx, Express startup at backend/src/index.js and backend/src/server.js, and Compose orchestration in docker-compose.yml.
2. Browser application and routing
The frontend is a React 18/Vite single-page application rooted in frontend/src/App.jsx. It provides authentication pages, an owner dashboard/editor/response viewer, and an anonymous public-form page under frontend/src/pages/.
frontend/src/components/ProtectedRoute.jsx establishes the client-side access boundary for owner workflows. frontend/src/context/AuthContext.jsx holds authentication state for UI components. API calls are centralized through frontend/src/api/apiClient.js, keeping page components dependent on an API boundary rather than direct backend details.
3. Edge delivery and API proxy boundary
Production frontend assets are built and served by Nginx through frontend/Dockerfile and frontend/nginx.conf. Nginx is the browser-facing service and proxies API requests to the Express backend, separating static SPA delivery from application API execution.
The frontend build is multi-stage: Node/Vite produces static assets, while the final Nginx image contains only runtime assets. The browser uses the configured API URL, with Compose providing the container-network deployment path.
4. Express API composition
backend/src/app.js composes Express middleware and mounts route groups. backend/src/routes/auth.js owns registration, login, and current-user operations; backend/src/routes/forms.js owns protected form lifecycle operations; and backend/src/routes/publicForms.js exposes anonymous retrieval and response submission. backend/src/routes/health.js supports service health observation.
The API divides control flow into authenticated owner operations versus public form consumption. This is the principal authorization boundary, enforced by backend/src/middleware/auth.js before protected handlers.
5. Identity and authorization
User identity is persisted by backend/src/models/user.js. Login/register handlers issue and validate JWTs through backend/src/utils/jwt.js; the auth middleware resolves bearer-token identity for protected routes.
The JWT secret is an environment-level security dependency, not frontend state. The frontend auth context and protected-route layer improve navigation behavior, but backend middleware remains the authoritative access-control enforcement point.
6. Form-definition and submission data model
PostgreSQL is the durable system of record. The relational schema is initialized by database/init.sql; backend database connectivity is owned by backend/src/config/db.js.
The form model spans backend/src/models/form.js, backend/src/models/question.js, and backend/src/models/option.js: an owner creates a form and its structured questions/options. Submission flow uses backend/src/models/response.js, which records a public response and its answers. Public lookup is keyed by a public form identifier, while owner-facing form operations are tied to authenticated ownership.
7. Container runtime and infrastructure
docker-compose.yml runs three cooperating services: frontend, backend, and PostgreSQL 15. They communicate on the isolated Compose network; frontend-to-backend traffic passes through Nginx, and backend-to-database traffic uses the PostgreSQL service connection string.
backend/Dockerfile packages the Node/Express runtime. frontend/Dockerfile packages the static UI in Nginx. Compose-managed PostgreSQL persistence uses a named volume, while initialization SQL establishes the schema on a fresh database. Environment inputs represented by .env.example include backend port, database URL, JWT secret, and frontend API URL.
Main entry points: app.js Express app · forms.js Owner form routes · db.js Database client · docker-compose.yml Docker Compose
Components 18
Browser & Edge
- React SPA · Owner and public form UI.
frontend/src/App.jsx - Auth state & guards · Maintains session UI state and owner navigation boundary.
frontend/src/context/AuthContext.jsx - API client
frontend/src/api/apiClient.js - Nginx edge · Serves the SPA and proxies API traffic.
frontend/nginx.conf
Express API
- Express app · Mounts middleware and route groups.
backend/src/app.js - Auth routes · Registration, login, and current-user endpoints.
backend/src/routes/auth.js - Owner form routes · Authenticated form lifecycle and response review.
backend/src/routes/forms.js - Public form routes · Anonymous form lookup and submission.
backend/src/routes/publicForms.js - Auth middleware · Resolves bearer-token identity before owner handlers.
backend/src/middleware/auth.js - JWT utility · Issues and validates login tokens using the environment secret.
backend/src/utils/jwt.js
Data & Identity
- Database client
backend/src/config/db.js - User model
backend/src/models/user.js - Form definition models · Forms, questions, and options owned by authenticated users.
backend/src/models/form.js - Response model · Stores public responses and answers.
backend/src/models/response.js - PostgreSQL 15 · Persists users, form definitions, and submissions.
database/init.sql
Container Runtime
- Docker Compose · Runs frontend, backend, and database on an isolated network.
docker-compose.yml - Frontend image · Builds Vite assets and runs only Nginx at runtime.
frontend/Dockerfile - Express runtime · Starts the Express API service.
backend/src/server.js
Connections 25
- React SPA → Auth state & guards: uses
- React SPA → API client: requests through
- Auth state & guards → API client: supplies session
- API client → Nginx edge: browser API traffic
- Nginx edge → Express app: proxies /api
- Express app → Auth routes: mounts
- Express app → Owner form routes: mounts
- Express app → Public form routes: mounts
- Owner form routes → Auth middleware: requires
- Auth middleware → JWT utility: validates token
- Auth routes → JWT utility: issues tokens
- Auth routes → User model: manages users
- Owner form routes → Form definition models: manages definitions
- Owner form routes → Response model: reviews responses
- Public form routes → Form definition models: loads published form
- Public form routes → Response model: records submission
- User model → Database client: queries via
- Form definition models → Database client: queries via
- Response model → Database client: queries via
- Database client → PostgreSQL 15: connects
- Docker Compose → Frontend image: runs frontend service
- Docker Compose → Express runtime: runs backend service
- Docker Compose → PostgreSQL 15: runs persistent database
- Frontend image → Nginx edge: packages
- Express runtime → Express app: starts