ShipFast Database Diagram
This diagram represents the structure of a NoSQL database (Firestore), showing relationships between four collections: users
, organizations
, user_organizations
, and subscriptions
. Below is the diagram of the schema:
Here's how it works:
1. users Collection
- Stores user information such as:
- id: Unique identifier for each user.
- email: User's email address.
- name: User's name.
- createdAt: Timestamp when the user was created.
- updatedAt: Timestamp when the user's details were last updated.
- status: Represents the user's current state (e.g., active, inactive).
2. organizations Collection
- Represents organizations, identified by an id.
- Contains fields such as:
- name: Name of the organization.
- description: A brief description of the organization.
- ownerId: Links to a user who owns the organization (from
users
collection). - status: Represents the organization's state (e.g., active, inactive).
- createdAt and updatedAt: Timestamps for creation and updates.
3. user_organizations Collection
- Acts as a linking collection to represent a many-to-many relationship between
users
andorganizations
. - Fields:
- id: Unique identifier for the relationship.
- organizationId: Links to an organization (from
organizations
collection). - userId: Links to a user (from
users
collection). - role: Defines the user's role within the organization (e.g., admin, member).
- jointedAt: Timestamp for when the user joined the organization.
4. subscriptions Subcollection
- This is a subcollection of
organizations
, meaning each organization can have its own set of subscriptions. - Fields:
- subscriptionId: Unique identifier for the subscription.
- organizationId: Links the subscription to its parent organization.
- customerId: Identifier for the customer associated with the subscription.
- priceId: Represents the pricing plan or tier for the subscription.
- scheduleId: Specifies the billing schedule for the subscription.
- defaultPaymentMethod: Store billing and pricing details.
- latestInvoiceId: Identifier for the most recent invoice related to the subscription.
- email: Contact email for the subscription.
- eventType: Type of event (e.g., downgraded, upgraded, cancelled, subscribed).
- interval: Billing interval (e.g., monthly, yearly).
- metadata: Stores custom metadata for the subscription.
- credits: Total credits available for the subscription, which determine the amount of resources or services the subscription provides.
- creditsUsed: The number of credits consumed so far by the subscription.
- freeCredits: Additional credits granted for free.
- status: Current status of the subscription.
- billingStartDate and billingEndDate: Track the billing period.
- createdAt: Timestamp for when the subscription was created.
Relationships:
-
users ↔ organizations:
- A many-to-many relationship, represented using the
user_organizations
collection. - A user can belong to multiple organizations, and an organization can have multiple users.
- A many-to-many relationship, represented using the
-
organizations ↔ subscriptions:
- A one-to-many relationship where
subscriptions
is a subcollection oforganizations
. - Each organization can manage its own subscriptions independently.
- A one-to-many relationship where