# zebdayacine/cnr-payment-blockchain architecture

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

- Interactive diagram: https://gitdiagram.com/zebdayacine/cnr-payment-blockchain
- Repository: https://github.com/zebdayacine/cnr-payment-blockchain

## Overview

##### Project type and purpose
- This is a full-stack, containerized microservices application for “CNR Payment Blockchain System.”
- Frontend: React + TypeScript (Vite, Tailwind).
- Backend: Go (Gin REST API) with Clean/Hexagonal architecture.
- Blockchain: Hyperledger Fabric network & custom chaincode.
- Data: MongoDB for off-chain storage, SFTP for secure document management, SMTP for email/notification.
- Orchestrated via Docker Compose for local development and deployment.

##### File structure
- Top-level:
- frontend/cnr → React application
- backend/ → Go service
– api/ → HTTP controllers, routers, middleware
– feature/ → domain/usecase/repository per bounded context (auth, dashboard, file, profile, version, notifications)
– pkg/ → shared code (config, MongoDB adapter)
– cmd/ → entry point (main.go)
– fabric/ → Fabric network definitions & chaincode Go file
– sftp/ → Docker Compose + sample upload directories
– util/ → email, token, common utilities
- mongo-init/ → DB seed data JSON scripts
- scripts/ → Fabric bin download, chaincode deploy/upgrade, smartcontract tests
- docker-compose.yml → orchestrates backend, frontend, mongo, sftp, Fabric network
- The presence of “feature → domain/usecase/repository” indicates a Clean/Hexagonal architecture.

##### README highlights
- Microservices architecture, Dockerized components, CI/CD ready.
- Real-time analytics dashboard, JWT auth, SFTP file handling, notification/email alerts.

