Technical Interview Assignment
Create a file processing system with two main components:
- An API server for file uploads and status monitoring
- A background processor that automatically processes files in the inbox folder
project-root/
├── data/
│ ├── inbox/ (uploaded files go here)
│ ├── processing/ (files being processed)
│ ├── completed/ (successfully processed)
│ └── failed/ (processing failed)
└── src/
├── api/ (API server code)
│ ├── server.ts
│ └── routes.ts
├── processor/ (Background processor code)
│ ├── worker.ts
└── shared/ (Shared code)
└── FileManager.ts
Handles external interactions through HTTP endpoints.
- Upload File
POST /api/upload
Content-Type: multipart/form-data
Body:
- file: (text file)
Response:
{
"message": "File uploaded successfully",
"filename": "example.txt",
"size": 1234
}
- Get System Status
GET /api/status
Response:
{
"inbox": number, // Files in inbox
"processing": number, // Files being processed
"completed": number, // Files completed
"failed": number // Files failed
}
- Get Processing Reports
GET /api/reports
Response:
{
"reports": ProcessingReport[]
}
Runs continuously to process files in the inbox folder.
- Periodically check inbox folder (e.g., every 30 seconds)
- Process one file at a time
- Move files through folders based on status
- Generate processing reports
- Handle errors appropriately
- Move file from
inbox
toprocessing
folder - Read and process file content:
- Count lines, words, characters
- Convert to uppercase
- Add timestamp
- Save processed file to
completed
folder - Generate processing report
- If any error occurs, move file to
failed
folder
class FileManager {
constructor(rootPath: string);
// Folder management
initialize(): Promise<void>;
getInboxFiles(): Promise<string[]>;
moveFile(filename: string, fromFolder: string, toFolder: string): Promise<void>;
// File operations
readTextFile(folder: string, filename: string): Promise<string>;
writeTextFile(folder: string, filename: string, content: string): Promise<void>;
// Status
getFolderCounts(): Promise<{
inbox: number;
processing: number;
completed: number;
failed: number;
}>;
}
interface ProcessingReport {
filename: string;
timestamp: string;
statistics: {
lines: number;
words: number;
characters: number;
};
processingTime: number;
}
- Initialize project:
mkdir file-processor
cd file-processor
npm init -y
- Install dependencies:
npm install express multer typescript ts-node @types/node @types/express @types/multer
- Running the System:
Start API Server:
npm run start:api
Start Background Processor:
npm run start:processor
-
Architecture (30%)
- Clean separation of components
- Proper file management
- Error handling
- Logging
-
API Implementation (35%)
- Proper file upload handling
- Status reporting
- Error handling
- Input validation
-
Background Processor (35%)
- Reliable file processing
- Proper queuing (one file at a time)
- Error recovery
- Report generation
- Start with the FileManager class
- Test file operations thoroughly
- Handle edge cases (empty files, large files)
- Add detailed logging
- Consider using PM2 or similar for process management
- Expected completion time: 2 hours
- Focus on core functionality first
- Add error handling and logging after basics work
You can test file upload using curl:
curl -F "[email protected]" http://localhost:3000/api/upload
Or using a simple HTML form:
<form action="/api/upload" method="post" enctype="multipart/form-data">
<input type="file" name="file" accept=".txt">
<input type="submit" value="Upload">
</form>