# grishj/expense_tracker architecture

> Architecture diagram of the GitHub repository grishj/expense_tracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/grishj/expense_tracker
- Repository: https://github.com/grishj/expense_tracker

## Overview

##### Project type and purpose
- This is a full-stack mobile expense-tracking application:
- Frontend: React Native (Expo) mobile app for iOS/Android
- Backend: Node.js/Express REST API with Prisma ORM
- Purpose: Allow users to authenticate (email/password or social), record expenses by category, view interactive charts, and manage profiles.

##### File structure
- Top-level
- .expo/         → Expo configuration & settings
- README.md      → Project overview, features, setup
- backend/       → REST API project
- frontend/      → React Native mobile app
- backend/
- src/index.js  → Express app entry point
- src/routes/   → Route definitions (auth, categories, expenses, profile)
- src/middleware/authMiddleware.js → JWT validation
- src/utils/    → Token generation, Prisma client wrapper
- prisma/       → Database schema and migrations (init, schema with category, expense, user, profile fields)
- frontend/
- App.js, index.js → App launcher and navigation setup
- src/navigation/AppNavigator.js → Screen routing
- src/screens/   → UI screens: Login, Signup, Home, AddExpense, AllExpenses, Chart, Profile
- src/utils/     → api.js (Axios instance), auth.js (AsyncStorage token helpers)
- assets/        → images for UI

##### README for additional insights
- Lists features: authentication (JWT + social), expense CRUD, charts (react-native-chart-kit), pull-to-refresh, floating button
- Specifies backend endpoints and expected payloads
- Mentions technologies: React Native, React Navigation, Axios, AsyncStorage, Express, Prisma

