Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# PyPI configuration file
.pypirc
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always",
"printWidth": 80
}
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"ms-python.python",
"ms-python.autopep8",
"ms-python.flake8",
"ms-python.isort",
"esbenp.prettier-vscode"
]
}
25 changes: 25 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// auto-formatter for python
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8",
"editor.formatOnSave": true,
},
// linting for python
"python.linting.flake8Enabled": true,
"python.linting.flake8Path": "flake8",
// auto-formatter for javascript
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
},
// auto-formatter for typescript
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
},
// auto-formatter for json
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
},
}
Empty file added backend/__init__.py
Empty file.
Empty file added backend/app/__init__.py
Empty file.
Empty file added backend/app/api/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions backend/app/core/events/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from .base import BaseEvent
from .enums import PlatformType, EventType
from .github_event import GitHubEvent
from .discord_event import DiscordEvent
from .slack_event import SlackEvent
from .event_bus import EventBus

__all__ = [
"BaseEvent",
"PlatformType",
"EventType",
"GitHubEvent",
"DiscordEvent",
"SlackEvent",
"EventBus",
]
23 changes: 23 additions & 0 deletions backend/app/core/events/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from datetime import datetime
from typing import Dict, Any, Optional
from pydantic import BaseModel, Field

class BaseEvent(BaseModel):
"""Base event model for all platform events"""
id: str = Field(..., description="Unique identifier for the event")
platform: str
event_type: str
timestamp: datetime = Field(default_factory=datetime.now, description="Timestamp of the event")
actor_id: str = Field(..., description="ID of the user who triggered the event")
actor_name: Optional[str] = Field(None, description="Name of the user who triggered the event")
raw_data: Dict[str, Any] = Field({}, description="Raw event data from the platform")
metadata: Dict[str, Any] = Field({}, description="Additional metadata for the event")

def to_dict(self) -> Dict[str, Any]:
"""Convert event to dictionary for serialization"""
return self.model_dump()

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> "BaseEvent":
"""Create event from dictionary"""
return cls(**data)
14 changes: 14 additions & 0 deletions backend/app/core/events/discord_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import List, Dict, Optional, Any
from pydantic import Field
from .base import BaseEvent
from .enums import PlatformType

class DiscordEvent(BaseEvent):
"""Discord specific event model"""
platform: PlatformType = PlatformType.DISCORD
guild_id: str
channel_id: str
message_id: Optional[str] = None
content: Optional[str] = None
attachments: List[Dict[str, Any]] = Field(default_factory=list)
mentions: List[str] = Field(default_factory=list)
28 changes: 28 additions & 0 deletions backend/app/core/events/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from enum import Enum

class PlatformType(str, Enum):
GITHUB = "github"
DISCORD = "discord"
SLACK = "slack"
DISCOURSE = "discourse"
SYSTEM = "system"

class EventType(str, Enum):
ISSUE_CREATED = "issue.created"
ISSUE_UPDATED = "issue.updated"
ISSUE_COMMENTED = "issue.commented"
PR_CREATED = "pr.created"
PR_UPDATED = "pr.updated"
PR_COMMENTED = "pr.commented"
PR_REVIEWED = "pr.reviewed"

MESSAGE_CREATED = "message.created"
MESSAGE_UPDATED = "message.updated"
REACTION_ADDED = "reaction.added"
USER_JOINED = "user.joined"

ONBOARDING_STARTED = "onboarding.started"
ONBOARDING_COMPLETED = "onboarding.completed"
FAQ_REQUESTED = "faq.requested"
KNOWLEDGE_UPDATED = "knowledge.updated"
ANALYTICS_COLLECTED = "analytics.collected"
21 changes: 21 additions & 0 deletions backend/app/core/events/event_bus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Dict, List, Union, Optional
from .base import BaseEvent
from .enums import EventType, PlatformType

class EventBus:
"""Central event bus for dispatching events to registered handlers"""
def __init__(self):
self.handlers = {}
self.global_handlers = []

def register_handler(self, event_type: Union[EventType, List[EventType]], handler_func, platform: Optional[PlatformType] = None):
"""Register a handler function for a specific event type and optionally platform"""
pass

def register_global_handler(self, handler_func):
"""Register a handler that will receive all events"""
pass

async def dispatch(self, event: BaseEvent):
"""Dispatch an event to all registered handlers"""
pass
16 changes: 16 additions & 0 deletions backend/app/core/events/github_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List, Optional
from pydantic import Field
from .base import BaseEvent
from .enums import PlatformType

class GitHubEvent(BaseEvent):
"""GitHub specific event model"""
platform: PlatformType = PlatformType.GITHUB
repository: str
organization: Optional[str] = None
issue_number: Optional[int] = None
pr_number: Optional[int] = None
labels: List[str] = Field(default_factory=list)
title: Optional[str] = None
body: Optional[str] = None
url: Optional[str] = None
14 changes: 14 additions & 0 deletions backend/app/core/events/slack_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import List, Dict, Optional, Any
from pydantic import Field
from .base import BaseEvent
from .enums import PlatformType

class SlackEvent(BaseEvent):
"""Slack specific event model"""
platform: PlatformType = PlatformType.SLACK
team_id: str
channel_id: str
message_ts: Optional[str] = None
text: Optional[str] = None
thread_ts: Optional[str] = None
blocks: List[Dict[str, Any]] = Field(default_factory=list)
Loading