Introduction
ThinkJS is a Node.js web application framework that builds on Koa to provide an opinionated MVC architecture. It supports TypeScript, multiple databases, session management, caching, WebSockets, and scheduled tasks out of the box, targeting enterprise teams that need a batteries-included server-side framework.
What ThinkJS Does
- Provides an MVC architecture with controllers, models, views, and middleware
- Supports MySQL, PostgreSQL, SQLite, and MongoDB through a unified model layer
- Includes built-in session management, caching (file, Redis, Memcached), and i18n
- Offers WebSocket support, scheduled tasks (cron), and CLI command tools
- Generates project scaffolding and module structure via the think-cli tool
Architecture Overview
ThinkJS is built on Koa 2.x and extends it with an application loader that auto-discovers controllers, models, services, and middleware from the project's directory structure. The framework follows a multi-module pattern where each module has its own controllers, models, and views. Configuration is environment-aware with separate files for development, testing, and production. The ORM layer (think-model) abstracts database access with query builders and relationship support. Middleware follows Koa's onion model with framework-provided defaults for parsing, security, and logging.
Self-Hosting & Configuration
- Install think-cli globally and scaffold a new project with
thinkjs new - Configure database connections, cache backends, and session stores in
src/config/ - Place controllers in
src/controller/, models insrc/model/, and views inview/ - Use environment-specific config files (adapter.development.js, adapter.production.js) for staging and production
- Deploy with PM2 or any Node.js process manager; the framework supports cluster mode
Key Features
- Built on Koa 2.x with async/await throughout the entire stack
- Multi-module project structure for organizing large applications
- Unified model layer supporting relational and document databases
- Built-in scheduled tasks, WebSocket handling, and REST API generation
- TypeScript support with decorators for controller routing and validation
Comparison with Similar Tools
- NestJS — TypeScript-first framework with decorators and dependency injection; ThinkJS is more convention-based with a simpler learning curve
- Egg.js — Alibaba's enterprise Node.js framework with a similar plugin model; ThinkJS provides a more traditional MVC structure
- Express — minimal and unopinionated; ThinkJS adds MVC conventions, ORM, caching, and session management on top
- Koa — ThinkJS's foundation; ThinkJS adds application structure, auto-loading, and enterprise features that Koa leaves to the developer
FAQ
Q: Does ThinkJS support TypeScript? A: Yes. ThinkJS 3.x supports TypeScript with decorators for routing and full type checking across controllers, models, and services.
Q: Can I use ThinkJS for REST API development? A: Yes. Controllers can return JSON directly, and the framework includes request validation and CORS middleware for API development.
Q: How does ThinkJS handle database migrations? A: ThinkJS uses think-model for ORM but does not include a built-in migration tool. Use a separate migration library like knex migrations alongside the ThinkJS model layer.
Q: Is ThinkJS suitable for high-traffic applications? A: Yes. Built on Koa with async I/O and cluster mode support, ThinkJS handles concurrent connections efficiently and scales horizontally behind a load balancer.