A full-stack application for selling farm-fresh eggs, featuring a Go 1.25 GraphQL backend and a modern React TypeScript frontend with a beautiful, responsive UI.
- π₯ Product Catalog: Browse different types of eggs with prices and availability
- π Shopping Cart: Add items to cart, adjust quantities, and checkout
- π³ Real-time Inventory: Automatic inventory updates after purchases
- π¨ Modern UI: Beautiful, responsive design with TailwindCSS
- π GraphQL API: Efficient data fetching with Apollo Client
- π³ Docker Support: Easy deployment with multi-stage builds
- π Security Scanning: TruffleHog integration for secret detection
- π CI/CD Pipeline: Automated testing and deployment with CircleCI
- Go 1.22+: High-performance backend
- gqlgen: GraphQL server implementation
- CORS Support: Cross-origin resource sharing enabled
- React 18: Modern UI framework
- TypeScript: Type-safe development
- Vite: Fast build tool and dev server
- Apollo Client: GraphQL client
- TailwindCSS: Utility-first CSS framework
- Lucide React: Beautiful icon library
- Go 1.22 or higher
- Node.js 20 or higher
- npm or yarn
- Clone the repository:
git clone https://github.com/jkzilla/egg.git
cd egg- Install backend dependencies:
go mod download- Install frontend dependencies:
cd frontend
npm install
cd ..- Run in development mode:
In one terminal, start the backend:
go run .In another terminal, start the frontend dev server:
cd frontend
npm run devThe backend will run on http://localhost:8080 and the frontend on http://localhost:5173
The application provides a GraphQL API with the following features:
Get all eggs:
query {
eggs {
id
type
price
quantityAvailable
description
}
}Get a specific egg by ID:
query {
egg(id: "1") {
id
type
price
quantityAvailable
description
}
}Purchase eggs:
mutation {
purchaseEgg(id: "1", quantity: 6) {
success
message
remainingQuantity
}
}Query all eggs:
curl -X POST http://localhost:8080/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ eggs { id type price quantityAvailable description } }"}'Purchase eggs:
curl -X POST http://localhost:8080/graphql \
-H "Content-Type: application/json" \
-d '{"query":"mutation { purchaseEgg(id: \"1\", quantity: 6) { success message remainingQuantity } }"}'Visit http://localhost:8080/playground in your browser to access the GraphQL Playground, where you can interactively explore the API and test queries.
The application comes pre-loaded with sample products:
- Half Dozen Eggs - $4.00 (20 available)
- Dozen Eggs - $7.50 (15 available)
For a complete guide on deploying the frontend to Netlify and backend to cloud platforms, see:
π NETLIFY_DEPLOY.md - Complete deployment guide with step-by-step instructions
Quick Start:
- Deploy backend to Render or Railway
- Deploy frontend to Netlify
- Set
VITE_GRAPHQL_ENDPOINTenvironment variable on Netlify - Update CORS settings in backend
Build and run the full-stack application with Docker:
# Build the image
docker build -t egg-shop .
# Run the container
docker run -p 8080:8080 egg-shopThe application will be available at http://localhost:8080
docker-compose upTo build the frontend and backend separately:
# Build frontend
cd frontend
npm run build
# Build backend
go build -o egg .
# Run
./eggegg/
βββ frontend/ # React TypeScript frontend
β βββ src/
β β βββ components/ # React components
β β βββ graphql/ # GraphQL queries and mutations
β β βββ App.tsx # Main app component
β β βββ main.tsx # Entry point
β β βββ types.ts # TypeScript types
β βββ public/ # Static assets
β βββ package.json # Frontend dependencies
βββ graph/ # GraphQL schema and resolvers
β βββ schema.graphqls # GraphQL schema definition
β βββ resolver.go # Resolver implementation
β βββ model/ # Generated models
βββ main.go # Application entry point
βββ server.go # HTTP server and routing
βββ Dockerfile # Multi-stage Docker build
If you modify the GraphQL schema in graph/schema.graphqls, regenerate the code:
go run github.com/99designs/gqlgen generateThe server port can be configured using the PORT environment variable:
PORT=3000 go run .The frontend uses Vite for fast development with hot module replacement:
cd frontend
npm run dev # Start dev server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLint
npm run test:e2e # Run E2E tests (headless)
npm run test:e2e:ui # Run E2E tests with UI
npm run test:e2e:headed # Run E2E tests in browserThe project includes five comprehensive UI tests using Playwright:
- Page Load Test - Verifies the page loads and displays egg products
- Add to Cart Test - Tests adding items to the shopping cart
- Cart Display Test - Validates cart sidebar opens and shows items
- Quantity Update Test - Tests updating item quantities in cart
- Clear Cart Test - Verifies clearing all items from cart
Setup E2E Tests:
cd frontend
npm install
npx playwright install chromium
npm run test:e2eView Test Report:
npx playwright show-report/- Frontend application (production)/graphql- GraphQL API endpoint/playground- GraphQL Playground (interactive API explorer)
This project uses CircleCI for continuous integration and deployment. The pipeline includes:
Automated Checks:
- π Security scanning with TruffleHog
- π§ͺ Backend unit tests with coverage reports
- βοΈ Frontend build and linting
- π Integration tests for GraphQL API
- π³ Docker image builds and testing
Pipeline Stages:
- Security Scan - Detects secrets and credentials
- Parallel Builds - Backend and frontend build simultaneously
- Integration Tests - End-to-end API validation
- Docker Build - Multi-stage container build (main/master/develop only)
Setup CircleCI:
- Connect your repository at circleci.com
- Add Docker Hub credentials (optional):
DOCKER_USERNAMEDOCKER_PASSWORD
- Pipeline runs automatically on every push and PR
See .circleci/README.md for detailed configuration documentation.
This project uses TruffleHog to scan for accidentally committed secrets, API keys, and credentials.
Install TruffleHog using the provided script:
./scripts/install-trufflehog.shOr install manually:
macOS (Homebrew):
brew install trufflehogLinux/macOS (curl):
curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sh -s -- -b /usr/local/binScan the entire repository:
trufflehog git file://. --only-verifiedScan since last commit:
trufflehog git file://. --since-commit HEAD --only-verifiedSet up automatic scanning before each commit:
# Install pre-commit
pip install pre-commit
# Install the hooks
pre-commit install
# Run manually on all files
pre-commit run --all-filesTruffleHog runs automatically on:
- Every push to
main,master, ordevelopbranches - Every pull request
- Manual workflow dispatch
View results in the Actions tab on GitHub.
TruffleHog settings are in .trufflehog.yaml:
- Excluded paths (node_modules, dist, etc.)
- Excluded file extensions
- Verification settings
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Note: All commits are scanned for secrets. Ensure no sensitive data is committed.
This project is licensed under the MIT License.