Skip to content

Directory Structure ​

Introduction ​

The dotblaze-app template is structured like a Laravel application, so moving between the two should feel familiar. The tree below is what dotnet new dotblaze-app -n DotBlazeApp generates:

app/
  Http/Controllers/HomeController.cs
  Models/User.cs
  Providers/AppServiceProvider.cs
  Providers/RouteServiceProvider.cs
config/
  App.cs  Auth.cs  Broadcasting.cs  Cache.cs  Database.cs  Filesystems.cs  Mail.cs  Queue.cs  Services.cs  Session.cs
database/
  migrations/CreateUsersTable.cs  migrations/CreateJobsTable.cs
  factories/UserFactory.cs
  seeders/DatabaseSeeder.cs
lang/
resources/
  css/app.css
  views/_ViewImports.cshtml  views/_ViewStart.cshtml
  views/layouts/app.blade.html  views/home/Index.blade.html
routes/
  web.cs  api.cs  console.cs  channels.cs
.env.example  .gitignore  package.json  Program.cs  DotBlazeApp.csproj

NOTE

Apart from views, folders are conventions, not requirements. DotBlaze finds providers, models, migrations, seeders, jobs, and listeners by their base class anywhere in the application assembly, so a class keeps working if you move it to another folder.

The Root Directory ​

The App Directory ​

The app directory contains the core code of your application: controllers, models, providers, and any other classes you add. It is described in more detail below.

The Config Directory ​

The config directory contains one C# class per area of the framework. The class name is the key prefix: AppConfig in config/App.cs holds the app.* keys. See Configuration.

The Database Directory ​

The database directory contains your migrations, model factories, and seeders. When you use SQLite, the database file (database/app.db) is created here as well; it is ignored by git.

The template ships with its migrations: the users table, the notifications table, and the jobs, failed_jobs, and job_batches tables used by the database queue driver.

The Lang Directory ​

The lang directory holds translation strings: lang/id.json for strings keyed by their default text, and lang/id/*.json for short keys. A new application has none until you add a language.

The Resources Directory ​

The resources directory contains your Razor views and the uncompiled CSS (resources/css/app.css). DotBlaze looks for views here rather than in ASP.NET Core's default Views folder, in this order:

/resources/views/{controller}/{view}.cshtml
/resources/views/{view}.cshtml
/resources/views/layouts/{view}.cshtml

_ViewImports.cshtml makes every view inherit DotBlazePage<TModel>, which adds Laravel-style helpers such as @Csrf() and @Route("name"). _ViewStart.cshtml sets the default layout of Razor views to layouts/app. The layout and the home page are Blade templates (.blade.html); Razor views (.cshtml) work alongside them.

The Routes Directory ​

The routes directory contains your route definitions: web.cs for pages (the web middleware group), api.cs for JSON endpoints under /api (the api group), console.cs for scheduled tasks, and channels.cs for broadcast channel authorization. Unlike Laravel, routes/web.cs is not a file loaded at runtime; it is a static class with a Map() method, compiled with the rest of the application and called by RouteServiceProvider:

csharp
namespace DotBlazeApp.Routes;

public static class Web
{
    public static void Map()
    {
        Route.Get<HomeController>("/", c => c.Index).Name("home");
    }
}

See Routing.

The Storage Directory ​

The storage directory does not exist in a fresh application; it is created on first use. With the default config/Filesystems.cs, the local disk stores files in storage/app/private and the public disk in storage/app/public. Files on the public disk are served under the /storage URL automatically, so there is no storage:link step. See File Storage.

The wwwroot Directory ​

wwwroot is ASP.NET Core's public directory, the equivalent of Laravel's public. npm run build writes the compiled CSS and Alpine.js to wwwroot/build, which is ignored by git. See Frontend.

Root Files ​

  • Program.cs is the entry point. It contains only DotBlaze.Application.Create(args).Run(), plus public partial class Program; so tests can boot the app with WebApplicationFactory<Program>. See Request Lifecycle.
  • DotBlazeApp.csproj references the DotBlaze package and adds global usings (see Namespaces).
  • package.json defines the frontend build.
  • .env.example lists the environment variables your config files expect; copy it to .env.

The App Directory ​

The Http/Controllers Directory ​

Controllers are ordinary ASP.NET Core MVC controllers. Extending DotBlaze's BaseController adds Laravel-style redirect helpers such as Back(), RedirectRoute(), and .With(...). See Controllers.

The Models Directory ​

Models extend Model<T>, DotBlaze's Eloquent-style active record on top of EF Core. The template includes a User model that implements IAuthenticatable for authentication, plus INotifiable, ICanResetPassword, and IMustVerifyEmail for notifications, password reset, and email verification. See Models.

The Providers Directory ​

Service providers register services and run startup code. The template contains AppServiceProvider, for your own registrations, and RouteServiceProvider, which maps routes/web.cs and routes/api.cs registers the schedule in routes/console.cs and the broadcast channels in routes/channels.cs.

Directories You May Add ​

The template creates only what a new application needs. As your application grows, add folders following the same convention, for example:

NOTE

The make:* generators create these classes for you, like php artisan make:controller. Console commands go in app/Commands.

Namespaces ​

The template's project file adds these global usings, so application code can use DotBlaze's facades and helpers without using statements:

xml
<ItemGroup>
  <Using Include="DotBlaze" />
  <Using Include="DotBlaze.Support" />
  <Using Include="DotBlaze.Support.Functions" Static="true" />
  <!-- Microsoft.AspNetCore.Routing also has a type named Route; the alias picks DotBlaze's facade. -->
  <Using Include="DotBlaze.Route" Alias="Route" />
</ItemGroup>

The Route alias is needed because a web project's implicit usings include Microsoft.AspNetCore.Routing, which has its own Route class. Without the alias, Route.Get(...) would be ambiguous.

Controllers live in the DotBlazeApp.Controllers namespace, not DotBlazeApp.Http.Controllers. A namespace segment named Http would hide DotBlaze's Http client facade inside every controller, so Http.Get(...) would no longer compile. The folder is still app/Http/Controllers, as in Laravel; only the namespace is shorter. For the same reason, avoid namespaces named after other facades, such as Storage or Queue.

Complete Feature File Map ​

The complete blog example adds this feature to a generated Blog project:

text
Blog/
  app/Models/Post.cs                       # Blog.Models.Post
  app/Http/Requests/PostRequest.cs          # Blog.Requests.PostRequest
  app/Http/Controllers/PostController.cs   # Blog.Controllers.PostController
  app/Policies/PostPolicy.cs               # Blog.Policies.PostPolicy
  database/migrations/CreatePostsTable.cs  # Blog.Database.Migrations.CreatePostsTable
  resources/views/post/Index.blade.html
  resources/views/post/Form.blade.html
  resources/views/post/Show.blade.html
  routes/web.cs                            # add to the existing Web.Map()
Blog.Tests/
  PostTest.cs                              # sibling project, references Blog

Model, migration, request, and policy discovery is based on compiled types. Route registration still needs the existing provider's call to Web.Map(). Views are found by their paths. In particular, PostController resolves View("Form", post) to resources/views/post/Form.blade.html.

Build from Blog with dotnet build; run migrations with dotblaze migrate; run the sibling test project from the parent directory with dotnet test Blog.Tests. A namespace change does not rename a table: use [Table] when the class-name convention differs from your schema.