Spaces:
Sleeping
Sleeping
| { | |
| "entities": { | |
| "User": { | |
| "$schema": "http://json-schema.org/draft-07/schema#", | |
| "title": "User", | |
| "type": "object", | |
| "description": "Represents a user of the ZeppFusion AI application.", | |
| "properties": { | |
| "id": { | |
| "type": "string", | |
| "description": "Unique identifier for the User entity." | |
| }, | |
| "email": { | |
| "type": "string", | |
| "description": "Email address of the user.", | |
| "format": "email" | |
| }, | |
| "displayName": { | |
| "type": "string", | |
| "description": "Display name of the user." | |
| }, | |
| "creationDate": { | |
| "type": "string", | |
| "description": "Date and time the user account was created.", | |
| "format": "date-time" | |
| }, | |
| "lastLogin": { | |
| "type": "string", | |
| "description": "Date and time of the user's last login.", | |
| "format": "date-time" | |
| }, | |
| "theme": { | |
| "type": "string", | |
| "description": "The user's preferred theme.", | |
| "enum": [ | |
| "light", | |
| "dark", | |
| "system" | |
| ] | |
| } | |
| }, | |
| "required": [ | |
| "id", | |
| "email", | |
| "displayName", | |
| "creationDate" | |
| ] | |
| }, | |
| "ChatSession": { | |
| "$schema": "http://json-schema.org/draft-07/schema#", | |
| "title": "ChatSession", | |
| "type": "object", | |
| "description": "Represents a chat session between a user and one or more AI models.", | |
| "properties": { | |
| "id": { | |
| "type": "string", | |
| "description": "Unique identifier for the ChatSession entity." | |
| }, | |
| "userId": { | |
| "type": "string", | |
| "description": "Reference to User. (Relationship: User 1:N ChatSession)" | |
| }, | |
| "modelUsed": { | |
| "type": "string", | |
| "description": "The AI model used in this chat session (e.g., Gemini, ChatGPT 3)." | |
| }, | |
| "startTime": { | |
| "type": "string", | |
| "description": "Date and time the chat session started.", | |
| "format": "date-time" | |
| }, | |
| "endTime": { | |
| "type": "string", | |
| "description": "Date and time the chat session ended.", | |
| "format": "date-time" | |
| } | |
| }, | |
| "required": [ | |
| "id", | |
| "userId", | |
| "modelUsed", | |
| "startTime" | |
| ] | |
| }, | |
| "Message": { | |
| "$schema": "http://json-schema.org/draft-07/schema#", | |
| "title": "Message", | |
| "type": "object", | |
| "description": "Represents a single message within a chat session.", | |
| "properties": { | |
| "id": { | |
| "type": "string", | |
| "description": "Unique identifier for the Message entity." | |
| }, | |
| "chatSessionId": { | |
| "type": "string", | |
| "description": "Reference to ChatSession. (Relationship: ChatSession 1:N Message)" | |
| }, | |
| "sender": { | |
| "type": "string", | |
| "description": "Indicates who sent the message (e.g., user, Gemini, ChatGPT)." | |
| }, | |
| "content": { | |
| "type": "string", | |
| "description": "The text content of the message." | |
| }, | |
| "timestamp": { | |
| "type": "string", | |
| "description": "Date and time the message was sent.", | |
| "format": "date-time" | |
| } | |
| }, | |
| "required": [ | |
| "id", | |
| "chatSessionId", | |
| "sender", | |
| "content", | |
| "timestamp" | |
| ] | |
| } | |
| }, | |
| "auth": { | |
| "providers": [ | |
| "password", | |
| "anonymous" | |
| ] | |
| }, | |
| "firestore": { | |
| "structure": [ | |
| { | |
| "path": "/users/{userId}", | |
| "definition": { | |
| "entityName": "User", | |
| "schema": { | |
| "$ref": "#/backend/entities/User" | |
| }, | |
| "description": "Stores user profile data. Path-based ownership enables simple security rules.", | |
| "params": [ | |
| { | |
| "name": "userId", | |
| "description": "The unique identifier of the user." | |
| } | |
| ] | |
| } | |
| }, | |
| { | |
| "path": "/users/{userId}/chatSessions/{chatSessionId}", | |
| "definition": { | |
| "entityName": "ChatSession", | |
| "schema": { | |
| "$ref": "#/backend/entities/ChatSession" | |
| }, | |
| "description": "Stores chat session data for a specific user. Nested under users for ownership.", | |
| "params": [ | |
| { | |
| "name": "userId", | |
| "description": "The unique identifier of the user." | |
| }, | |
| { | |
| "name": "chatSessionId", | |
| "description": "The unique identifier of the chat session." | |
| } | |
| ] | |
| } | |
| }, | |
| { | |
| "path": "/users/{userId}/chatSessions/{chatSessionId}/messages/{messageId}", | |
| "definition": { | |
| "entityName": "Message", | |
| "schema": { | |
| "$ref": "#/backend/entities/Message" | |
| }, | |
| "description": "Stores messages within a chat session. Nested under chat sessions for data locality and ownership.", | |
| "params": [ | |
| { | |
| "name": "userId", | |
| "description": "The unique identifier of the user." | |
| }, | |
| { | |
| "name": "chatSessionId", | |
| "description": "The unique identifier of the chat session." | |
| }, | |
| { | |
| "name": "messageId", | |
| "description": "The unique identifier of the message." | |
| } | |
| ] | |
| } | |
| } | |
| ], | |
| "reasoning": "The Firestore structure is designed to ensure authorization independence, clarity, and scalability. User data is stored under `/users/{userId}`, providing path-based ownership, and chat sessions and messages are nested under the user for clear ownership and easy querying. Denormalization is avoided since the application use case fits a strict ownership model. This structure allows for simple and robust security rules based on `request.auth.uid` without requiring complex `get()` calls, thus ensuring atomic operations and ease of debugging. The structure also facilitates secure list operations, as each collection has a consistent security posture due to the path-based ownership and nested structure." | |
| } | |
| } |