Sara Bareilles always knew she was destined for the stage. Cast albums from “Les Misérables,” “Chess,” “Miss Saigon,” and “The Secret Garden” filled her childhood soundtrack. She performed in choirs and school musicals, and sang duets from hit shows with her sister.

Her future — she was certain — involved musical theater, maybe even Broadway.

But in college, Bareilles got her “feet wet as a jazz singer.” Later, she performed her own music in clubs, perfecting the soulful melodies, clever lyrics, and catchy choruses that would launch her career. Soon her musical stage morphed into the recording studio and a life on tour.

“The fact that my career kind of developed in another realm was sort of a surprise to me,” said Bareilles, who has released four albums and had a number of hits, including “Love Song” (2007) and “Brave” (2013). “So it feels really nice. It feels like a homecoming in some ways to come back toward the theater.”

Bareilles is behind the music and lyrics for the American Repertory Theater’s new musical, “Waitress,” which opens Sunday and runs through Sept. 27. Adapted from the 2007 movie directed by Adrienne Shelly and starring Keri Russell, the musical centers on Jenna, a waitress trapped in a small town and a loveless marriage who dreams of a better life.

Unsurprisingly, it was the show’s director, Diane Paulus, who engineered Bareilles’ return to musical theater. Since her arrival in 2008, Paulus, the A.R.T.’s Terrie and Bradley Bloom Artistic Director, has embraced the musical in her programming, energizing the stage with ballads, song-and-dance numbers, live bands, and seasoned singers belting it out in leading roles.

“For me, the theater is music,” Paulus told an Oberon audience during a discussion in 2010 with the lyricist and composer Stephen Schwartz. In Cambridge she has stayed true to that ethos, animating through song everything from baseball to the Bard.

Now baking — the lead character makes mouthwatering pies — is being added to the mix.

“I knew immediately that it had a heartbeat as a musical,” said Paulus of her reaction to watching “Waitress” on DVD. “There was something about both the humor and whimsy and intimacy of it as a film and [its] emotional heft.”

Paulus’ only remaining question: Who could write a score that would evoke the story’s humor and heartache? Her instincts turned her from traditional theater to the world of pop. Her intuition locked on Bareilles for her ability to tell “personal and deeply emotional stories” with her songs, and for her talent with witty, “often ironic lyrics.”

“I thought she could capture the right tone,” said Paulus.

In 2012 the two had lunch in New York. “Just watch the film,” Paulus told her, “and see what happens. See if it starts to flow.”

Soon, a song appeared in Paulus’ inbox. Nervously, the director clicked it open. Then she breathed a sigh of relief.

“My heart melted. I was so unbelievably moved by how she captured the point of view of this waitress,” said Paulus of Bareilles’ “She Used to Be Mine,” which would eventually become the centerpiece for the musical.

“She completely put herself into that title character, and then it just felt [like] destiny. She was born to write this.”

Like Paulus, Bareilles was struck by the story’s emotional depth and the “relatable concept” of waking up one day like Jenna, reflecting on your life, and wondering how you got there.

“We can all end up in positions in our lives where we don’t recognize ourselves anymore,” said Bareilles of the inspiration for “She Used to Be Mine.” The song, she said, was “the inroad into finding my voice on behalf of these characters.”

Still, turning from the studio to the stage has been a learning process for the young composer. While writing a song for a musical, like creating a song for an album, involves “trying to express part of the human condition,” ultimately a song for the stage involves much more. A piece in a musical always must advance the storyline, said Bareilles, or offer the audience insight into a character’s mindset or background.

Writing for the stage, she said, means not luxuriating “in your own self-indulgence.”

“There’s plenty of songs that I’ve written where I am just wallowing in something and it’s cathartic for me as an artist and as a person to get to kind of revel in my state of being. But with the musical … the story and character remain king.”

Actress and singer Jessie Mueller, a recent Tony award winner for her performance as Carole King in “Beautiful,” said it’s been a joy to watch Bareilles embrace the process.

“As an actor it’s so satisfying, because she writes what you need,” said Mueller, who plays Jenna. “Not only is it so melodically satisfying and on a completely different note, so fun to sing, but lyrically what she’s done is so informative … so much is revealed about the characters through the song.”

Much of what’s revealed — broken dreams, broken marriages — covers difficult emotional terrain. Jenna is trapped in an abusive marriage and her husband’s rage bubbles over on stage. But Paulus has never backed away from charged narratives, instead often using theater to open a dialogue about issues such as same-sex relationships (“Witness Uganda”), human-rights abuses (“Prometheus Bound”), and the psychological effects of war (“Ajax”).

For “Waitress,” the A.R.T. is partnering with Harvard’s Office of Sexual Assault Prevention & Response and will host a discussion following the matinee performance on Sept. 12 with representatives of the office.

“Artists have a unique opportunity to frame the subject in a way that maybe gets people to look at it … in powerful, unique ways,” said Paulus. “And I am hoping this musical will do that.”