How tappn/grpc-chat works
Project Type and Purpose
• The README mentions “grpc-chat” with the note that it uses “grpcのstream” for a real-time chat API server. This tells us the project is focused on real-time communication using gRPC, built in Go.
• It’s essentially a network/server application providing chat and room management via gRPC streams.
File Structure and Key Components
• Top-Level Files:
• main.go: The entry point of the application.
• Makefile and docker-compose.yml: Build and deployment orchestration.
• go.mod and go.sum: Go dependency management.
• Directory Breakdown:
• proto/: Contains protocol buffer definitions for chat and room (proto/chat/v1/chat.proto, proto/room/v1/room.proto). This defines the service APIs and message formats.
• gen/: Holds the generated Go code based on the protos (chat.pb.go, chat_grpc.pb.go, room.pb.go, room_grpc.pb.go) used by the server for gRPC communication.
• handler/: Contains business logic handlers for chat and room operations (chat.go, room.go). These files likely map gRPC calls to internal operations.
• model/: Contains domain models (message.go, room.go, model.go) which define the data structures used throughout the project.
• repository/: Provides the data persistence layer (message.go, room.go) to interact with a database. These are the interfaces to the underlying DB.
• db/: Holds the database configuration (my.cnf) and SQL script (create_table.sql) to set up the schema.
• doc/: Contains documentation for both chat and room components, potentially with versioned docs outlining API endpoints or integration details.
a. Components to Include:
• gRPC Clients: Representing external consumers initiating streaming chat connections.
• API Server (main.go): The central execution point that starts all services.
• Handlers: Each for chat and room (handler/chat.go and handler/room.go) which process incoming gRPC requests.
• Protocol Buffer Layer: The proto definitions along with the generated code (proto/ and gen/ directories) that provide the interface contract.
• Business/Domain Logic: The models (model/) defining chat room and message entities.
• Repository/Data Layer: The repository/ accessing persistence (with SQL in db/).
• Database: The SQL database configured by db/my.cnf and created via db/create_table.sql.
• Deployment/DevOps Components: Represent the orchestration via docker-compose and build processes via the Makefile.
• Documentation Components: (doc/) for API usage and system design notes.
b. Relationships and Data Flow:
• gRPC Clients connect to the API Server to establish chat streams.
• API Server (through main.go) routes requests to appropriate handlers.
• Handlers (chat and room) utilize the generated gRPC code (from proto/gen) to serialize/deserialize messages.
• The handlers then interact with the model layer (domain logic) and call the repository layer to persist or retrieve data.
• Repository components interact with the database to store or fetch chat messages and room information.
• Optionally, include components for configuration and deployment that show how docker-compose orchestrates the environment.
c. Architectural Patterns and Design Principles:
• Separation of Concerns: Each layer (API, handler, domain/model, repository, and persistence) has a clear responsibility.
• Use of gRPC Streaming: The architectural emphasis on real-time, bidirectional communication.
• Modular Structure: Distinct directories for proto definitions, generated code, handlers, models, and database scripts indicate modularity.
• Clear API Contracts: Protobuf definitions ensure that the interfaces between components remain consistent.
d. Technology, Frameworks, and Tools:
• Go (golang) as the programming language.
• gRPC for communication (protocol buffers in proto/ and generated Go gRPC code in gen/).
• SQL Database configured through db/ scripts.
• Docker (docker-compose.yml) for containerization and deployment.
• Makefile for build automation.