# cjohnston079/odin-inventory-application architecture

> Architecture diagram of the GitHub repository cjohnston079/odin-inventory-application, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cjohnston079/odin-inventory-application
- Repository: https://github.com/cjohnston079/odin-inventory-application

## Overview

##### Main Components

A. Frontend Layer:
- Views (EJS Templates)
- Public Assets (SASS/CSS, Client-side JavaScript)
- Form Handlers and Input Validation

B. Backend Layer:
- Express.js Application Server
- Controllers
- Models
- Routing Layer

C. Data Layer:
- PostgreSQL Database
- Database Pool
- Query Handlers

##### Component Relationships

**[Client Browser] ←→ [Frontend Layer] ←→ [Backend Layer] ←→ [Data Layer]**

##### Detailed Component Breakdown

Frontend Layer (Top):
- Authors
- Books
- Countries
- Decades
- Genres
- A Public Assets section showing:
- SASS/CSS Styles
- Client-side JavaScript
- Form Handlers

Backend Layer (Middle):
- Express.js Server (Central)
- Routes Container showing all routes:
- authorsRouter
- booksRouter
- countriesRouter
- decadesRouter
- genresRouter
- Controllers Container showing:
- authorsController
- booksController
- countriesController
- decadesController
- genresController
- Models Container showing:
- Author
- Book
- Genre

Data Layer (Bottom):
- PostgreSQL Database
- Database Pool
- Query Handlers Container showing:
- queryAuthors
- queryBooks
- queryCountries
- queryGenres

##### Additional Details

Specific elements:
- Database seeding flow
- Static asset handling
- Form validation flow
- Error handling paths

##### Notes for Implementation

- The MVC pattern implementation
- CRUD operations flow
- Form validation and handling
- Database interaction patterns
- Static asset serving
- Template rendering process

