Git Product home page Git Product logo

mak-thevar / core-webapi-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 203 KB

The Project Name is a .NET Core 6.x based template that follows a n-layered architecture and includes pre-configured libraries such as Swagger, JWT, AutoMapper, and more. It provides developers with a solid foundation for building robust and scalable applications.

Home Page: https://github.com/mak-thevar/core-webapi-boilerplate

License: MIT License

C# 100.00%
3-layer-arcitecture api asp-net-core boilerplate csharp dotnet dotnet-core dotnetcore entity-framework-core jwt-authentication net6 nlayer-architecture rest-api swagger template webapi csharp-code repository-pattern serilog

core-webapi-boilerplate's Introduction

Build Status Contributors Issues LinkedIn

CoreWebApi-BoilerPlate

Built on .NET Core 6.x, this template follows a n-layered architecture and includes pre-configured libraries like Swagger, JWT, and AutoMapper, among others. It's a reliable starting point for developers seeking to create strong and adaptable applications, offering a simplified development experience.

πŸ‘©β€πŸ’»Are you in need of a frontend solution?

You can access the frontend for this repository at the following link: core-webapi-boilerplate-frontend

πŸ“‹ Table of Contents

🏁 Getting Started

Prerequisites

πŸ—ƒοΈ File Structure

β”‚   appsettings.Development.json
β”‚   appsettings.json
β”‚   CoreWebApiBoilerPlate.csproj
β”‚   CoreWebApiBoilerPlate.csproj.user
β”‚   Program.cs
β”‚
β”œβ”€β”€β”€BusinessLogicLayer
β”‚   β”‚   PredicateBuilder.cs
β”‚   β”‚
β”‚   β”œβ”€β”€β”€DTO
β”‚   β”‚       ApiResponseModel.cs
β”‚   β”‚       CommentRequestModel.cs
β”‚   β”‚       CommentResponseModel.cs
β”‚   β”‚       Constants.cs
β”‚   β”‚       RoleRequestModel.cs
β”‚   β”‚       RoleResponseModel.cs
β”‚   β”‚       TodoRequestModel.cs
β”‚   β”‚       TodoResponseModel.cs
β”‚   β”‚       UserRequestModel.cs
β”‚   β”‚       UserResponseModel.cs
β”‚   β”‚
β”‚   └───Exceptions
β”‚           AppException.cs
β”‚
β”œβ”€β”€β”€Controllers
β”‚       ApiBaseController.cs
β”‚       AuthController.cs
β”‚       TodosController.cs
β”‚       UsersController.cs
β”‚
β”œβ”€β”€β”€DataAccessLayer
β”‚   β”œβ”€β”€β”€Context
β”‚   β”‚       DefaultDBContext.cs
β”‚   β”‚       SeedingData.cs
β”‚   β”‚
β”‚   β”œβ”€β”€β”€Entities
β”‚   β”‚   β”‚   Comment.cs
β”‚   β”‚   β”‚   Role.cs
β”‚   β”‚   β”‚   Todo.cs
β”‚   β”‚   β”‚   TodoStatus.cs
β”‚   β”‚   β”‚   User.cs
β”‚   β”‚   β”‚
β”‚   β”‚   └───Base
β”‚   β”‚           EntityBase.cs
β”‚   β”‚           IAuditedEntity.cs
β”‚   β”‚           IStatusEntity.cs
β”‚   β”‚
β”‚   └───Repository
β”‚       β”œβ”€β”€β”€Impl
β”‚       β”‚       RepositoryBase.cs
β”‚       β”‚       RepositoryWrapper.cs
β”‚       β”‚       TodoRepository.cs
β”‚       β”‚       UserRepository.cs
β”‚       β”‚
β”‚       └───Interfaces
β”‚               IRepository.cs
β”‚               IRepositoryWrapper.cs
β”‚               ITodoRepository.cs
β”‚               IUserRepository.cs
β”‚
β”œβ”€β”€β”€Infrastructure
β”‚   β”‚   AutoMapperProfile.cs
β”‚   β”‚   Configuration.cs
β”‚   β”‚   IdentityClientConfiguration.cs
β”‚   β”‚   JWT.cs
β”‚   β”‚   RegisterDBDependency.cs
β”‚   β”‚   SwaggerGen.cs
β”‚   β”‚
β”‚   └───Middlewares
β”‚           ExceptionHandlerMiddleWare.cs
β”‚
β”œβ”€β”€β”€Migrations
β”‚       20220716122039_Initial.cs
β”‚       20220716122039_Initial.Designer.cs
β”‚       20220804091809_AddingRole.cs
β”‚       20220804091809_AddingRole.Designer.cs
β”‚       DefaultDBContextModelSnapshot.cs

Installation

  • Clone the repository
git clone https://github.com/mak-thevar/core-webapi-boilerplate.git
  • Open the solution file 'CoreWebApiBoilerPlate.sln' directly in Visual Studio

  • The database is cofigured to use sqllite you can change it to appropriate sql like MSSQL or mysql, the settings can be found on the RegisterSqliteDatabaseContext method in DataLayer\RegisterDBDependency.cs file

        services.AddDbContext<DefaultDBContext>(options =>
        {
            options.UseSqlite(connectionString, options =>
            {
                options.MigrationsAssembly(typeof(DefaultDBContext).Assembly.FullName);
            });
            options.EnableDetailedErrors();
            options.EnableSensitiveDataLogging();
        });
  • The initial seeding data can be found on *DataLayer\Context\SeedingData.cs file

    Show Code

    public static List GetTodoStatus()
        {
            return new List
            {
                new TodoStatus{ Id =1 , Description = "Todo", IsDefault = true},
                new TodoStatus{ Id =2 , Description = "In Progress", IsDefault = true},
                new TodoStatus {Id =3, Description = "Completed" , IsDefault  = true},
            };
        }
    
    public static List<Role> GetRoles()
    {
        return new List<Role>
         {
             new Role{ Id =1 , Description = "Admin", IsActive = true, CreatedOn = DateTime.UtcNow}
         };
    }
    
    public static List<User> GetUsers()
    {
        return new List<User>
        {
            new User{ Id =1 , CreatedOn = DateTime.UtcNow, EmailId = "[email protected]", IsActive = true, Name = "mak thevar", RoleId =1, Username = "mak-thevar", Password = EasyEncryption.MD5.ComputeMD5Hash("12345678")},
        };
    }
    
  • Now Build the project and run, Initially for the very first time it will create the database and will execute the migration scripts automatically.

βœ… Features

  • Uses Serilog for stuctured logging.
  • JWT has been configured for authentication and authorization.
  • Custom request, response and error handling has been configured for maintaning a detailed log of errors and requests.
  • Swagger for API documentation has been added.
  • Entityframework Core has been configured for database communication. (Currently have added SQLLite for sample DB)
  • Follows Repository pattern for the database operations.
  • A Sample controller to Add Todos with Register user and Login User has been added.

πŸ”˜ Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“Έ Screenshots

login_screen
Login Using Insomnia/PostMan
swagger_doc
Swagger Documentation
RegisterUser
Register User API
swagger_login
Login Using Swagger

🎫 License

Distributed under the MIT License. See LICENSE for more information.

πŸ“± Contact

Name - Muthukumar Thevar - [email protected]

Project Link: https://github.com/mak-thevar/core-webapi-boilerplate

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.