Skip to content

Commit b5a5350

Browse files
Alec CunninghamAlec Cunningham
Alec Cunningham
authored and
Alec Cunningham
committed
feat: add design doc
1 parent 416a59d commit b5a5350

File tree

2 files changed

+116
-2
lines changed

2 files changed

+116
-2
lines changed

docs/DESIGN.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Design
2+
3+
## API Design
4+
5+
### Endpoint Structure
6+
7+
#### Authentication Endpoints:
8+
9+
- `POST /login`: User login via GitHub OAuth.
10+
- `POST /logout`: User logout.
11+
12+
#### Data Retrieval Endpoints:
13+
14+
- `GET /stats`: Retrieve aggregated statistics.
15+
- `GET /workflows`: List workflows with statuses.
16+
- `GET /workflows/:id`: Get details of a specific workflow.
17+
18+
#### Data Management Endpoints:
19+
20+
- `POST /repositories`: Add a repository to monitor.
21+
- `DELETE /repositories/:id`: Remove a repository.
22+
23+
### API Features
24+
25+
- **Pagination**: Implement for endpoints returning lists.
26+
- **Filtering**: Allow filtering by date ranges, status, etc.
27+
- **Error Handling**: Provide meaningful error messages and HTTP status codes.
28+
- **Throttling**: Implement rate limiting to prevent abuse.
29+
30+
## Data Collection Strategy
31+
32+
Option A: Polling the GitHub API
33+
34+
- **Scheduled Fetching**: Use a scheduler (like cron jobs) to periodically fetch data from the GitHub API.
35+
- **Rate Limiting**: Implement logic to handle GitHub's API rate limits (e.g., using conditional requests with ETags).
36+
37+
Option B: GitHub Webhooks
38+
- **Real-Time Updates**: Set up webhooks to receive events when workflows are triggered, succeed, or fail.
39+
- **Event Handling**: Create endpoints to handle incoming webhook events securely.
40+
41+
Recommended Approach
42+
- **Combine Both**: Use webhooks for real-time updates and periodic polling to handle missed events or initial data population.
43+
44+
## Authentication and Authorization
45+
46+
- **GitHub Authentication**: Use a GitHub App or Personal Access Token (PAT) to authenticate API requests.
47+
- **User Authentication**: Implement OAuth 2.0 to allow users to log in with their GitHub accounts.
48+
- **Permissions**: Ensure the service respects user permissions and data privacy.
49+
50+
## Tech Stack
51+
52+
- **Programming Language**: Golang for its performance and concurrency support.
53+
- **Web Framework**: Use gin-gonic/gin for routing and middleware support.
54+
- **Database**: PostgreSQL for relational data storage and complex queries.
55+
- **ORM**: Use gorm for interacting with the database.
56+
- **Caching**: Implement Redis for caching frequently accessed data.
57+
- **HTTP Client**: Use net/http and oauth2 packages for making authenticated requests to GitHub.
58+
59+
## Architectural Design
60+
61+
### Backend Services
62+
63+
- **API Server**: Handles incoming HTTP requests from the frontend.
64+
- **Worker Service**: Processes background tasks like polling the GitHub API or handling webhook events.
65+
66+
### Data Flow
67+
68+
- **Data Ingestion**: Collect data via webhooks or polling.
69+
- **Data Storage**: Store raw data in the database.
70+
- **Data Processing**: Calculate statistics and store them in a summarized form.
71+
- **API Layer**: Expose endpoints for the frontend to retrieve data.
72+
73+
### Database Schema Design
74+
75+
- Tables:
76+
- users: Stores user information.
77+
- repositories: Tracks repositories being monitored.
78+
- workflows: Contains workflow definitions.
79+
- workflow_runs: Records individual workflow executions.
80+
- statistics: Stores precomputed stats for quick access.
81+
82+
- Relationships:
83+
- Establish foreign keys between tables for referential integrity.
84+
85+
- Indexing:
86+
- Index columns frequently used in queries (e.g., timestamps, status).
87+
88+
### Implementing Concurrency
89+
90+
- **Goroutines**: Use for handling multiple simultaneous tasks (e.g., processing webhook events).
91+
- **Channels**: Communicate between goroutines safely.
92+
- **Mutexes**: Ensure thread-safe operations when accessing shared resources.
93+
94+
### Security Measures
95+
96+
- **Secure Communication**: Use HTTPS for all client-server communication.
97+
- **Input Validation**: Sanitize and validate all inputs to prevent injection attacks.
98+
- **Secrets Management**: Store sensitive information (like API keys) securely, using environment variables or a secrets manager.
99+
- **Webhook Security**: Validate GitHub webhook payloads using the shared secret.
100+
101+
### Testing Strategy
102+
103+
- **Unit Tests**: Test individual functions and methods.
104+
- **Integration Tests**: Test interactions with the GitHub API and the database.
105+
- **End-to-End Tests**: Simulate user interactions with the API.
106+
- **Mocking**: Use interfaces and mocking libraries to simulate external services.
107+
108+
### Example Workflow
109+
110+
- **User Authentication**: A user logs in via GitHub OAuth and grants permissions.
111+
- **Repository Selection**: The user selects repositories to monitor.
112+
- **Data Collection Initiation**: The system sets up webhooks and begins polling if necessary.
113+
- **Data Ingestion**: Workflow events are received and stored.
114+
- **Data Processing**: Statistics are calculated and updated in the database.
115+
- **Data Presentation**: The frontend requests data via the API and presents it to the user.

pkg/auth/oauth.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import (
99
"os"
1010

1111
"github.com/gin-gonic/gin"
12+
"github.com/moosh3/github-actions-aggregator/pkg/db"
1213
"github.com/moosh3/github-actions-aggregator/pkg/db/models"
1314
"golang.org/x/oauth2"
1415
"golang.org/x/oauth2/github"
15-
16-
"github.com/moosh3/github-actions-aggregator/pkg/db"
1716
)
1817

1918
var (

0 commit comments

Comments
 (0)