# josiah-o/thrift-crowd-staking architecture

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

- Interactive diagram: https://gitdiagram.com/josiah-o/thrift-crowd-staking
- Repository: https://github.com/josiah-o/thrift-crowd-staking

## Overview

##### Main Components
- Frontend – Located in the "frontend" directory. This is built with React and Redux. It handles user interactions such as creating/joining Crowd Stake Groups and managing wallets.
- Backend – Found in the "backend" directory. Written in Haskell using Servant, it orchestrates the core logic, API endpoints, database interactions, and communication with Cardano nodes.
- Smart Contracts – In the "smart-contracts" directory. These contain Haskell/Plutus code for blockchain interactions and deployment procedures.
- Database – Although there isn’t a dedicated “database” directory, SQL files (schema and migrations) in the backend indicate integration with a PostgreSQL database.
- Blockchain Components – Cardano nodes and wallet integrations are essential external systems, specified in the README, for processing and verifying transactions on both Testnet and Mainnet.
- Infrastructure & Deployment – Dockerfiles in both the backend and frontend folders, docker-compose configuration, and environment configuration indicate that containerization and orchestration are part of the deployment architecture.
- Documentation & Guides – The "docs" directory contains technical and UX guides which can be referenced for additional architectural details not immediately evident in the code.

##### Mapping Out Relationships and Interactions
- The backend interacts with:
- The PostgreSQL database for storing group details and user information (schema.sql and migrations).
- The Cardano blockchain—configurable for Testnet or Mainnet—to process transactions and dispatch smart contract calls.
- The backend also interacts with the smart contracts by triggering deployments or transaction calls to the Cardano network.
- Docker deployments and orchestration (via docker-compose.yml) suggest that each of these major sections are containerized for modular deployment.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Notice how the project’s various functions (UI, API, blockchain smart contracts, and database interactions) are separated into distinct directories.
- Full-Stack Architecture: For a dApp, it is important to highlight interaction between the frontend, backend, blockchain integrations, and external databases.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Subgraph: User Interface
    subgraph "User Interface"
        FE["Frontend (React/Redux)"]:::frontend
        WIN["Wallet Interface (Daedalus/Yoroi)"]:::external
    end

    %% Subgraph: Application Logic
    subgraph "Application Logic"
        BE["Backend (Haskell Servant API)"]:::backend
    end

    %% Subgraph: Blockchain & Smart Contracts
    subgraph "Blockchain & Smart Contracts"
        SC["Smart Contracts (Plutus/Haskell)"]:::blockchain
        CB["Cardano Blockchain (Testnet/Mainnet)"]:::blockchain
    end

    %% Subgraph: Supporting Infrastructure
    subgraph "Supporting Infrastructure"
        DB["PostgreSQL Database"]:::database
        DDEP["Docker & Deployment"]:::infra
        DOC["Documentation & Guides"]:::docs
    end

    %% Interactions
    FE -->|"api_calls"| BE
    BE -->|"SQL_queries"| DB
    BE -->|"trigger_contract"| SC
    BE -->|"transaction_call"| CB
    FE -->|"wallet_connection"| WIN
    WIN -->|"blockchain_interaction"| CB

    %% Infrastructure connections (dashed lines for containerization/management)
    DDEP --- FE
    DDEP --- BE
    DDEP --- SC

    DOC --- FE
    DOC --- BE
    DOC --- SC

    %% Click Events
    click FE "https://github.com/josiah-o/thrift-crowd-staking/tree/develop/frontend/"
    click BE "https://github.com/josiah-o/thrift-crowd-staking/tree/develop/backend/"
    click SC "https://github.com/josiah-o/thrift-crowd-staking/blob/develop/smart-contracts/src/CSGContract.hs"
    click DB "https://github.com/josiah-o/thrift-crowd-staking/blob/develop/backend/db/schema.sql"
    click DB "https://github.com/josiah-o/thrift-crowd-staking/blob/develop/backend/migrations/001_initial_schema.sql"
    click DDEP "https://github.com/josiah-o/thrift-crowd-staking/blob/develop/docker-compose.yml"
    click DDEP "https://github.com/josiah-o/thrift-crowd-staking/tree/develop/backend/Dockerfile"
    click DDEP "https://github.com/josiah-o/thrift-crowd-staking/tree/develop/frontend/Dockerfile"
    click DOC "https://github.com/josiah-o/thrift-crowd-staking/blob/develop/docs/technical_guide.md"
    click DOC "https://github.com/josiah-o/thrift-crowd-staking/blob/develop/docs/ux_guide.md"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef blockchain fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef infra fill:#D2B4DE,stroke:#512E5F,stroke-width:2px;
    classDef docs fill:#FAD7A0,stroke:#B9770E,stroke-width:2px;
    classDef external fill:#E6B0AA,stroke:#641E16,stroke-width:2px;
```
