Skip to content

MadHouseLabs/anybase

Repository files navigation

AnyBase

Firebase-like API Layer for AWS DocumentDB

A high-performance, scalable backend service with real-time capabilities, MCP support, and enterprise-grade security

Go Version Next.js License Docker

✨ Features

Core Capabilities

  • πŸš€ RESTful API - Fast, scalable REST API with JWT authentication
  • πŸ“Š Dynamic Collections - Schema-flexible document storage with validation
  • πŸ” Advanced Querying - MongoDB-compatible query language with aggregation support
  • 🎯 Views & Aggregations - Pre-defined queries with parameterized execution
  • πŸ” Row-Level Security - Fine-grained access control with RBAC
  • πŸ”‘ Access Keys - API key authentication with scoped permissions
  • πŸ€– MCP Integration - Model Context Protocol support for AI applications

Dashboard Features

  • πŸ“ˆ Real-time Analytics - Monitor system health and usage metrics
  • πŸ‘₯ User Management - Complete user administration interface
  • πŸ—‚οΈ Collection Explorer - Visual database management tools
  • πŸ”§ Settings Management - System and user configuration
  • πŸ“ Schema Editor - Visual JSON schema builder

πŸš€ Quick Start

Prerequisites

  • Go 1.22 or higher
  • Node.js 20+ and pnpm
  • Database: MongoDB, AWS DocumentDB, or PostgreSQL
  • Docker (optional)

Installation

Using Docker Compose (Recommended)

# Clone the repository
git clone https://github.com/MadHouseLabs/anybase.git
cd anybase

# Start with Docker Compose
docker-compose up -d

Manual Installation

# Clone the repository
git clone https://github.com/MadHouseLabs/anybase.git
cd anybase

# Install backend dependencies
go mod download

# Install dashboard dependencies
cd dashboard
pnpm install

# Set up environment variables
cp .env.example .env.local
# Edit .env.local with your configuration

# Run the backend
go run cmd/server/main.go

# In another terminal, run the dashboard
cd dashboard
pnpm dev

πŸ“ Project Structure

anybase/
β”œβ”€β”€ api/                    # API handlers and routes
β”‚   └── v1/                # Version 1 API implementation
β”œβ”€β”€ cmd/                   # Application entrypoints
β”‚   └── server/           # Main server application
β”œβ”€β”€ internal/             # Private application code
β”‚   β”œβ”€β”€ accesskey/       # Access key management
β”‚   β”œβ”€β”€ auth/           # Authentication logic
β”‚   β”œβ”€β”€ collection/     # Collection operations
β”‚   β”œβ”€β”€ config/        # Configuration management
β”‚   β”œβ”€β”€ database/      # Database connectivity
β”‚   β”œβ”€β”€ governance/    # RBAC and permissions
β”‚   β”œβ”€β”€ middleware/    # HTTP middleware
β”‚   β”œβ”€β”€ models/        # Data models
β”‚   β”œβ”€β”€ settings/      # Settings management
β”‚   └── user/         # User management
β”œβ”€β”€ dashboard/          # Next.js dashboard application
β”‚   β”œβ”€β”€ app/          # App router pages
β”‚   β”œβ”€β”€ components/   # React components
β”‚   └── lib/         # Utility functions
└── docker/          # Docker configurations

πŸ”§ Configuration

Database Configuration

AnyBase supports multiple database backends. Choose one:

MongoDB Configuration

# MongoDB/DocumentDB Connection
ANYBASE_DATABASE_TYPE=mongodb
ANYBASE_DATABASE_URI=mongodb://localhost:27017
ANYBASE_DATABASE_DATABASE=anybase

PostgreSQL Configuration

# PostgreSQL Connection
ANYBASE_DATABASE_TYPE=postgres
ANYBASE_DATABASE_URI=postgres://username@localhost/anybase?sslmode=disable
ANYBASE_DATABASE_DATABASE=anybase

Environment Variables

Create a .env file in the root directory:

