A modern React TypeScript application for inventory management, built with Create React App, TanStack Query, and Tailwind CSS.
- React 19 with TypeScript for type safety
- TanStack Query for efficient data fetching and caching
- Tailwind CSS for modern, responsive UI design
- MSW (Mock Service Worker) for API mocking in development and testing
- Vitest for comprehensive testing
- Docker support for containerization
- Pods Architecture for scalable code organization
- React 19.1.1
- TypeScript 4.9.5
- TanStack Query 5.87.4
- Tailwind CSS 3.4.17
- MSW 2.0.0
- Vitest 3.2.4
- React Testing Library 16.3.0
- Node.js 18+
- npm or yarn
- Docker (optional)
- Backend API running on port 3002 (for full functionality)
-
Clone the repository
git clone <repository-url> cd inventory-frontend
-
Install dependencies
npm install
-
Start the development server
npm start
-
Open your browser Navigate to http://localhost:3001
Development:
docker-compose --profile dev up --buildProduction:
docker-compose --profile prod up --buildCreate a .env file with:
# Frontend Configuration
HOST_PORT=3001
PORT=3001- Frontend: http://localhost:3001
Build the production image:
docker build -t inventory-frontend .Run the production container:
docker run -p 3001:80 inventory-frontendBuild the development image:
docker build -f Dockerfile.dev -t inventory-frontend-dev .Run the development container:
docker run -p 3001:3001 -v $(pwd):/app -v /app/node_modules inventory-frontend-dev# Run all tests
npm run test:vitest:run
# Run tests in watch mode
npm run test:vitest
# Run tests with UI
npm run test:vitest:ui
# Run tests with coverage
npm run test:vitest:coverage
# Run traditional Jest tests
npm testThe project includes comprehensive test coverage:
- Unit Tests: Components, hooks, and utilities
- Integration Tests: Full component flows
- MSW Integration: API mocking for consistent testing
src/
βββ common/ # Shared components and utilities
β βββ components/ # Reusable UI components
β βββ constants/ # Application constants
βββ infra/ # Infrastructure layer
β βββ product.repository.ts
β βββ product.dto.ts
βββ pods/ # Feature-based modules
β βββ product/ # Product management feature
β βββ components/ # Product-specific components
β βββ __tests__/ # Product tests
β βββ *.tsx # Product containers and hooks
βββ test/ # Testing utilities
β βββ mocks/ # MSW handlers and responses
β βββ utils.tsx # Test utilities
βββ App.tsx # Main application component
npm start- Start development servernpm run build- Build for productionnpm run eject- Eject from Create React App
npm test- Run Jest testsnpm run test:vitest- Run Vitest testsnpm run test:vitest:ui- Run Vitest with UInpm run test:vitest:run- Run Vitest oncenpm run test:vitest:coverage- Run tests with coverage
Create a .env file in the root directory:
REACT_APP_API_URL=http://localhost:3002The backend URL is now completely configurable at build time with no hardcoded defaults, making it perfect for Kubernetes deployments with ConfigMaps.
Copy env.example to .env and configure your backend URL:
cp env.example .env
# Edit .env with your backend URL - this is REQUIREDImportant: The REACT_APP_API_URL environment variable is required - no defaults are provided.
Build with a specific backend URL:
# Using the build script
./build-with-env.sh production "http://backend-service:3000"
# Or directly with Docker
docker build \
--build-arg REACT_APP_API_URL="http://backend-service:3000" \
--build-arg NODE_ENV=production \
-t inventory-frontend:production .The application is designed to work with Kubernetes ConfigMaps. See k8s-config-example.yaml for configuration examples.
Important: React applications require environment variables at build time, not runtime. The backend URL gets compiled into the JavaScript bundle during the build process.
For CI/CD pipelines, you can pass the backend URL as a build argument:
# Example GitHub Actions or GitLab CI
- name: Build Docker image
run: |
docker build \
--build-arg REACT_APP_API_URL="${{ env.BACKEND_URL }}" \
--build-arg NODE_ENV=production \
-t inventory-frontend:${{ github.sha }} .Or using the provided build script:
./build-with-env.sh production "$BACKEND_URL"-
Build the application
npm run build
-
Deploy the
buildfolder to your hosting service
-
Build the Docker image
docker build -t inventory-frontend . -
Deploy to your container orchestration platform
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Port already in use:
# Kill process on port 3001
npx kill-port 3001Docker build fails:
# Clean Docker cache
docker system prune -aTests fail:
# Clear npm cache
npm cache clean --force
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install