chains-api/
│
├── 📂 tests/ # All test files (organized)
│ ├── 📂 unit/ # Unit tests for modules
│ │ ├── dataService.test.js # 31 tests
│ │ └── rpcMonitor.test.js # 14 tests
│ │
│ ├── 📂 integration/ # Integration/API tests
│ │ └── api.test.js # 19 tests
│ │
│ ├── 📂 fixtures/ # Reusable test data
│ │ └── README.md
│ │
│ ├── 📂 helpers/ # Test utilities
│ │ └── README.md
│ │
│ └── 📄 README.md # Tests overview
│
├── 📂 node_modules/ # Dependencies (gitignored)
│
├── 📂 coverage/ # Test coverage reports (gitignored)
│
├── 📄 index.js # Main API server (Fastify)
├── 📄 dataService.js # Data loading & indexing
├── 📄 rpcMonitor.js # RPC endpoint monitoring
├── 📄 mcp-server.js # MCP server (stdio)
├── 📄 mcp-server-http.js # MCP server (HTTP)
│
├── 📄 package.json # Project config & scripts
├── 📄 package-lock.json # Dependency lock file
├── 📄 vitest.config.js # Test configuration
│
├── 📄 TESTING.md # Testing guide (updated)
├── 📄 TEST_SUMMARY.md # Test results summary
├── 📄 PROJECT_STRUCTURE.md # This file
│
├── 📄 README.md # Project documentation
└── 📄 .gitignore # Git ignore rules
- Separation of concerns - Tests separated from source code
- Easy navigation - Clear hierarchy (unit/integration/fixtures/helpers)
- Scalable - Easy to add new test files in appropriate directories
- Industry standard - Follows common Node.js project structure
- Clear purpose - Each directory has a specific role
- Documented - README in each directory explaining its purpose
- Easy to find tests - All in
tests/directory - Filtered test runs - Run unit or integration tests separately
- Reusable code - Fixtures and helpers prevent duplication
- Selective testing - Run only unit tests in CI for speed
- Clear reporting - Test output shows directory structure
- Coverage tracking - Easy to see which modules need more tests
Purpose: Test individual functions in isolation
Speed: Fast (< 10ms per file)
Mocking: Heavy (mock all external dependencies)
Coverage: Internal logic, data transformations
Purpose: Test API endpoints end-to-end
Speed: Moderate (100-500ms per file)
Mocking: Minimal (test real interactions)
Coverage: Request/response cycles, error handling
Purpose: Reusable test data
Usage: Import in multiple test files
Examples: Mock chains, endpoints, responses
Purpose: Test utility functions
Usage: Common setup/teardown, assertions
Examples: Server setup, mock factories
npm test # All 64 testsnpx vitest run tests/unit # Unit tests only (45 tests)
npx vitest run tests/integration # Integration tests only (19 tests)npx vitest run tests/unit/dataService.test.js # 31 tests
npx vitest run tests/unit/rpcMonitor.test.js # 14 tests
npx vitest run tests/integration/api.test.js # 19 testsnpm run test:watch # Auto-rerun on changesnpm run test:coverage # Generate coverage report<module>.test.js- Unit tests<feature>.test.js- Integration tests- Location:
tests/unit/ortests/integration/
<data-type>.fixture.js- Location:
tests/fixtures/ - Export: Named exports
<purpose>.helper.js- Location:
tests/helpers/ - Export: Named exports
<module>.js- Source code- Location: Project root
- Pattern: camelCase
import { function } from '../../module.js'; // Source code
import { mockData } from '../fixtures/data.fixture.js'; // Fixture
import { helper } from '../helpers/util.helper.js'; // Helperimport { function } from '../../module.js'; // Source code
import { mockData } from '../fixtures/data.fixture.js'; // Fixture- 64 tests across 3 files
- Organized directory structure
- Unit and integration tests
- Documentation
- Add fixtures for common test data
- Add helpers for server setup
- Increase coverage to 80%+
- Add performance tests
- E2E tests with real data sources
- Load testing
- Security testing
- Mutation testing
| File | Purpose |
|---|---|
| TESTING.md | Complete testing guide |
| TEST_SUMMARY.md | Test results & coverage |
| tests/README.md | Test directory overview |
| tests/fixtures/README.md | Fixtures guide |
| tests/helpers/README.md | Helpers guide |
| PROJECT_STRUCTURE.md | This file |
✅ Separation of Concerns
- Tests separated from source code
- Unit tests separated from integration tests
✅ DRY Principle
- Fixtures for reusable data
- Helpers for common utilities
✅ Single Responsibility
- Each test file tests one module
- Each test case tests one behavior
✅ Clear Naming
- Descriptive file names
- "should X when Y" test names
✅ Documentation
- README in each directory
- Inline comments where needed
# Development
npm start # Start API server
npm run dev # Start with auto-reload
# Testing
npm test # Run all tests
npm run test:watch # Watch mode
npm run test:coverage # Coverage report
# MCP Servers
npm run mcp # Start MCP server (stdio)
npm run mcp:http # Start MCP server (HTTP)- Total Files: 11 source + 3 test files
- Total Tests: 64 tests (all passing ✅)
- Test Coverage: Unit (45) + Integration (19)
- LOC: ~2000+ lines of code
- Dependencies: Fastify, Vitest, MCP SDK
Structure Last Updated: 2025 All Tests Passing: ✅ 64/64