Episode 2 - JSON API using ASP.NET Core, Docker & MongoDB: Project Structure
Tags: blog, howto, dotnetcore, beginners
Published: 2018-12-19 10:06:26

---
title: Episode 2 - JSON API using ASP.NET Core, Docker & MongoDB: Project Structure
published: true
tags: blog,how-to,dotnet-core,beginners
canonical_url: https://garfbradaz.github.io/blog/2018/12/19/Episode-2-JSON-API-Dotnet-Core-Docker-Project-Structure.html
published: true
cover_image: https://thepracticaldev.s3.amazonaws.com/i/abi2arzus9vlb8s6rp7p.PNG
series: ASP.NET Core Web API Episodes
---

## Previously on Dcoding

In [Episode 1](https://dev.to/garfbradaz/episode-1-json-api-net-core-using-docker--mongo-26md) I set the scene for what this series will contain. Today’s episode is simply on setting your _directory_ structure and creating the relevant projects. 

## Directory Structure

Firstly, create a directory structure for your _Source (src)_ where our **dotnet projects** will be saved, _tests_ will hold our **Unit** and **Integration** tests and lastly, _docker_ which will hold our **docker-compose**.

```
    .
    ├── src
    ├── tests
    ├── docker

```

### Src

Change directory to _src_ and we will run the following _dotnet_ command to new up a Project. Before we move on any further and do that though, lets talk about _dotnet new_ for people who have not used it.

This command will create a dotnet project based off a default project template. You get a bunch of defaults with the SDK ([and you can create your own](https://docs.microsoft.com/en-us/dotnet/core/tutorials/create-custom-template). Run the following:

```
dotnet new --help

```

This will give you a list of available templates you can use:

![templates](https://garfbradaz.github.io/assets/img/posts/ep2-dotnet-new.png)

Take note of the _short name_ as this is what we will be using next. So now we know what `dotnet new` does, lets create the project:

```
dotnet new webapi --auth Individual -o api -n BookStore.WebApi

```

This will create a folder with the name _api_ and in it will create a new _webapi_ project using authentication (we will explore this more in a later episode). The project will be called _BookStore.WebApi_.

**Tip:** You can do a `dotnet new webapi --help` and see all the available switches for that short name.

Your directory structure should look like this now:

```
    .
    ├── src
    | ├── api
    | |
    | ├── BookStore.WebApi
    ├── tests
    ├── docker

```

### Tests

Change directory to the _tests_ folder. Firstly mainly create a _integration_ test folder. These will hold our **Postman** tests (again for another episode). Secondly, we need to create our Unit Test project. I will be using _Xunit_, but as you can see, there were a few different projects for testing when you did a `dotnet new --help`.

```
dotnet new xunit -o unit -n BookStore.Tests

```

Again this will create a _xunit_ project type within a folder called _unit_. The project name will be _BookStore.Tests_. Within the _integration_ folder just add an empty **postman.json** file.

```
    .
    ├── src
    | ├── api
    | |
    | ├── BookStore.WebApi
    ├── tests
    | ├── integration
    | ├── unit
    | ├── BookStore.Tests
    ├── docker

```

### Docker

Change directory to _docker_ folder and for now just create two empty files:

> docker-compose.yml
> 
> docker-compose.dev.yml

Yes you guessed it, this files will become apparent (and fatter) in a future episode.

## Next time

So now we have set up our Project directory structure, we can move on to setting up our **Docker** environment, using _Dockerfiles_ and _docker-compose_. Join me next time.

**Side note:** Episode 1 can be found on my [Github Repository](https://github.com/garfbradaz/webapi-episodes)