Bridge the gap between your .NET backend and frontend applications
CodeBridge is a powerful SDK generator that creates type-safe TypeScript/JavaScript clients for React and Next.js applications from your .NET APIs. No more manual API client coding - let CodeBridge do the heavy lifting!
- π― Type-Safe - Generate TypeScript types from your C# models
- βοΈ React Hooks - Auto-generate custom hooks for your API endpoints
- π Next.js Support - Server Components and API routes helpers
- π Watch Mode - Regenerate SDK on code changes during development
- ποΈ Build Integration - Optional MSBuild task for automatic generation
- β Validation - Generate Zod schemas from FluentValidation rules
- π¨ Configurable - Extensive customization options
- π¦ npm Ready - Generates publishable npm packages
dotnet add package CodeBridgedotnet tool install -g CodeBridge.Clicd your-api-project
codebridge init --template react --output ./generated-sdkThis creates a codebridge.json configuration file. Customize it with your project paths and settings.
[GenerateSdk] // Mark endpoints for SDK generation
[HttpGet]
public async Task<ActionResult<ProductResponse>> GetProduct(Guid id)
{
// Your implementation
}If you don't use attributes, CodeBridge will auto-discover all API endpoints.
codebridge generateThat's it! π Your TypeScript SDK is ready in the output folder with:
- β
package.json(with TypeScript and dependencies) - β
tsconfig.json(configured for your project) - β
README.md(usage documentation) - β Type-safe TypeScript code (API clients, hooks, types, validation)
- Getting Started Guide
- Configuration Options
- CLI Commands
- Build Integration
- React Hooks
- Next.js Integration
Your .NET API:
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
[HttpGet]
public async Task<ActionResult<List<ProductResponse>>> GetProducts()
{
// Your implementation
}
[HttpPost]
public async Task<ActionResult<ProductResponse>> CreateProduct(
[FromBody] CreateProductCommand command)
{
// Your implementation
}
}Generated TypeScript SDK:
// Auto-generated types
export interface ProductResponse {
id: string;
name: string;
price: number;
// ... more properties
}
export interface CreateProductCommand {
name: string;
price: number;
// ... more properties
}
// Auto-generated API client
export async function getProducts(): Promise<ProductResponse[]> {
const response = await httpClient.get('/api/products');
return response.data;
}
export async function createProduct(
command: CreateProductCommand
): Promise<ProductResponse> {
const response = await httpClient.post('/api/products', command);
return response.data;
}
// Auto-generated React hooks
export function useGetProducts() {
return useQuery({
queryKey: ['products'],
queryFn: () => getProducts()
});
}
export function useCreateProduct() {
return useMutation({
mutationFn: (data: CreateProductCommand) => createProduct(data)
});
}Use in your React app:
import { useGetProducts, useCreateProduct } from '@yourorg/api-client';
function ProductList() {
const { data: products, isLoading } = useGetProducts();
const createProduct = useCreateProduct();
// Fully type-safe! π
}Run codebridge init to create a codebridge.json configuration file, or create one manually:
{
"SolutionPath": "./MyApp.sln",
"ProjectPaths": [],
"Output": {
"Path": "./generated-sdk",
"PackageName": "@myapp/api-client",
"PackageVersion": "1.0.0",
"License": "MIT"
},
"Target": {
"Framework": 0,
"Language": "typescript",
"ModuleSystem": 0
},
"Api": {
"BaseUrl": "https://api.myapp.com",
"Authentication": {
"Type": 1,
"Storage": 0
}
},
"Features": {
"GenerateReactHooks": true,
"IncludeValidation": true,
"IncludeAuthentication": true,
"GenerateDocComments": true
},
"Generation": {
"Mode": 0
}
}Note: Use codebridge init --interactive for a guided setup experience.
codebridge generatecodebridge watch{
"generation": {
"mode": "build-integration",
"buildEvents": ["AfterBuild"]
}
}Now dotnet build automatically generates your SDK! π
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ using:
- Roslyn for C# code analysis
- System.CommandLine for CLI
- Inspired by the needs of modern full-stack development
- π Report a bug
- π‘ Request a feature
- π Read the docs
CodeBridge - Bridging .NET and Frontend, One SDK at a Time π