A modern Node.js REST API template with TypeScript, automatic documentation, and comprehensive tooling setup.
This project was originally built for the ModelVault take-home assignment but has evolved into a comprehensive Node.js API template. The assignment required building a lightweight local REST API for offline AI prompt processing, which served as the foundation for this well-structured, production-ready template.
- Node.js + TypeScript: Chosen for rapid development, strong typing, and excellent ecosystem
- Express.js: Lightweight, battle-tested web framework with minimal overhead
- Zodios: Type-safe API contracts with automatic OpenAPI generation - eliminates manual documentation
- Vitest: Fast, modern testing framework with excellent TypeScript support
- Contract-first API design: Using Zodios for type-safe endpoints and automatic documentation
- Layered architecture: Controller β Service pattern for clean separation of concerns
- OpenAPI integration: Auto-generated documentation at
/api-docs
with custom content-type handling - Path aliases: TypeScript path mapping for clean imports (
@src/
)
- ESLint + Prettier: Code quality and consistent formatting
- TypeScript strict mode: Maximum type safety
- ts-node: Direct TypeScript execution for development
- tsc-alias: Resolves TypeScript path aliases in compiled output
- Node.js 18+
- npm or yarn
- Docker and Docker Compose (for local Ollama setup)
npm install
Copy the example environment file and configure as needed:
cp .env.example .env
Edit .env
to customize settings:
LOGS_DIR
: Directory for log files (default:logs
)OLLAMA_BASE_URL
: Base URL for Ollama API (required, example:http://localhost:11434
)OLLAMA_MODEL
: Default AI model to use (required, example:llama3.2:1b
)
The service features an hourly rotating log system that automatically creates new log files each hour. All API interactions are logged to JSONL files with the following naming pattern:
logs/log-YYYY-MM-DD-HH.jsonl
Examples:
logs/log-2025-07-10-09.jsonl
(for 9 AM)logs/log-2025-07-10-10.jsonl
(for 10 AM)logs/log-2025-07-10-23.jsonl
(for 11 PM)
Each log entry contains:
timestamp
: ISO 8601 timestampinput
: The user's promptoutput
: The generated response
Start the Ollama service using Docker:
# Start Ollama in the background
docker-compose up -d
# Pull the model specified in your .env file (default: llama3.2:1b)
docker exec -it offline-prompt-ollama ollama pull llama3.2:1b
# Alternative models (choose one based on your needs and update OLLAMA_MODEL in .env):
# docker exec -it offline-prompt-ollama ollama pull gemma2:2b # 2GB model
# docker exec -it offline-prompt-ollama ollama pull qwen2.5:1.5b # 1.5GB model
Important: Make sure to update your .env
file with the correct OLLAMA_MODEL
value matching the model you pulled.
Verify Ollama is running:
curl http://localhost:11434/api/tags
Test Prompt to ensure Ollama is working properly:
curl -X POST http://localhost:11434/api/generate -H "Content-Type: application/json" -d \
'{"model": "llama3.2:1b", "prompt": "Say hi", "stream": false}'
npm run dev
Server starts at http://localhost:3000
# Run all tests
npm test
# Manual API testing
# Visit http://localhost:3000/api-docs for interactive documentation
# Code quality
npm run lint
npm run format
# Production build
npm run build && npm start
Once running, visit:
- Homepage:
http://localhost:3000
- Service overview with links - API Docs:
http://localhost:3000/api-docs
- Interactive Swagger UI - OpenAPI Spec:
http://localhost:3000/api-docs/openapi.json
- Raw specification
The project includes comprehensive testing setup:
- Unit tests for services and controllers
- API contract validation
- Documentation generation tests
Run with: npm test
src/
βββ api/ # API modules organized by feature
β βββ root/ # Homepage/health check endpoint
β βββ root.contract.ts # Zodios API contract
β βββ root.controller.ts # Request handlers
β βββ root.service.ts # Business logic
βββ app.ts # Express app configuration
βββ openapi.ts # OpenAPI spec generation
βββ index.ts # Server entry point
test/ # Test files mirroring src structure
tsconfig.json # TypeScript configuration
vitest.config.ts # Test configuration
See package.json
for complete list. Key commands:
npm run dev
- Development server with TypeScriptnpm test
- Run test suitenpm run build
- Production buildnpm start
- Run production buildnpm run lint
- Code lintingnpm run format
- Code formattingdocker-compose up -d
- Start Ollama servicedocker-compose down
- Stop Ollama service
The project uses Vitest for testing with:
- Unit tests for services and controllers
- API contract validation
- Type-safe test utilities
β What's Included:
- REST API foundation with Express + TypeScript
- Type-safe contracts with automatic documentation
- Clean, modular architecture
- Comprehensive testing setup
- Interactive API documentation
- Development tooling (linting, formatting, building)
- Path aliases for clean imports
- Clone or fork this repository
- Update
package.json
with your project details - Start Ollama with
docker-compose up -d
and pull a model - Modify the root endpoint in
src/api/root/
or create new API modules - Add your business logic in the service layer
- Write tests in the
test/
directory - Build and deploy
The Docker configuration is optimized for Mac Mini M1 with <2GB RAM usage:
- Memory limit: 2GB max, 512MB reserved
- Single model loading: Only one model loaded at a time
- Parallel processing: Limited to 1 for memory efficiency
- Flash attention: Enabled for better performance
- Persistent storage: Models are stored in a Docker volume
Recommended models for low-memory usage:
llama3.2:1b
(~1GB) - Best balance of performance and sizegemma2:2b
(~1.4GB) - Good performance, slightly largerqwen2.5:1.5b
(~1.1GB) - Efficient alternative
This template provides a solid foundation for building modern, type-safe REST APIs with excellent developer experience.
This template was created to fulfill the ModelVault API assignment, which calls for:
- A local REST API with
/generate
endpoint for prompt processing - Offline operation (no cloud APIs)
- JSON logging to
logs/log.jsonl
- Clean, modular code structure
The template exceeds the assignment requirements by providing a full development framework with testing, documentation, and modern tooling.