Docker Infrastructure
Relevant source files
The following files were used as context for generating this wiki page:
The Docker infrastructure for the MuteTaxes project provides a containerized environment to support relationship-based authorization and data persistence. Its primary purpose is to orchestrate the core services required for the backend logic, specifically the OpenFGA server for authorization and a PostgreSQL database for application data.
The infrastructure ensures that developers can spin up the necessary external dependencies with consistent configurations, allowing the Node.js backend to interact with standardized APIs for identity and access management.
Sources: PLAN.md:16-20, PLAN.md:129-132
Core Components
The infrastructure consists of two primary external services defined within the Docker Compose orchestration layer.
Service Architecture
| Service | Purpose | Port |
|---|---|---|
| PostgreSQL | Primary relational database for User, Role, and Table metadata. | 5432 |
| OpenFGA | Authorization server used to store and evaluate relationship tuples. | 8080 |
Sources: PLAN.md:21-23, PLAN.md:133-136
The following diagram illustrates the relationship between the Docker-managed infrastructure and the application components:
Sources: PLAN.md:17-27, PLAN.md:133-136
OpenFGA Infrastructure Integration
The infrastructure supports a Fine-Grained Authorization (FGA) model. The backend interacts with the OpenFGA service via the @openfga/sdk.
Configuration and Model Loading
The system is designed to automatically verify and load the authorization model into the OpenFGA container if it is not already present. It reads the model definition from infra/openfga/model.fga.
- API URL: Managed via
OPENFGA_API_URL(typicallyhttp://localhost:8080). - Store Management: The backend creates an OpenFGA "Store" (e.g., named "mutetaxes") within the containerized service if one does not exist.
- Model Transformation: Uses
@openfga/syntax-transformerto convert DSL (Domain Specific Language) from the infrastructure directory into JSON format for the OpenFGA API.
Sources: backend/src/fga/fgaClient.ts:18-62, backend/package.json:16-17, backend/src/seed.ts:74-90
Tuple Management Flow
The following sequence diagram shows how the application interacts with the Docker-hosted OpenFGA server during a permission check:
Database Infrastructure
The PostgreSQL container serves as the persistent storage for the application's entity relationships that are not handled by FGA.
Persistence Logic
- ORM: Prisma is used to manage the schema and migrations against the PostgreSQL container.
- Data Seeding: A
seed.tsscript populates the database with initial users (super_admin), roles (superadmin), and default tables (clients,companies,invoices, etc.).
Sources: PLAN.md:18, backend/src/seed.ts:17-48
Database Connectivity Configuration
| Environment Variable | Description |
|---|---|
DATABASE_URL | Connection string for PostgreSQL (e.g., postgresql://postgres:postgres@localhost:5432/mutetaxes) |
OPENFGA_API_URL | Endpoint for the containerized OpenFGA server. |
Sources: PLAN.md:213-217, backend/src/fga/fgaClient.ts:13-16
Infrastructure Lifecycle
The lifecycle of the infrastructure is managed through standard Docker Compose commands.
- Deployment: Services are started using
docker compose up -dfrom theinfra/directory. - Initialization: Upon service availability, the backend runs Prisma migrations and a seed script to prepare both the SQL database and the FGA store.
- Connectivity: The backend waits for the infrastructure to be ready before listening on its configured port (default
5050).
Sources: PLAN.md:144-150, backend/src/index.ts:28-30
Summary
The MuteTaxes Docker infrastructure provides a localized, reproducible environment for testing relationship-based access control. By encapsulating PostgreSQL and OpenFGA, it offloads complex authorization logic to a specialized service while maintaining standard relational data in a secondary database. This dual-infrastructure approach allows the system to perform complex permission checks (can_read, can_write) based on relationship tuples stored in the OpenFGA container.
Sources: PLAN.md:5-10, PLAN.md:129-136