{"id":28087700,"url":"https://github.com/dataideaorg/dataidea-logger-backend","last_synced_at":"2025-05-13T11:42:30.777Z","repository":{"id":283014933,"uuid":"950154029","full_name":"dataideaorg/dataidea-logger-backend","owner":"dataideaorg","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-19T19:47:42.000Z","size":1312,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T21:33:02.664Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dataideaorg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-17T18:01:16.000Z","updated_at":"2025-03-18T13:28:47.000Z","dependencies_parsed_at":"2025-04-19T20:38:15.108Z","dependency_job_id":"973dfddc-a014-4a3b-8ccc-bc7a403cfa76","html_url":"https://github.com/dataideaorg/dataidea-logger-backend","commit_stats":null,"previous_names":["dataideaorg/dataidea-logger-backend"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dataideaorg%2Fdataidea-logger-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dataideaorg%2Fdataidea-logger-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dataideaorg%2Fdataidea-logger-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dataideaorg%2Fdataidea-logger-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dataideaorg","download_url":"https://codeload.github.com/dataideaorg/dataidea-logger-backend/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253936920,"owners_count":21987250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-13T11:42:30.109Z","updated_at":"2025-05-13T11:42:30.753Z","avatar_url":"https://github.com/dataideaorg.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DataIdea Logger - Backend API\n\nA Django REST Framework-based API service for the DataIdea Logger, enabling secure logging of application events and LLM interactions with proper authentication and authorization.\n\n## Features\n\n- **User Authentication**: JWT-based authentication system\n- **API Key Management**: Generate and validate API keys for client applications\n- **Dual Logging System**:\n  - **Event Logger**: Store and retrieve application events with severity levels\n  - **LLM Logger**: Track AI model interactions with query and response content\n- **User Management**: User registration and profile management\n- **Admin Interface**: Django admin interface for managing data\n\n## Technologies Used\n\n- **Django 4.2+**: High-level Python web framework\n- **Django REST Framework**: Toolkit for building Web APIs\n- **JWT Authentication**: JSON Web Token authentication\n- **SQLite/PostgreSQL**: Database storage (SQLite for development, PostgreSQL recommended for production)\n- **CORS**: Cross-Origin Resource Sharing enabled for frontend integration\n\n## API Endpoints\n\nThe API provides the following main endpoints:\n\n- `/api/auth/register/` - User registration\n- `/api/auth/login/` - User login (returns JWT tokens)\n- `/api/auth/refresh/` - Refresh JWT token\n- `/api/apikeys/` - List and create API keys\n- `/api/apikeys/\u003cid\u003e/` - Retrieve, update, delete specific API key\n- `/api/event-logs/` - List event log messages\n- `/api/event-log/` - Create event log messages\n- `/api/llm-logs/` - List LLM log messages\n- `/api/llm-log/` - Create LLM log messages\n- `/api/user/profile/` - User profile management\n- `/api/user/stats/` - Get user logging statistics\n\nFull API documentation is available at `/api/docs/` when the server is running.\n\n## Getting Started\n\n### Prerequisites\n\n- Python 3.8 or higher\n- pip (Python package manager)\n- virtualenv (recommended)\n\n### Installation\n\n1. Clone the repository\n   ```\n   git clone https://github.com/your-org/dataidea-logger.git\n   cd dataidea-logger/backend\n   ```\n\n2. Create and activate a virtual environment\n   ```\n   python -m venv .venv\n   source .venv/bin/activate  # On Windows: .venv\\Scripts\\activate\n   ```\n\n3. Install dependencies\n   ```\n   pip install -r requirements.txt\n   ```\n\n4. Configure environment variables\n   Create a `.env` file in the backend directory with the following:\n   ```\n   SECRET_KEY=your_secret_key\n   DEBUG=True\n   ALLOWED_HOSTS=localhost,127.0.0.1\n   CORS_ALLOWED_ORIGINS=http://localhost:5173\n   ```\n\n5. Run migrations\n   ```\n   python manage.py migrate\n   ```\n\n6. Create a superuser\n   ```\n   python manage.py createsuperuser\n   ```\n\n7. Start the development server\n   ```\n   python manage.py runserver\n   ```\n\n8. Access the admin interface at `http://localhost:8000/admin/`\n\n## Database Configuration\n\nBy default, the application uses SQLite for development. For production, it's recommended to use PostgreSQL:\n\n1. Install PostgreSQL and create a database\n2. Update your `.env` file:\n   ```\n   DATABASE_URL=postgres://user:password@localhost:5432/dataidea_logger\n   ```\n\n## Creating Requirements File\n\nIf you add new dependencies, update the requirements file:\n\n```\npip freeze \u003e requirements.txt\n```\n\n## Testing\n\nRun the test suite:\n\n```\npython manage.py test\n```\n\n## Deployment\n\nFor production deployment:\n\n1. Set appropriate environment variables:\n   ```\n   DEBUG=False\n   ALLOWED_HOSTS=your-domain.com\n   SECRET_KEY=your-secure-secret-key\n   ```\n\n2. Collect static files:\n   ```\n   python manage.py collectstatic\n   ```\n\n3. Configure a production-ready web server like Gunicorn with Nginx.\n\n## Project Structure\n\n```\nbackend/\n├── main/                  # Project settings and configuration\n├── logger/                # Main application code\n│   ├── migrations/        # Database migrations\n│   ├── models.py          # Data models\n│   ├── serializers.py     # API serializers\n│   ├── views.py           # API views\n│   ├── urls.py            # URL routing\n│   └── admin.py           # Admin interface configuration\n├── manage.py              # Django management script\n└── requirements.txt       # Python dependencies\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Usage Examples\n\n### Event Logging\n\nUse the event logging endpoint to track application events with different severity levels:\n\n```python\nimport requests\nimport json\n\napi_key = \"your-api-key\"\nurl = \"http://localhost:8000/api/event-log/\"\n\npayload = {\n    \"api_key\": api_key,\n    \"user_id\": \"user123\",\n    \"message\": \"User successfully logged in\",\n    \"level\": \"info\",  # Options: info, warning, error, debug\n    \"metadata\": {\n        \"ip_address\": \"192.168.1.1\",\n        \"browser\": \"Chrome\",\n        \"session_id\": \"abc123\"\n    }\n}\n\nresponse = requests.post(\n    url,\n    headers={\"Content-Type\": \"application/json\"},\n    data=json.dumps(payload)\n)\n\nprint(response.status_code)\nprint(response.json())\n```\n\n### LLM Logging\n\nUse the LLM logging endpoint to track interactions with AI models:\n\n```python\nimport requests\nimport json\n\napi_key = \"your-api-key\"\nurl = \"http://localhost:8000/api/llm-log/\"\n\npayload = {\n    \"api_key\": api_key,\n    \"user_id\": \"user123\",\n    \"source\": \"gpt-4\",\n    \"query\": \"What is the capital of France?\",\n    \"response\": \"The capital of France is Paris.\",\n    \"metadata\": {\n        \"tokens\": 15,\n        \"model_version\": \"gpt-4-0613\",\n        \"session_id\": \"abc123\",\n        \"latency_ms\": 250\n    }\n}\n\nresponse = requests.post(\n    url,\n    headers={\"Content-Type\": \"application/json\"},\n    data=json.dumps(payload)\n)\n\nprint(response.status_code)\nprint(response.json())\n```\n\n### JavaScript Example\n\nHere's how to use both logging endpoints from a JavaScript client:\n\n```javascript\n// Event Log Example\nasync function logEvent(apiKey, userId, message, level, metadata) {\n  const response = await fetch('http://localhost:8000/api/event-log/', {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application/json',\n    },\n    body: JSON.stringify({\n      api_key: apiKey,\n      user_id: userId,\n      message: message,\n      level: level,\n      metadata: metadata || {}\n    })\n  });\n  \n  return response.json();\n}\n\n// LLM Log Example\nasync function logLlmInteraction(apiKey, userId, source, query, response, metadata) {\n  const response = await fetch('http://localhost:8000/api/llm-log/', {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application/json',\n    },\n    body: JSON.stringify({\n      api_key: apiKey,\n      user_id: userId,\n      source: source,\n      query: query,\n      response: response,\n      metadata: metadata || {}\n    })\n  });\n  \n  return response.json();\n}\n\n// Usage\nlogEvent('your-api-key', 'user123', 'Button clicked', 'info', { button: 'submit', page: 'checkout' });\n# DataIdea Logger - Backend API\n\nA Django REST Framework-based API service for the DataIdea Logger, enabling secure logging of application events and LLM interactions with proper authentication and authorization.\n\n## Features\n\n- **User Authentication**: JWT-based authentication system\n- **API Key Management**: Generate and validate API keys for client applications\n- **Dual Logging System**:\n  - **Event Logger**: Store and retrieve application events with severity levels\n  - **LLM Logger**: Track AI model interactions with query and response content\n- **User Management**: User registration and profile management\n- **Admin Interface**: Django admin interface for managing data\n\n## Technologies Used\n\n- **Django 4.2+**: High-level Python web framework\n- **Django REST Framework**: Toolkit for building Web APIs\n- **JWT Authentication**: JSON Web Token authentication\n- **SQLite/PostgreSQL**: Database storage (SQLite for development, PostgreSQL recommended for production)\n- **CORS**: Cross-Origin Resource Sharing enabled for frontend integration\n\n## API Endpoints\n\nThe API provides the following main endpoints:\n\n- `/api/auth/register/` - User registration\n- `/api/auth/login/` - User login (returns JWT tokens)\n- `/api/auth/refresh/` - Refresh JWT token\n- `/api/apikeys/` - List and create API keys\n- `/api/apikeys/\u003cid\u003e/` - Retrieve, update, delete specific API key\n- `/api/event-logs/` - List event log messages\n- `/api/event-log/` - Create event log messages\n- `/api/llm-logs/` - List LLM log messages\n- `/api/llm-log/` - Create LLM log messages\n- `/api/user/profile/` - User profile management\n- `/api/user/stats/` - Get user logging statistics\n\nFull API documentation is available at `/api/docs/` when the server is running.\n\n## Getting Started\n\n### Prerequisites\n\n- Python 3.8 or higher\n- pip (Python package manager)\n- virtualenv (recommended)\n\n### Installation\n\n1. Clone the repository\n   ```\n   git clone https://github.com/your-org/dataidea-logger.git\n   cd dataidea-logger/backend\n   ```\n\n2. Create and activate a virtual environment\n   ```\n   python -m venv .venv\n   source .venv/bin/activate  # On Windows: .venv\\Scripts\\activate\n   ```\n\n3. Install dependencies\n   ```\n   pip install -r requirements.txt\n   ```\n\n4. Configure environment variables\n   Create a `.env` file in the backend directory with the following:\n   ```\n   SECRET_KEY=your_secret_key\n   DEBUG=True\n   ALLOWED_HOSTS=localhost,127.0.0.1\n   CORS_ALLOWED_ORIGINS=http://localhost:5173\n   ```\n\n5. Run migrations\n   ```\n   python manage.py migrate\n   ```\n\n6. Create a superuser\n   ```\n   python manage.py createsuperuser\n   ```\n\n7. Start the development server\n   ```\n   python manage.py runserver\n   ```\n\n8. Access the admin interface at `http://localhost:8000/admin/`\n\n## Database Configuration\n\nBy default, the application uses SQLite for development. For production, it's recommended to use PostgreSQL:\n\n1. Install PostgreSQL and create a database\n2. Update your `.env` file:\n   ```\n   DATABASE_URL=postgres://user:password@localhost:5432/dataidea_logger\n   ```\n\n## Creating Requirements File\n\nIf you add new dependencies, update the requirements file:\n\n```\npip freeze \u003e requirements.txt\n```\n\n## Testing\n\nRun the test suite:\n\n```\npython manage.py test\n```\n\n## Deployment\n\nFor production deployment:\n\n1. Set appropriate environment variables:\n   ```\n   DEBUG=False\n   ALLOWED_HOSTS=your-domain.com\n   SECRET_KEY=your-secure-secret-key\n   ```\n\n2. Collect static files:\n   ```\n   python manage.py collectstatic\n   ```\n\n3. Configure a production-ready web server like Gunicorn with Nginx.\n\n## Project Structure\n\n```\nbackend/\n├── main/                  # Project settings and configuration\n├── logger/                # Main application code\n│   ├── migrations/        # Database migrations\n│   ├── models.py          # Data models\n│   ├── serializers.py     # API serializers\n│   ├── views.py           # API views\n│   ├── urls.py            # URL routing\n│   └── admin.py           # Admin interface configuration\n├── manage.py              # Django management script\n└── requirements.txt       # Python dependencies\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdataideaorg%2Fdataidea-logger-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdataideaorg%2Fdataidea-logger-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdataideaorg%2Fdataidea-logger-backend/lists"}