Database Schema
Relevant source files
The following files were used as context for generating this wiki page:
The Database Schema for the Fikak application defines how user profiles, social clubs, and community events are structured and persisted. The system relies on a NoSQL document-based structure (Firebase Firestore) to manage relationships between users and the organizations they belong to.
The schema is designed to support a multi-tenant environment where users can create or join multiple clubs, and these clubs can host specific events. The data layer is decoupled from the UI through a dedicated service layer that handles the mapping between Firestore documents and Dart objects.
Core Data Models
The application's data architecture is built around three primary entities: Users, Clubs, and Events. Each entity is represented by a class that includes methods for converting data to and from JSON formats suitable for database storage.
User Entity
The FikakUser model stores personal identification and preference data. It serves as the primary identifier for authentication and authorization within the system.
| Field | Type | Description |
|---|---|---|
uid | String | Unique identifier for the user (Primary Key) |
name | String | Display name of the user |
email | String | User's email address |
profile_pic | String | URL to the user's profile image |
Sources: lib/models/fikak_user.dart:1-20
Club Entity
Clubs represent the organizational unit within the application. They contain metadata about the group and maintain references to their members.
| Field | Type | Description |
|---|---|---|
id | String | Unique club identifier |
name | String | Name of the club |
description | String | Detailed information about the club's purpose |
admin_id | String | UID of the user who created/manages the club |
members | List | Collection of UIDs belonging to the club |
Sources: lib/models/club.dart:1-25
Event Entity
Events are time-bound activities hosted by clubs. They are linked to a specific club via a foreign key relationship.
| Field | Type | Description |
|---|---|---|
id | String | Unique event identifier |
club_id | String | ID of the parent club (Foreign Key) |
title | String | Name of the event |
date | DateTime | Scheduled time for the event |
location | String | Physical or virtual venue |
Sources: lib/models/event.dart:1-30
Entity Relationships
The following ER diagram illustrates the logical connections between the data entities. A user can be an administrator of multiple clubs and a member of many. Each club can host multiple events, but an event is owned by exactly one club.
The diagram shows the one-to-many relationship between Clubs and Events, and the many-to-many relationship between Users and Clubs (through membership).
Sources: lib/models/club.dart:10-15, lib/models/event.dart:5-12
Data Access and Transformation
The DatabaseService class acts as the mediator between the raw Firestore data and the application models. It implements specialized mapping functions to ensure type safety when retrieving documents.
Mapping Logic
The service uses "FromSnapshot" patterns to transform Firestore DocumentSnapshot objects into local model instances.
// Example of the mapping pattern used across the service
FikakUser _userDataFromSnapshot(DocumentSnapshot snapshot) {
return FikakUser(
uid: snapshot.id,
name: snapshot.data()['name'],
email: snapshot.data()['email'],
);
}
Sources: lib/services/database.dart:45-55
Transaction Flow
The sequence below demonstrates the data flow when a user retrieves club information, showing the transition from the Database Service to the Model layer.
The data flow ensures that the UI layer only interacts with strongly typed Dart objects rather than raw JSON or Map structures.
Sources: lib/services/database.dart:10-30, lib/models/club.dart:20-25
Database Collections
The Firestore implementation uses three top-level collections to organize data.
- users: Stores individual user profiles.
- clubs: Contains organization details and member arrays.
- events: Stores all scheduled activities across the platform.
Sources: lib/services/database.dart:5-8, README.md
Conclusion
The Fikak App database schema leverages a document-oriented structure that prioritizes membership-based access. By separating the data definitions in lib/models/ from the persistence logic in lib/services/database.dart, the architecture maintains a clear separation of concerns, allowing for scalable club and event management.