Skip to content

A simple CRUD system for configuration management with authentication, built in Go with MongoDB and Ristretto cache.

License

Notifications You must be signed in to change notification settings

MartinezAvellan/confy

Repository files navigation

Confy - Configuration Management System

A powerful CRUD system for configuration management with JWT authentication and access token support, built in Go with MongoDB and Ristretto cache. Features a cyberpunk-themed web interface with OpenBMC Web UI Style Guide compliance.

✨ Features

  • πŸ” Dual Authentication: JWT for user auth + Access tokens for API integration
  • πŸ“ Complete Configuration CRUD: Create, read, update, delete settings
  • 🎯 Access Token Management: Generate tokens for external applications
  • πŸš€ Ristretto Cache: High-performance in-memory caching with automatic invalidation
  • 🌐 Public API: Token-based endpoints for external consumption
  • 🎨 Cyberpunk UI: Modern responsive interface with Vice City theme
  • πŸ“Š MongoDB Database: Reliable document storage
  • 🐳 Docker Ready: Containerized with distroless image
  • πŸ”” Toast Notifications: OpenBMC compliant notification system
  • πŸŽ›οΈ Toggle Controls: Enable/disable settings and tokens

πŸ› οΈ Technologies Used

  • Backend: Go (Gin framework)
  • Database: MongoDB
  • Cache: Ristretto (In-memory)
  • Authentication: JWT + Access Tokens
  • Frontend: HTML5, CSS3, JavaScript (Cyberpunk theme)
  • UI Framework: OpenBMC Web UI Style Guide
  • Containerization: Docker & Docker Compose
  • Middleware: Custom authentication & logging

Installation and Setup

Using Docker (Recommended)

  1. Clone the repository:
git clone https://github.com/MartinezAvellan/confy.git
cd confy
  1. Run with Docker Compose:
docker-compose up --build
  1. Access the application at http://localhost:8080

Local Development

  1. Make sure you have Go 1.24+ and MongoDB installed

  2. Configure environment variables:

cp .env.example .env
# Edit the .env file as needed
  1. Install dependencies:
go mod tidy
  1. Run the application:
go run main.go

Usage

1. User Registration

  • Go to /register
  • Fill in username, email and password
  • Click "Register"

2. Login

  • Go to /login
  • Use your credentials to login
  • You will be redirected to the dashboard

3. Manage Configurations

  • In the dashboard, you can:
    • Create new settings with environment support
    • Edit existing configurations inline
    • Delete configurations (with double-click confirmation)
    • Toggle enable/disable settings
    • View all your configurations with search/filter

4. Access Token Management

  • Generate access tokens for external applications
  • Manage token permissions and status
  • Use tokens to access public API endpoints

5. API Integration

  • Use the Postman collection for easy API testing
  • Integrate with external applications using access tokens
  • Access settings via public API endpoints

πŸ“‘ API Endpoints

Authentication

  • POST /api/register - Register new user
  • POST /api/login - User login (returns JWT token)

Settings Management (JWT Authentication)

  • POST /api/settings - Create configuration
  • GET /api/settings - List all configurations
  • GET /api/settings/:id - Get specific configuration
  • PUT /api/settings/:id - Update configuration
  • PATCH /api/settings/:id/toggle - Toggle enable/disable
  • DELETE /api/settings/:id - Delete configuration

Access Tokens (JWT Authentication)

  • POST /api/tokens - Create access token
  • GET /api/tokens - List all tokens
  • PUT /api/tokens/:id - Update token
  • PATCH /api/tokens/:id/toggle - Toggle enable/disable
  • DELETE /api/tokens/:id - Delete token

Public API (Access Token Authentication)

  • GET /api/public/settings - Get settings (key-value format)
    • Query params: ?environment=dev&key=database_url
  • GET /api/public/settings/all - Get all settings (full objects)
    • Query params: ?environment=dev&key=database_url
  • GET /api/public/settings/:id - Get specific setting by ID

πŸ“¬ Postman Collection

We provide a comprehensive Postman collection for easy API testing and integration:

πŸ“ Location: /postman/Confy_API_Collection.json

Features:

  • βœ… All endpoints included with example requests
  • βœ… Auto-token management - JWT and access tokens saved automatically
  • βœ… Environment variables - Configurable base URL and IDs
  • βœ… Complete workflow - From registration to API consumption
  • βœ… Detailed documentation - Step-by-step usage guide

