URL Strategy & Routing
Clean, industry-standard URL patterns that eliminate redundancy and match how major APIs structure their endpoints.
π― The Clean URL Decision
Our Implementation
β Backend (Clean)
api.altsportsleagues.ai/v1/leagues
No redundant /api/ prefix - subdomain already indicates it's an API
β Frontend (Namespace)
altsportsleagues.ai/api/v1/leagues
Keeps /api/ for clear namespace separation in frontend code
What We're Avoiding
β api.altsportsleagues.ai/api/v1/leagues
Redundant - "api" appears twice (subdomain + path)
π Industry Standard Patterns
All major APIs follow the clean pattern (no /api/ in path):
Stripe: api.stripe.com/v1/charges
GitHub: api.github.com/repos
OpenAI: api.openai.com/v1/chat/completions
Twilio: api.twilio.com/2010-04-01/Accounts
Notice: None use /api/ in the URL path!
π How The Rewrite Works
The Magic of Vercel Rewrites
Vercel's rewrite happens server-side and is invisible to the browser. The browser thinks all requests are same-origin (altsportsleagues.ai), eliminating CORS complexity!
Rewrite Configuration (vercel.json):
{
"rewrites": [
{
"source": "/api/v1/:path*",
"destination": "https://api.altsportsleagues.ai/v1/:path*"
}
]
}π URL Pattern Benefits
Comparison Matrix
| Feature | Clean Pattern | Redundant Pattern |
|---|---|---|
| Readability | β Excellent | β Confusing |
| Industry Standard | β Matches leaders | β Non-standard |
| Frontend Code | β Simple | β οΈ Same |
| External Docs | β Professional | β Awkward |
| API Versioning | β Clear (v1, v2) | β οΈ Cluttered |
| CORS Handling | β Same (rewrite) | β Same (rewrite) |
Benefits Summary
- Cleaner URLs - Easier to remember and share
- Professional - Matches industry expectations
- Simpler Backend - Less path nesting
- Better Docs - Cleaner API reference examples
- Future-Proof - Easy to add v2, v3, etc.
π Complete URL Reference
Backend API (api.altsportsleagues.ai)
Base URL: https://api.altsportsleagues.ai
/ β API info and version
/health β Health check
/docs β Swagger UI (FastAPI)
/openapi.json β OpenAPI 3.0 schema
/v1/leagues β League operations
/v1/teams β Team operations
/v1/players β Player operations
/v1/stats β Statistics
/v1/predictions β AI predictions
/tools/* β MCP tools
/webhooks/* β Webhook endpointsFrontend (altsportsleagues.ai)
Base URL: https://altsportsleagues.ai
/ β Homepage
/leagues β League directory
/leagues/[slug] β Individual league
/teams β Team directory
/dashboard β User dashboard
/onboarding β League owner onboarding
/api/v1/* β API calls (rewritten to backend)
/docs β Redirect to docs.altsportsleagues.aiDocumentation (docs.altsportsleagues.ai)
Base URL: https://docs.altsportsleagues.ai
/ β Documentation homepage
/getting-started β Onboarding guides
/architecture β Architecture docs (you are here!)
/api/reference β API documentation
/schemas β Schema explorer
/integrations β Integration guides
/guides β How-to guidesπ API Access Patterns
From Frontend (Browser)
Use relative URLs - goes through Vercel rewrite:
// β
RECOMMENDED
const response = await fetch('/api/v1/leagues');
// Browser sees: altsportsleagues.ai/api/v1/leagues
// Actually hits: api.altsportsleagues.ai/v1/leagues
// No CORS issues!From External Consumers
Use direct API URLs - requires CORS configuration:
// β
For external apps/partners
const response = await fetch('https://api.altsportsleagues.ai/v1/leagues', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});From n8n Workflows
Use direct API URLs with authentication:
// HTTP Request Node in n8n
{
"url": "https://api.altsportsleagues.ai/v1/leagues",
"method": "POST",
"headers": {
"Authorization": "Bearer {{$env.API_KEY}}",
"Content-Type": "application/json"
}
}π Migration Impact
Implementation Required: Backend routers need to be updated to use /v1/* instead of /api/v1/*.
See the Deployment Workflow for step-by-step instructions.
Files That Need Updates
- Backend Routers - Change prefix from
/api/v1to/v1 - Frontend Config - Update
vercel.jsonrewrite destination - n8n Workflows - Update HTTP request node URLs
- Documentation - Update API examples (automated)
Estimated Migration Time: ~30 minutes
Risk Level: Low (rollback available)
π Related Documentation