A full-stack application that generates word clouds from random words fetched from an external API. The frontend displays words with sizes based on their frequency and assigns each word a unique color.
The word cloud uses a simple scaling function to determine font sizes:
const getFontSize = (count, minCount, maxCount) => {
const minSize = 12;
const maxSize = 64;
if (maxCount === minCount) return minSize;
const ratio = (count - minCount) / (maxCount - minCount);
return minSize + (maxSize - minSize) * ratio;
};What this does:
- Takes each word's frequency count
- Finds the minimum and maximum counts across all words
- Calculates where this word falls between min and max (the ratio)
- Maps that ratio to a font size between 12px and 64px
- Result: More frequent words get bigger font sizes
Example: If a word appears 100 times and the range is 10-100, it gets the maximum size (64px). A word appearing 10 times gets the minimum size (12px).
The backend fetches 6000 random words from an external API efficiently using batching and concurrency:
Batching:
- Instead of making 6000 individual requests, we split them into batches of 600
- This means 10 batches total (6000 ÷ 600 = 10)
- Reduces overhead and is easier to manage
Concurrency:
- Within each batch, all 600 requests run at the same time using
Promise.all() - We don't wait for one request to finish before starting the next
- This is much faster than doing them one by one
Why this approach:
- Making 6000 requests at once would overwhelm the system
- Making them one at a time would take forever
- Batches of 600 concurrent requests is a good balance
- Each batch completes before starting the next one
The result: We can fetch 6000 words in seconds instead of minutes.
Prerequisites:
- Docker Desktop installed and running
Steps:
- Navigate to the project directory:
cd E:\src- Start the application:
docker-compose up --build-
Access the application:
- Frontend: http://localhost:5173
- Backend API: http://localhost:3000
-
To stop:
- Press
Ctrl+Cin the terminal
- Press
Prerequisites:
- Node.js 18 or higher installed
- npm installed
Backend:
- Navigate to backend directory:
cd E:\src\word-cloud-gen-backend- Install dependencies:
npm install- Start the server:
npm run devThe backend will run on http://localhost:3000
Frontend:
- Open a new terminal and navigate to frontend directory:
cd E:\src\word-cloud-gen-frontend- Install dependencies:
npm install- Start the development server:
npm run devThe frontend will run on http://localhost:5173
- Open http://localhost:5173 in your browser
- Click the "Get Words" button
- Wait a few seconds while the backend fetches 6000 random words
- The word cloud will display with:
- Larger words appearing more frequently
- Each word in a unique color
- Words rotated horizontally or vertically
E:\src\
├── word-cloud-gen-backend/ # Express API
│ ├── src/
│ │ ├── server.ts # Main server file
│ │ └── services/
│ │ └── word-api.ts # Word fetching logic
│ ├── Dockerfile
│ └── package.json
│
├── word-cloud-gen-frontend/ # React app
│ ├── src/
│ │ ├── App.tsx # Main component
│ │ └── App.css # Styles
│ ├── Dockerfile
│ └── package.json
│
└── docker-compose.yml # Docker orchestration
- Backend: Node.js, Express, TypeScript
- Frontend: React, TypeScript, Vite
- Containerization: Docker, Docker Compose
- External API: https://random-word-api.vercel.app
- Fetches 6000 random words from external API
- Calculates word frequency
- Dynamic font sizing based on frequency
- Unique persistent color for each word
- Horizontal and vertical word rotation
- Responsive design
- Dockerized for easy deployment