This document provides guidance for AI agents working in this repository.
This is a real-time communication platform with a React frontend and Go microservices backend.
minor-kursach/
├── frontend/ # React 19 application
├── backend/
│ ├── services/ # Go microservices (auth_service, user_service, etc.)
│ └── shared/ # Shared Go modules
└── deploy/ # Docker deployment configs
cd frontend/
npm install # Install dependencies
npm start # Start dev server (http://localhost:3000)
npm run build # Production buildcd backend/
go work sync # Sync workspace dependencies
go build ./... # Build all services
go mod download # Download dependencies
go mod tidy # Clean up go.mod/go.sumcd backend/services/auth_service/
go run cmd/auth/main.go # Run auth servicecd backend/services/user_service/
make migrate-up # Apply all migrations
make migrate-down # Rollback last migration
make migrate-force version=N # Force to specific version
make migrate-version # Show current version
make migrate-create name=xxx # Create new migrationNote: Requires migrate CLI tool installed.
cd frontend/
npm test # Run all tests (watch mode)
npm test -- --watchAll=false # Run once (CI mode)
npm test -- --testPathPattern=App # Run specific test file
npm test -- -t "test name" # Run test by name pattern
npm test -- --coverage # Generate coverage reportcd backend/
go test ./... # Run all tests
go test ./services/auth_service/... # Test specific service
go test -v ./... # Verbose output
go test -run TestName # Run specific test by nameNote: Most backend services currently have no test files.
Formatting:
- Use standard
go fmtformatting (tabs for indentation) - Run
go fmt ./...before committing
Naming Conventions:
- Package names: lowercase, single words (e.g.,
service,repository) - Struct names: PascalCase (e.g.,
AuthorizationService) - Variable names: camelCase (e.g.,
authRepository) - Constants: camelCase or SCREAMING_SNAKE_CASE for config constants
- Files: lowercase with underscores (e.g.,
auth.go,postgres.go)
Directory Structure (per service):
internal/
├── app/ # Application setup
├── config/ # Configuration loading (YAML/env)
├── http-server/ # HTTP handlers and middleware
│ ├── handler/ # Request handlers
│ └── middleware/ # HTTP middleware (CORS, JWT, etc.)
├── lib/ # Shared libraries (logger, JWT, response)
├── model/ # Data models
├── repository/ # Database access layer
│ └── postgres/ # PostgreSQL implementations
└── service/ # Business logic layer
Error Handling Pattern:
const op = "service.auth.Login"
func (s *Service) DoSomething() error {
err := doSomething()
if err != nil {
return fmt.Errorf("%s: %w", op, err)
}
return nil
}Logging:
- Use
go.uber.org/zapfor structured logging - Always include operation context:
log.With(zap.String("op", op))
Imports:
- Standard library first, then third-party, then internal
- Use aliases for disambiguation (e.g.,
authHandler "...") - Group with blank lines between groups
Dependencies:
- Chi v5 (
github.com/go-chi/chi/v5) for HTTP routing - pgx/v5 (
github.com/jackc/pgx/v5) for PostgreSQL - zap for logging
- cleanenv for config loading
Formatting:
- No Prettier config; follow ESLint defaults
- Use semicolons at end of statements
- Use double quotes for strings
Naming Conventions:
- Components: PascalCase (e.g.,
VoiceChannel.jsx) - Functions/Variables: camelCase
- Constants: SCREAMING_SNAKE_CASE
Component Patterns:
import { useState, useEffect } from 'react';
const VoiceChannel = ({ channelId, userId }) => {
const [isActive, setIsActive] = useState(false);
useEffect(() => {
// cleanup
return () => {};
}, []);
return <div className="voice-channel">{/* ... */}</div>;
};
export default VoiceChannel;Imports:
- React imports first
- Then external libraries
- Then internal components/utils
- Then CSS/assets
Testing:
- Use
@testing-library/reactand@testing-library/user-event - Follow patterns in
src/App.test.js
- Create directory under
backend/services/<service_name>/ - Initialize Go module:
go mod init github.com/sudo-odner/minor/backend/services/<service_name> - Create
internal/structure with app, config, handlers, etc. - Add to
backend/go.work
- Add handler method in appropriate handler file
- Register route in
main.gousing chi router - Follow the pattern: handler -> service -> repository
- Store in
.envfiles (not committed) - Use
cleanenvfor YAML/env loading - Required vars documented in config files
- API Gateway: Routes requests to appropriate services
- Auth Service: JWT-based authentication
- User Service: User management and relationships
- NATS: Inter-service communication
- PostgreSQL: Primary database (user_service, auth_service)
- Traefik: Reverse proxy and load balancer
| File | Purpose |
|---|---|
backend/go.work |
Go workspace configuration |
frontend/package.json |
Frontend dependencies and scripts |
deploy/docker-compose.yaml |
Full stack deployment |
.env (per service) |
Environment variables |