Understanding Default Folder Structure

Understanding Default Folder Structure

Before we move forward let understand auto generated web API Project folder structure.

📁 Folder Structure (Auto-generated while creating .NET Web API App):

MyWebApi/
├── Controllers/
├── Properties/
├── appsettings.json
├── Program.cs
├── MyWebApi.csproj        

🔍 What Each Folder/File Does:

📁 Controllers/

  • Contains your API controller classes.
  • Example: WeatherForecastController.cs (default)
  • Each controller handles routing and logic for HTTP requests (GET, POST, etc.).

📁 Properties/

  • Contains the launchSettings.json file (for local development).
  • Defines how the project launches (ports, profiles like IIS Express, etc.).

📄 appsettings.json

  • Main configuration file for your app (like web.config in old ASP.NET).
  • Stores environment settings, connection strings, logging config, etc.

{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    }
  },
  "AllowedHosts": "*"
}        

📄 Program.cs

  • The entry point of your Web API.
  • Sets up the web server and services (using WebApplication.CreateBuilder).
  • In .NET 6+, this uses the minimal hosting model.

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
var app = builder.Build();
app.MapControllers();
app.Run();        

📄 MyWebApi.csproj

  • Your project file (C# project metadata).
  • Declares dependencies, target framework, and build settings.

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>
</Project>        

✅ Summary:

Each part plays a specific role in the app's behavior:

  • Controllers → Handle requests
  • Program.cs → Bootstraps the app
  • appsettings.json → Configuration
  • .csproj → Project definition
  • launchSettings → Local debug setup


🔧 Dependencies

🪄 “The Brain of the Application”

Because they determine what your app knows and can do — everything from routing, database access to authentication comes from here.

Located in Solution Explorer → Dependencies (in Visual Studio) or managed via *.csproj file.

✅ What It Includes:

  • NuGet packages (Microsoft.AspNetCore.*, EntityFrameworkCore, etc.)
  • Framework references (net8.0)
  • Project references (if your solution has multiple projects)

🧠 Purpose & Importance:

  • Define what libraries your project needs
  • Controls build, runtime behavior, and external capabilities
  • Keeps your project modular and maintainable

📦 Example from .csproj:

<ItemGroup>
  <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
  <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>        

⚙️ appsettings.json

📋 “The Control Center”

The single source of truth for your app’s behavior. It configures how your app talks, logs, connects, and behaves across environments.

Located at the root of your project.

✅ What It’s For:

A centralized configuration file to store:

  • Connection strings
  • Logging levels
  • API keys (non-sensitive)
  • Custom application settings

🧠 Why It’s Important:

  • Allows easy environment-specific settings
  • Supports strongly-typed binding (IOptions<T>)
  • Cleaner than hardcoding values in your code

📝 Example:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "ConnectionStrings": {
    "Default": "Server=.;Database=MyDb;Trusted_Connection=True;"
  },
  "AllowedHosts": "*"
}        

🔄 Load in Program.cs:

var config = builder.Configuration;
var connStr = config.GetConnectionString("Default");        

🚀launchSettings.json

🧪 “The Local Launchpad”

Your dev-only turbo booster. It sets up how your app starts, which environment it mimics, and what URL it lives on while you test it.

Located in Properties/launchSettings.json

✅ What It Controls:

Defines how your app runs locally during development:

  • Launch profiles (IIS Express, Kestrel, etc.)
  • Application URLs (ports)
  • Environment variables (ASPNETCORE_ENVIRONMENT)

🧠 Why It’s Useful:

  • Sets up dev environment without changing production code
  • Helps simulate different environments
  • Automatically sets environment name (like Development)

📝 Example:

{
  "profiles": {
    "MyWebApi": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}        

🧩 Summary Table:

Article content


To view or add a comment, sign in

More articles by Prashant Parmar

Others also viewed

Explore content categories