Skip to content

Commit 2d94f4d

Browse files
authored
Merge pull request #1 from geniustechspace/copilot/create-tenant-aware-structure
Implement production-ready domain-driven protobuf schemas with multi-tenancy, Buf integration, runtime validation, and comprehensive inline documentation
2 parents abdd518 + ea1905c commit 2d94f4d

33 files changed

+8375
-1
lines changed

.github/workflows/buf.yml

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
name: Buf CI/CD
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
pull_request:
9+
branches:
10+
- main
11+
- develop
12+
13+
jobs:
14+
buf:
15+
name: Buf Lint, Format, and Breaking Changes
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Buf Lint, Format, and Breaking
22+
uses: bufbuild/buf-action@v1
23+
with:
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
format: true
26+
lint: true
27+
breaking: ${{ github.event_name == 'pull_request' }}
28+
breaking_against: 'https://github.com/${{ github.repository }}.git#branch=${{ github.base_ref || 'main' }}'
29+
setup_only: false
30+
pr_comment: true
31+
32+
build:
33+
name: Build and Generate
34+
runs-on: ubuntu-latest
35+
needs: [buf]
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
40+
- name: Setup Buf and Generate
41+
uses: bufbuild/buf-action@v1
42+
with:
43+
token: ${{ secrets.GITHUB_TOKEN }}
44+
setup_only: false
45+
46+
- name: Generate code
47+
run: buf generate
48+
49+
- name: List generated files
50+
run: |
51+
echo "=== Generated Go files ==="
52+
find gen/go -name "*.go" 2>/dev/null | head -20 || echo "No Go files generated"
53+
echo ""
54+
echo "=== Generated Python files ==="
55+
find gen/python -name "*.py" 2>/dev/null | head -20 || echo "No Python files generated"
56+
echo ""
57+
echo "=== Generated Java files ==="
58+
find gen/java -name "*.java" 2>/dev/null | head -20 || echo "No Java files generated"
59+
echo ""
60+
echo "=== Generated TypeScript files ==="
61+
find gen/typescript -name "*.ts" 2>/dev/null | head -20 || echo "No TypeScript files generated"
62+
63+
- name: Upload generated artifacts
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: generated-code
67+
path: gen/
68+
retention-days: 7
69+
70+
schema-list:
71+
name: List Proto Schemas
72+
runs-on: ubuntu-latest
73+
needs: [buf]
74+
steps:
75+
- name: Checkout code
76+
uses: actions/checkout@v4
77+
78+
- name: Setup Buf
79+
uses: bufbuild/buf-action@v1
80+
with:
81+
token: ${{ secrets.GITHUB_TOKEN }}
82+
setup_only: true
83+
84+
- name: List all proto files by domain
85+
run: |
86+
echo "# Proto Schema Inventory" > schema-list.md
87+
echo "" >> schema-list.md
88+
echo "Generated on: $(date)" >> schema-list.md
89+
echo "" >> schema-list.md
90+
91+
for domain in proto/*/; do
92+
domain_name=$(basename "$domain")
93+
echo "## Domain: $domain_name" >> schema-list.md
94+
echo "" >> schema-list.md
95+
96+
for version in "$domain"*/; do
97+
if [ -d "$version" ]; then
98+
version_name=$(basename "$version")
99+
echo "### Version: $version_name" >> schema-list.md
100+
echo "" >> schema-list.md
101+
102+
for proto_file in "$version"*.proto; do
103+
if [ -f "$proto_file" ]; then
104+
echo "- \`$(basename "$proto_file")\`" >> schema-list.md
105+
106+
# Extract services
107+
services=$(grep "^service " "$proto_file" | awk '{print $2}' || true)
108+
if [ -n "$services" ]; then
109+
echo " - Services: $services" >> schema-list.md
110+
fi
111+
112+
# Extract messages
113+
messages=$(grep "^message " "$proto_file" | awk '{print $2}' | head -5 || true)
114+
if [ -n "$messages" ]; then
115+
echo " - Key Messages: $(echo $messages | tr '\n' ', ' | sed 's/,$//')" >> schema-list.md
116+
fi
117+
fi
118+
done
119+
echo "" >> schema-list.md
120+
fi
121+
done
122+
done
123+
124+
- name: Display schema list
125+
run: cat schema-list.md
126+
127+
- name: Upload schema list
128+
uses: actions/upload-artifact@v4
129+
with:
130+
name: schema-list
131+
path: schema-list.md
132+
133+
push-to-buf-registry:
134+
name: Push to Buf Schema Registry
135+
runs-on: ubuntu-latest
136+
needs: [buf, build]
137+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
138+
steps:
139+
- name: Checkout code
140+
uses: actions/checkout@v4
141+
142+
- name: Push to Buf Schema Registry
143+
uses: bufbuild/buf-action@v1
144+
with:
145+
token: ${{ secrets.GITHUB_TOKEN }}
146+
push: true
147+
# To enable BSR push, add BUF_TOKEN to GitHub secrets
148+
# buf_token: ${{ secrets.BUF_TOKEN }}
149+
150+
generate-clients:
151+
name: Generate Language-Specific Clients
152+
runs-on: ubuntu-latest
153+
needs: [buf, build]
154+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
155+
strategy:
156+
matrix:
157+
domain: [core, auth, users, access_policy, tenants, billing, notifications]
158+
language: [go, python, java, typescript]
159+
steps:
160+
- name: Checkout code
161+
uses: actions/checkout@v4
162+
163+
- name: Setup Buf
164+
uses: bufbuild/buf-action@v1
165+
with:
166+
token: ${{ secrets.GITHUB_TOKEN }}
167+
setup_only: true
168+
169+
- name: Generate ${{ matrix.language }} client for ${{ matrix.domain }}
170+
run: |
171+
echo "Generating ${{ matrix.language }} client for ${{ matrix.domain }} domain"
172+
buf generate --template buf.gen.yaml --path proto/${{ matrix.domain }}/
173+
174+
# Package the generated code for the specific domain and language
175+
mkdir -p clients/${{ matrix.domain }}/${{ matrix.language }}
176+
177+
case "${{ matrix.language }}" in
178+
go)
179+
if [ -d "gen/go/${{ matrix.domain }}" ]; then
180+
cp -r gen/go/${{ matrix.domain }}/* clients/${{ matrix.domain }}/${{ matrix.language }}/
181+
fi
182+
;;
183+
python)
184+
if [ -d "gen/python/${{ matrix.domain }}" ]; then
185+
cp -r gen/python/${{ matrix.domain }}/* clients/${{ matrix.domain }}/${{ matrix.language }}/
186+
fi
187+
;;
188+
java)
189+
if [ -d "gen/java" ]; then
190+
find gen/java -path "*/${{ matrix.domain }}/*" -type f -exec cp --parents {} clients/${{ matrix.domain }}/${{ matrix.language }}/ \;
191+
fi
192+
;;
193+
typescript)
194+
if [ -d "gen/typescript/${{ matrix.domain }}" ]; then
195+
cp -r gen/typescript/${{ matrix.domain }}/* clients/${{ matrix.domain }}/${{ matrix.language }}/
196+
fi
197+
;;
198+
esac
199+
200+
- name: Upload ${{ matrix.language }} client for ${{ matrix.domain }}
201+
uses: actions/upload-artifact@v4
202+
with:
203+
name: client-${{ matrix.domain }}-${{ matrix.language }}
204+
path: clients/${{ matrix.domain }}/${{ matrix.language }}/
205+
retention-days: 30
206+
207+
documentation:
208+
name: Generate Documentation
209+
runs-on: ubuntu-latest
210+
needs: [buf]
211+
steps:
212+
- name: Checkout code
213+
uses: actions/checkout@v4
214+
215+
- name: Setup Buf
216+
uses: bufbuild/buf-action@v1
217+
with:
218+
token: ${{ secrets.GITHUB_TOKEN }}
219+
setup_only: true
220+
221+
- name: Generate documentation
222+
run: |
223+
buf generate --template buf.gen.yaml
224+
225+
# Create a comprehensive documentation index
226+
cat > gen/docs/README.md << 'EOF'
227+
# Protobuf API Documentation
228+
229+
This documentation is auto-generated from the protobuf definitions.
230+
231+
## Domains
232+
233+
- [Core](core/v1/) - Common types and tenant context
234+
- [Auth](auth/v1/) - Authentication and session management
235+
- [Users](users/v1/) - User management
236+
- [Access Policy](access-policy/v1/) - Role-based access control
237+
- [Tenants](tenants/v1/) - Multi-tenant management
238+
- [Billing](billing/v1/) - Subscription and billing
239+
- [Notifications](notifications/v1/) - Notification system
240+
241+
## Versioning
242+
243+
Each domain supports multiple versions (v1, v2, etc.) to ensure backward compatibility.
244+
245+
## Client Libraries
246+
247+
Generated client libraries are available for:
248+
- Go
249+
- Python
250+
- Java
251+
- TypeScript
252+
- C#
253+
254+
EOF
255+
256+
- name: Upload documentation
257+
uses: actions/upload-artifact@v4
258+
with:
259+
name: documentation
260+
path: gen/docs/
261+
retention-days: 30
262+
263+
- name: Deploy documentation to GitHub Pages
264+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
265+
uses: peaceiris/actions-gh-pages@v4
266+
with:
267+
github_token: ${{ secrets.GITHUB_TOKEN }}
268+
publish_dir: ./gen/docs
269+
publish_branch: gh-pages

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Generated code
2+
gen/
3+
4+
# Buf cache
5+
.buf/
6+
7+
# IDE
8+
.vscode/
9+
.idea/
10+
*.swp
11+
*.swo
12+
*~
13+
14+
# OS
15+
.DS_Store
16+
Thumbs.db
17+
18+
# Build artifacts
19+
*.o
20+
*.a
21+
*.so
22+
*.dylib
23+
*.dll
24+
*.exe
25+
26+
# Dependency directories
27+
node_modules/
28+
vendor/
29+
30+
# Temporary files
31+
tmp/
32+
temp/
33+
*.tmp
34+
35+
# Logs
36+
*.log

0 commit comments

Comments
 (0)