Quick Start:

  1. Import postman/Confy_API_Collection.json into Postman
  2. Follow the requests in order: Register β†’ Login β†’ Create Token β†’ Use APIs
  3. Tokens are automatically saved and used in subsequent requests

πŸ“– Read the complete Postman guide for detailed instructions.

πŸ“ Project Structure

confy/
β”œβ”€β”€ config/          # Configurations (DB, Cache, Environment)
β”œβ”€β”€ handlers/        # HTTP Handlers (Auth, Settings, Tokens)
β”œβ”€β”€ middleware/      # Middlewares (Auth, Token Auth, Logger)
β”œβ”€β”€ models/          # Data Models (User, Setting, Token)
β”œβ”€β”€ templates/       # Frontend Templates
β”‚   β”œβ”€β”€ css/         # Cyberpunk theme styles
β”‚   β”œβ”€β”€ js/          # JavaScript functionality
β”‚   β”œβ”€β”€ *.html       # HTML templates
β”œβ”€β”€ postman/         # API Testing Collection
β”‚   β”œβ”€β”€ Confy_API_Collection.json
β”‚   └── README.md    # Postman guide
β”œβ”€β”€ main.go          # Application entry point
β”œβ”€β”€ Dockerfile       # Docker configuration
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ CONTRIBUTING.md  # Contribution guidelines
└── README.md        # This file

βš™οΈ Environment Variables

Variable Description Default
MONGO_URI MongoDB connection URI mongodb://localhost:27017
DB_NAME Database name confy
JWT_SECRET JWT secret key your-secret-key
JWT_EXPIRATION_HOURS JWT token expiration time 24
CACHE_TTL_MINUTES Cache TTL in minutes 5
SERVER_PORT Server port 8080
GIN_MODE Gin mode (debug/release) debug

πŸš€ Cache Features

The system uses Ristretto for high-performance in-memory caching:

  • Per-user setting cache with automatic invalidation
  • Public API cache with application-specific keys
  • Configurable TTL (default: 5 minutes)
  • Pattern-based invalidation for related cache entries
  • Optimized queries to reduce database load

πŸ”’ Security

The project implements several security practices:

  • Dual Authentication: JWT for users + Access tokens for APIs
  • Distroless Image: Final container without shell, package managers or unnecessary binaries
  • Non-root User: Application runs with nonroot user
  • Password Hashing: Bcrypt for secure password hashing
  • Input Validation: Strict validation of all input data
  • Token-based Access: Secure API access with revocable tokens
  • User Isolation: Users can only access their own settings
  • Cache Security: User-specific cache keys prevent data leakage

Contributing

We welcome contributions from the community! Please read our Contributing Guide for details on:

  • πŸ› Reporting bugs
  • πŸ’‘ Requesting features
  • πŸ”§ Submitting code changes
  • πŸ“– Improving documentation

Development Setup

# Clone the repository
git clone https://github.com/MartinezAvellan/confy.git
cd confy

# Set up development environment
make dev-setup

# Start development server
make up

🎨 UI/UX Features

The modern web interface includes:

Cyberpunk Vice City Theme

  • Color Palette: Neon blues (#00a8ff), pinks (#f4afc2), purples (#b28bc0)
  • Dark Gradient Background: Professional cyberpunk aesthetic
  • Glowing Effects: Text shadows and box shadows for depth
  • Responsive Design: Works seamlessly on desktop and mobile

OpenBMC Web UI Style Guide Compliance

  • Toast Notifications: Auto-dismiss success (10s), manual dismiss for errors
  • Consistent Typography: Sans-serif fonts throughout
  • Proper Spacing: 8px/0.5rem grid system
  • Interactive Elements: Hover effects and smooth transitions

User Experience

  • Toggle Switches: Visual enable/disable controls
  • Double-click Confirmation: Prevents accidental deletions
  • Modal Centering: Perfect positioning for all screen sizes
  • Disabled State Handling: Clear visual feedback for inactive items
  • Loading States: Smooth transitions and feedback

Support the Project

If you find Confy useful, consider supporting the development:

⭐ Star this repository - Help others discover Confy! πŸ› Report issues - Help improve the project πŸ’‘ Suggest features - Share your ideas πŸ”§ Contribute code - Join the development

License

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

Acknowledgments

  • Built with ❀️ using Go, MongoDB, and modern web technologies
  • Thanks to all contributors who help make Confy better!

About

A simple CRUD system for configuration management with authentication, built in Go with MongoDB and Ristretto cache.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published