Skip to content

codervaruns/ArangoDB-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ArangoDB Multimodal Demo App

A comprehensive demonstration of ArangoDB's multimodal database capabilities, showcasing Document, Graph, and Key-Value operations in a single application.

๐Ÿš€ Features

๐Ÿ“„ Document Store

  • User Management: Create and manage user profiles with flexible JSON schemas
  • Post System: Store blog posts, articles, or social media content
  • Rich Queries: Query documents with complex filters and aggregations

๐Ÿ•ธ๏ธ Graph Database

  • Social Relationships: Model follow relationships between users
  • Interaction Tracking: Track likes, comments, and other user interactions
  • Complex Graph Queries: Find mutual connections, recommendation algorithms, and social network analysis

๐Ÿ”‘ Key-Value Store

  • User Settings: Store user preferences and configuration
  • Session Management: Fast key-value lookups for user sessions
  • Caching Layer: Use as a high-performance cache for frequently accessed data

๐Ÿ› ๏ธ Technology Stack

  • Backend: Node.js with Express.js
  • Database: ArangoDB (multimodal database)
  • Frontend: Vanilla HTML/CSS/JavaScript
  • Database Driver: ArangoJS

๐Ÿ“‹ Prerequisites

  1. ArangoDB: Install ArangoDB from https://www.arangodb.com/download/
  2. Node.js: Version 14+ required
  3. npm: Comes with Node.js

๐Ÿš€ Quick Start

1. Install ArangoDB

Download and install ArangoDB from the official website. The default installation will:

  • Run on http://localhost:8529
  • Have username root with no password (change this in production!)

2. Install Dependencies

npm install

3. Configure Environment

Copy the .env file and update if necessary:

# Default configuration should work for local ArangoDB installation
ARANGO_URL=http://localhost:8529
ARANGO_DATABASE=multimodal_demo
ARANGO_USERNAME=root
ARANGO_PASSWORD=
PORT=3000

4. Start the Application

npm start

The app will:

  • Automatically create the database and collections
  • Set up the graph structure
  • Start the web server on http://localhost:3000

๐ŸŽฎ Using the Demo

Document Operations

  1. Create Users: Add user profiles with username, display name, email, and bio
  2. Create Posts: Add posts with titles, content, and tags
  3. View All: Load and browse all users and posts

Graph Operations

  1. Follow Users: Create follow relationships between users
  2. Like Posts: Add like relationships from users to posts
  3. Get User Feed: Retrieve posts from followed users (complex graph traversal)
  4. Popular Users: Find users with most followers

Key-Value Operations

  1. Set Settings: Store user preferences like theme, notifications, etc.
  2. Get Settings: Retrieve specific user settings by key

๐Ÿ—๏ธ Database Schema

Collections

Document Collections

  • users: User profiles and metadata
  • posts: Blog posts, articles, social media content
  • user_settings: Key-value pairs for user preferences

Edge Collections

  • follows: User-to-User follow relationships
  • likes: User-to-Post like relationships

Graph

  • social_network: Combines all relationships for complex queries

Sample Data Structures

User Document

{
  "_key": "12345",
  "username": "john_doe",
  "displayName": "John Doe",
  "email": "john@example.com",
  "bio": "Software developer and ArangoDB enthusiast",
  "followerCount": 42,
  "followingCount": 15,
  "createdAt": "2024-01-01T12:00:00Z"
}

Post Document

{
  "_key": "67890",
  "authorId": "12345",
  "title": "Getting Started with ArangoDB",
  "content": "ArangoDB is an amazing multimodal database...",
  "tags": ["database", "arangodb", "tutorial"],
  "likeCount": 23,
  "createdAt": "2024-01-02T10:30:00Z"
}

Follow Edge

{
  "_from": "users/12345",
  "_to": "users/67890",
  "createdAt": "2024-01-01T15:30:00Z"
}

๐Ÿ” Key Multimodal Queries

Complex Feed Query

This query demonstrates ArangoDB's ability to traverse graphs and join documents:

FOR follow in follows
  FILTER follow._from == "users/12345"
  FOR post in posts
    FILTER post.authorId == PARSE_IDENTIFIER(follow._to).key
    SORT post.createdAt DESC
    LIMIT 10
    LET author = DOCUMENT(follow._to)
    RETURN {
      post: post,
      author: {
        username: author.username,
        displayName: author.displayName
      }
    }

Mutual Connections

Find mutual follows between two users:

LET user1_follows = (
  FOR follow in follows
    FILTER follow._from == "users/user1"
    RETURN PARSE_IDENTIFIER(follow._to).key
)

LET user2_follows = (
  FOR follow in follows
    FILTER follow._from == "users/user2"
    RETURN PARSE_IDENTIFIER(follow._to).key
)

LET mutual = INTERSECTION(user1_follows, user2_follows)

FOR userId in mutual
  LET user = DOCUMENT('users', userId)
  RETURN user

๐Ÿš€ API Endpoints

Document Operations

  • POST /api/users - Create user
  • GET /api/users - Get all users
  • GET /api/users/:id - Get specific user
  • POST /api/posts - Create post
  • GET /api/posts - Get all posts

Graph Operations

  • POST /api/users/:followerId/follow/:followeeId - Follow user
  • POST /api/users/:userId/like/:postId - Like post
  • GET /api/users/:userId/feed - Get user feed
  • GET /api/users/popular - Get popular users
  • GET /api/users/:userId1/mutual/:userId2 - Get mutual follows

Key-Value Operations

  • POST /api/users/:userId/settings/:key - Set user setting
  • GET /api/users/:userId/settings/:key - Get user setting

๐Ÿ”ง Development

Run in Development Mode

npm run dev

This uses nodemon for automatic restarts when files change.

Project Structure

โ”œโ”€โ”€ app.js              # Main application server
โ”œโ”€โ”€ database.js         # ArangoDB connection and operations
โ”œโ”€โ”€ package.json        # Dependencies and scripts
โ”œโ”€โ”€ .env               # Environment configuration
โ”œโ”€โ”€ public/
โ”‚   โ””โ”€โ”€ index.html     # Demo web interface
โ””โ”€โ”€ README.md          # This file

๐ŸŒŸ Why ArangoDB's Multimodal Approach?

Traditional Approach

  • Multiple Databases: Separate MongoDB for documents, Neo4j for graphs, Redis for caching
  • Complex Architecture: Multiple connections, different query languages, data synchronization issues
  • Performance Overhead: Network calls between different systems

ArangoDB Multimodal

  • Unified Database: One system for all data models
  • Single Query Language: AQL works across documents, graphs, and key-value data
  • ACID Transactions: Consistent transactions across all data models
  • Performance: Local joins and traversals, no network overhead

๐Ÿš€ Production Considerations

Security

  • Change default ArangoDB password
  • Enable authentication and SSL
  • Use environment variables for sensitive config
  • Implement API rate limiting

Performance

  • Add database indices for frequently queried fields
  • Use connection pooling
  • Implement caching strategies
  • Monitor query performance

Scalability

  • Consider ArangoDB cluster deployment
  • Implement horizontal scaling strategies
  • Use ArangoDB's built-in sharding capabilities

๐Ÿ“š Learning Resources

๐Ÿค Contributing

Feel free to submit issues, fork the repository, and create pull requests for any improvements.

๐Ÿ“„ License

MIT License - see LICENSE file for details.


Happy coding with ArangoDB! ๐Ÿš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published