System Architecture
6 min read
2026-08-10

Case Study: Designing a Zero-Trust 3-Tier Architecture with Isolated Microservices & Firebase

MJ
Muhammad Jahaanzeb
AI Automation & SaaS Developer
"Why embedding database credentials in frontend apps is a security vulnerability, and how to build a 3-isolated-service architecture (Frontend, Admin, Backend) on independent ports."

Executive Summary

A common anti-pattern in modern web development is embedding database credentials (like Firebase or Supabase keys) directly inside client-side single-page applications. Even with database security rules, exposing direct database sockets to public client bundles increases surface-area vulnerabilities and couples client code directly to database schemas.

To solve this, I designed a 3-Tier Decoupled Microservice Architecture for a Daily Checklist & Management platform. The architecture segregates the Frontend Client, Admin Audit Portal, and Backend Database Gateway into three completely isolated services running on independent ports.


The Core Rule: Zero-Trust Database Isolation

The foundational rule of this architecture is strict separation of concerns:

  1. 1.Service 1 (Frontend App): Handles user authentication, checklist management, and item toggles with zero database credentials.
  2. 2.Service 2 (Admin Panel): Handles user auditing, checklist inspection, and platform metrics with zero database credentials.
  3. 3.Service 3 (Backend API): The sole service holding Firebase Firestore credentials, SDK initializations, and database access logic.

Architecture Communication Topology

CODE_SNIPPETUTF-8
+------------------------------------+       +------------------------------------+
| SERVICE 1: FRONTEND APP            |       | SERVICE 2: ADMIN PANEL             |
| - User Login / Signup              |       | - User & Checklist Audit Views     |
| - Daily Checklist CRUD UI          |       | - Firebase Admin Auth              |
| - Runs on Port 3000 (No DB Keys)   |       | - Runs on Port 3001 (No DB Keys)   |
+------------------------------------+       +------------------------------------+
                  │                                             │
                  │ HTTP REST Requests                          │ HTTP REST Requests
                  └──────────────────────┬──────────────────────┘
                                         │
                                         ▼
                      +------------------------------------+
                      | SERVICE 3: BACKEND API             |
                      | - Express.js Gateway Controller    |
                      | - Holds Firebase Admin SDK Keys    |
                      | - Runs on Port 5000                |
                      +------------------------------------+
                                         │
                                         │ Native Admin SDK Connection
                                         ▼
                      +------------------------------------+
                      | FIREBASE FIRESTORE DATABASE        |
                      | - Protected Isolated Data Store    |
                      +------------------------------------+

Key Technical Features

1. Enforcing Proxy API Communication

Neither the Frontend nor the Admin panel connects to Firestore directly. All data mutation requests follow a strict proxy pattern:

  • Creating a Checklist Item:Frontend AppPOST /api/checklists/itemBackend API (Validation)Firestore Insert
  • Admin User Inspection:Admin PanelGET /api/admin/users-summaryBackend API (Auth Check)Firestore Query
JAVASCRIPT_SNIPPETUTF-8
// Express.js Backend API Controller (Sole Database Gateway)
const express = require('express');
const router = express.Router();
const { db } = require('../config/firebaseAdmin'); // Firestore initialized ONLY here

// Protected Route for Fetching User Checklists
router.get('/api/checklists/:userId', async (req, res) => {
  try {
    const { userId } = req.params;
    
    // Server-side query execution
    const snapshot = await db.collection('checklists')
      .where('userId', '==', userId)
      .get();

    const checklists = snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
    return res.status(200).json({ success: true, data: checklists });
  } catch (error) {
    return res.status(500).json({ success: false, error: error.message });
  }
});

module.exports = router;

2. Frontend Checklist App

The client application focuses purely on user experience and state management:

  • Authentication: User signup and session persistence handled via token exchange with the Backend API.
  • Checklist Operations: Creating daily checklists, adding sub-items, and marking items complete via async REST API calls.

3. Isolated Admin Audit Portal

Built with Firebase Admin Authentication middleware running on its own dedicated port:

  • User Auditing: Lists all registered users across the platform inside a private view.
  • Checklist Inspection: Allows administrators to inspect checklists created by specific users to monitor engagement without exposing raw database connection strings to the admin frontend bundle.

Architectural Lessons Learned

  • Security Through Decoupling: Isolating database credentials inside a dedicated backend microservice prevents accidental API key leaks in client JavaScript bundles.
  • Simplified Maintenance: Because database schema logic is encapsulated inside the Backend service, database migrations or SDK updates do not require re-deploying or modifying the Frontend or Admin client applications.

Need an Architecture Built or Automated?

Let's discuss how n8n workflows, custom tool-calling agents, or a modern SaaS MVP can accelerate your business.