# Database Configuration (see above for database-specific settings)
ANYBASE_DATABASE_TYPE=mongodb  # or postgres
ANYBASE_DATABASE_URI=mongodb://localhost:27017
ANYBASE_DATABASE_DATABASE=anybase

# JWT Configuration
JWT_SECRET=your-secret-key-here
JWT_EXPIRY=24h
REFRESH_TOKEN_EXPIRY=168h

# Server Configuration
PORT=8080
HOST=0.0.0.0
MODE=development

# Initial Admin User (created on first startup)
INIT_ADMIN_EMAIL=admin@anybase.local
INIT_ADMIN_PASSWORD=admin123  # Change this immediately after first login!

# Dashboard Configuration
NEXT_PUBLIC_API_URL=http://localhost:8080

Database Indexes

AnyBase automatically creates necessary indexes on startup:

  • MongoDB: Native MongoDB indexes with compound and unique constraints
  • PostgreSQL: B-tree and GIN indexes on JSONB fields for optimal query performance

πŸ“– API Documentation

Complete API documentation is available in the OpenAPI specification. You can:

  • Import it into Postman or Insomnia for testing
  • Use it to generate client SDKs
  • View it with Swagger UI or ReDoc

πŸ”Œ API Usage

Authentication

# Register a new user
curl -X POST http://localhost:8080/api/v1/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email":"user@example.com","password":"securepass","name":"John Doe"}'

# Login
curl -X POST http://localhost:8080/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"user@example.com","password":"securepass"}'

Collections

# Create a collection
curl -X POST http://localhost:8080/api/v1/collections \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "products",
    "description": "Product catalog",
    "schema": {
      "type": "object",
      "properties": {
        "name": {"type": "string"},
        "price": {"type": "number"},
        "category": {"type": "string"}
      },
      "required": ["name", "price"]
    }
  }'

# Insert a document
curl -X POST http://localhost:8080/api/v1/data/products \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"Widget","price":29.99,"category":"Hardware"}'

Access Keys

# Create an access key
curl -X POST http://localhost:8080/api/v1/access-keys \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production API Key",
    "permissions": ["collection:products:read", "collection:products:write"]
  }'

πŸ€– MCP (Model Context Protocol) Integration

AnyBase supports MCP for AI model integration. Configure your MCP client to connect to:

http://localhost:8080/mcp

The MCP server provides collection-specific tools with full schema awareness for optimal AI interactions.

🐳 Docker Deployment

Using Pre-built Images

# Pull the images
docker pull ghcr.io/madhouselabs/anybase-backend:latest
docker pull ghcr.io/madhouselabs/anybase-dashboard:latest

# Run with docker-compose
docker-compose up -d

Building from Source

# Build backend
docker build -t anybase-backend .

# Build dashboard
docker build -t anybase-dashboard ./dashboard

πŸ§ͺ Testing

# Run backend tests
go test ./...

# Run backend tests with coverage
go test -cover ./...

# Run dashboard tests
cd dashboard
pnpm test

πŸ“Š Performance

AnyBase is optimized for high performance:

  • Connection Pooling: Efficient MongoDB connection management
  • Indexed Queries: Automatic index creation for optimal query performance
  • Caching: Built-in caching for frequently accessed data
  • Rate Limiting: Per-IP rate limiting to prevent abuse
  • Concurrent Processing: Go's goroutines for parallel request handling

πŸ”’ Security

  • JWT Authentication: Secure token-based authentication
  • RBAC: Role-based access control with fine-grained permissions
  • Input Validation: JSON Schema validation for all inputs
  • Rate Limiting: Built-in rate limiting to prevent abuse
  • CORS: Configurable CORS policies
  • Secure Headers: Security headers for XSS and CSRF protection

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

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

πŸ“ License

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

πŸ™ Acknowledgments

πŸ“ž Support


Made with ❀️ by MadHouse Labs

About

Firebase-like API layer on AWS DocumentDB with MCP support

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages