# adonisjs/core architecture

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

- Interactive diagram: https://gitdiagram.com/adonisjs/core
- Repository: https://github.com/adonisjs/core

## Overview

##### Main Components Organization

a) Core Framework Layer
- Container/IoC System (modules/container.ts)
- Application Core (modules/app.ts)
- Configuration System (modules/config.ts)
- Service Providers (providers/ directory)

b) HTTP Layer
- Server (services/server.ts)
- Router (services/router.ts)
- Middleware System (commands/make/middleware.ts)
- Controllers (commands/make/controller.ts)
- Body Parser (modules/bodyparser/)

c) Security Layer
- Encryption (modules/encryption.ts)
- Hashing (modules/hash/)
- Authentication (implied by structure)

d) Developer Tools
- CLI (modules/ace/)
- REPL (commands/repl.ts)
- Testing Utils (src/test_utils/)
- Development Server (commands/serve.ts)

##### Component Relationships

**HTTP Request Flow:**
**Server → Router → Middleware → Controller → Response**

**Service Layer:**
**Controllers ←→ Services**
**Services ←→ Events System**
**Services ←→ Database (external)**

**Provider System:**
**Service Providers → Container**
**Container → Framework Services**

##### Key Architectural Patterns to Highlight

- Dependency Injection (shown by the Container's relationships)
- Event-driven architecture (modules/events.ts)
- MVC pattern (controllers, views, implied models)
- Middleware pipeline
- Service Provider pattern

##### Important Details

a) Framework Bootstrap Flow:
**Ignitor (src/ignitor/) → App Provider → Service Providers → Application**

b) Command System Structure:
**Ace Kernel → Commands → Command Handlers**

c) Development Tools Integration:
**CLI Tools ←→ Application Core**
**Testing Utils ←→ HTTP Layer**
**REPL ←→ Application Context**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core["Core Framework Layer"]
        Container["Container/IoC"]:::core
        AppCore["Application Core"]:::core
        Config["Configuration System"]:::core
        ServiceProviders["Service Providers"]:::core
        Events["Events System"]:::core
        Logger["Logger"]:::core
        Env["Environment"]:::core
    end

    subgraph HTTP["HTTP Layer"]
        Server["HTTP Server"]:::http
        Router["Router"]:::http
        Middleware["Middleware System"]:::http
        Controllers["Controllers"]:::http
        BodyParser["Body Parser"]:::http
    end

    subgraph Security["Security Layer"]
        Encryption["Encryption"]:::security
        Hashing["Hashing"]:::security
        Auth["Authentication"]:::security
    end

    subgraph DevTools["Developer Tools"]
        CLI["CLI System"]:::devtools
        REPL["REPL"]:::devtools
        TestUtils["Testing Utils"]:::devtools
        DevServer["Development Server"]:::devtools
    end

    %% Core relationships
    Container --> AppCore
    Container --> ServiceProviders
    AppCore --> Config
    AppCore --> Events
    AppCore --> Logger
    AppCore --> Env

    %% HTTP Flow
    Server --> Router
    Router --> Middleware
    Middleware --> Controllers
    Controllers --> Events
    BodyParser --> Middleware

    %% Security Integration
    Controllers --> Auth
    Auth --> Encryption
    Auth --> Hashing

    %% DevTools Integration
    CLI --> AppCore
    REPL --> AppCore
    TestUtils --> HTTP
    DevServer --> Server

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef http fill:#4CAF50,stroke:#2E7D32,color:white
    classDef security fill:#FFC107,stroke:#FFA000,color:black
    classDef devtools fill:#9C27B0,stroke:#7B1FA2,color:white

    %% Click events
    click Container "https://github.com/adonisjs/core/blob/6.x/modules/container.ts"
    click AppCore "https://github.com/adonisjs/core/blob/6.x/modules/app.ts"
    click Config "https://github.com/adonisjs/core/blob/6.x/modules/config.ts"
    click ServiceProviders "https://github.com/adonisjs/core/tree/6.x/providers/"
    click Server "https://github.com/adonisjs/core/blob/6.x/services/server.ts"
    click Router "https://github.com/adonisjs/core/blob/6.x/services/router.ts"
    click Middleware "https://github.com/adonisjs/core/blob/6.x/commands/make/middleware.ts"
    click Controllers "https://github.com/adonisjs/core/blob/6.x/commands/make/controller.ts"
    click BodyParser "https://github.com/adonisjs/core/tree/6.x/modules/bodyparser/"
    click Encryption "https://github.com/adonisjs/core/blob/6.x/modules/encryption.ts"
    click Hashing "https://github.com/adonisjs/core/tree/6.x/modules/hash/"
    click CLI "https://github.com/adonisjs/core/tree/6.x/modules/ace/"
    click REPL "https://github.com/adonisjs/core/blob/6.x/modules/repl.ts"
    click TestUtils "https://github.com/adonisjs/core/tree/6.x/src/test_utils/"
    click DevServer "https://github.com/adonisjs/core/blob/6.x/commands/serve.ts"
    click Events "https://github.com/adonisjs/core/blob/6.x/modules/events.ts"
    click Logger "https://github.com/adonisjs/core/blob/6.x/modules/logger.ts"
    click Env "https://github.com/adonisjs/core/tree/6.x/modules/env/"
```
