{"id":34782106,"url":"https://github.com/miltonj23/calcrpc","last_synced_at":"2026-05-08T02:01:57.058Z","repository":{"id":326563947,"uuid":"1106088419","full_name":"MiltonJ23/CalcRpc","owner":"MiltonJ23","description":"Calculator Microservice built with Go (Gin + gRPC) and Next.js 16. Implements Clean Architecture with dual-protocol support (HTTP/gRPC), Docker containerization, and automated CI/CD to GHCR.","archived":false,"fork":false,"pushed_at":"2025-11-28T17:40:58.000Z","size":92,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-30T22:37:38.213Z","etag":null,"topics":["clean-architecture","gchr","gin-gonic","grpc","grpc-golang","microservice","nextjs16-typescript","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MiltonJ23.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-28T15:59:12.000Z","updated_at":"2025-11-28T17:42:22.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/MiltonJ23/CalcRpc","commit_stats":null,"previous_names":["miltonj23/calcrpc"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/MiltonJ23/CalcRpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MiltonJ23%2FCalcRpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MiltonJ23%2FCalcRpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MiltonJ23%2FCalcRpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MiltonJ23%2FCalcRpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MiltonJ23","download_url":"https://codeload.github.com/MiltonJ23/CalcRpc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MiltonJ23%2FCalcRpc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32763518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"online","status_checked_at":"2026-05-08T02:00:05.879Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clean-architecture","gchr","gin-gonic","grpc","grpc-golang","microservice","nextjs16-typescript","typescript"],"created_at":"2025-12-25T08:57:03.166Z","updated_at":"2026-05-08T02:01:57.051Z","avatar_url":"https://github.com/MiltonJ23.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go gRPC \u0026 HTTP Calculator Service\n\nA production-grade implementation of a Calculator Service using **Clean Architecture**. This project demonstrates how to build a Dual-Protocol Microservice (gRPC + HTTP) using **Go** for the backend and **Next.js** for the frontend, fully containerized for deployment.\n\nBased on the original gRPC concept by Engr. Daniel Moune, upgraded to a modern web stack.\n\n-----\n\n## 🏗 Architecture\n\nThis project strictly follows **Clean Architecture** (Hexagonal Architecture) principles. The goal is to separate the business logic (Core) from the delivery mechanisms (HTTP/gRPC) and the user interface.\n\n### The \"Dual-Protocol\" Design\n\nThe backend exposes two \"ports\" (entry points) simultaneously:\n\n1.  **Primary Port (gRPC - `:50051`)**: For high-performance internal communication between microservices.\n2.  **Secondary Port (HTTP/Gin - `:8080`)**: Acts as an API Gateway/Adapter for the web frontend.\n\n### Layers\n\n* **Domain (Core):** Pure Go business logic. It knows nothing about JSON, HTTP, or gRPC. It simply calculates numbers.\n* **Adapters (Infrastructure):**\n    * **gRPC Adapter:** Maps Protobuf requests to the Core Service.\n    * **HTTP Adapter (Gin):** Maps JSON REST requests to the Core Service.\n* [cite\\_start]**Contract:** Defined via Protocol Buffers (`calculator.proto`), serving as the single source of truth for the API definition[cite: 31, 39].\n\n### Sequence Diagram\n\nHere is the flow of data when a user performs a calculation via the web interface:\n\n```mermaid\nsequenceDiagram\n    participant User\n    participant FE as Next.js Frontend\n    participant HTTP as Gin Adapter (HTTP)\n    participant Core as Core Service (Logic)\n    participant gRPC as gRPC Adapter\n\n    Note over User, FE: Web Interaction\n    User-\u003e\u003eFE: Clicks \"Add 5 + 10\"\n    FE-\u003e\u003eHTTP: POST /add {num1: 5, num2: 10}\n    \n    Note over HTTP, Core: Backend Processing\n    HTTP-\u003e\u003eCore: service.Add(5, 10)\n    Core--\u003e\u003eHTTP: returns 15\n    \n    HTTP--\u003e\u003eFE: JSON {result: 15}\n    FE--\u003e\u003eUser: Displays \"Result: 15\"\n\n    Note over Core, gRPC: Alternative Access\n    Note right of gRPC: External microservices can\u003cbr/\u003ecall Core via gRPC port 50051\u003cbr/\u003esimultaneously.\n```\n\n-----\n\n## 📂 Project Structure\n\n```text\ncalculator-app/\n├── proto/               # Protocol Buffer definitions (The Contract)\n├── backend/             # Go Backend\n│   ├── cmd/server/      # Main entry point (starts Gin + gRPC)\n│   ├── internal/\n│   │   ├── core/        # Pure Business Logic (Service Layer)\n│   │   └── adapter/     # Protocol Adapters (gRPC Server, Gin Handlers)\n│   └── pkg/pb/          # Generated Go Code from Protobuf\n├── frontend/            # Next.js 14 Frontend\n│   ├── app/             # App Router pages\n│   └── lib/             # API clients\n├── docker-compose.yml   # Local orchestration\n└── .github/workflows/   # CI/CD Pipeline\n```\n\n-----\n\n## 🚀 Getting Started\n\n### Prerequisites\n\n* **Go**: v1.22+\n* **Node.js**: v18+\n* **Docker** (Optional, for container run)\n* **Protoc Compiler** (Only if modifying `.proto` files)\n\n### Option 1: Quick Start (Docker Compose)\n\nThe easiest way to run the entire stack (Backend + Frontend) is using Docker.\n\n1.  **Clone the repository:**\n\n    ```bash\n    git clone https://github.com/YOUR_USERNAME/calculator-service.git\n    cd calculator-service\n    ```\n\n2.  **Run with Compose:**\n\n    ```bash\n    docker-compose up --build\n    ```\n\n3.  **Access the App:**\n\n    * **Frontend:** Open [http://localhost:3000](https://www.google.com/search?q=http://localhost:3000)\n    * **Backend API:** [http://localhost:8080](https://www.google.com/search?q=http://localhost:8080)\n    * **gRPC Server:** `localhost:50051`\n\n-----\n\n### Option 2: Run Locally (Manual)\n\nIf you want to develop and run the services individually without Docker:\n\n#### 1\\. Backend Setup (Go)\n\n```bash\ncd backend\n\n# Install dependencies\ngo mod tidy\n\n# Run the server\ngo run cmd/server/main.go\n```\n\n*Output:* \\\u003e `gRPC Server listening on port 50051`\n\n\u003e `HTTP Gin Server listening on port 8080`\n\n#### 2\\. Frontend Setup (Next.js)\n\nOpen a new terminal:\n\n```bash\ncd frontend\n\n# Install dependencies\nnpm install\n\n# Run the development server\nnpm run dev\n```\n\n*Output:*\n\n\u003e `Ready in 5.4s`\n\u003e `url: http://localhost:3000`\n\n-----\n\n## 🛠 Features Implemented\n\n* [cite\\_start]**Operations:** Supports all 5 operations defined in the original specification[cite: 44, 45]:\n    * Addition (`Add`)\n    * Subtraction (`Sub`)\n    * Multiplication (`Mul`)\n    * Division (`Div`) - *includes error handling for div by zero*\n    * Modulo (`Mod`)\n* [cite\\_start]**Type Safety:** Uses Protobuf `int32` types for consistent data handling across languages[cite: 50, 58].\n* [cite\\_start]**Concurrency:** The Go backend handles the HTTP and gRPC listeners in concurrent goroutines, mirroring the thread pool concept from the Python reference[cite: 204].\n* **CI/CD:** Includes GitHub Actions workflow to auto-build and push Docker images to GHCR on every push to `main`.\n\n-----\n\n## 🐳 Deployment\n\nThis project is configured for containerized deployment.\n\n* **Frontend:** Built as a standalone Next.js artifact (minimal size).\n* **Backend:** Built as a static Go binary running on a `distroless` image (high security, \\\u003c20MB size).\n\n**CI/CD Pipeline:**\nThe `.github/workflows/deploy.yml` file automatically:\n\n1.  Logs into GitHub Container Registry (GHCR).\n2.  Builds the Backend and Frontend images.\n3.  Pushes them with tags `:latest` and `:sha-\u003ccommit-hash\u003e`.\n\n-----\n\n## 📜 References\n\n* Concept based on \"gRPC Implementation: Calculator Service\" by Engr. Daniel Moune.\n* gRPC Official Documentation: [grpc.io](https://grpc.io/)\n* Protocol Buffers: [developers.google.com/protocol-buffers](https://developers.google.com/protocol-buffers)\n\n-----\n\n**Author:** Zingui Fred Mike\n**License:** MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiltonj23%2Fcalcrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiltonj23%2Fcalcrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiltonj23%2Fcalcrpc/lists"}