I'm getting a syntax error in combination of class and package description

0 votes
asked May 23 in Question / help by Li
Hi I have the following but I'm getting a syntax error but can't tell why - complaint is about line 20 but when I break it down each part works fine on its own. Any insight is appreciated. I'm very new to this ....

@startuml

package "Web Server Application" {
    [Web Server]
    [Database]
    [Client Browser]
    [Load Balancer]

    [Web Server] --> [Database] : Read/Write Data
    [Web Server] --> [Client Browser] : Serve Web Pages
    [Client Browser] --> [Web Server] : Send HTTP Requests
    [Client Browser] --> [Load Balancer] : Send HTTP Requests
    [Load Balancer] --> [Web Server] : Distribute Requests
}

package "Python Code" {
    [Web Server] --> [Python Code] : Handle HTTP Requests
    [Python Code] --> [Database] : Query Database
    [Python Code] --> [Client Browser] : Send HTTP Responses
    
    class PythonCode {
        +handle_request(request: HttpRequest) : HttpResponse
    }

    class HttpRequest {
        +method : str
        +path : str
        +headers : dict
        +body : str
    }

    class HttpResponse {
        +status_code : int
        +headers : dict
        +body : str
    }

    class Database {
        +query(sql: str) : Result
    }

    class Result {
        +rows : list
    }
}

@enduml
commented May 24 by Li
Thank you for the response - I'm just starting to learn -

I wanted to show both the high level communications interfaces/components and the functions/objects  together - just as a way of documenting.

1 Answer

0 votes
answered May 23 by The-Lu (57,460 points)

Hi Li., and all,

  • What are your goals?
    You can not directly mix component and class....

If you want to mix `component diagram` with `class diagram`, for that use dummy label and sub-diagram like:

@startuml

package "Web Server Application" {
    [Web Server]
    [Database]
    [Client Browser]
    [Load Balancer]

    [Web Server] --> [Database] : Read/Write Data
    [Web Server] --> [Client Browser] : Serve Web Pages
    [Client Browser] --> [Web Server] : Send HTTP Requests
    [Client Browser] --> [Load Balancer] : Send HTTP Requests
    [Load Balancer] --> [Web Server] : Distribute Requests
}

package "Python Code" {
    [Web Server] --> [Python Code] : Handle HTTP Requests
    [Python Code] --> [Database] : Query Database
    [Python Code] --> [Client Browser] : Send HTTP Responses
    
    label l [{{
    class "PythonCode" {
        +handle_request(request: HttpRequest) : HttpResponse
    }

    class HttpRequest {
        +method : str
        +path : str
        +headers : dict
        +body : str
    }

    class HttpResponse {
        +status_code : int
        +headers : dict
        +body : str
    }

    class Database {
        +query(sql: str) : Result
    }

    class Result {
        +rows : list
    }
    }}]
}

@enduml

Regards.
Th.

...