Remember to indicate the environment configuration requirements and database seeding process as auxiliary components that are crucial for the application setup but not part of the runtime architecture.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph Frontend["Frontend Layer"]
        Views["Views Container"]:::frontend
        click Views "https://github.com/cJohnston079/odin-inventory-application/tree/main/views/"
        
        subgraph ViewComponents["View Components"]
            AuthorViews["Author Views"]:::frontend
            BookViews["Book Views"]:::frontend
            GenreViews["Genre Views"]:::frontend
            CountryViews["Country Views"]:::frontend
            DecadeViews["Decade Views"]:::frontend
            click AuthorViews "https://github.com/cJohnston079/odin-inventory-application/tree/main/views/authors/"
            click BookViews "https://github.com/cJohnston079/odin-inventory-application/tree/main/views/books/"
            click GenreViews "https://github.com/cJohnston079/odin-inventory-application/tree/main/views/genres/"
            click CountryViews "https://github.com/cJohnston079/odin-inventory-application/tree/main/views/countries/"
            click DecadeViews "https://github.com/cJohnston079/odin-inventory-application/tree/main/views/decades/"
        end

        subgraph Assets["Public Assets"]
            Styles["SASS/CSS"]:::frontend
            ClientJS["Client JavaScript"]:::frontend
            FormHandlers["Form Handlers"]:::frontend
            InputValidation["Input Validation"]:::frontend
            click Styles "https://github.com/cJohnston079/odin-inventory-application/tree/main/public/sass/"
            click ClientJS "https://github.com/cJohnston079/odin-inventory-application/tree/main/public/scripts/"
            click FormHandlers "https://github.com/cJohnston079/odin-inventory-application/tree/main/public/scripts/form-handlers/"
            click InputValidation "https://github.com/cJohnston079/odin-inventory-application/tree/main/public/scripts/form-handlers/input-handlers/"
        end
    end

    subgraph Backend["Backend Layer"]
        ExpressServer["Express.js Server"]:::backend
        click ExpressServer "https://github.com/cJohnston079/odin-inventory-application/blob/main/app.js"

        subgraph Routes["Routing Layer"]
            AuthorsRouter["Authors Router"]:::backend
            BooksRouter["Books Router"]:::backend
            CountriesRouter["Countries Router"]:::backend
            DecadesRouter["Decades Router"]:::backend
            GenresRouter["Genres Router"]:::backend
            click AuthorsRouter "https://github.com/cJohnston079/odin-inventory-application/blob/main/routes/authorsRouter.js"
            click BooksRouter "https://github.com/cJohnston079/odin-inventory-application/blob/main/routes/booksRouter.js"
            click CountriesRouter "https://github.com/cJohnston079/odin-inventory-application/blob/main/routes/countriesRouter.js"
            click DecadesRouter "https://github.com/cJohnston079/odin-inventory-application/blob/main/routes/decadesRouter.js"
            click GenresRouter "https://github.com/cJohnston079/odin-inventory-application/blob/main/routes/genresRouter.js"
        end

        subgraph Controllers["Controllers"]
            AuthorsController["Authors Controller"]:::backend
            BooksController["Books Controller"]:::backend
            CountriesController["Countries Controller"]:::backend
            DecadesController["Decades Controller"]:::backend
            GenresController["Genres Controller"]:::backend
            click AuthorsController "https://github.com/cJohnston079/odin-inventory-application/blob/main/controllers/authorsController.js"
            click BooksController "https://github.com/cJohnston079/odin-inventory-application/blob/main/controllers/booksController.js"
            click CountriesController "https://github.com/cJohnston079/odin-inventory-application/blob/main/controllers/countriesController.js"
            click DecadesController "https://github.com/cJohnston079/odin-inventory-application/blob/main/controllers/decadesController.js"
            click GenresController "https://github.com/cJohnston079/odin-inventory-application/blob/main/controllers/genresController.js"
        end

        subgraph Models["Models"]
            AuthorModel["Author Model"]:::backend
            BookModel["Book Model"]:::backend
            GenreModel["Genre Model"]:::backend
            click AuthorModel "https://github.com/cJohnston079/odin-inventory-application/blob/main/models/Author.js"
            click BookModel "https://github.com/cJohnston079/odin-inventory-application/blob/main/models/Book.js"
            click GenreModel "https://github.com/cJohnston079/odin-inventory-application/blob/main/models/Genre.js"
        end

        Utils["Utilities"]:::backend
        Logger["Logger"]:::backend
        click Utils "https://github.com/cJohnston079/odin-inventory-application/blob/main/js/utils.js"
        click Logger "https://github.com/cJohnston079/odin-inventory-application/blob/main/js/logger.js"
    end

    subgraph Data["Data Layer"]
        Database[(PostgreSQL)]:::data
        DBPool["Database Pool"]:::data
        click DBPool "https://github.com/cJohnston079/odin-inventory-application/blob/main/db/pool.js"

        subgraph QueryHandlers["Query Handlers"]
            AuthorsQueries["Authors Queries"]:::data
            BooksQueries["Books Queries"]:::data
            CountriesQueries["Countries Queries"]:::data
            GenresQueries["Genres Queries"]:::data
            click AuthorsQueries "https://github.com/cJohnston079/odin-inventory-application/blob/main/db/queries/queryAuthors.js"
            click BooksQueries "https://github.com/cJohnston079/odin-inventory-application/blob/main/db/queries/queryBooks.js"
            click CountriesQueries "https://github.com/cJohnston079/odin-inventory-application/blob/main/db/queries/queryCountries.js"
            click GenresQueries "https://github.com/cJohnston079/odin-inventory-application/blob/main/db/queries/queryGenres.js"
        end

        DBSchema["Database Schema"]:::data
        DBSeed["Data Seeding"]:::data
        click DBSchema "https://github.com/cJohnston079/odin-inventory-application/blob/main/db/seed/schema.sql"
        click DBSeed "https://github.com/cJohnston079/odin-inventory-application/blob/main/db/seed/seed.js"
    end

    %% Connections
    Browser <--> Views
    Views <--> ExpressServer
    Assets --> Browser
    
    ExpressServer <--> Routes
    Routes <--> Controllers
    Controllers <--> Models
    Models <--> DBPool
    DBPool <--> QueryHandlers
    QueryHandlers <--> Database
    
    Utils --> Controllers
    Logger --> ExpressServer

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef data fill:#e67e22,stroke:#d35400,color:white

    %% Legend
    subgraph Legend
        Frontend_Component["Frontend Component"]:::frontend
        Backend_Component["Backend Component"]:::backend
        Data_Component["Data Component"]:::data
    end
```