a. Main components
1. Mobile Client (Expo/React Native App)
2. API Gateway / Express Server
3. Authentication Layer (JWT + social OAuth)
4. Business Logic Layer (routes/controllers for categories, expenses, profile)
5. Data Layer (Prisma ORM + relational database)
6. External OAuth Providers (Facebook, Google)
b. Relationships & interactions
- Mobile Client ⇄ Express API (HTTPS/JSON)
- Express API uses authMiddleware to verify JWT on protected routes
- For social login: Express API exchanges OAuth tokens with Facebook/Google, issues JWT
- Express API ⇄ Database via Prisma Client
c. Architectural patterns & principles
- Layered architecture: Presentation (mobile), API/Controller, Service/ORM, Database
- RESTful design: Separate endpoints for resource operations (GET, POST)
- Token-based stateless authentication
- MVC-lite: Routes as controllers, Prisma models as data layer
d. Key technologies & libraries
- React Native (Expo) + React Navigation + react-native-chart-kit
- Axios for HTTP client, AsyncStorage for token storage
- Node.js, Express.js, JWT for auth, Prisma ORM, PostgreSQL (or compatible)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Client Layer
    subgraph "Mobile Client" 
        direction TB
        MobileClient["Expo React Native App"]:::frontend
        subgraph "Entry & Navigation"
            direction TB
            AppJs["App.js"]:::frontend
            IndexJs["index.js"]:::frontend
            AppNav["AppNavigator.js"]:::frontend
        end
        subgraph "Screens"
            direction TB
            Login["LoginScreen.js"]:::frontend
            Signup["SignupScreen.js"]:::frontend
            Home["HomeScreen.js"]:::frontend
            AddExp["AddExpenseScreen.js"]:::frontend
            AllExp["AllExpenses.js"]:::frontend
            Chart["ChartScreen.js"]:::frontend
            ProfileScr["Profile.js"]:::frontend
        end
        subgraph "Utilities"
            direction TB
            ApiUtil["api.js"]:::frontend
            AuthUtil["auth.js"]:::frontend
        end
    end

    %% External OAuth Providers
    Facebook["Facebook OAuth"]:::external
    Google["Google OAuth"]:::external

    %% Backend Layer
    subgraph "Backend API" 
        direction TB
        Express["Express Server"]:::backend
        click Express "https://github.com/grishj/expense_tracker/blob/main/backend/src/index.js"
        subgraph "Routes & Controllers"
            direction TB
            AuthRoute["auth.js"]:::backend
            CatsRoute["categories.js"]:::backend
            ExpRoute["expenses.js"]:::backend
            ProfRoute["profile.js"]:::backend
        end
        subgraph "Middleware & Utils"
            direction TB
            AuthMW["authMiddleware.js"]:::backend
            GenToken["generateToken.js"]:::backend
            PrismaClient["prismaClient.js"]:::backend
        end
    end

    %% Database Layer
    subgraph "Database"
        direction TB
        PrismaSchema["schema.prisma"]:::database
        Migrations["migrations/"]:::database
        DB["PostgreSQL"]:::database
    end

    %% README & Config
    README["README.md"]:::external
    ExpoConfig[".expo/"]:::external

    %% Connections
    MobileClient -->|HTTPS/JSON| Express
    AppJs -->|Imports| AppNav
    AppNav -->|Navigates| Login
    AppNav -->|Navigates| Signup
    AppNav -->|Navigates| Home
    AppNav -->|Navigates| AddExp
    AppNav -->|Navigates| AllExp
    AppNav -->|Navigates| Chart
    AppNav -->|Navigates| ProfileScr
    MobileClient -->|Uses| ApiUtil
    MobileClient -->|Uses| AuthUtil

    Express -->|uses| AuthRoute
    Express -->|uses| CatsRoute
    Express -->|uses| ExpRoute
    Express -->|uses| ProfRoute
    AuthRoute -->|POST /auth/login etc| AuthMW
    AuthRoute -->|calls| GenToken
    AuthRoute -->|calls| Facebook
    AuthRoute -->|calls| Google

    CatsRoute -->|protected via| AuthMW
    ExpRoute -->|protected via| AuthMW
    ProfRoute -->|protected via| AuthMW

    AuthRoute -->|DB ops| PrismaClient
    CatsRoute -->|DB ops| PrismaClient
    ExpRoute -->|DB ops| PrismaClient
    ProfRoute -->|DB ops| PrismaClient

    PrismaClient -->|queries| PrismaSchema
    PrismaClient -->|runs migrations| Migrations
    PrismaSchema -->|defines tables| DB
    Migrations -->|applied to| DB

    README -->|docs| MobileClient
    README -->|docs| Express
    ExpoConfig -->|configures| MobileClient

    %% Click Events
    click MobileClient "https://github.com/grishj/expense_tracker/tree/main/frontend/"
    click AppJs "https://github.com/grishj/expense_tracker/blob/main/frontend/App.js"
    click IndexJs "https://github.com/grishj/expense_tracker/blob/main/frontend/index.js"
    click AppNav "https://github.com/grishj/expense_tracker/blob/main/frontend/src/navigation/AppNavigator.js"
    click Login "https://github.com/grishj/expense_tracker/blob/main/frontend/src/screens/LoginScreen.js"
    click Signup "https://github.com/grishj/expense_tracker/blob/main/frontend/src/screens/SignupScreen.js"
    click Home "https://github.com/grishj/expense_tracker/blob/main/frontend/src/screens/HomeScreen.js"
    click AddExp "https://github.com/grishj/expense_tracker/blob/main/frontend/src/screens/AddExpenseScreen.js"
    click AllExp "https://github.com/grishj/expense_tracker/blob/main/frontend/src/screens/AllExpenses.js"
    click Chart "https://github.com/grishj/expense_tracker/blob/main/frontend/src/screens/ChartScreen.js"
    click ProfileScr "https://github.com/grishj/expense_tracker/blob/main/frontend/src/screens/Profile.js"
    click ApiUtil "https://github.com/grishj/expense_tracker/blob/main/frontend/src/utils/api.js"
    click AuthUtil "https://github.com/grishj/expense_tracker/blob/main/frontend/src/utils/auth.js"
    click Express "https://github.com/grishj/expense_tracker/blob/main/backend/src/index.js"
    click AuthRoute "https://github.com/grishj/expense_tracker/blob/main/backend/src/routes/auth.js"
    click CatsRoute "https://github.com/grishj/expense_tracker/blob/main/backend/src/routes/categories.js"
    click ExpRoute "https://github.com/grishj/expense_tracker/blob/main/backend/src/routes/expenses.js"
    click ProfRoute "https://github.com/grishj/expense_tracker/blob/main/backend/src/routes/profile.js"
    click AuthMW "https://github.com/grishj/expense_tracker/blob/main/backend/src/middleware/authMiddleware.js"
    click GenToken "https://github.com/grishj/expense_tracker/blob/main/backend/src/utils/generateToken.js"
    click PrismaClient "https://github.com/grishj/expense_tracker/blob/main/backend/src/utils/prismaClient.js"
    click PrismaSchema "https://github.com/grishj/expense_tracker/blob/main/backend/prisma/schema.prisma"
    click Migrations "https://github.com/grishj/expense_tracker/tree/main/backend/prisma/migrations/"
    click README "https://github.com/grishj/expense_tracker/blob/main/README.md"
    click ExpoConfig "https://github.com/grishj/expense_tracker/tree/main/.expo/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef database fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
