Skip to content

nitishhsinghhh/case-conversion-api

Repository files navigation

Case Conversion API

This project demonstrates a full-stack architecture where a native C++ string conversion engine is exposed through a .NET REST API and consumed by a modern frontend UI. It adheres to production-grade deployment standards, including environment isolation and artifact promotion workflows.


Components

1. C++ Conversion Engine

  • Implements multiple string conversion strategies (Alternating Case, Capitalize Words, Snake Case, etc.).
  • Built as a shared library using CMake:
    • Windows → ProcessString.dll
    • macOS → libProcessString.dylib
    • Linux → libProcessString.so

2. .NET REST API Wrapper

  • Uses P/Invoke to call the exported C++ DLL functions.
  • Provides REST endpoints (e.g., /api/WordCase/convert) for frontend consumption.
  • Built and published with dotnet publish.

3. Frontend UI (Vite + React/TypeScript)

  • Provides a user interface to input text and select conversion type.
  • Calls the .NET REST API endpoints to perform conversions.
  • Built with npm run build → outputs static files in dist/.

Build Pipeline

The project is designed to be built in sequence:

1.Build C++ DLL

mkdir -p CaseConversionAPI/CppLib/build
cd CaseConversionAPI/CppLib/build
cmake ..
cmake --build . --config Release

2.Build .NET API

dotnet restore CaseConversionAPI/DotNetAPI
dotnet publish CaseConversionAPI/DotNetAPI -c Release -o ./publish
cp CaseConversionAPI/CppLib/build/libProcessString.* ./publish/

3.Build Frontend

cd string-conversion-ui
npm install
npm run build

C++ DLL Interop (ProcessStringDLL)

The project exposes a C++ string conversion engine to the .NET REST API using a DLL and P/Invoke.

Purpose

ProcessStringDLL.cpp acts as a bridge between:

  • C++ conversion logic
  • C# service layer
  • REST API controller

It dispatches user input to the appropriate conversion strategy using Factory + Strategy pattern.

Exported Function

extern "C" PROCESSSTRING_API const char* processStringDLL(const char* input, int choice);

Parameters

  • input → C-string input text
  • choice → integer representing conversion type

Returns

  • Converted string (C-style pointer)
  • Returns original input if invalid choice

Supported Conversion Choices

Choice Conversion
1 Alternating Case
2 Capitalize Words
3 Lower Case
4 Upper Case
5 Sentence Case
6 Toggle Case
7 Reverse
8 Remove Vowels
9 Remove Spaces
10 Invert Words
11 Snake Case
12 Kebab Case
13 Leet Speak

Design Patterns Used

  • Strategy Pattern
  • Factory Pattern
  • Client Dispatcher

Flow

