Skip to content

iNineBD/VisionData-6Sem2025Server

Repository files navigation

Vision Data API

A REST API developed in Go using the Gin framework, integrated with Elasticsearch for logging, Redis for caching, and MongoDB for data persistence.

πŸ“ Project Structure

β”œβ”€β”€ cmd/                          # Application entry point
β”‚   └── api/
β”‚       β”œβ”€β”€ main.go              # Main application file
β”‚       └── main_test.go         # Main tests
β”œβ”€β”€ docker-compose.yml           # Docker Compose configuration
β”œβ”€β”€ dockerfile                   # Application Docker image
β”œβ”€β”€ go.mod                       # Go dependencies
β”œβ”€β”€ go.sum                       # Dependencies checksums
β”œβ”€β”€ index_tickets.json          # Elasticsearch index configuration
β”œβ”€β”€ internal/                    # Internal application code
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── config.go           # Application configuration
β”‚   β”œβ”€β”€ middleware/             # HTTP middlewares
β”‚   β”‚   β”œβ”€β”€ cors.go            # CORS middleware
β”‚   β”‚   β”œβ”€β”€ id.go              # ID generation middleware
β”‚   β”‚   β”œβ”€β”€ jwt.go             # JWT authentication middleware
β”‚   β”‚   β”œβ”€β”€ logger.go          # Logging middleware
β”‚   β”‚   β”œβ”€β”€ server.go          # Server configuration
β”‚   β”‚   └── throttling.go      # Rate limiting middleware
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── generic_response.go # Generic response models
β”‚   β”œβ”€β”€ repositories/           # Data access layer
β”‚   β”‚   β”œβ”€β”€ elsearch/
β”‚   β”‚   β”‚   └── connection.go   # Elasticsearch connection
β”‚   β”‚   β”œβ”€β”€ mongo/
β”‚   β”‚   β”‚   └── connection.go   # MongoDB connection
β”‚   β”‚   └── redis/
β”‚   β”‚       β”œβ”€β”€ connection.go   # Redis connection
β”‚   β”‚       └── methods.go      # Redis methods
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── routes.go          # API routes definition
β”‚   β”œβ”€β”€ service/               # Service layer
β”‚   β”‚   └── healthcheck/
β”‚   β”‚       └── health.go      # Health check service
β”‚   └── utils/
β”‚       └── hosts.go           # Host utilities
β”œβ”€β”€ pkg/                       # Reusable packages
β”‚   └── logger/
β”‚       └── logger.go         # Custom logging system
└── README.md                 # This file

πŸ—οΈ Architecture

The application follows a layered architecture:

  • cmd/: Entry point and initial configuration
  • internal/: Application-specific code (non-exportable)
    • config/: Configuration management
    • middleware/: HTTP middlewares (CORS, JWT, logging, etc.)
    • models/: Data structures
    • repositories/: Data access (Elasticsearch, MongoDB, Redis)
    • routes/: API routes definition
    • service/: Business logic
    • utils/: Various utilities
  • pkg/: Reusable and exportable packages

πŸš€ How to Run

Prerequisites

  • Docker and Docker Compose installed
  • SSL certificates in ./certs/ (for HTTPS)

Using Docker Compose

Clone the repository and run:

# Start all services
docker-compose up -d

# Check logs
docker-compose logs -f vision-data-api

# Stop services
docker-compose down

# Rebuild and start (after code changes)
docker-compose up -d --build

Checking Service Status

# Check running containers
docker-compose ps

# Follow logs in real-time
docker-compose logs -f

# Access container shell
docker-compose exec vision-data-api sh

βš™οΈ Configuration

Environment Variables

The application uses the following environment variables (configured in .env):

# Application settings - PRODUCTION
ENVIRONMENT_APP=prod
APP_PORT=8080
APP_PORT_TLS=8443
APP_CERT_FILE=/app/certs/server.crt
APP_KEY_FILE=/app/certs/server.key

# Elasticsearch - PRODUCTION
ELASTICSEARCH_URL=https://********:9200/
ELASTICSEARCH_USERNAME=elastic
ELASTICSEARCH_PASSWORD=**********

# Redis - PRODUCTION
REDIS_HOST=redis
REDIS_PORT=6379

SSL Certificates

For HTTPS execution, place certificates in the ./certs/ folder:

  • server.crt - Public certificate
  • server.key - Private key

πŸ”Œ Endpoints

Health Check

GET /healthcheck/

Returns the application status and its dependencies.

πŸ“Š Monitoring and Logs

Elasticsearch

  • URL: https://********:9200/
  • Username: elastic
  • Application logs are automatically sent to Elasticsearch

Redis

  • Host: redis:6379
  • Used for caching and sessions

Kibana

  • Interface for Elasticsearch log visualization
  • Configure access through Elasticsearch

🐳 Docker Services

The Docker Compose setup includes:

vision-data-api

  • Ports: 8080 (HTTP), 8443 (HTTPS)
  • Volumes: SSL certificates mounted as read-only
  • Dependencies: Redis

redis

  • Image: redis:7.4-alpine
  • Port: 6379
  • Persistence: Local volume for data storage
  • Configuration: Appendonly disabled for performance

πŸ“ Features

  • REST API: Built with Gin Framework
  • Logging: Elasticsearch integration via custom middleware
  • Caching: Redis for performance optimization
  • Authentication: JWT middleware for security
  • CORS: Cross-origin access configuration
  • Rate Limiting: Request throttling control
  • Health Check: Application monitoring endpoint
  • HTTPS: TLS support with custom certificates

πŸ”§ Troubleshooting

Common Issues

  1. Port conflicts: Make sure ports 8080, 8443, and 6379 are available
  2. SSL certificates: Ensure certificates are properly placed in ./certs/
  3. Elasticsearch connection: Verify the Elasticsearch URL and credentials
  4. Redis connection: Check if Redis service is running

Logs and Debugging

# View application logs
docker-compose logs vision-data-api

# View Redis logs
docker-compose logs redis

# View all services logs
docker-compose logs

🀝 Contributing

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.

πŸ†˜ Support

For support and questions:

  • Open an issue in the repository
  • Contact the development team

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 5