high‐level system design - Project-MRP/finance-tracker GitHub Wiki
Certainly! Here's a high-level system design for an expense manager mobile application, considering both the backend and frontend components, as well as how they interact.
Client driven UI: offline mode YES, dynamic UI changes NO Server driven UI: offline mode NO, dynamic UI changes YES
1. Overview of the System
The system can be divided into the following key components:
- Mobile App (Frontend)
- Backend Services (API Layer)
- Database Layer
- Authentication and Authorization
- Notifications Service
- Data Analytics and Reporting
- Cloud Infrastructure and Deployment
2. Mobile App (Frontend)
- Platforms: iOS and Android (possibly built using a cross-platform framework like Flutter or React Native).
- Primary Responsibilities:
- User Interface: Allows users to log in, manage accounts, view transactions, and generate reports.
- Local Data Storage: For offline access to recent transactions, accounts, and categories.
- API Integration: Communicates with the backend services for data synchronization, account management, and user authentication.
- Data Visualization: Displays charts and graphs for income/expense tracking.
- Notifications: Integrates with push notification services to remind users about transactions or updates.
3. Backend Services (API Layer)
- Framework: Node.js, Django, or Flask (any web framework that suits your team's expertise).
- Primary Responsibilities:
CRUD operations for: User Account Transaction Category
Statistics is dynamic, hence every time this has to computed whether locally or cloud. Cases: localDB - Data Y => Compute locally, sync data to cloudDB localDB - Data N, cloudDB - data Y => fetch data from cloudDb, sync data to localDB localDB - Data N, cloudDB - data N => Case of no Data
Case: Network issue while syncing
Specific API calls:
Sign in/ Sign up page [USER] createUser Email (Email + password) Phone (OTP Based) Google Auth (no password) Facebook Auth Apple Auth Twitter Auth logInUser Dashboard page (OFTEN VISITED) [USER, TRANSACTION] getUser Title Profile settings => route to settings getTrendsCard Tiles/Cards getTrendsChart Recent trends chart Add transaction page (OFTEN VISITED) [TRANSACTION, CATEGORY, ACCOUNT] CRUD for a transaction All transactions page (OFTEN VISITED) [TRANSACTION, CATEGORY, ACCOUNT] Periodical views (drop down) Daily view Monthly view Annual view Period view Calendar view Search Bar Stats (OFTEN VISITED) [TRANSACTION, CATEGORY, ACCOUNT] Pie chart: allocation of money Trends chart (RE-VISIT) based on Income, Expense, Transfer Week Monthly Annual Period Trends chart based on Category Week Monthly Annual Period Account page (NOT OFTEN VISITED) [ACCOUNT] Income, Expense, Balance of each accounts maintained Maintaining accounts (can be added here) Settings page (NOT OFTEN VISITED) [CATEGORY, ACCOUNT, USER] Category (CRUD) Accounts (CRUD) Default option for: Type of transaction, Category, Account User Delete user CRUD photo, name, email, phone (Can be provided in the Dashboard) Log out user Add security : PIN/face/fingerprint Add a remainder (notifications)
- User Management: Handles user registration, login, and profile management.
- Account Management: Manages user accounts (e.g., savings, checking) and provides CRUD operations for them.
- Transaction Management: Handles creation, updating, and deletion of transactions, including categorization and linking to accounts.
- Category Management: Allows users to create, update, or delete custom categories.
- Reporting Service/Statistics: Generates reports based on user transactions and provides insights like monthly expenses or income distribution.
- Synchronization Service: Handles data synchronization between the mobile app and the server when the user comes online.
4. Database Layer
- Type: Document-based NoSQL database (e.g., MongoDB) or a combination with a relational database (e.g., PostgreSQL).
- Primary Collections/Tables:
- Users: Stores user details, authentication information, and preferences.
- Accounts: Stores account details such as name, type, balance, and currency.
- Transactions: Stores transaction records, linking them to users, accounts, categories, and transaction types.
- Categories: Stores both system-defined and user-defined categories.
- Transaction Types: Stores types of transactions (e.g., Income, Expense, Transfer).
5. Authentication and Authorization
- OAuth2/OpenID Connect: Integrate with OAuth providers (e.g., Google, Facebook) for easy user registration and login.
- JWT (JSON Web Tokens): Use JWT for secure and stateless authentication between the mobile app and backend services.
6. Notifications Service
- Push Notifications: Use services like Firebase Cloud Messaging (FCM) for Android and Apple Push Notification Service (APNS) for iOS to send notifications to users.
- Event-Driven Notifications: Trigger notifications based on certain events, such as a low account balance, large transactions, or monthly spending reports.
7. Data Analytics and Reporting
- Analytics Engine: Use a dedicated service or third-party tool (e.g., Google Analytics, Mixpanel) for tracking user behavior, generating insights, and reporting.
- Batch Processing: Use tools like Apache Kafka or AWS Lambda for processing large volumes of transactions to generate monthly or yearly reports.
8. Cloud Infrastructure and Deployment
- Platform: Consider using cloud providers like AWS, Google Cloud, or Azure.
- Components:
- Load Balancer: Distributes traffic across multiple instances of the backend services.
- Auto-Scaling: Automatically adjusts the number of backend instances based on traffic.
- CDN (Content Delivery Network): Speeds up content delivery to mobile apps.
- API Gateway: Manages and secures API requests.
- Data Storage: Use cloud-based storage for backups and large datasets (e.g., AWS S3).
- Monitoring and Logging: Implement monitoring with tools like Prometheus, Grafana, or AWS CloudWatch for real-time insights and logging.
9. Security Considerations
- Encryption: Encrypt sensitive data both at rest (in the database) and in transit (between the app and backend).
- Data Privacy: Ensure compliance with data protection regulations (e.g., GDPR, CCPA) depending on the app's user base.
- Regular Security Audits: Perform periodic security audits to identify and mitigate potential vulnerabilities.
10. API Design
- RESTful API: Design RESTful endpoints to handle various operations:
- /api/v1/users: For user management.
- /api/v1/accounts: For account management.
- /api/v1/transactions: For transaction management.
- /api/v1/categories: For category management.
- /api/v1/reports: For generating reports and analytics.
11. Data Synchronization
- Real-Time Sync: Implement WebSocket or Server-Sent Events (SSE) for real-time data synchronization between the mobile app and backend.
- Offline Sync: Use local databases like SQLite in mobile apps to store data offline and sync when the device is online.
12. Scaling and Performance
- Database Sharding: Implement sharding in your database to handle large volumes of transactions.
- Cache Layer: Use caching mechanisms (e.g., Redis) to store frequently accessed data like user profiles or recent transactions.
- Rate Limiting: Implement rate limiting on APIs to prevent abuse and ensure fair usage.