Skip to content

A microservice showcasing a dual API architecture (REST & gRPC) for real-time crypto portfolio tracking. Observe how a single business logic core can serve both human-facing and machine-to-machine communication patterns.

License

Notifications You must be signed in to change notification settings

xAPT42/Dual-api-crypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Dual API Crypto

Docker Build Docker Hub

Un microservice Go dΓ©montrant une architecture "Dual API" avec une API REST et une API gRPC pour le suivi de portefeuille crypto en temps rΓ©el.

🎯 Objectif

Ce projet illustre comment une seule logique mΓ©tier peut servir deux types de clients :

  • API REST : Pour les interfaces web et les intΓ©grations simples
  • API gRPC : Pour la communication machine-Γ -machine haute performance

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Client REST   β”‚    β”‚   Client gRPC   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚                      β”‚
          β–Ό                      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Dual API Server                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ REST API    β”‚  β”‚   gRPC API      β”‚   β”‚
β”‚  β”‚ Port 8080   β”‚  β”‚   Port 9090     β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚         β”‚                   β”‚           β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”‚                   β–Ό                     β”‚
β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
β”‚         β”‚  Business Logic  β”‚             β”‚
β”‚         β”‚  (Portfolio)    β”‚             β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        CoinGecko API                    β”‚
β”‚     (Prix crypto temps rΓ©el)           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ DΓ©marrage Rapide

PrΓ©requis

  • Docker et Docker Compose
  • Go 1.24+ (pour le dΓ©veloppement local)

Lancement avec Docker Hub

# Utiliser l'image prΓ©-construite depuis Docker Hub
docker pull idablaq/dual-api-crypt:latest

# Lancer le conteneur
docker run -d -p 8080:8080 -p 9090:9090 --name dual-api-crypt idablaq/dual-api-crypt:latest

Lancement avec Docker Compose

# Cloner le projet
git clone https://github.com/xAPT42/Dual-api-crypt.git
cd Dual-api-crypt

# Construire et lancer
docker-compose up --build

DΓ©veloppement Local

# Installer les dΓ©pendances
go mod tidy

# GΓ©nΓ©rer le code gRPC
protoc --go_out=. --go_opt=paths=source_relative \
       --go-grpc_out=. --go-grpc_opt=paths=source_relative \
       api/portfolio.proto

# Lancer l'application
go run cmd/server/main.go

πŸ“‘ API Endpoints

REST API (Port 8080)

Obtenir la valeur du portefeuille

curl http://localhost:8080/portfolio

RΓ©ponse :

{
  "value": 12543.67,
  "currency": "EUR",
  "timestamp": "2024-01-15T10:30:00Z"
}

Health Check

curl http://localhost:8080/health

gRPC API (Port 9090)

Lister les services

grpcurl -plaintext localhost:9090 list

Appeler GetPortfolioValue

grpcurl -plaintext localhost:9090 portfolio.PortfolioService/GetPortfolioValue

πŸ’Ό Portefeuille par DΓ©faut

Le portefeuille est dΓ©fini dans le code et contient :

  • Bitcoin : 0.5 BTC
  • Ethereum : 5.0 ETH
  • Cardano : 1000 ADA
  • Solana : 50 SOL
  • Chainlink : 100 LINK

πŸ› οΈ Structure du Projet

dual-api-crypto/
β”œβ”€β”€ api/                    # Contrats gRPC
β”‚   β”œβ”€β”€ portfolio.proto     # DΓ©finition du service
β”‚   β”œβ”€β”€ portfolio.pb.go     # Code gΓ©nΓ©rΓ©
β”‚   └── portfolio_grpc.pb.go
β”œβ”€β”€ cmd/server/             # Point d'entrΓ©e
β”‚   └── main.go            # Serveurs REST et gRPC
β”œβ”€β”€ internal/service/      # Logique mΓ©tier
β”‚   └── portfolio.go       # Calcul du portefeuille
β”œβ”€β”€ Dockerfile             # Image Docker
β”œβ”€β”€ docker-compose.yml     # Orchestration
β”œβ”€β”€ go.mod                 # DΓ©pendances Go
└── README.md              # Documentation

πŸ”§ Technologies UtilisΓ©es

  • Go 1.24 : Langage principal
  • gRPC : Communication haute performance
  • Protocol Buffers : SΓ©rialisation efficace
  • Docker : Conteneurisation
  • CoinGecko API : DonnΓ©es crypto temps rΓ©el

πŸ§ͺ Tests

Test REST API

# Test de base
curl -X GET http://localhost:8080/portfolio

# Test avec jq pour un affichage formatΓ©
curl -s http://localhost:8080/portfolio | jq

Test gRPC API

# Installer grpcurl
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest

# Lister les services
grpcurl -plaintext localhost:9090 list

# Appeler la mΓ©thode
grpcurl -plaintext localhost:9090 portfolio.PortfolioService/GetPortfolioValue

πŸ“Š Monitoring

Le service expose un endpoint de santΓ© sur /health pour le monitoring.

πŸ”„ CI/CD et Docker Hub

Workflow GitHub Actions

Le projet utilise GitHub Actions pour automatiser le build et le push des images Docker vers Docker Hub :

  • DΓ©clenchement :

    • Push sur la branche main β†’ tag latest
    • Tags Git (ex: v1.0.0) β†’ tags versionnΓ©s
    • Pull Requests β†’ build de test uniquement
  • Multi-architecture : Les images sont buildΓ©es pour linux/amd64 et linux/arm64

  • Cache : Utilise GitHub Actions cache pour accΓ©lΓ©rer les builds

Configuration des Secrets GitHub

Pour activer le workflow, configurez les secrets suivants dans votre dΓ©pΓ΄t GitHub :

  1. Allez dans Settings β†’ Secrets and variables β†’ Actions
  2. Ajoutez les secrets suivants :
    • DOCKERHUB_USERNAME : Votre nom d'utilisateur Docker Hub
    • DOCKERHUB_TOKEN : Votre token d'accΓ¨s Docker Hub (crΓ©er un token sur hub.docker.com)

Images Docker Hub

Les images sont disponibles sur : idablaq/dual-api-crypt

# Dernière version
docker pull idablaq/dual-api-crypt:latest

# Version spΓ©cifique
docker pull idablaq/dual-api-crypt:v1.0.0

πŸ”’ SΓ©curitΓ©

  • Utilisateur non-root dans le conteneur
  • Certificats SSL pour les requΓͺtes HTTPS
  • Headers CORS configurΓ©s
  • Timeouts configurΓ©s

🀝 Contribution

  1. Fork le projet
  2. CrΓ©er une branche feature (git checkout -b feature/AmazingFeature)
  3. Commit les changements (git commit -m 'Add some AmazingFeature')
  4. Push vers la branche (git push origin feature/AmazingFeature)
  5. Ouvrir une Pull Request

πŸ“ Licence

Ce projet est sous licence MIT. Voir le fichier LICENSE pour plus de dΓ©tails.

πŸŽ“ Apprentissage

Ce projet dΓ©montre :

  • Architecture Dual API : Une logique mΓ©tier, deux interfaces
  • gRPC vs REST : Quand utiliser chaque technologie
  • Microservices : Design et implΓ©mentation
  • Docker : Conteneurisation d'applications Go
  • API externes : IntΓ©gration avec CoinGecko

Développé avec ❀️ pour démontrer les architectures microservices modernes

About

A microservice showcasing a dual API architecture (REST & gRPC) for real-time crypto portfolio tracking. Observe how a single business logic core can serve both human-facing and machine-to-machine communication patterns.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published