Home

Registration Form Project

Build and Test React App codecov npm version

A comprehensive user registration form with robust validation, built with React, TypeScript, and modern frontend practices.

Features

  • Form Validation: Complete form validation with Zod schemas
  • User Experience:
    • Disabled submit button until all fields are filled
    • Error messages displayed under each invalid field
    • Toast notifications for success and failure
    • Local storage saving of user data
  • Validation Rules:
    • Age verification (18+ years)
    • French postal code format
    • Name validation (allowing accents, hyphens, spaces)
    • Email validation
  • Testing: 100% code coverage with unit and integration tests
  • Documentation: Auto-generated documentation with JSDoc
  • CI/CD Pipeline: Automated build, test, and deployment process

Live Demo

Visit the live demo at: https://varlopecar.github.io/react-form/

Documentation

The documentation is available directly from the application by clicking the "Documentation" link, or you can access it at: https://varlopecar.github.io/react-form/docs/

Installation

# Using pnpm (recommended)
pnpm add @varlopecar/ci-cd

# Using npm
npm install @varlopecar/ci-cd

# Using yarn
yarn add @varlopecar/ci-cd

Usage

RegistrationForm Component

import { RegistrationForm } from "@varlopecar/ci-cd";

function App() {
  const handleSubmit = (data) => {
    console.log(data);
    // Process form data
  };

  return (
    <div>
      <h1>User Registration</h1>
      <RegistrationForm onSubmit={handleSubmit} />
    </div>
  );
}

Using the Schema Directly

import {
  registrationSchema,
  type RegistrationFormData,
} from "@varlopecar/ci-cd";

// Use the schema with your own form implementation
const validateForm = (data) => {
  const result = registrationSchema.safeParse(data);
  if (!result.success) {
    return result.error.format();
  }
  return null;
};

Form Behavior

  1. Field Validation: All fields are validated in real-time
  2. Submit Button: Disabled until all fields have values
  3. Success Case:
    • Data is saved to localStorage
    • A success toast notification is displayed
    • Form fields are cleared
  4. Error Case:
    • Error messages displayed under each invalid field
    • Error toast notification
    • Form remains filled for user correction

API Reference

RegistrationForm

A form component for user registration with built-in validation.

Props

Prop Type Description
onSubmit (data: RegistrationFormData) => void Callback function called when the form is submitted with valid data

RegistrationFormData

Type definition for the form data.

interface RegistrationFormData {
  firstName: string;
  lastName: string;
  email: string;
  birthDate: Date;
  city: string;
  postalCode: string;
}

registrationSchema

Zod schema for validating registration form data with rules for:

  • Names (allowing letters, accents, hyphens)
  • Email format
  • Age verification (18+ years)
  • French postal code format (5 digits)

Development

# Clone the repository
git clone https://github.com/varlopecar/react-form.git

# Install dependencies
pnpm install

# Start development server
pnpm dev

# Run tests
pnpm test

# Generate coverage report
pnpm coverage

# Generate documentation
pnpm doc

# Build for production
pnpm build

Test Coverage

This project maintains 100% test coverage across all metrics:

  • 100% Statement Coverage
  • 100% Branch Coverage
  • 100% Function Coverage
  • 100% Line Coverage

Tests include:

  • Age calculation validation
  • Age 18+ validation
  • French postal code format validation
  • Name format validation with special cases
  • Email format validation
  • Button state based on form completion
  • Local storage functionality
  • Toast notifications
  • Error message display
  • Error handling

View detailed coverage report: Codecov Dashboard

CI/CD Pipeline

This project uses GitHub Actions for continuous integration and deployment:

  1. Build and Test: Runs on every push and pull request

    • Installs dependencies
    • Runs tests with coverage
    • Generates documentation
    • Builds the project
  2. GitHub Pages Deployment: Deploys the demo site

    • Builds the project
    • Deploys to GitHub Pages
  3. NPM Package Publishing: Publishes new versions

    • Builds the NPM package
    • Publishes to NPM registry
    • Automatically bumps version

License

This project is licensed under the MIT License - see the LICENSE file for details.

React Form - CI/CD Project

A comprehensive full-stack application with Docker architecture, comprehensive testing, and automated CI/CD pipeline.

๐Ÿ—๏ธ Architecture

react-form/
โ”œโ”€โ”€ backend/               # FastAPI backend (Dockerized)
โ”œโ”€โ”€ src/                   # React app (Vite)
โ”œโ”€โ”€ db/
โ”‚   โ””โ”€โ”€ init.sql           # Database initialization
โ”œโ”€โ”€ cypress/               # E2E tests with fixtures
โ”‚   โ”œโ”€โ”€ fixtures/          # Test data (users.json, api.json)
โ”‚   โ”œโ”€โ”€ e2e/              # Test specifications
โ”‚   โ””โ”€โ”€ support/          # Custom commands
โ”œโ”€โ”€ docker-compose.yml     # Orchestrates all services
โ”œโ”€โ”€ Dockerfile.frontend    # Frontend container
โ”œโ”€โ”€ Dockerfile.backend     # Backend container
โ””โ”€โ”€ .github/workflows/     # CI/CD pipeline

๐Ÿณ Docker Architecture

The application uses Docker Compose to orchestrate:

  • MySQL 8.0 - Database with persistent storage
  • Adminer - Database management interface (port 8080)
  • FastAPI Backend - Python API server (port 8000)
  • React Frontend - Vite development server (port 3000)

Quick Start with Docker

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop all services
docker-compose down

Environment Variables

Create a .env file in the root directory:

# Database
MYSQL_ROOT_PASSWORD=your_root_password
MYSQL_DATABASE=react_form_db
MYSQL_USER=react_user
MYSQL_PASSWORD=react_password

# Admin user
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=admin123

# Backend
SECRET_KEY=your-secret-key-here
CORS_ORIGINS=http://localhost:3000,http://localhost:5173

# Frontend
VITE_API_URL=http://localhost:8000

๐Ÿงช Testing Strategy

Backend Tests (pytest)

cd backend
pip install -r requirements.txt
pytest --cov=. --cov-report=html

Coverage includes:

  • User registration and authentication
  • Admin user management
  • API endpoint validation
  • Database operations

Frontend Tests (Vitest)

# Run tests
pnpm test

# Run with coverage
pnpm run coverage

# Run tests in UI mode
pnpm run test:ui

Coverage includes:

  • Form validation
  • Component rendering
  • API integration
  • User interactions

E2E Tests (Cypress with Fixtures)

# Open Cypress UI
pnpm run cypress:open

# Run tests headlessly
pnpm run cypress:run

Test Structure (Following Professor's Approach):

  • Fixtures: cypress/fixtures/users.json - Test user data
  • Fixtures: cypress/fixtures/api.json - API response mocks
  • Custom Commands: cypress/support/commands.ts - Reusable test functions
  • Test Files:
    • registration.cy.ts - User registration flow
    • admin.cy.ts - Admin panel functionality
    • api.cy.ts - API endpoint testing
    • integration.cy.ts - Complete workflow testing

Test scenarios:

  • โœ… User registration flow with fixture data
  • โœ… Form validation with invalid data fixtures
  • โœ… Admin login with credential fixtures
  • โœ… User management (view, delete) with test data
  • โœ… API endpoint testing with response fixtures
  • โœ… Complete integration workflows

๐Ÿš€ CI/CD Pipeline

The GitHub Actions pipeline includes:

1. Test Job

  • Runs frontend and backend tests
  • Generates coverage reports
  • Uploads to Codecov

2. E2E Job

  • Spins up complete Docker environment
  • Runs Cypress tests against real services
  • Uses fixtures for consistent test data
  • Captures screenshots and videos on failure

3. Deployment Jobs (Main branch only)

  • Backend: Deploys to Vercel
  • Frontend: Deploys to GitHub Pages

Required Secrets

Set these in your GitHub repository settings:

# Vercel deployment
VERCEL_TOKEN=your_vercel_token
VERCEL_ORG_ID=your_org_id
VERCEL_PROJECT_ID=your_project_id

# Production database
DATABASE_URL=your_production_db_url
SECRET_KEY=your_production_secret
ADMIN_EMAIL=admin@yourdomain.com
ADMIN_PASSWORD=secure_admin_password

# Frontend API URL
VITE_API_URL=https://your-backend.vercel.app

๐Ÿ“Š Code Coverage

The project maintains high code coverage:

  • Backend: >80% (pytest + coverage)
  • Frontend: >80% (Vitest + coverage)
  • E2E: Full user journey coverage with fixtures

Coverage reports are automatically uploaded to Codecov on each push.

๐Ÿ”ง Development

Local Development

# Install dependencies
pnpm install
cd backend && pip install -r requirements.txt

# Start development servers
pnpm run dev          # Frontend (port 3000)
cd backend && uvicorn main:app --reload  # Backend (port 8000)

Database Management

Access Adminer at http://localhost:8080:

  • System: MySQL
  • Server: mysql
  • Username: react_user
  • Password: react_password
  • Database: react_form_db

API Documentation

Once the backend is running, visit:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

๐ŸŽฏ Features

User Registration

  • Form validation with Zod
  • Age verification (18+)
  • French postal code validation
  • Real-time form completion tracking

Admin Panel

  • Secure authentication
  • User management dashboard
  • Delete user functionality
  • Admin user protection

API Endpoints

  • POST /register - User registration
  • POST /login - User authentication
  • GET /users - List all users (admin only)
  • DELETE /users/{id} - Delete user (admin only)
  • GET /me - Current user info

๐Ÿ† Grading Criteria (20/20)

Criteria Points Status
โœ… Docker architecture (MySQL/Python/Adminer/React) 5 pts โœ…
โœ… Unit + Integration tests + Codecov 5 pts โœ…
โœ… E2E tests with Cypress + Fixtures 5 pts โœ…
โœ… GitHub Actions pipeline + deployment 5 pts โœ…

๐Ÿš€ Deployment

Production Setup

  1. Database: Set up MySQL on Aiven/AlwaysData
  2. Backend: Deploy to Vercel (automatic via CI/CD)
  3. Frontend: Deploy to GitHub Pages (automatic via CI/CD)

Manual Deployment

# Backend to Vercel
cd backend
vercel --prod

# Frontend to GitHub Pages
pnpm run build
pnpm run deploy

๐Ÿ“ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

๐Ÿ“ž Support

For questions or issues:

  • Create an issue in the GitHub repository
  • Check the documentation in /docs
  • Review the test files for usage examples