SuperTokens architecture
SuperTokens uses a three-tier architecture designed to provide maximum flexibility, security, and developer experience. This page explains how the components work together.Overview
The SuperTokens architecture consists of three main components:This documentation covers SuperTokens Core - the HTTP service that provides the authentication logic and database operations.
Component details
1. Frontend SDK
Purpose: Manages client-side authentication state and provides UI components Responsibilities:- Stores session tokens (access and refresh tokens)
- Automatically refreshes expired access tokens
- Renders pre-built UI components for login, signup, etc.
- Handles CSRF protection
- Communicates with your Backend SDK
- React.js
- React Native
- Vue.js
- Angular
- Vanilla JavaScript
- iOS (Swift)
- Android (Kotlin)
- Flutter
2. Backend SDK
Purpose: Exposes authentication APIs for your frontend to call Responsibilities:- Provides authentication endpoints (signup, signin, signout, etc.)
- Session verification middleware
- Communicates with SuperTokens Core for auth operations
- Integrates with your existing backend framework
- Handles API key authentication with Core
- Node.js (Express, Fastify, Hapi, Koa, Loopback, AWS Lambda)
- Python (FastAPI, Flask, Django)
- Go (net/http, Gin, Mux)
- .NET (coming soon)
3. SuperTokens Core (this project)
Purpose: Centralized authentication service with database management Responsibilities:- Core authentication logic
- User database operations
- Session creation and verification
- Token signing and rotation
- Password hashing
- Multi-tenancy management
- Recipe (authentication method) implementation
- Self-hosted (Docker, binary, from source)
- Managed hosting (SuperTokens cloud)
4. Database
Purpose: Persistent storage for users, sessions, and authentication data Supported databases:- PostgreSQL 11+
- MySQL 5.7+
- MongoDB 4.2+
- SQLite (development only)
Request flow
Let’s trace a typical authentication request through the architecture:Sign-up flow
Core processes request
- Validates email format
- Hashes password (BCrypt or Argon2)
- Checks for duplicate user
- Creates user in database
- Returns user ID and status
Session verification flow
Frontend makes authenticated request
Frontend SDK automatically includes access token in request headers
Backend middleware verifies token
Most session verification happens locally in the Backend SDK without calling Core. The SDK verifies the JWT signature using cached public keys.
Performance optimization: Session verification is designed to be extremely fast. In most cases, the Backend SDK verifies JWTs locally without contacting SuperTokens Core, enabling the Core to handle hundreds of thousands of users with a single instance.
Deployment models
Model 1: Self-hosted Core
- Complete data control
- No external dependencies
- Works in air-gapped environments
- Custom compliance requirements
Model 2: Managed Core (SuperTokens cloud)
- Managed infrastructure
- Automatic scaling
- High availability
- Regular updates
Scaling strategies
Horizontal scaling
Multiple Core instances can run behind a load balancer:All Core instances must connect to the same database. The database becomes the single source of truth for all authentication state.
Database scaling
Read replicas: For read-heavy workloadsconfig.yaml
Multi-tenancy architecture
SuperTokens Core has built-in multi-tenancy support with a hierarchical structure:- Single tenant:
http://localhost:3567/recipe/signup - Multi-tenant:
http://localhost:3567/appid-abc/tenantid-xyz/recipe/signup
Security considerations
Network security
Recommended setup:API key authentication
Configure API keys inconfig.yaml:
Token signing
Core uses dynamic signing key rotation by default:- New signing keys generated every 168 hours (configurable)
- Old keys retained for verification
- JWT tokens include
kid(key ID) for verification
Learn more
Session management
Deep dive into how sessions work
Multi-tenancy
Learn about apps and tenants
Self-hosting
Deploy SuperTokens Core
API reference
Explore the HTTP APIs