{"id":19569949,"url":"https://github.com/meenachinmay/microservices-golang","last_synced_at":"2025-07-29T10:39:22.015Z","repository":{"id":244008826,"uuid":"813921628","full_name":"Meenachinmay/microservices-golang","owner":"Meenachinmay","description":"A microservices setup using golang, rabbitmq, docker, postgres, mongodb.","archived":false,"fork":false,"pushed_at":"2024-06-27T15:18:37.000Z","size":454745,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-27T03:31:54.980Z","etag":null,"topics":["gin-framework","golnag","microservice","rabbitmq","rate","redis"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Meenachinmay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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}},"created_at":"2024-06-12T02:10:46.000Z","updated_at":"2025-03-22T20:26:35.000Z","dependencies_parsed_at":"2025-04-27T03:33:10.518Z","dependency_job_id":"61c59c70-5d29-464c-9716-34c8af518680","html_url":"https://github.com/Meenachinmay/microservices-golang","commit_stats":null,"previous_names":["meenachinmay/microservices-golang"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meenachinmay%2Fmicroservices-golang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meenachinmay%2Fmicroservices-golang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meenachinmay%2Fmicroservices-golang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meenachinmay%2Fmicroservices-golang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Meenachinmay","download_url":"https://codeload.github.com/Meenachinmay/microservices-golang/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meenachinmay%2Fmicroservices-golang/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259053293,"owners_count":22798429,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["gin-framework","golnag","microservice","rabbitmq","rate","redis"],"created_at":"2024-11-11T06:13:00.215Z","updated_at":"2025-06-10T10:05:29.599Z","avatar_url":"https://github.com/Meenachinmay.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Microservices with Golang\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Table of Contents.\n\n- [Introduction](#introduction)\n- [Architecture](#architecture)\n- [Getting Started](#getting-started)\n  - [Prerequisites](#prerequisites)\n  - [Installation](#installation)\n  - [Running the Services](#running-the-services)\n- [Services](#services)\n  - [API Gateway](#api-gateway)\n  - [Authentication Service](#authentication-service)\n  - [Logger Service](#logger-service)\n  - [Mailer Service](#mailer-service)\n  - [Listener Service](#listener-service)\n  - [Payment Service](#payment-service)\n- [Technologies Used](#technologies-used)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Introduction\n\nThis repository contains a microservices-based application built with Golang. The application demonstrates how to use microservices to create a scalable and maintainable architecture. It includes services for authentication, logging, mailing, and a listener service that processes events from RabbitMQ.\n\n## Architecture\n\nThe architecture is composed of multiple services that communicate with each other through REST APIs and message queues. The services are:\n\n- **API Gateway**: The entry point for all client requests.\n- **Authentication Service**: Handles user authentication.\n- **Logger Service**: Page application events.\n- **Mailer Service**: Sends emails.\n- **Listener Service**: Listens for events from RabbitMQ and processes them.\n- **Payment Service**: Listens for gRPC calls from api-gateway to Process payments using credit card.\n\n\n## Getting Started\n\n### Prerequisites\n\nBefore you begin, ensure you have the following installed:\n\n- [Golang](https://golang.org/doc/install)\n- [Docker](https://docs.docker.com/get-docker/)\n- [Docker Compose](https://docs.docker.com/compose/install/)\n\n### Installation\n\n1. Clone the repository:\n\n    ```sh\n    git clone https://github.com/Meenachinmay/microservices-golang.git\n    cd microservices-golang\n    ```\n\n2. Create an `.env` file in the root directory and set the necessary environment variables. An example `.env` file is provided as `.env.example`.\n\n    ```sh\n    cp .env.example .env\n    ```\n\n### Running the Services\n\n1. Build and run the services using Docker Compose using Makefile:\n\n    ```sh\n    make up_build\n    ```\n\n2. The services will be available at the following ports:\n\n    - API Gateway: `http://localhost:8080`\n    - Authentication Service: `http://localhost:8081`\n    - Logger Service: `http://localhost:8082`\n    - Mailer Service: `http://localhost:8083`\n    - Listener Service: `http://localhost:8084`\n    - Payment Service: `http://localhost:8085`\n\n## Services\n\n### API Gateway (Broker-service)\n\nThe API Gateway is the main entry point for all incoming requests. It routes requests to the appropriate service based on the action specified.\n\n### Authentication Service\n\nThe Authentication Service handles user authentication. It provides endpoints for login, signup, and password reset. (as of now just login is there for simulation, I will add more like signup, session, cookies and everything)\n\n### Logger Service\n\nThe Logger Service logs application events. It listens for log events from RabbitMQ and stores them in a log file.\n\n### Mailer Service\n\nThe Mailer Service sends emails. It listens for mail events from RabbitMQ and sends emails using the configured SMTP server. (I am using mailhog as of now, later I will use sendgrid)\n\n### Listener Service\n\nThe Listener Service listens for events from RabbitMQ and processes them. It handles log and mail events, delegating tasks to the appropriate services.\n\n### Payment Service\nThe payment service uses stripe payment gateway API to enable credit card payment for now. Payment service\nneed to communicate with async calls with api-gateway and api-gateway with client, so for the communication\nbetween api-gateway and Payment service I am enabling gRPC calls, rather than using RabbitMQ. \nIn this service I planned to use rabbitMQ to generate email invoices for payments on a completion of \nsuccessful payments from users.\n\n## Technologies Used\n\n- **Golang**: The primary language used for building the services.\n- **Docker**: Used for containerizing the services.\n- **Docker Compose**: Used for orchestrating the multi-container Docker application.\n- **RabbitMQ**: Used for messaging between services.\n- **PostgreSQL**: The database used by the Authentication Service.\n- **MongoDB**: The database used by the Logger Service.\n- **gRPC**: Communication method between api-gateway and other services where it needs async calls.\n\n\n### Command to generate gRPC code \n``` sh \n     protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative \u003cname of file\u003e.proto\n```\n\n## Service methods and Diagram\n## Services:\n1. Api-gateway\n2. Enquiry-service -\u003e Postgres DB\n3. Mail-service\n4. Logger-service -\u003e Postgres DB\n5. Listener-service\n6. frontend\n\n### DB tables:\n- users table\n- enquiry tables\n- schedules table\n- logs tables\n\n### Microservice communication\n- http\n- gRPC\n- Rabbitmq message broker\n\n### Containerization\n- Docker\n\n### Databases\n- Postgres -\u003e data store\n- Redis -\u003e Cache, Rate Limiting\n\n### 3rd party API Integration\n- Sendgrid\n\n### Service wise methods\n\u003e ### Api-gateway\n##### HTTP\n```go\nfunc HandleSubmission(c *gin.Context)\nfunc (lac *LocalApiConfig) FetchAllProperties(c *gin.Context)\nfunc connect() (*amqp.Connection, error)\n```\n##### gRPC\n```go\nfunc EnquiryViaGRPC(c *gin.Context, enquiryPayload types.EnquiryPayload)\nfunc (lac *LocalApiConfig) GetAllLogs(c *gin.Context)\nfunc (lac *LocalApiConfig) WriteLog(c *gin.Context)\nfunc (lac *LocalApiConfig) CreateNewUser(c *gin.Context, userPayload types.UserPayload)\n```\n\n\u003e ### Enquiry-service\n##### HTTP\n```go\nfunc (localApiConfig *LocalApiConfig) HandleFetchAllProperties(c *gin.Context)\n```\n```go\nfunc StartGrpcServer(localApiConfig *handlers.LocalApiConfig)\nfunc connect() (*amqp.Connection, error)\nfunc connectToDB() *sql.DB\nfunc ProcessScheduledTasks(s *handlers.EnquiryServer)\n```\n##### handlers\n```go\nfunc StartGrpcUserServer(localApiConfig *handlers.LocalApiConfig)\nfunc (e *EnquiryServer) HandleCustomerEnquiry(ctx context.Context, request *enquiries.CustomerEnquiryRequest) (*enquiries.CustomerEnquiryResponse, error)\nfunc (e *EnquiryServer) getTotalEnquiriesLastWeek(c context.Context, updatedUser database.User) (int, error)\nfunc (e *EnquiryServer) SendEmail(payload EnquiryMailPayloadUsingSendgrid) error\nfunc (e *EnquiryServer) notifyUserAboutEnquiry(input *enquiries.CustomerEnquiry, totalEnquiries int, mailPayload EnquiryMailPayloadUsingSendgrid) error\nfunc (e *EnquiryServer) executeTask(input *enquiries.CustomerEnquiry, mailPayload EnquiryMailPayloadUsingSendgrid) error\nfunc (e *EnquiryServer) scheduleTask(input *enquiries.CustomerEnquiry, mailPayload EnquiryMailPayloadUsingSendgrid) error\nfunc (u *UserServer) CreateNewUser(ctx context.Context, request *users.CreateUserRequest) (*users.CreateUserResponse, error)\n```\n##### rabbitmq actions\n```go\nfunc (e *Emitter) declareExchange(ch *amqp.Channel) error\nfunc (e *Emitter) Emit(event string) error\nfunc NewEmitter(conn *amqp.Connection, exchange, routingKey string) (*Emitter, error)\n```\n\u003e ### Listener-service\n##### rabbitmq actions\n```go\nfunc DeclareExchange(ch *amqp.Channel) error\nfunc DeclareRandomQueue(ch *amqp.Channel) (amqp.Queue, error)\nfunc DeclareMailExchange(ch *amqp.Channel) error\nfunc DeclareMailQueue(ch *amqp.Channel) (amqp.Queue, error)\nfunc DeclareEnquiryMailQueue(ch *amqp.Channel) (amqp.Queue, error)\nfunc NewLogConsumer(conn *amqp.Connection) (*LogConsumer, error)\nfunc (consumer *LogConsumer) ConsumeLogs(topics []string) error\nfunc logEvent(log LogPayload) error\nfunc NewMailConsumer(conn *amqp.Connection) (*MailConsumer, error)\nfunc (consumer *MailConsumer) ConsumeMails() error\nfunc (consumer *MailConsumer) ConsumeEnquiryMails() error\nfunc sendEnquiryMail(payload EnquiryMailPayloadUsingSendgrid) (time.Duration, error)\nfunc logMailSendingResult(payload EnquiryMailPayloadUsingSendgrid, elapsed time.Duration, err error) error\nfunc startLogConsumer(conn *amqp.Connection)\nfunc startMailConsumer(conn *amqp.Connection)\nfunc startEnquiryMailConsumer(conn *amqp.Connection)\n```\n\u003e ### Logger-service\n##### HTTP\n```go\nfunc (apiConfig *LocalApiConfig) WriteLog(c *gin.Context)\n```\n##### gRPC\n```go\nfunc (l *LogServer) WriteLog(ctx context.Context, req *logs.LogRequest) (*logs.LogResponse, error)\nfunc (l *LogServer) GetAllLogs(ctx context.Context, request *logs.GetAllLogsRequest) (*logs.GetAllLogsResponse, error)\nfunc GRPCListener(localApiConfig *LocalApiConfig)\n```\n\u003e ### Mail-service\n##### HTTP\n```go\nfunc (app *Config) SendMailViaSendGrid(w http.ResponseWriter, r *http.Request)\n```\n\n### Diagram\n![img.png](img.png)\n\n## Contributing\n\nContributions are welcome! Please read the [CONTRIBUTING.md](./CONTRIBUTING.md) file for more information on how to contribute to this project.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE.md) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeenachinmay%2Fmicroservices-golang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeenachinmay%2Fmicroservices-golang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeenachinmay%2Fmicroservices-golang/lists"}