Introduction
What is Mongalayer?
Mongalayer is an abstraction layer between a MongoDB database and a TypeScript (JavaScript) client. It consist of a server @mongalayer/server package and client @mongalayer/client. The server package is responsible for validating schemas, enforcing access rules, and executing MongoDB operations. The client package is a lightweight HTTP client that communicates with the server.
It was created as a self-hosted replacement after MongoDB Atlas App Services deprecation, specifically its Data Model / Data Access Permissions parts and the ability to query MongoDB collections from a client application as you would in a Node.js environment.
It provides:
- Schema validation using Zod to ensure data integrity
- Role-based access control at the document and field level
- Full type safety from server to client
- A client SDK with a familiar API that mirrors the server-side MongoDB methods
- With support for batch operations and flexible request formatting
Use case
Mongalayer is designed for basic CRUD applications where access control and data integrity matter more than raw throughput. It is a good fit for admin panels, content management systems, multi-tenant platforms, and similar applications.
Architecture
Mongalayer utilizes the MongoDB Node.js driver to communicate with MongoDB. It does not handle authentication or authorization of incoming HTTP requests — that is your responsibility. Instead, Mongalayer focuses on data access control: once a request reaches Mongalayer, it determines what data the caller can read, create, update, or delete based on the access definitions you configure.
┌─────────────────────────┐ ┌──────────────────────────┐ ┌───────────┐
│ Client App │ ────> │ API Endpoint │ ────> │ MongoDB │
│ (+ @mongalayer/client) │ <──── │ (+ @mongalayer/server) │ <──── │ │
└─────────────────────────┘ └──────────────────────────┘ └───────────┘
Packages
Mongalayer is published under the @mongalayer scope with two packages:
General requirements
- TypeScript 5+ (recommended)
- Zod 4+
@mongalayer/server
The core server-side library. Initializes the Mongalayer instance, validates schemas, enforces access rules, and executes MongoDB operations.
Requirements
- Node.js 22+
- MongoDB Node.js driver 7+
@mongalayer/client
A lightweight HTTP client SDK that communicates with a Mongalayer server. Works in any JavaScript runtime with fetch.
Requirements
- JavaScript environment supporting
fetch