REST API (C#)
     ↓
ProcessStringService (P/Invoke)
     ↓
processStringDLL (C++)
     ↓
Factory → Strategy → Client
     ↓
Converted String

Build Output

The C++ project builds a shared library:

  • Windows → ProcessString.dll
  • macOS → libProcessString.dylib
  • Linux → libProcessString.so

This library is loaded by the C# service using P/Invoke.

Integration Layer (C#)

The .NET service calls the DLL:

[DllImport("ProcessString")]
private static extern IntPtr processStringDLL(string input, int choice);

This enables the REST API to use native C++ performance-critical logic.

Architecture Overview

C++ Conversion Engine
        ↑
   DLL Export Layer
        ↑
C# P/Invoke Wrapper
        ↑
ProcessStringService
        ↑
WordCaseController
        ↑
REST API

Architecture View

                +---------------------+
                |   Frontend (React)  |
                |   Vite + TypeScript |
                +----------+----------+
                           |
                       REST API call
                           |
                +----------v----------+
                |   REST API (C#)     |
                |   WordCaseController|
                +----------+----------+
                           |
                       P/Invoke
                           |
                +----------v----------+
                |  ProcessStringDLL   |  <-- DLL wrapper
                +----------+----------+
                           |
                +----------v----------+
                |   Core C++ Logic    |
                | (Factory + Strategy)|
                +----------+----------+
                           |
         +-----------------+-----------------+
         |                                   |
+--------v--------+               +----------v--------+
|  main.cpp CLI   |               | Google Tests      |
|  Local testing  |               | Unit testing      |
+-----------------+               +-------------------+
         

Tech Stack

  • C++ (conversion logic, built with CMake)
  • .NET 8 (REST API wrapper, P/Invoke)
  • React + Vite + TypeScript (frontend UI)
  • GitHub Actions (CI/CD pipeline)
  • Azure App Service + GitHub Pages (deployment targets)

Run Backend using Docker

  1. Create Dockerfile (Project Root)
# ---------- Build C++ ----------
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

RUN apt-get update && apt-get install -y \
    build-essential \
    cmake

WORKDIR /src
COPY . .

# Clean old CMake cache
RUN rm -rf CaseConversionAPI/CppLib/build

# Build C++ shared library
RUN cmake -S CaseConversionAPI/CppLib -B CaseConversionAPI/CppLib/build -DCMAKE_BUILD_TYPE=Release
RUN cmake --build CaseConversionAPI/CppLib/build --parallel

# Publish .NET API
RUN dotnet publish CaseConversionAPI/DotNetAPI -c Release -o /app/publish

# Copy shared library
RUN cp CaseConversionAPI/CppLib/build/lib/libProcessStringDLL.so /app/publish/

# ---------- Runtime ----------
FROM mcr.microsoft.com/dotnet/aspnet:8.0

WORKDIR /app
COPY --from=build /app/publish .

EXPOSE 8080

ENTRYPOINT ["dotnet", "DotNetAPI.dll"]

2.Start Docker Desktop

Make sure Docker Desktop is running. You can use commmand in terminal to start the ddocker

open -a Docker

3.Build Docker image

From the project root (where the Dockerfile exists):

docker build -t case-conversion-api .

4.Run container

docker run -p 8080:8080 case-conversion-api

You should see:

Now listening on: http://[::]:8080

5.Open Swagger UI Open in browser:

http://localhost:8080/

Running Full Stack using Docker Compose

To run Frontend + Backend together, use Docker Compose.

1.Update Frontend API URL

ENsure the react frontned calls:

http://localhost:8080/api/WordCase/convert

2.Create docker-compose.yml (Project Root)

version: "3.9"

services:
  backend:
    build: .
    container_name: case-api
    ports:
      - "8080:8080"
    restart: unless-stopped

  frontend:
    image: node:20
    container_name: case-ui
    working_dir: /app
    volumes:
      - ./string-conversion-ui:/app
    ports:
      - "5173:5173"
    command: sh -c "npm install && npm run dev -- --host"
    depends_on:
      - backend

3.Run Full Stack

docker compose up --build

This will start:

Environment-Based Deployment (Dev → Staging → Prod)

This project supports multi-environment deployment using Docker Compose and image promotion.

Deployment Strategy

The system follows

Development → Staging → Production
  • Build once in dev
  • Promote the same Docker image forward
  • Avoid rebuilding for each environment

Docker Image Tagging Strategy

Environment Tag
Dev dev
Staging staging
Production latest
nitishhsinghhh/case-api:dev
nitishhsinghhh/case-api:staging
nitishhsinghhh/case-api:latest

Development Environment

Used for local development with hot reload and debugging.

Run Dev

docker compose -f docker-compose.dev.yml up --build

Features

  • Builds image locally
  • Uses ASPNETCORE_ENVIRONMENT=Development
  • Frontend runs with npm run dev
  • Debug logs enabled

Staging Environment

Used for production-like validation before release

Promote Image from Dev

docker tag nitishhsinghhh/case-api:dev nitishhsinghhh/case-api:staging
docker push nitishhsinghhh/case-api:staging

Run Staging

docker compose -f docker-compose.staging.yml up -d

Features

  • Uses pre-built Docker image
  • Uses ASPNETCORE_ENVIRONMENT=Staging
  • No local builds
  • Simulates production behavior

Production Environment

Used for final deployment.

Promote Image from Staging

docker tag nitishhsinghhh/case-api:staging nitishhsinghhh/case-api:latest
docker push nitishhsinghhh/case-api:latest

Run Production

docker compose -f docker-compose.prod.yml up -d

Features

  • Uses stable image (latest)
  • Uses ASPNETCORE_ENVIRONMENT=Production
  • Restart policies enabled
  • Health checks enabled

Full deployment flow

# Step 1: Build in Dev
docker compose -f docker-compose.dev.yml up --build -d
docker push nitishhsinghhh/case-api:dev

# Step 2: Promote to Staging
docker tag nitishhsinghhh/case-api:dev nitishhsinghhh/case-api:staging
docker push nitishhsinghhh/case-api:staging
docker compose -f docker-compose.staging.yml up -d

# Step 3: Promote to Production
docker tag nitishhsinghhh/case-api:staging nitishhsinghhh/case-api:latest
docker push nitishhsinghhh/case-api:latest
docker compose -f docker-compose.prod.yml up -d

Docker compose file

File Purpose
docker-compose.dev.yml Local development
docker-compose.staging.yml Pre-production testing
docker-compose.prod.yml Production deployment

Key Principles

  • Single artifact promotion (same image across environments)
  • Environment-specific configuration via ASPNETCORE_ENVIRONMENT
  • No rebuilds after dev
  • Isolation of environments

Resulting Architecture

Developer → Dev Build → Docker Image
                        ↓
                    Staging
                        ↓
                    Production

Architecture (Containerized)

                +---------------------+
                |   Frontend (React)  |
                |   Vite + TypeScript |
                |   (Docker)          |
                +----------+----------+
                           |
                       HTTP (REST)
                           |
                +----------v----------+
                |   .NET REST API     |
                |   ASP.NET Core      |
                |   (Docker)          |
                +----------+----------+
                           |
                        P/Invoke
                           |
                +----------v----------+
                |  C++ Shared Library |
                |  libProcessString   |
                +----------+----------+
                           |
                +----------v----------+
                | Factory + Strategy  |
                |  Conversion Engine  |
                +---------------------+

Deployment Architecture (Docker Compose)

+-------------------+        +-------------------+
|   Frontend        | -----> |   Backend API     |
|   React + Vite    |        |   .NET + C++ DLL  |
|   Port 5173       |        |   Port 8080       |
+-------------------+        +-------------------+

Runtime Flow

         Browser
            ↓
         React UI (Docker)
            ↓
         HTTP REST Call
            ↓
         ASP.NET Core API (Docker)
            ↓
         P/Invoke
            ↓
         C++ Shared Library
            ↓
         Strategy Pattern Conversion
            ↓
         Response back to UI

About

Full-stack system showcasing C++/C# interoperability via P/Invoke, wrapped in a .NET 8 API and consumed by a React frontend, with Dockerized deployment and CI/CD-based environment promotion.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors