How cohuk/sudoku works
Project type and purpose
• This is a full-stack, containerized web application: a responsive Sudoku game with a static frontend (HTML/CSS/JS) and a Node.js/Express backend. It showcases modern build, containerization, and cloud-deployment practices on AWS Elastic Beanstalk behind Cloudflare.
File structure
• Top-level:
• Dockerfile, Dockerfile.production, docker-compose.yml, Dockerrun.aws.json → container/build/deploy
• .ebextensions/ → Elastic Beanstalk environment config
• scripts/ → build optimization, versioning, cloud deploy
• backend/server.js → Express server, RESTful API, session management
• frontend/ → static assets (index.html, script.js, style.css, critical.css)
• Patterns:
• Single Node service serving both API and static files
• Static assets built/optimized via scripts → minified CSS/JS and an optimized HTML variant
• Docker container as unit of deployment, AWS EB for orchestration, Cloudflare as CDN/SSL
Key insights from README
• Traffic flow: Internet → Cloudflare CDN → AWS Elastic Beanstalk → EC2 → Docker container
• No external database: sessions and game state are in‐memory / browser localStorage, with auto‐recovery
• Build & deploy pipeline: npm scripts & custom shell/Node scripts → Docker Hub → EB
Main components and their relationships
• User’s Browser (UI layer)
• Fetches static assets (HTML/CSS/JS) from Cloudflare edge
• Calls backend REST API for game operations (/api/new-game, /api/validate-move, etc.)
• Persists game state in localStorage and sends X-Session-ID on each request
• Cloudflare CDN
• Caches and serves static assets
• Terminates SSL, provides DNS/DDoS protection
• Forwards API calls to the EB load balancer
• AWS Elastic Beanstalk (Platform)
• Manages environment, auto-scaling, health checks
• Hosts an Application Load Balancer in front of EC2
• EC2 Instance(s)
• Runs Docker container(s) as defined by Dockerrun.aws.json / Dockerfile.production
• Docker Container
• Node.js runtime running backend/server.js
• Serves static files and REST endpoints
• Manages session store in memory (with recovery on restart)
• Build & Deployment Pipeline (external)
• scripts/build.js → generates optimized frontend artifacts
• scripts/version.sh → bumps version
• scripts/cloud_deploy.sh / npm run cloud-deploy → builds image, pushes to Docker Hub, triggers EB deploy
Architectural patterns & design principles
• Single-page (static) frontend served by same process via Express
• Stateless container: session info is ephemeral but persisted on client side; server recovers sessions gracefully
• Infrastructure as code: Dockerfiles, EB config, shell scripts for reproducible deploys
• Separation of concerns: static asset pipeline in scripts/, runtime in backend/, infra config in root