Skip to content

sodiqyekeen/codebridge

Repository files navigation

CodeBridge πŸŒ‰

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!

NuGet CLI NuGet Core NuGet MSBuild Downloads License: MIT

✨ Features

  • 🎯 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

πŸš€ Quick Start

1. Install the package

dotnet add package CodeBridge

2. Install the CLI tool

dotnet tool install -g CodeBridge.Cli

3. Initialize configuration

cd your-api-project
codebridge init --template react --output ./generated-sdk

This creates a codebridge.json configuration file. Customize it with your project paths and settings.

4. Add the [GenerateSdk] attribute (optional)

[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.

5. Generate your SDK

codebridge generate

That'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)

πŸ“– Documentation

🎯 Usage Example

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! πŸŽ‰
}

βš™οΈ Configuration

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.

πŸ”§ Generation Modes

Manual (CLI)

codebridge generate

Watch Mode

codebridge watch

Build Integration

{
  "generation": {
    "mode": "build-integration",
    "buildEvents": ["AfterBuild"]
  }
}

Now dotnet build automatically generates your SDK! πŸš€

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

Built with ❀️ using:

πŸ“¬ Support


CodeBridge - Bridging .NET and Frontend, One SDK at a Time πŸŒ‰

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages