MCPcopy Index your code
hub / github.com/andersonmarquesgit/chargeback

github.com/andersonmarquesgit/chargeback @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
273 symbols 526 edges 71 files 18 documented · 7%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Chargeback: Construindo uma Arquitetura Event-Driven Resiliente com Go, RabbitMQ, MinIO e FTP

Go RabbitMQ Postgres Cassandra MinIO License

Este projeto é uma arquitetura completa e resiliente para processar chargebacks, simulando o fluxo real de estornos em bancos e instituições financeiras, incluindo o envio de arquivos NDJSON via FTP para redes de pagamento (ex.: Mastercard).

Tecnologias Utilizadas

  • Golang: alto desempenho e concorrência nativa.
  • RabbitMQ: mensageria para desacoplamento entre microserviços.
  • PostgreSQL: persistência de batches e controle de envio.
  • Cassandra: armazenamento de chargebacks com alta disponibilidade.
  • MinIO: simulação local de S3 para armazenar arquivos NDJSON.
  • FTP (Pure-FTPd): simulação de envio de arquivos para a Mastercard.
  • K6: ferramenta para estresse e carga em APIs.

Arquitetura

  • Chargeback API: Serviço HTTP que recebe pedidos de chargeback e publica eventos chargeback-opened no RabbitMQ.
  • Chargeback Processor: Worker que consome os eventos e processa os chargebacks, persistindo no Cassandra e escrevendo em arquivos NDJSON.
  • Chargeback Batch: Serviço que gerencia o envio dos arquivos NDJSON para a Mastercard via FTP, com lógica de retries e controle diário.
  • FTP Server: Simula o servidor da Mastercard para receber os arquivos.
  • MinIO: Armazena os arquivos NDJSON simulando um bucket S3.

Exemplo da Estrutura de Diretórios

chargeback-api/
├── cmd/
│   └── main.go
├── internal/
│   ├── application/
│   │   └── application.go
│   ├── domain/
│   │   ├── models/
│   │   │   └── chargeback.go
│   │   └── repositories/
│   │       └── chargeback_repository.go
│   ├── infrastructure/
│   │   ├── respositories/
│   │   │   └── cassandra/
│   │   │       └── chargeback_repository.go
│   │   ├── rabbitmq/
│   │   │   ├── producers/
│   │   │   │   └── chargeback-opened-producers.go
│   │   │   ├── connection.go
│   │   │   └── event.go
│   │   ├── logging/
│   │   │   └── logging.go
│   │   └── middlewares/
│   ├── interfaces/
│   │   ├── http/
│   │   │   ├── handlers/
│   │   │   │   └── chargeback_handler.go
│   │   │   └── routes/
│   │   │       └── routes.go
│   │   └── messaging/
│   │       └── publisher.go
│   ├── presentation/
│   ├── usecases/
│   └── config/
│       └── config.go
├── docs/ # Swagger docs
├── go.mod
├── chargeback-api.dockerfile

Execução do Projeto

Build e Subida dos Contêineres:

cd project
make up_build

Esse comando irá:

Fazer go build para cada microserviço.

Gerar a documentação Swagger (para o Chargeback API).

Subir todos os serviços via docker-compose.

Para subir sem rebuild:

make up

Parar os containers:

make down

URLs Importantes

Serviço URL - Chargeback API http://localhost:8080/swagger/index.html - RabbitMQ Management http://localhost:15672 (guest/guest) - MinIO Console http://localhost:9001 (admin/password) - FTP Server (Mastercard) ftp://localhost (admin/admin) - Postgres (Batch) postgres://admin:admin@localhost:5432/batch - Cassandra cqlsh cassandra:9042

Configurações

Todos os microserviços usam variáveis de ambiente para configuração. Exemplos personalizáveis:

  • NEW_RELIC_ENABLED
  • CHARGEBACK_MAX_RECORDS, CHARGEBACK_MAX_DURATION_VALUE, CHARGEBACK_MAX_DURATION_UNIT
  • FTP_HOST, FTP_PORT
  • SCHEDULER_INTERVAL_VALUE, SCHEDULER_INTERVAL_UNIT, BATCH_MAX_FILES_PER_DAY

Confira o docker-compose.yml para ver como aplicar facilmente.

Testes de Carga

Utilizamos o K6 para simular carga alta de chargebacks.

Exemplo para rodar o teste:

k6 run chargeback-load-test.js

k6 run chargeback-load-test.js

Extension points exported contracts — how you extend this code

Uploader (Interface)
(no doc) [1 implementers]
chargeback-processor/internal/infrastructure/objectstorage/uploader.go
Downloader (Interface)
(no doc) [1 implementers]
chargeback-batch/internal/infrastructure/objectstorage/downloader.go
ChargebackRepository (Interface)
(no doc)
chargeback-api/internal/domain/respositories/chargeback-repository.go
ChargebackRepository (Interface)
(no doc)
chargeback-processor/internal/domain/respositories/chargeback-repository.go
Client (Interface)
(no doc) [1 implementers]
chargeback-batch/internal/infrastructure/transfer/ftp/client.go
BatchFilesRepository (Interface)
(no doc) [1 implementers]
chargeback-batch/internal/domain/repositories/batch-files-repository.go

Core symbols most depended-on inside this repo

Close
called by 20
chargeback-batch/internal/infrastructure/transfer/ftp/client.go
getEnv
called by 14
chargeback-batch/internal/config/config.go
getEnv
called by 13
chargeback-processor/internal/config/config.go
getEnv
called by 6
chargeback-api/internal/config/config.go
rotateFile
called by 3
chargeback-processor/internal/infrastructure/filewriter/chargeback-writer.go
Stop
called by 2
chargeback-api/internal/interfaces/http/server.go
getEnvAsDuration
called by 2
chargeback-api/internal/config/config.go
Write
called by 2
chargeback-processor/internal/infrastructure/filewriter/chargeback-writer.go

Shape

Function 137
Struct 73
Method 57
Interface 6

Languages

Go100%

Modules by API surface

chargeback-processor/internal/infrastructure/logging/logging.go21 symbols
chargeback-batch/internal/infrastructure/logging/logging.go21 symbols
chargeback-api/internal/infrastructure/logging/logging.go21 symbols
chargeback-batch/internal/config/config.go15 symbols
chargeback-processor/internal/config/config.go14 symbols
chargeback-api/internal/config/config.go11 symbols
chargeback-processor/internal/infrastructure/rabbitmq/consumers/consumers.go6 symbols
chargeback-processor/internal/infrastructure/logging/logging-hooks.go6 symbols
chargeback-processor/internal/infrastructure/filewriter/chargeback-writer.go6 symbols
chargeback-batch/internal/infrastructure/repositories/postgres/batch-files-repo-postgres.go6 symbols
chargeback-batch/internal/infrastructure/rabbitmq/consumers/consumers.go6 symbols
chargeback-batch/internal/infrastructure/logging/logging-hooks.go6 symbols

Datastores touched

batchDatabase · 1 repos

For agents

$ claude mcp add chargeback \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact