A Node.js/Express backend service for ingesting and storing comprehensive test execution results with detailed test case analytics.
- Comprehensive Test Data - Ingest and store test suites
- MVC Architecture - Clean separation of concerns with routes, controllers, services, and models
- API Token Authentication - Secure Bearer token authentication
- Idempotent Ingestion - Safe retries with duplicate detection
- Real-time Metrics - Track API usage with auto-updating counters
- Rate Limiting - 100 requests per 15 minutes per IP
- MongoDB Storage - Scalable document-based storage
- Node.js (v14 or higher)
- MongoDB (local or Atlas)
- npm or yarn
# Clone the repository
git clone <repository-url>
cd test-result-ingetion-backend
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Edit .env with your MongoDB connection string
# PORT=3002
# MONGODB_URI=mongodb://localhost:27017
# DB_NAME=test_analyticsnpm run devnpm startnpm testGET /health
GET /metrics
Returns real-time API usage statistics.
POST /orgs
Content-Type: application/json
{
"name": "My Organization"
}
POST /projects
Content-Type: application/json
{
"org_id": "org_xyz",
"name": "My Project"
}
POST /tokens
Content-Type: application/json
{
"project_id": "proj_xyz",
"name": "CI-Token",
"token" : "tap...".
"message" : "API token created successfully. Save this token - it will not be shown again!"
}
POST /ingest
Authorization: Bearer <token>
Content-Type: application/json
{
"run_id": "tr_test_001",
"environment": "staging",
"timestamp": "2026-01-12T10:00:00.000Z",
"summary": {
"total_test_cases": 8,
"passed": 5,
"failed": 2,
"flaky": 1,
"skipped": 0,
"duration_ms": 15420
},
"test_suites": [
{
"suite_name": "Authentication Tests",
"total_cases": 3,
"passed": 2,
"failed": 1,
"duration_ms": 5200,
"test_cases": [
{
"name": "should login with valid credentials",
"status": "passed",
"duration_ms": 1800,
"steps": 3,
"error_message": null
}
]
}
]
}
run_id- Unique identifier withtr_prefix (e.g.,tr_test_123)environment- Execution environment (e.g.,staging,production)timestamp- ISO 8601 timestampsummary- Test execution summary objecttest_suites- Array of test suites (can be empty)
total_test_cases- Total number of test casespassed- Number of passed testsfailed- Number of failed testsflaky- Number of flaky testsskipped- Number of skipped testsduration_ms- Total execution time in milliseconds
suite_name- Name of the test suitetotal_cases- Number of test cases in suitepassed- Passed tests in suitefailed- Failed tests in suiteduration_ms- Suite execution timetest_cases- Array of test case objects
name- Test case namestatus-passed,failed,flaky, orskippedduration_ms- Execution timesteps- Number of test steps (optional)error_message- Error details if failed (null if passed)
src/
βββ controllers/ # HTTP request/response handling
β βββ organization.controller.js
β βββ project.controller.js
β βββ token.controller.js
β βββ testRun.controller.js
β βββ metrics.controller.js
βββ services/ # Business logic
β βββ organization.service.js
β βββ project.service.js
β βββ token.service.js
β βββ testRun.service.js
βββ middleware/ # Request processing
β βββ auth.middleware.js
β βββ validation.middleware.js
βββ models/ # Data models
β βββ organization.model.js
β βββ project.model.js
β βββ apiToken.model.js
β βββ testRun.model.js
βββ utils/ # Helpers
β βββ response.util.js
βββ routes/ # Route definitions
β βββ routes.js
βββ config/ # Configuration
β βββ db.config.js
βββ test/ # Test scripts
β βββ manual-test.js
β βββ test-client.js
β βββ mockTestData.js
βββ server.js # Express app setup
Docs/ # Documentation
βββ CURL_COMMANDS.md # API testing commands
βββ IMPLEMENTATION_SUMMARY.md # Technical implementation details
The API uses Bearer token authentication:
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:3002/ingest \
-d '{ ... }'Tokens are:
- Generated per project
- Permanent (no expiration)
- Hashed in database using bcrypt
- Shown only once upon creation
Track API usage in real-time:
curl http://localhost:3002/metricsResponse:
{
"uptime_seconds": 1234,
"counters": {
"requests_total": 0,
"orgs_created": 5,
"projects_created": 10,
"tokens_created": 8,
"test_runs_ingested": 150,
"duplicate_runs_rejected": 12,
"errors": 0
},
"timestamp": "2026-01-12T11:53:53.000Z"
}Metrics automatically update when:
- Organizations are created
- Projects are created
- Tokens are generated
- Test runs are ingested
- Duplicate runs are detected
We chose simple in-memory counters for this project to provide immediate, zero-configuration observability.
- Simplicity: No need to set up external monitoring stacks (Prometheus, Grafana) for basic health checks.
- Real-time: Instant feedback on ingestion rates and error counts.
- Lightweight: Minimal performance overhead compared to complex instrumentation.
- Sufficiency: For many deployments, knowing the current failure/success counts since the last restart is sufficient for operational awareness.
npm testRuns comprehensive integration tests including:
- Organization creation
- Project creation
- Token generation
- Test run ingestion
- Idempotency verification
- Authentication validation
- Input validation
node src/manual-test.jsInteractive testing utility for individual endpoints.
Test run ingestion is idempotent using the run_id:
- First ingestion: Returns
201 Created - Duplicate ingestion: Returns
200 OKwithduplicate: true - Safe for retries
The CPU.
The current authentication implementation uses bcrypt to verify tokens on every request. bcrypt is intentionally computationally expensive (CPU intensive) to resist brute-force attacks.
In a single-threaded Node.js environment, a 10x increase in authenticated traffic would likely cause the Event Loop to block while computing hashes, leading to high latency and eventual timeouts (503 Service Unavailable), even if the database is fine.
Database Sharding. MongoDB can handle millions of documents and high throughput on a single replica set. Sharding introduces significant operational complexity (balancing chunks, query routing). It is better to scale vertically (larger instances) or optimize indexes first. Sharding should only be considered when the working set exceeds RAM or write throughput hits single-node limits.
- Metrics Reset: Since metrics are in-memory, they reset to zero whenever the server restarts or re-deploys.
- No Token Revocation: Once issued, a token is valid forever until deleted from the database. There is no expiry mechanism.
Create a .env file with:
PORT=3002
MONGODB_URI=mongodb://localhost:27017
DB_NAME=test_analytics- Start MongoDB
- Install dependencies:
npm install - Create
.envfile with your MongoDB URI - Start server:
npm run dev - Run tests:
npm test - Check health:
curl http://localhost:3002/health
- CURL Commands - Complete API testing guide
- Implementation Summary - Deep dive into architecture and features
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB
- Validation: Custom middleware
- Architecture: MVC pattern
MIT
Contributions welcome! Please follow the MVC architecture pattern.
Built with β€οΈ for better test analytics