# kosasih/pi-cryptoconnect architecture

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

- Interactive diagram: https://gitdiagram.com/kosasih/pi-cryptoconnect
- Repository: https://github.com/kosasih/pi-cryptoconnect

## Overview

##### Main Components
a. User Interfaces
– Mobile App (mobile_app/app.py)
– Web Interface (web_interface/app.py + templates/index.html)
– React/Redux Frontend (if present under src/ or Pi-CryptoConnect-Xtreme UI)
– Command-Line & GUI interfaces (src/interface/cli.py, gui.py)
– E-paper Badge Display on Raspberry Pi (Pi-CryptoConnect-Xtreme/app/main.py driving e-paper)
b. API & Gateway Layer
– Central HTTP/REST API endpoints (app.py, routes.py, Pi-CryptoConnect-Xtreme/app/api.py)
– Authentication/Authorization (access_control/auth.py, two_factor_auth.py)
c. Core Services & Microservices
– Trading Engine (Pi-CryptoConnect-Xtreme/app/trading.py, trading/trading_logic.py)
– Exchange Adapters (exchanges/*.py, advanced_strategies/utils/exchange_api.py)
– Market Data Ingestion & Analytics (real_time_market_data_analitycs/market_data.py, telemetry/*)
– Backtesting & Simulation (backtesting/backtester.py, simulator.py)
– AI/ML Modules (ai/*, advanced_strategies/genetic_algorithms, neural_networks, reinforcement_learning)
– Automation & Scheduling (automation/celery.py, tasks.py)
– Pi Network & Blockchain Node Control (pi-network-launcher, blockchain/*.py, PiNetworkService.js)
– Portfolio & Risk Management (portfolio/*.py, risk_management/*.py)
– Alerting & Notification (alerting/notification.py)
– Security & Audit (security/*.py)
d. Data Persistence Layer
– Relational/NoSQL Databases (data_persistence/database.py, schemas.py)
– Time-Series Database for metrics (telemetry/influxdb.py)
– Logging (logging.conf, Pi-CryptoConnect-Xtreme/logs/*.log)
e. External Dependencies & Integrations
– Cryptocurrency Price APIs (CoinGecko REST API, integrations/ta_lib.js, integrations/zipline.py)
– Exchange REST/WebSocket APIs (Binance, Coinbase, Kraken, etc.)
– Cloud Services (integrations/aws.py, google_cloud.py)
– Kubernetes/Docker (Dockerfiles, .circleci/config.yml for CI/CD)
– Third-party frameworks (Flask/Django, Express.js, React, Redux, Celery, TensorFlow/PyTorch in AI modules)

##### Relationships & Data Flows
– From the API layer, show calls to the Authentication Service and Routing to appropriate microservices.
– Show asynchronous task flows through the Celery broker: API/Web UI → Task Queue → Worker Services (backtesting, notifications, automation).
– Show data writes to persistence: core services → primary database; telemetry → time-series DB; logs → log files or ELK stack.

##### Architectural Patterns & Principles
– Microservices: each service (trading, backtesting, AI, blockchain) lives in its own module/namespace.
– Adapter/Plugin Pattern: exchange connectors implement a common interface under exchanges/ and advanced_strategies/exchanges/.
– Publish/Subscribe: Celery for background tasks and alerting notifications.
– MVC or Hexagonal style in web_frontend and web_interface.
– Data-driven ML pipeline with separation of preprocessing, training, and inference.
– Infrastructure as Code/CI-CD: use of .circleci, Kubernetes manifests, Docker.

##### Call Out Key Technologies & Frameworks
– Python (Flask/FastAPI, Celery, pandas, scikit-learn/TensorFlow)
– JavaScript/Node.js (Express, React, Redux)
– Databases (PostgreSQL/MySQL via SQLAlchemy, InfluxDB)
– Message Broker (RabbitMQ/Redis for Celery)
– Raspberry Pi GPIO & E-paper libraries
– Docker & Kubernetes

##### Capturing Essential Details
– Don’t overcrowd: focus on one instance of each microservice group rather than every file.
– Ensure every path of data flow is represented: user → API → service → DB → back.
– Call out security boundaries (authentication, 2FA, encrypted storage).
– Indicate CI/CD pipelines and deployment environments (dev/staging/prod on Kubernetes).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Clients
    subgraph "Frontend Clients"
        direction TB
        MobileApp["Mobile App UI\n(Python/Flask)"]:::frontend
        WebUI["Web Interface UI\n(Python/Flask)"]:::frontend
        ReactSPA["React/Redux SPA"]:::frontend
        CLI["CLI Interface"]:::frontend
        GUI["GUI Interface"]:::frontend
        EPaper["E-paper Badge Display\n(Python)"]:::frontend
    end

    %% API & Gateway
    API["API Gateway\n(Flask/FastAPI)"]:::backend
    API -->|HTTP/REST| Auth
    Auth["Authentication & Authorization\n(Python)"]:::backend

    %% Core Microservices
    subgraph "Core Services"
        direction TB
        Trading["Trading Engine\n(Python)"]:::service
        Exchange["Exchange Adapters\n(Python)"]:::service
        MarketData["Market Data Ingestion\n& Analytics"]:::service
        Backtesting["Backtesting & Simulation"]:::service
        AI["AI/ML Modules"]:::service
        Automation["Automation & Scheduling"]:::service
        Blockchain["Pi Network & Blockchain\nControl"]:::service
        Portfolio["Portfolio & Risk Management"]:::service
        Alerting["Alerting & Notification"]:::service
        SecuritySvc["Security & Audit Service"]:::service
    end

    %% Data Persistence
    subgraph "Data Persistence"
        direction TB
        PrimaryDB["Primary DB\n(SQL/NoSQL)"]:::database
        TimeSeriesDB["Time-Series DB\n(InfluxDB)"]:::database
        Logs["Logs & Logging\n(ELK/Rolling Files)"]:::database
    end

    %% External Integrations
    subgraph "External Systems"
        direction TB
        CryptoExchanges["Crypto Exchange APIs"]:::external
        CoinGecko["CoinGecko API"]:::external
        CloudServices["Cloud Services\n(AWS/GCP)"]:::external
        CI_CD["CI/CD & IaC"]:::external
    end

    %% Connections: Frontend to API
    MobileApp -->|HTTP/REST| API
    WebUI -->|HTTP/REST| API
    ReactSPA -->|HTTP/REST| API
    CLI -->|RPC/HTTP| API
    GUI -->|RPC/HTTP| API
    EPaper -->|Local IPC| API

    %% API to Core Services
    API -->|routes| Trading
    API -->|routes| MarketData
    API -->|routes| Backtesting
    API -->|routes| AI
    API -->|routes| Automation
    API -->|routes| Blockchain
    API -->|routes| Portfolio
    API -->|routes| Alerting
    API -->|routes| SecuritySvc

    %% Auth usage
    Trading -->|verify| Auth
    Backtesting -->|verify| Auth
    Portfolio -->|verify| Auth
    SecuritySvc -->|audit| Auth

    %% Core service interactions
    Trading <-->|market data| MarketData
    Trading <-->|order execution| Exchange
    Exchange -->|REST/WebSocket| CryptoExchanges
    MarketData -->|metrics| TimeSeriesDB
    MarketData -->|telemetry| Logs
    Backtesting -->|historical data| PrimaryDB
    AI -->|train/infer| PrimaryDB
    AI -->|metrics| TimeSeriesDB
    Automation -->|tasks| Backtesting
    Automation -->|alerts| Alerting
    Blockchain -->|node control| PrimaryDB
    Portfolio -->|positions| PrimaryDB
    Alerting -->|notify| CLI
    SecuritySvc -->|audit logs| Logs

    %% Data persistence flows
    Trading -->|write/read| PrimaryDB
    Portfolio -->|write/read| PrimaryDB
    SecuritySvc -->|secure store| PrimaryDB

    %% External integrations
    MarketData -->|pull| CoinGecko
    Automation -->|deploy| CI_CD
    Blockchain -->|cloud| CloudServices

    %% Click Events
    click MobileApp "https://github.com/kosasih/pi-cryptoconnect/blob/main/mobile_app/app.py"
    click WebUI "https://github.com/kosasih/pi-cryptoconnect/blob/main/web_interface/app.py"
    click ReactSPA "https://github.com/kosasih/pi-cryptoconnect/tree/main/src/"
    click CLI "https://github.com/kosasih/pi-cryptoconnect/blob/main/src/interface/cli.py"
    click GUI "https://github.com/kosasih/pi-cryptoconnect/blob/main/src/interface/gui.py"
    click EPaper "https://github.com/kosasih/pi-cryptoconnect/blob/main/Pi-CryptoConnect-Xtreme/app/main.py"
    click API "https://github.com/kosasih/pi-cryptoconnect/blob/main/app.py"
    click Auth "https://github.com/kosasih/pi-cryptoconnect/blob/main/access_control/auth.py"
    click Auth "https://github.com/kosasih/pi-cryptoconnect/blob/main/security/two_factor_auth.py"
    click Trading "https://github.com/kosasih/pi-cryptoconnect/blob/main/Pi-CryptoConnect-Xtreme/app/trading.py"
    click Trading "https://github.com/kosasih/pi-cryptoconnect/blob/main/trading/trading_logic.py"
    click Exchange "https://github.com/kosasih/pi-cryptoconnect/blob/main/exchanges/binance_exchange.py"
    click Exchange "https://github.com/kosasih/pi-cryptoconnect/blob/main/exchanges/coinbase_exchange.py"
    click Exchange "https://github.com/kosasih/pi-cryptoconnect/blob/main/advanced_strategies/utils/exchange_api.py"
    click Exchange "https://github.com/kosasih/pi-cryptoconnect/blob/main/Pi-CryptoConnect-Xtreme/app/exchange.py"
    click MarketData "https://github.com/kosasih/pi-cryptoconnect/blob/main/real_time_market_data_analitycs/market_data.py"
    click MarketData "https://github.com/kosasih/pi-cryptoconnect/blob/main/telemetry/influxdb.py"
    click MarketData "https://github.com/kosasih/pi-cryptoconnect/blob/main/telemetry/metrics.py"
    click Backtesting "https://github.com/kosasih/pi-cryptoconnect/blob/main/backtesting/backtester.py"
    click Backtesting "https://github.com/kosasih/pi-cryptoconnect/blob/main/backtesting/simulator.py"
    click Backtesting "https://github.com/kosasih/pi-cryptoconnect/blob/main/backtesting/templates/backtest_results.html"
    click AI "https://github.com/kosasih/pi-cryptoconnect/tree/main/ai/"
    click AI "https://github.com/kosasih/pi-cryptoconnect/tree/main/advanced_strategies/genetic_algorithms/"
    click AI "https://github.com/kosasih/pi-cryptoconnect/tree/main/advanced_strategies/neural_networks/"
    click AI "https://github.com/kosasih/pi-cryptoconnect/tree/main/advanced_strategies/reinforcement_learning/"
    click Automation "https://github.com/kosasih/pi-cryptoconnect/blob/main/automation/celery.py"
    click Automation "https://github.com/kosasih/pi-cryptoconnect/blob/main/automation/tasks.py"
    click Blockchain "https://github.com/kosasih/pi-cryptoconnect/blob/main/pi-network-launcher/pi_network_launcher.py"
    click Blockchain "https://github.com/kosasih/pi-cryptoconnect/blob/main/blockchain/app.py"
    click Blockchain "https://github.com/kosasih/pi-cryptoconnect/blob/main/blockchain/PiNetworkService.js"
    click Portfolio "https://github.com/kosasih/pi-cryptoconnect/blob/main/portfolio/portfolio.py"
    click Portfolio "https://github.com/kosasih/pi-cryptoconnect/blob/main/portfolio/models.py"
    click Portfolio "https://github.com/kosasih/pi-cryptoconnect/blob/main/portfolio/optimization.py"
    click Alerting "https://github.com/kosasih/pi-cryptoconnect/blob/main/alerting/notification.py"
    click Alerting "https://github.com/kosasih/pi-cryptoconnect/blob/main/alerting/models.py"
    click SecuritySvc "https://github.com/kosasih/pi-cryptoconnect/blob/main/security/encrypted_data_storage.py"
    click SecuritySvc "https://github.com/kosasih/pi-cryptoconnect/blob/main/security/security_audit.py"
    click SecuritySvc "https://github.com/kosasih/pi-cryptoconnect/blob/main/security/penetration_testing.py"
    click PrimaryDB "https://github.com/kosasih/pi-cryptoconnect/blob/main/data_persistence/database.py"
    click PrimaryDB "https://github.com/kosasih/pi-cryptoconnect/blob/main/data_persistence/schemas.py"
    click PrimaryDB "https://github.com/kosasih/pi-cryptoconnect/blob/main/data_persistence/models.py"
    click Logs "https://github.com/kosasih/pi-cryptoconnect/tree/main/Pi-CryptoConnect-Xtreme/logs/"
    click Logs "https://github.com/kosasih/pi-cryptoconnect/blob/main/logging.conf"
    click CloudServices "https://github.com/kosasih/pi-cryptoconnect/blob/main/integrations/aws.py"
    click CloudServices "https://github.com/kosasih/pi-cryptoconnect/blob/main/integrations/google_cloud.py"
    click CloudServices "https://github.com/kosasih/pi-cryptoconnect/blob/main/integrations/ta_lib.py"
    click CloudServices "https://github.com/kosasih/pi-cryptoconnect/blob/main/integrations/zipline.py"
    click CI_CD "https://github.com/kosasih/pi-cryptoconnect/blob/main/.circleci/config.yml"
    click CI_CD "https://github.com/kosasih/pi-cryptoconnect/tree/main/Dockerfile"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#3B79C1,color:#000
    classDef backend fill:#DFF2D8,stroke:#4C9A2A,color:#000
    classDef service fill:#E8F0C1,stroke:#8F9A15,color:#000
    classDef database fill:#FFE8A1,stroke:#D29E00,color:#000
    classDef external fill:#EEEEEE,stroke:#999999,color:#000
```
