# dsquare-io/splinter architecture

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

- Interactive diagram: https://gitdiagram.com/dsquare-io/splinter
- Repository: https://github.com/dsquare-io/splinter

## Overview

##### Main System Components

a) Frontend Layer:
- React-based UI (evidenced by the /ui directory with TypeScript and React components)
- Frontend modules:
- Authentication views
- Dashboard components
- Expense management
- Management
- Activity tracking

b) Backend Layer (Django-based):
- Core Apps:
- User Management (/apps/user)
- Authentication (/apps/authn)
- Expense Management (/apps/expense)
- Management (/apps/group)
- Friend Management (/apps/friend)
- Currency Management (/apps/currency)
- Activity Tracking (/apps/activity)
- Multi-factor Authentication (/apps/mfa)

c) Infrastructure Layer:
- Database (indicated by Django models and migrations)
- Celery for async tasks (celery_app.py)
- Cache system (settings/cache.py)
- Email service (settings/email.py)

##### Relationships and Data Flow

- API interactions between frontend and backend
- Database operations
- Authentication flow
- Expense splitting calculations
- Activity logging flow
- Currency conversion paths

##### Architectural Patterns to Highlight

- Django's MVT (Model-View-Template) pattern
- REST API architecture (evidenced by serializers and views)
- Component-based frontend architecture
- Service-oriented backend structure (each app as a service)

##### Technical Implementation Details

- Blue rectangles: Frontend components
- Green rectangles: Backend services
- Yellow diamonds: External services
- Red hexagons: Security components

##### Specific Elements

a) Frontend Section:
- Route structure (/ui/src/routes)
- Component hierarchy (/ui/src/components)
- State management (React Query indicated by useApiQuery)
- API integration layer

b) Backend Section:
- Django apps architecture
- Authentication flow
- Database models
- API endpoints
- Task queue system

c) Infrastructure Section:
- Docker containers
- Database
- Caching layer
- Task queue
- Email service

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#3498db,color:white
    classDef backend fill:#2ecc71,color:white
    classDef infrastructure fill:#f1c40f,color:white
    classDef database fill:#9b59b6,color:white
    classDef security fill:#e74c3c,color:white
    classDef api fill:#95a5a6,color:white

    %% Frontend Layer
    subgraph Frontend
        UI[React UI]
        AuthViews[Authentication Views]:::frontend
        DashViews[Dashboard Views]:::frontend
        ExpenseComp[Expense Components]:::frontend
        GroupComp[Group Components]:::frontend
        ApiIntegration[API Integration Layer]:::frontend
    end

    click AuthViews "https://github.com/dsquare-io/splinter/tree/main/ui/src/routes/auth"
    click DashViews "https://github.com/dsquare-io/splinter/tree/main/ui/src/routes/_dashboard"
    click ExpenseComp "https://github.com/dsquare-io/splinter/tree/main/ui/src/components/modals/AddExpense"
    click GroupComp "https://github.com/dsquare-io/splinter/tree/main/ui/src/routes/_dashboard/groups"
    click ApiIntegration "https://github.com/dsquare-io/splinter/blob/main/ui/src/hooks/useApiQuery.ts"

    %% Backend Layer
    subgraph Backend
        CoreServices[Core Services]
        UserMgmt[User Management]:::backend
        AuthN[Authentication]:::backend
        ExpenseMgmt[Expense Management]:::backend
        GroupMgmt[Group Management]:::backend
        FriendMgmt[Friend Management]:::backend
        CurrencyMgmt[Currency Management]:::backend
        ActivityTrack[Activity Tracking]:::backend
        MFA[Multi-factor Auth]:::backend
    end

    click CoreServices "https://github.com/dsquare-io/splinter/tree/main/splinter/core"
    click UserMgmt "https://github.com/dsquare-io/splinter/tree/main/splinter/apps/user"
    click AuthN "https://github.com/dsquare-io/splinter/tree/main/splinter/apps/authn"
    click ExpenseMgmt "https://github.com/dsquare-io/splinter/tree/main/splinter/apps/expense"
    click GroupMgmt "https://github.com/dsquare-io/splinter/tree/main/splinter/apps/group"
    click FriendMgmt "https://github.com/dsquare-io/splinter/tree/main/splinter/apps/friend"
    click CurrencyMgmt "https://github.com/dsquare-io/splinter/tree/main/splinter/apps/currency"
    click ActivityTrack "https://github.com/dsquare-io/splinter/tree/main/splinter/apps/activity"
    click MFA "https://github.com/dsquare-io/splinter/tree/main/splinter/apps/mfa"

    %% Infrastructure Layer
    subgraph Infrastructure
        DB[(Database)]:::database
        Cache[(Cache)]:::infrastructure
        CeleryTasks[Celery Tasks]:::infrastructure
        EmailService[Email Service]:::infrastructure
        ApiDocs[API Documentation]:::api
        DBModels[Database Models]:::database
    end

    click CeleryTasks "https://github.com/dsquare-io/splinter/blob/main/splinter/celery_app.py"
    click Cache "https://github.com/dsquare-io/splinter/blob/main/splinter/settings/cache.py"
    click EmailService "https://github.com/dsquare-io/splinter/blob/main/splinter/settings/email.py"
    click DB "https://github.com/dsquare-io/splinter/blob/main/splinter/settings/database.py"
    click ApiDocs "https://github.com/dsquare-io/splinter/tree/main/splinter/core/openapi"
    click DBModels "https://github.com/dsquare-io/splinter/tree/main/splinter/db/models"

    %% Relationships
    UI --> ApiIntegration
    ApiIntegration --> CoreServices
    AuthViews --> AuthN
    DashViews --> CoreServices
    ExpenseComp --> ExpenseMgmt
    GroupComp --> GroupMgmt

    CoreServices --> UserMgmt
    CoreServices --> AuthN
    CoreServices --> ExpenseMgmt
    CoreServices --> GroupMgmt
    CoreServices --> FriendMgmt
    CoreServices --> CurrencyMgmt
    CoreServices --> ActivityTrack
    CoreServices --> MFA

    AuthN --> DB
    UserMgmt --> DB
    ExpenseMgmt --> DB
    GroupMgmt --> DB
    FriendMgmt --> DB
    CurrencyMgmt --> DB
    ActivityTrack --> DB
    MFA --> DB

    CoreServices --> Cache
    CoreServices --> CeleryTasks
    CoreServices --> EmailService
    DB --> DBModels
    CoreServices --> ApiDocs

    %% Legend
    subgraph Legend
        FE[Frontend Component]:::frontend
        BE[Backend Service]:::backend
        INF[Infrastructure]:::infrastructure
        SEC[Security Component]:::security
        DBS[(Data Store)]:::database
        API[API Component]:::api
    end
```