##### Essential elements
- Don’t omit the Clean Architecture layers in backend (controllers, use cases, repos, adapters).
- Microservice boundaries (each containerized service).
- That Docker Compose glues together all containers on a private network.
- Chaincode deployment scripts and CI/CD entry points if discussing DevOps.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    Browser["Web Browser"]:::external

    %% Frontend
    Browser -->|"HTTP/HTTPS"| Frontend["React + Vite Frontend"]:::frontend
    click Frontend "https://github.com/zebdayacine/cnr-payment-blockchain/tree/master/frontend/cnr"

    %% Orchestration
    Compose["Docker Compose"]:::orchestrator
    click Compose "https://github.com/zebdayacine/cnr-payment-blockchain/blob/master/docker-compose.yml"
    Compose --> Frontend

    %% Backend Service Container
    subgraph "Backend Service Container"
        BackendService["Go Service\n(main.go)"]:::backend
        click BackendService "https://github.com/zebdayacine/cnr-payment-blockchain/blob/master/backend/cmd/main.go"
        Dockerfile["Dockerfile"]:::backend
        click Dockerfile "https://github.com/zebdayacine/cnr-payment-blockchain/tree/master/backend/Dockerfile"
    end
    Frontend -->|"REST API (JWT)"| BackendService
    Compose --> BackendService
    Compose --> Dockerfile

    %% API Layer inside Backend
    subgraph "API Layer"
        Gin["Gin Server"]:::backend
        click Gin "https://github.com/zebdayacine/cnr-payment-blockchain/blob/master/backend/api/servers/gin.go"
        Routers["HTTP Routers"]:::backend
        click Routers "https://github.com/zebdayacine/cnr-payment-blockchain/tree/master/backend/api/router"
        Controllers["HTTP Controllers"]:::backend
        click Controllers "https://github.com/zebdayacine/cnr-payment-blockchain/tree/master/backend/api/controller"
    end
    BackendService --> Gin
    Gin --> Routers
    Routers --> Controllers

    %% Domain / Business Logic
    Controllers --> Usecases["Use Cases\n(domain/usecase/repository)"]:::backend
    click Usecases "https://github.com/zebdayacine/cnr-payment-blockchain/tree/master/backend/feature"

    %% Shared & Adapters
    subgraph "Shared Config & Adapters"
        Config["Config"]:::backend
        click Config "https://github.com/zebdayacine/cnr-payment-blockchain/blob/master/backend/pkg/config.go"
        MongoAdapter["MongoDB Adapter"]:::backend
        click MongoAdapter "https://github.com/zebdayacine/cnr-payment-blockchain/tree/master/backend/pkg/database"
        SFTPAdapter["SFTP Adapter"]:::backend
        click SFTPAdapter "https://github.com/zebdayacine/cnr-payment-blockchain/blob/master/backend/api/servers/sftp.go"
        EmailUtil["Email Utility"]:::backend
        click EmailUtil "https://github.com/zebdayacine/cnr-payment-blockchain/tree/master/backend/util/email"
        TokenUtil["Token Utility"]:::backend
        click TokenUtil "https://github.com/zebdayacine/cnr-payment-blockchain/tree/master/backend/util/token"
        Tools["Misc Utilities"]:::backend
        click Tools "https://github.com/zebdayacine/cnr-payment-blockchain/blob/master/backend/util/tools.go"
    end
    Usecases --> Config
    Usecases --> MongoAdapter
    Usecases --> SFTPAdapter
    Usecases --> EmailUtil
    Usecases --> TokenUtil

    %% Off-chain & External Services
    subgraph "Infrastructure Services"
        Mongo["MongoDB"]:::db
        SFTPService["SFTP Server"]:::sftp
        SMTP["SMTP Server"]:::external
    end
    Compose --> Mongo
    Compose --> SFTPService
    MongoAdapter --> Mongo
    SFTPAdapter --> SFTPService
    EmailUtil --> SMTP

    %% Blockchain Network
    subgraph "Hyperledger Fabric Network"
        FabricDefs["Fabric Definitions"]:::fabric
        click FabricDefs "https://github.com/zebdayacine/cnr-payment-blockchain/tree/master/backend/fabric"
        Orderer["Orderer"]:::fabric
        Org1["Org1 Peer"]:::fabric
        Org2["Org2 Peer"]:::fabric
        CA["Certificate Authority"]:::fabric
        Chaincode["Chaincode"]:::fabric
        click Chaincode "https://github.com/zebdayacine/cnr-payment-blockchain/blob/master/backend/fabric/smart_contract.go"
    end
    Compose --> Orderer
    Compose --> Org1
    Compose --> Org2
    Compose --> CA
    FabricDefs --> Orderer
    FabricDefs --> Org1
    FabricDefs --> Org2
    FabricDefs --> CA
    FabricDefs --> Chaincode
    Usecases -->|"gRPC invoke/query"| Orderer
    Usecases -->|"gRPC invoke/query"| Org1
    Usecases -->|"gRPC invoke/query"| Org2

    %% Scripts & CI/CD
    subgraph "DevOps Scripts"
        Seed["MongoDB Seed Data"]:::script
        click Seed "https://github.com/zebdayacine/cnr-payment-blockchain/tree/master/mongo-init"
        DownloadFAB["Download Fabric Binaries"]:::script
        click DownloadFAB "https://github.com/zebdayacine/cnr-payment-blockchain/blob/master/script/download-fabric.sh"
        DeployCC["Deploy Chaincode"]:::script
        click DeployCC "https://github.com/zebdayacine/cnr-payment-blockchain/blob/master/script/deploy-cc.sh"
        UpgradeCC["Upgrade Chaincode"]:::script
        click UpgradeCC "https://github.com/zebdayacine/cnr-payment-blockchain/blob/master/script/upgrade-cc.sh"
        Tests["Smartcontract Tests"]:::script
        click Tests "https://github.com/zebdayacine/cnr-payment-blockchain/blob/master/script/smartcontract_test.go"
    end

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#3399FF,color:#000;
    classDef backend fill:#DFF7D0,stroke:#33AA00,color:#000;
    classDef db fill:#EEEEEE,stroke:#888888,color:#000;
    classDef sftp fill:#F0D0FF,stroke:#AA33FF,color:#000;
    classDef fabric fill:#FFE3B8,stroke:#FF9900,color:#000;
    classDef external fill:#FFFFFF,stroke:#666666,color:#000;
    classDef orchestrator fill:#F0F0F0,stroke:#444444,color:#000;
    classDef script fill:#F7D0D0,stroke:#CC3333,color:#000;
```
