Skip to content
Back to the blog
  • MongoDB
  • Express
  • React
  • NodeJS
  • Docker

OliBase Odyssey

The Saga of Building a Backend as a Service (BaaS) in MERN: Where Code Becomes Architecture

The journey began not with a *bug*, but with a developer's existential crisis. For months on end, immersion in the MERN Stack (MongoDB, Express, React, Node) had been methodical and successful. Courses, documentation, and small portfolio projects were completed with Swiss watch precision. However, a cold, cutting truth hung in the air: "I still hadn't built something big enough to force me to make difficult decisions."

The problem wasn't a lack of knowledge, but the absence of a challenge that would force the transition from "knowing how to do" to "knowing how to architect." The ambition was clear: to go beyond the tutorial, embrace the chaos of refactoring, make mistakes, correct them, and finally, understand the soul of *backend* decisions. It was in this scenario of searching for a greater technical purpose that the idea of OliBase ascended, like a digital phoenix.

The Call of Architecture: The BaaS Inspiration (Phase 1)

The inspiration came from the giants that simplify the universe of development: BaaS (Backend as a Service), such as the ubiquitous Firebase and the elegant Supabase. These platforms solve complex problems—authentication, data management, security—with almost magical ease. So I, fascinated by this abstraction, launched the ultimate challenge:

"What if I tried to build something that replicated this complexity, from scratch, using MERN? Not to compete in the market, but to force a deep learning experience, where each line of code was an architectural lesson?"

OliBase was born, then, as a technical manifesto. A minimal, elegant, and above all, honest BaaS, where the Backend would be the absolute protagonist, demanding mastery of each layer of the *stack*.

The First Labyrinth: The Separation of Identities (Phases 2 and 3)

The first obstacle was not technical, but conceptual: authentication. In a BaaS system, there are actually two classes of users, and mixing them would be a fatal design flaw. The critical perception was that:

  • Authentication for the dashboard (the "human user" who manages the BaaS) is one thing.

  • Authentication for end users (the customers of the applications that use the BaaS) is something completely different.

This distinction imposed the need for two isolated authentication systems. The first step was the implementation of Human Auth, the administrative foundation. It was here that JWT (JSON Web Token) was employed to protect the routes, ensuring that only legitimate administrators could create projects and generate access keys. A solid foundation, without which the house of cards would collapse.

The Great Test: Creating the Multi-Tenant Universe (Phase 4)

OliBase could not be just a data repository; it needed to be a universe of isolated data. The golden rule was true multi-tenancy. This means that if Project Alpha and Project Beta use OliBase, Alpha's data must be absolutely invisible to Beta, and vice versa. The technical question was the most crucial:

"How to guarantee the strict separation of data from different applications, even if they share the same physical database?"

The answer was the creation of the Project model and the linking of API Keys to each one. Isolation was transformed into a protocol requirement, requiring each data request to carry two mandatory *headers*, like a passport and a visa:

  1. x-api-key: The secret key that identifies the application.

  2. x-project-id: The unique identifier of the project.

Membership validation became the most rigorous *middleware* in the system. The mental test that guided this phase was the security mantra: "If someone, by mistake or bad faith, tries to use the key of one project to access data from another, the system MUST fail categorically and immediately." It was at this point that true isolation was consolidated, elevating OliBase to the level of a production system.

The Voice of Conscience: Logging and Observability (Phases 5 and 6)

With security established, it was time to give OliBase a voice. A complex system needs observability, the ability to know what is happening in real time. Before building the complete database, a simple KV (Key-Value) system was implemented to validate the data flow and, more importantly, Logging.

The Logging Middleware was the solution. It was not a luxury, but an auditing necessity. Designed to be asynchronous and non-blocking, it recorded the duration, status code, and route of each request, but with a golden rule: never record sensitive *payloads*. From that moment on, OliBase gained a memory, allowing the developer to see, in real time, the pulsating life of their creation. The project ceased to be mere code and became a "product" with self-auditing capabilities.

The Inflection Point: End-User Authentication (Phases 7 and 8)

The real trial by fire came with the implementation of End-User Auth. The complexity was exponential: the system needed to manage the identity of users who, although they might have the same email, belonged to completely different data universes (projects). The architectural decision was brutally elegant:

  • The end user is always a citizen of a project.

  • A JWT and a Secret completely separate from the dashboard authentication were created.

  • The end-user JWT carries, inseparably, the projectId, ensuring that they can only interact with their own universe.

Endpoints like POST /api/auth/signup and POST /api/auth/login were just the tip of the *iceberg*. The real engineering was in the Critical Validations: the API Key had to be valid, belong to the project, and, most importantly, the email had to be unique within that specific project. After a battery of tests that simulated the chaos of the real world, the result was a real multi-tenant Auth working, a triumph that validated the entire isolation architecture.

The Crown of Security: Row Level Security (RLS) (Phases 9 and 10)

A BaaS without a robust data system is just an authentication system. The implementation of the Data Layer, with dynamic Collections and Documents, required the application of an advanced concept: Row Level Security (RLS). Inspired by the most sophisticated database systems, RLS is the security layer that ensures that the user only sees what they are allowed to see.

The access rules were like universal laws of OliBase:

  1. The Common User (the application's end customer) can only see and manipulate the documents they created themselves (identified by the ownerId).

  2. The project Admin (the dashboard user) has a panoramic view, being able to see everything within their project.

  3. Projects remain in absolute isolation, with no chance of data crossing.

The testing phase focused on negative cases: the attempt by User A to spy on User B's data, or the audacity of Project A to access Project B's database. Success was measured by the correct failure of these attempts. OliBase proved to be not just a data repository, but a guardian of privacy and multi-tenant isolation.

The Baptism of Fire: The Reality of Correction (Phase 11)

The most learning-rich part of any project is the moment when theory meets failure. The crucible of learning came with the discovery of a subtle bug: the administrator *Role* was not being saved correctly on *signup*. This was not a syntax error, but a flow logic error.

The correction required surgical intervention: a tweak to the signup, an explicit validation in the user creation flow, and a complete refactoring of the authorization *middleware*. "This is real backend," was the conclusion. The failure proved that the system was not magical, but the result of meticulous engineering work, where each error was transformed into a stronger foundation.

Closing the Circle: The Dashboard and Eventum (Phases 12, 13 and 14)

To manage this architectural complexity, the Dashboard was built in React, in an act of self-reference: it consumed OliBase's own API. With a minimalist cyberpunk and *mobile-first* design, it was the command center for managing Projects, End Users, Collections, RLS, and, most vitally, viewing Logs in real time.

The development cycle was completed with Eventum, a real client application. Eventum was not a portfolio project; it was the living proof that OliBase worked. It performed:

  • User authentication via OliBase.

  • CRUD operations protected by RLS.

  • Generation of logs visible in the dashboard.

The final validation was a chorus of success: OliBase functional, Eventum functional, RLS working, Isolation working. The project left the realm of theory and established itself as a functional and robust reality.

The Legacy: Proof That You Build Systems (Phase 15)

What started as a search for a study project has transformed into a complex system that touches on all the pillars of modern software engineering.

The code, this work of engineering, will be made available under an open source license, and the journey has been documented on video, serving as a beacon for other developers seeking the transition from tutorial to architecture.

If you are passionate about backend, system architecture, or the power of the MERN Stack, this project is an invitation to a deep technical conversation.

Odyssey Resources:

Demonstration Video (Proof of Concept): OliBase - Complete Architecture Demonstration

Open Source Repository (The Open Code): OliBase Source Code