-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroadmap.py
More file actions
357 lines (290 loc) · 11.6 KB
/
roadmap.py
File metadata and controls
357 lines (290 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
from __future__ import annotations
from datetime import datetime
from typing import Annotated, List, Literal, Optional
from pydantic import AnyHttpUrl, BaseModel, ConfigDict, Field, field_validator
from sqlalchemy import (
JSON,
Boolean,
DateTime,
Integer,
String,
Text,
UniqueConstraint,
func,
)
from sqlalchemy.orm import Mapped, mapped_column
from app.core.database import Base
class RepoCommitChunk(Base):
"""Stores commit chunks that feed the roadmap RAG pipeline."""
__tablename__ = "repo_commit_chunks"
__table_args__ = (UniqueConstraint("chunk_hash", name="uq_repo_commit_chunk_hash"),)
id: Mapped[int] = mapped_column(Integer, primary_key=True)
repo_full_name: Mapped[str] = mapped_column(String(255), index=True, nullable=False)
commit_sha: Mapped[str] = mapped_column(String(40), index=True, nullable=False)
chunk_type: Mapped[str] = mapped_column(String(32), nullable=False)
chunk_hash: Mapped[str] = mapped_column(String(64), nullable=False)
content: Mapped[str] = mapped_column(Text, nullable=False)
authored_at: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True))
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
class GeneratedRoadmap(Base):
"""Stores the latest generated roadmap for a repository."""
__tablename__ = "generated_roadmaps"
__table_args__ = (
UniqueConstraint("repo_full_name", name="uq_generated_roadmap_full_name"),
)
id: Mapped[int] = mapped_column(Integer, primary_key=True)
repo_full_name: Mapped[str] = mapped_column(String(255), nullable=False)
primary_language: Mapped[Optional[str]] = mapped_column(String(64))
languages: Mapped[Optional[list]] = mapped_column(JSON)
topics: Mapped[Optional[list]] = mapped_column(JSON)
difficulty: Mapped[Optional[str]] = mapped_column(String(32))
star_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
fork_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
last_pushed_at: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True))
license: Mapped[Optional[str]] = mapped_column(String(128))
contributor_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
view_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
sync_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
rating_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
rating_sum: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
repo_summary: Mapped[dict] = mapped_column(JSON, nullable=False)
timeline: Mapped[list] = mapped_column(JSON, nullable=False)
cached: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
generated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
server_default=func.now(),
onupdate=func.now(),
nullable=False,
)
class UserSyncedRepo(Base):
"""Tracks which repositories a user has pinned to the sidebar."""
__tablename__ = "user_synced_repos"
__table_args__ = (
UniqueConstraint("user_id", "repo_full_name", name="uq_user_synced_repo"),
)
id: Mapped[int] = mapped_column(Integer, primary_key=True)
user_id: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
repo_full_name: Mapped[str] = mapped_column(String(255), nullable=False)
status: Mapped[str] = mapped_column(String(32), nullable=False, default="synced")
is_archived: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
progress_percent: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
pinned_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
server_default=func.now(),
onupdate=func.now(),
nullable=False,
)
class RoadmapRating(Base):
"""Stores user ratings (1-5 stars) for repositories."""
__tablename__ = "roadmap_ratings"
__table_args__ = (
UniqueConstraint(
"user_id", "repo_full_name", name="uq_roadmap_rating_user_repo"
),
)
id: Mapped[int] = mapped_column(Integer, primary_key=True)
user_id: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
repo_full_name: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
rating: Mapped[int] = mapped_column(Integer, nullable=False)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
server_default=func.now(),
onupdate=func.now(),
nullable=False,
)
class GuideChatSession(Base):
"""Stores the latest guide chat history per user/repo/stage."""
__tablename__ = "guide_chat_sessions"
__table_args__ = (
UniqueConstraint(
"user_id",
"repo_full_name",
"stage_id",
name="uq_guide_chat_user_repo_stage",
),
)
id: Mapped[int] = mapped_column(Integer, primary_key=True)
user_id: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
repo_full_name: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
stage_id: Mapped[Optional[str]] = mapped_column(
String(255), nullable=True, index=True
)
messages: Mapped[list] = mapped_column(JSON, nullable=False, default=list)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
server_default=func.now(),
onupdate=func.now(),
nullable=False,
)
class RoadmapViewTracker(Base):
"""Tracks views to prevent spam and implement anti-spam logic."""
__tablename__ = "roadmap_view_tracker"
__table_args__ = (
UniqueConstraint(
"repo_full_name", "user_id", name="uq_roadmap_view_tracker_repo_user"
),
)
id: Mapped[int] = mapped_column(Integer, primary_key=True)
repo_full_name: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
user_id: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
viewed_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
class RoadmapRequest(BaseModel):
repo_url: AnyHttpUrl = Field(description="GitHub repository URL")
force_refresh: bool = Field(
default=False, description="Bypass cache and recompute the roadmap"
)
class CatalogFilters(BaseModel):
"""Filters for roadmap catalog search."""
language: Optional[str] = Field(None, description="Filter by programming language")
tag: Optional[str] = Field(None, description="Filter by topic/tag")
difficulty: Optional[Literal["beginner", "intermediate", "advanced"]] = Field(
None, description="Filter by difficulty level"
)
min_rating: Optional[float] = Field(
None, ge=1.0, le=5.0, description="Minimum average rating"
)
min_views: Optional[int] = Field(None, ge=0, description="Minimum view count")
min_syncs: Optional[int] = Field(None, ge=0, description="Minimum sync count")
sort: Optional[
Literal["newest", "most_viewed", "most_synced", "highest_rated", "trending"]
] = Field("newest", description="Sort order")
class CatalogPage(BaseModel):
"""Paginated catalog response."""
items: List["RoadmapResponse"]
page: int = Field(ge=1, description="Current page number")
page_size: int = Field(ge=1, le=100, description="Number of items per page")
total_count: int = Field(ge=0, description="Total number of items")
total_pages: int = Field(ge=0, description="Total number of pages")
class TimelineResource(BaseModel):
label: str
href: Annotated[str, Field(max_length=500)]
class StageTask(BaseModel):
label: str
steps: List[str]
files: List[str] = []
commands: List[str] = []
class CodeExample(BaseModel):
file: str
language: str
description: str
snippet: str
class TimelineStage(BaseModel):
id: str
index: int = 0
title: str
summary: str
status: Literal["not-started", "in-progress", "done"]
eta: str
category: Literal[
"setup",
"feature",
"refactor",
"testing",
"ops",
"perf",
"docs",
"style",
"chore",
"other",
] = "other"
difficulty: Literal["intro", "easy", "medium", "hard"] = "medium"
goals: List[str] = []
prerequisites: List[str] = []
checkpoints: List[str] = []
tasks: List[StageTask]
code_examples: List[CodeExample] = []
resources: List[TimelineResource]
commit_window: List[str] = []
@field_validator("tasks", mode="before")
@classmethod
def convert_legacy_tasks(cls, v):
if isinstance(v, list) and len(v) > 0 and isinstance(v[0], str):
return [StageTask(label="Tasks", steps=v)]
return v
class RoadmapRepoSummary(BaseModel):
full_name: str
description: Optional[str]
language: Optional[str]
stars: int
default_branch: str
html_url: Optional[AnyHttpUrl]
owner_avatar_url: Optional[AnyHttpUrl]
primary_language: Optional[str] = None
languages: Optional[list[str]] = None
topics: Optional[list[str]] = None
difficulty: Optional[str] = None
star_count: Optional[int] = None
fork_count: Optional[int] = None
last_pushed_at: Optional[datetime] = None
license: Optional[str] = None
contributor_count: Optional[int] = None
view_count: Optional[int] = None
sync_count: Optional[int] = None
rating_count: Optional[int] = None
rating_sum: Optional[int] = None
class RoadmapResponse(BaseModel):
repo: RoadmapRepoSummary
timeline: List[TimelineStage]
cached: bool
generated_at: datetime
model_config = ConfigDict(from_attributes=True)
class RoadmapCatalogPage(BaseModel):
items: List[RoadmapResponse]
page: int
page_size: int
total_count: int
total_pages: int
class UserRepoStateResponse(BaseModel):
repo_full_name: str
status: str
is_archived: bool
progress_percent: int
pinned_at: Optional[datetime] = None
repo: Optional[RoadmapRepoSummary] = None
model_config = ConfigDict(from_attributes=True)
class RatingRequest(BaseModel):
rating: int = Field(ge=1, le=5, description="Rating from 1 to 5 stars")
class RatingResponse(BaseModel):
rating: int
repo_full_name: str
user_id: str
created_at: datetime
updated_at: datetime
model_config = ConfigDict(from_attributes=True)
class ChatRequest(BaseModel):
message: Optional[str] = None
repo_full_name: str
stage_id: Optional[str] = None
messages: Optional[List[dict]] = None # For full chat history context
class ChatResponse(BaseModel):
response: str
class SaveChatRequest(BaseModel):
repo_full_name: str
stage_id: Optional[str] = None
messages: List[dict]
class ChatHistoryResponse(BaseModel):
repo_full_name: str
stage_id: Optional[str] = None
messages: List[dict]